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
20 def mimic1056(self,packetData,runTime):
24 #FIGURE out how to clear buffers
25 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
26 packet1 = self.client.rxpacket();
28 packetParsed = self.client.packet2parsed(packet1);
29 #keep sniffing till we read a packet
30 while( packet1 == None or packetParsed.get('sID') != 1056 ):
31 packet1 = self.client.rxpacket()
33 packetParsed = self.client.packet2parsed(packet1)
34 recieveTime = time.time()
35 packetParsed = self.client.packet2parsed(packet1)
36 if( packetParsed['sID'] != 1056):
37 print "Sniffed wrong packet"
39 countInitial = ord(packetParsed['db3']) #initial count value
41 #set data packet to match what was sniffed or at least what was input
44 if(packetData.get(idx) == None):
45 packet.append(ord(packetParsed.get(idx)))
47 packet.append(packetData.get(idx))
49 #### split SID into different regs
50 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
51 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
52 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
53 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
55 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
57 self.client.txpacket(packet);
59 while( (time.time()-recieveTime) < runTime):
60 #care about db3 or packet[8] that we want to count at the rate that it is
61 dT = time.time()-tpast
63 db3 = (countInitial + math.floor((time.time()-recieveTime)/0.2))%255
65 self.client.txpacket(packet)
69 self.client.MCPrts(TXB0=True)
70 tpast = time.time() #update our transmit time on the one before
74 def cycledb1_1056(self,runTime):
78 #FIGURE out how to clear buffers
79 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
80 packet1 = self.client.rxpacket();
82 packetParsed = self.client.packet2parsed(packet1);
83 #keep sniffing till we read a packet
84 while( packet1 == None or packetParsed.get('sID') != 1056 ):
85 packet1 = self.client.rxpacket()
87 packetParsed = self.client.packet2parsed(packet1)
88 recieveTime = time.time()
89 packetParsed = self.client.packet2parsed(packet1)
90 if( packetParsed['sID'] != 1056):
91 print "Sniffed wrong packet"
94 #set data packet to match what was sniffed or at least what was input
97 packet.append(ord(packetParsed.get(idx)))
99 packet[1] = packetValue;
102 #### split SID into different regs
103 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
104 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
105 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
106 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
107 # lower nibble is DLC
108 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
110 self.client.txpacket(packet);
112 while( (time.time()-recieveTime) < runTime):
113 #care about db3 or packet[8] that we want to count at the rate that it is
114 dT = time.time()-tpast
115 packetValue = (packetValue+1)%255
116 packet[1] = packetValue
117 self.client.txpacket(packet)
119 tpast = time.time() #update our transmit time on the one before
122 if __name__ == "__main__":
123 fe = FordExperiments();
125 packetData['db4'] = 4;
127 #fe.mimic1056(packetData, runTime)
128 fe.cycledb1_1056(runTime)