Skip to content

Commit

Permalink
Strengthen VIN detection
Browse files Browse the repository at this point in the history
Replaces a counter with a check of the dictionary contents to work around a potential bug: if the same VIN piece were received twice, it would still have incremented the counter.
  • Loading branch information
DavidWAbrahams authored Jun 15, 2018
1 parent 813218d commit 2a8c2c2
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions examples/tesla_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def tesla_tester():

print("Reading VIN from 0x568. This is painfully slow and can take up to 3 minutes (1 minute per message; 3 messages needed for full VIN)...")

cnt = 0
vin = {}
while True:
#Read the VIN
Expand All @@ -53,11 +52,10 @@ def tesla_tester():
vin_string = binascii.hexlify(dat)[2:] #rest of the string is the actual VIN data
vin[vin_index] = vin_string.decode("hex")
print("Got VIN index " + str(vin_index) + " data " + vin[vin_index])
cnt += 1
#if we have all 3 parts of the VIN, print it and break out of our while loop
if cnt == 3:
if 0 in vin and 1 in vin and 2 in vin:
print("VIN: " + vin[0] + vin[1] + vin[2][:3])
break

if __name__ == "__main__":
tesla_tester()
tesla_tester()

0 comments on commit 2a8c2c2

Please sign in to comment.