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;
15 class FordExperiments(GoodFETMCPCANCommunication):
18 super(FordExperimetns,self).__init__(self) #initialize chip
21 def mimic1056(self,packetData,runTime):
25 #FIGURE out how to clear buffers
26 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
27 packet1 = self.client.rxpacket();
29 packetParsed = self.client.packet2parsed(packet1);
30 #keep sniffing till we read a packet
31 while( packet1 == None or packetParsed.get('sID') != 1056 ):
32 packet1 = self.client.rxpacket()
34 packetParsed = self.client.packet2parsed(packet1)
35 recieveTime = time.time()
36 packetParsed = self.client.packet2parsed(packet1)
37 if( packetParsed['sID'] != 1056):
38 print "Sniffed wrong packet"
40 countInitial = ord(packetParsed['db3']) #initial count value
42 #set data packet to match what was sniffed or at least what was input
45 if(packetData.get(idx) == None):
46 packet.append(ord(packetParsed.get(idx)))
48 packet.append(packetData.get(idx))
50 #### split SID into different regs
51 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
52 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
53 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
54 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
56 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
58 self.client.txpacket(packet);
60 while( (time.time()-recieveTime) < runTime):
61 #care about db3 or packet[8] that we want to count at the rate that it is
62 dT = time.time()-tpast
64 db3 = (countInitial + math.floor((time.time()-recieveTime)/0.2))%255
66 self.client.txpacket(packet)
70 self.client.MCPrts(TXB0=True)
71 tpast = time.time() #update our transmit time on the one before
75 def cycledb1_1056(self,runTime):
79 #FIGURE out how to clear buffers
80 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
81 packet1 = self.client.rxpacket();
83 packetParsed = self.client.packet2parsed(packet1);
84 #keep sniffing till we read a packet
85 while( packet1 == None or packetParsed.get('sID') != 1056 ):
87 packet1 = self.client.rxpacket()
89 packetParsed = self.client.packet2parsed(packet1)
90 recieveTime = time.time()
91 packetParsed = self.client.packet2parsed(packet1)
92 if( packetParsed['sID'] != 1056):
93 print "Sniffed wrong packet"
96 #set data packet to match what was sniffed or at least what was input
99 packet.append(ord(packetParsed.get(idx)))
101 packet[1] = packetValue;
104 #### split SID into different regs
105 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
106 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
107 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
108 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
109 # lower nibble is DLC
110 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
112 self.client.txpacket(packet);
114 while( (time.time()-recieveTime) < runTime):
115 #care about db3 or packet[8] that we want to count at the rate that it is
116 dT = time.time()-tpast
119 #temp = ((packetValue+1))%2
121 # pV = packetValue%255
127 self.client.txpacket(packet)
129 tpast = time.time() #update our transmit time on the one before
132 def getBackground(self,sId):
133 packet1 = self.client.rxpacket();
135 packetParsed = self.client.packet2parsed(packet1);
136 #keep sniffing till we read a packet
137 while( packet1 == None or packetParsed.get('sID') != sId ):
138 packet1 = self.client.rxpacket()
140 packetParsed = self.client.packet2parsed(packet1)
142 #recieveTime = time.time()
146 def oscillateTemperature(self,time):
148 self.client.serInit()
150 #FIGURE out how to clear buffers
151 self.addFilter([1056, 1056, 1056, 1056,1056, 1056], verbose=False)
152 packetParsed = self.getBackground(1056)
154 #set data packet to match what was sniffed or at least what was input
157 packet.append(ord(packetParsed.get(idx)))
159 packet[1] = packetValue;
162 #### split SID into different regs
163 SIDlow = (1056 & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
164 SIDhigh = (1056 >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
165 packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
166 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
167 # lower nibble is DLC
168 packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]]
170 self.client.txpacket(packet);
171 startTime = tT.time()
172 while( (tT.time()-startTime) < runTime):
173 dt = tT.time()-startTime
174 inputValue = ((2.0*math.pi)/20.0)*dt
175 value = 30*math.sin(inputValue)+130
177 #packet[5] = int(value)
184 self.client.txpacket(packet)
186 #tpast = time.time() #update our transmit time on the one before
190 if __name__ == "__main__":
191 fe = FordExperiments();
193 packetData['db4'] = 4;
195 #fe.mimic1056(packetData, runTime)
196 #fe.cycledb1_1056(runTime)
197 fe.oscillateTemperature(runTime)