_FINGERPRINTS  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  " ACURA ILX 2016 ACURAWATCH PLUS " :  { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    1024 L :  5 ,  513 L :  5 ,  1027 L :  5 ,  1029 L :  8 ,  929 L :  4 ,  1057 L :  5 ,  777 L :  8 ,  1034 L :  5 ,  1036 L :  8 ,  398 L :  3 ,  399 L :  7 ,  145 L :  8 ,  660 L :  8 ,  985 L :  3 ,  923 L :  2 ,  542 L :  7 ,  773 L :  7 ,  800 L :  8 ,  432 L :  7 ,  419 L :  8 ,  420 L :  8 ,  1030 L :  5 ,  422 L :  8 ,  808 L :  8 ,  428 L :  8 ,  304 L :  8 ,  819 L :  7 ,  821 L :  5 ,  57 L :  3 ,  316 L :  8 ,  545 L :  4 ,  464 L :  8 ,  1108 L :  8 ,  597 L :  8 ,  342 L :  6 ,  983 L :  8 ,  344 L :  8 ,  804 L :  8 ,  1039 L :  8 ,  476 L :  4 ,  892 L :  8 ,  490 L :  8 ,  1064 L :  7 ,  882 L :  2 ,  884 L :  7 ,  887 L :  8 ,  888 L :  8 ,  380 L :  8 ,  1365 L :  5 , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # sent messages 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    0xe4 :  5 ,  0x1fa :  8 ,  0x200 :  3 ,  0x30c :  8 ,  0x33d :  5 , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  " HONDA CIVIC 2016 TOURING " :  { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    1024 L :  5 ,  513 L :  5 ,  1027 L :  5 ,  1029 L :  8 ,  777 L :  8 ,  1036 L :  8 ,  1039 L :  8 ,  1424 L :  5 ,  401 L :  8 ,  148 L :  8 ,  662 L :  4 ,  985 L :  3 ,  795 L :  8 ,  773 L :  7 ,  800 L :  8 ,  545 L :  6 ,  420 L :  8 ,  806 L :  8 ,  808 L :  8 ,  1322 L :  5 ,  427 L :  3 ,  428 L :  8 ,  304 L :  8 ,  432 L :  7 ,  57 L :  3 ,  450 L :  8 ,  929 L :  8 ,  330 L :  8 ,  1302 L :  8 ,  464 L :  8 ,  1361 L :  5 ,  1108 L :  8 ,  597 L :  8 ,  470 L :  2 ,  344 L :  8 ,  804 L :  8 ,  399 L :  7 ,  476 L :  7 ,  1633 L :  8 ,  487 L :  4 ,  892 L :  8 ,  490 L :  8 ,  493 L :  5 ,  884 L :  8 ,  891 L :  8 ,  380 L :  8 ,  1365 L :  5 , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # sent messages 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    0xe4 :  5 ,  0x1fa :  8 ,  0x200 :  3 ,  0x30c :  8 ,  0x33d :  5 ,  0x35e :  8 ,  0x39f :  8 , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  " HONDA ACCORD 2016 TOURING " :  { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    1024 L :  5 ,  929 L :  8 ,  1027 L :  5 ,  773 L :  7 ,  1601 L :  8 ,  777 L :  8 ,  1036 L :  8 ,  398 L :  3 ,  1039 L :  8 ,  401 L :  8 ,  145 L :  8 ,  1424 L :  5 ,  660 L :  8 ,  661 L :  4 ,  918 L :  7 ,  985 L :  3 ,  923 L :  2 ,  542 L :  7 ,  927 L :  8 ,  800 L :  8 ,  545 L :  4 ,  420 L :  8 ,  422 L :  8 ,  808 L :  8 ,  426 L :  8 ,  1029 L :  8 ,  432 L :  7 ,  57 L :  3 ,  316 L :  8 ,  829 L :  5 ,  1600 L :  5 ,  1089 L :  8 ,  1057 L :  5 ,  780 L :  8 ,  1088 L :  8 ,  464 L :  8 ,  1108 L :  8 ,  597 L :  8 ,  342 L :  6 ,  983 L :  8 ,  344 L :  8 ,  804 L :  8 ,  476 L :  4 ,  1296 L :  3 ,  891 L :  8 ,  1125 L :  8 ,  487 L :  4 ,  892 L :  8 ,  490 L :  8 ,  871 L :  8 ,  1064 L :  7 ,  882 L :  2 ,  884 L :  8 ,  506 L :  8 ,  507 L :  1 ,  380 L :  8 ,  1365 L :  5 
 
							 
						 
					
						
							
								
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  " HONDA CR-V 2016 TOURING " :  { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    57 L :  3 ,  145 L :  8 ,  316 L :  8 ,  340 L :  8 ,  342 L :  6 ,  344 L :  8 ,  380 L :  8 ,  398 L :  3 ,  399 L :  6 ,  401 L :  8 ,  420 L :  8 ,  422 L :  8 ,  426 L :  8 ,  432 L :  7 ,  464 L :  8 ,  474 L :  5 ,  476 L :  4 ,  487 L :  4 ,  490 L :  8 ,  493 L :  3 ,  507 L :  1 ,  542 L :  7 ,  545 L :  4 ,  597 L :  8 ,  660 L :  8 ,  661 L :  4 ,  773 L :  7 ,  777 L :  8 ,  800 L :  8 ,  804 L :  8 ,  808 L :  8 ,  882 L :  2 ,  884 L :  7 ,  888 L :  8 ,  891 L :  8 ,  892 L :  8 ,  923 L :  2 ,  929 L :  8 ,  983 L :  8 ,  985 L :  3 ,  1024 L :  5 ,  1027 L :  5 ,  1029 L :  8 ,  1033 L :  5 ,  1036 L :  8 ,  1039 L :  8 ,  1057 L :  5 ,  1064 L :  7 ,  1108 L :  8 ,  1125 L :  8 ,  1296 L :  8 ,  1365 L :  5 ,  1424 L :  5 ,  1600 L :  5 ,  1601 L :  8 , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # sent messages 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    0x194 :  4 ,  0x1fa :  8 ,  0x30c :  8 ,  0x33d :  5 , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								def  eliminate_incompatible_cars ( msg ,  candidate_cars ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  """ Removes cars that could not have sent msg. 
  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     Inputs : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      msg :  A  cereal / log  CanData  message  from  the  car . 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      candidate_cars :  A  list  of  cars  to  consider . 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     Returns : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      A  list  containing  the  subset  of  candidate_cars  that  could  have  sent  msg . 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  """ 
  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  compatible_cars  =  [ ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  for  car_name  in  candidate_cars : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    adr  =  msg . address 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  msg . src  !=  0  or  ( adr  in  _FINGERPRINTS [ car_name ]  and 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        _FINGERPRINTS [ car_name ] [ adr ]  ==  len ( msg . dat ) ) : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      compatible_cars . append ( car_name ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      pass 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      #isin = adr in _FINGERPRINTS[car_name] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      #print "eliminate", car_name, hex(adr), isin, len(msg.dat), msg.dat.encode("hex") 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  compatible_cars 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								def  all_known_cars ( ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  """ Returns a list of all known car strings. """ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  _FINGERPRINTS . keys ( ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# **** for use live only **** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								def  fingerprint ( logcan ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import  selfdrive . messaging  as  messaging 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  from  cereal  import  car 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  from  common . realtime  import  sec_since_boot 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import  os 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  os . getenv ( " SIMULATOR " )  is  not  None  or  logcan  is  None : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # send message 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret  =  car . CarParams . new_message ( ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . carName  =  " simulator " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . radarName  =  " nidec " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . carFingerprint  =  " THE LOW QUALITY SIMULATOR " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . enableSteer  =  True 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . enableBrake  =  True 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . enableGas  =  True 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . enableCruise  =  False 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . wheelBase  =  2.67 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . steerRatio  =  15.3 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . slipFactor  =  0.0014 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . steerKp ,  ret . steerKi  =  12.0 ,  1.0 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  ret 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  print  " waiting for fingerprint... " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  brake_only  =  True 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  candidate_cars  =  all_known_cars ( ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  finger  =  { } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  st  =  None 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  while  1 : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  a  in  messaging . drain_sock ( logcan ,  wait_for_one = True ) : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  st  is  None : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        st  =  sec_since_boot ( ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      for  can  in  a . can : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        # pedal 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  can . address  ==  0x201  and  can . src  ==  0 : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          brake_only  =  False 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  can . src  ==  0 : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          finger [ can . address ]  =  len ( can . dat ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        candidate_cars  =  eliminate_incompatible_cars ( can ,  candidate_cars ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # if we only have one car choice and it's been 100ms since we got our first message, exit 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  len ( candidate_cars )  ==  1  and  st  is  not  None  and  ( sec_since_boot ( ) - st )  >  0.1 : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    elif  len ( candidate_cars )  ==  0 : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      print  map ( hex ,  finger . keys ( ) ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      raise  Exception ( " car doesn ' t match any fingerprints " ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  print  " fingerprinted " ,  candidate_cars [ 0 ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  # send message 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret  =  car . CarParams . new_message ( ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . carName  =  " honda " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . radarName  =  " nidec " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . carFingerprint  =  candidate_cars [ 0 ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . enableSteer  =  True 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . enableBrake  =  True 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . enableGas  =  not  brake_only 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . enableCruise  =  brake_only 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  #ret.enableCruise = False 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . wheelBase  =  2.67 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . steerRatio  =  15.3 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ret . slipFactor  =  0.0014 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  candidate_cars [ 0 ]  ==  " HONDA CIVIC 2016 TOURING " : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . steerKp ,  ret . steerKi  =  12.0 ,  1.0 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  elif  candidate_cars [ 0 ]  ==  " ACURA ILX 2016 ACURAWATCH PLUS " : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  not  brake_only : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      # assuming if we have an interceptor we also have a torque mod 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ret . steerKp ,  ret . steerKi  =  6.0 ,  0.5 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ret . steerKp ,  ret . steerKi  =  12.0 ,  1.0 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  elif  candidate_cars [ 0 ]  ==  " HONDA ACCORD 2016 TOURING " : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ret . steerKp ,  ret . steerKi  =  12.0 ,  1.0 
 
							 
						 
					
						
							
								
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  elif  candidate_cars [ 0 ]  ==  " HONDA CR-V 2016 TOURING " : 
 
							 
						 
					
						
							
								
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ret . steerKp ,  ret . steerKi  =  6.0 ,  0.5 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  else : 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    raise  ValueError ( " unsupported car  %s "  %  candidate_cars [ 0 ] ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  ret