import os
_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 ,
} ,
" TOYOTA PRIUS 2017 " : {
896 L : 8 , 832 L : 8 , 898 L : 8 , 899 L : 8 , 577 L : 8 , 528 L : 8 , 529 L : 8 , 530 L : 8 , 531 L : 8 , 532 L : 8 , 533 L : 8 , 534 L : 8 , 535 L : 8 , 536 L : 8 , 537 L : 8 , 538 L : 8 , 539 L : 8 , 540 L : 8 , 541 L : 8 , 542 L : 8 , 543 L : 8 , 544 L : 8 , 545 L : 8 , 546 L : 8 , 547 L : 8 , 548 L : 8 , 549 L : 8 , 550 L : 8 , 551 L : 8 , 296 L : 6 , 553 L : 6 , 554 L : 6 , 555 L : 6 , 556 L : 6 , 557 L : 6 , 558 L : 6 , 559 L : 6 , 560 L : 7 , 561 L : 8 , 562 L : 8 , 883 L : 8 , 837 L : 8 , 833 L : 8 , 576 L : 8 , 321 L : 4 , 834 L : 8 , 835 L : 8 , 580 L : 8 , 581 L : 8 , 897 L : 8 , 584 L : 8 , 1136 L : 4 , 976 L : 8 , 977 L : 8 , 978 L : 8 , 291 L : 7 , 881 L : 8 , 352 L : 8 , 353 L : 7 , 867 L : 8 , 868 L : 8 , 869 L : 8 , 1126 L : 3 , 304 L : 7 , 880 L : 8 , 552 L : 6 , 882 L : 8 , 979 L : 8 , 884 L : 8 , 885 L : 8 , 836 L : 8
}
}
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
if os . getenv ( " SIMULATOR " ) is not None or logcan is None :
return ( " simulator " , None )
elif os . getenv ( " SIMULATOR2 " ) is not None :
return ( " simulator2 " , None )
print " waiting for fingerprint... "
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 :
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 ]
return ( candidate_cars [ 0 ] , finger )