4 import csv, time, argparse;
7 from random import randrange
8 from GoodFETMCPCAN import GoodFETMCPCAN;
9 from GoodFETMCPCANCommunication import GoodFETMCPCANCommunication
10 from intelhex import IntelHex;
14 class FordExperiments(GoodFETMCPCANCommunication):
17 super(FordExperimetns,self).__init__(self) #initialize chip
19 def mimic1056(self,packetData,runTime):
23 #FIGURE out how to clear buffers
24 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
25 packet1 = self.client.rxpacket();
26 recieveTime = time.time()
27 packetParsed = self.client.packet2parsed(packet1)
28 if( packetParsed['sID'] != 1056):
29 print "Sniffed wrong packet"
31 countInitial = ord(packetParsed['db3'].get()) #initial count value
33 #set data packet to match what was sniffed or at least what was input
36 if(packetData.get(idx) == None):
37 packet.append(ord(packetParsed.get(idx)))
38 #### split SID into different regs
39 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
40 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
41 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
42 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
44 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
45 self.client.txpacket(packet);
47 while( (time.time()-recieveTime) < runTime):
48 #care about db3 or packet[8] that we want to count at the rate that it is
49 dT = time.time()-tpast
51 db3 = (countInitial + math.floor((time.time()-recieveTime)/0.2))%255
54 self.client.MCPrts(TXB0=True):
55 tpast = time.time() #update our transmit time on the one before
61 if __name__ == "__main__":
62 fe = FordExperiments();
64 packetData['db4'] = 4;
66 fe.mimic1056(packetData, runTime)