X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFETMCPCAN.py;h=c740003b327cb7f39c6fe6ab2588256f75b4727b;hp=aa06b260adcd152cd4dc4a2078a7110b01d8687e;hb=c731d103ee96698aa0a00198f0f6d6cc6381f0ab;hpb=0a4e61c633bfe1cb455f1cd1ecd73afca0306a50 diff --git a/client/GoodFETMCPCAN.py b/client/GoodFETMCPCAN.py index aa06b26..c740003 100644 --- a/client/GoodFETMCPCAN.py +++ b/client/GoodFETMCPCAN.py @@ -290,56 +290,48 @@ class GoodFETMCPCAN(GoodFETSPI): toprint=toprint+("%02x "%ord(bar)) return toprint; - def packet2parsed(self,data): + + ## This code could be drastica + def packet2parsedstr(self,data): dp1 = ord(data[0]) dp2 = ord(data[1]) dp5 = ord(data[4]) #converts the CAN message to a string msg=""; - for bar in data: - msg=msg+("%02x"%ord(bar)) - packet = {'msg':msg} + #get the ide bit. allows us to check to see if we have an extended #frame - packet['ide'] = (dp2 & 0x0f)>>3 + ide = (dp2 & 0x0f)>>3 #we have an extended frame - if( packet['ide'] != 0): + if( ide != 0): #get lower nibble, last 2 bits eId = dp2 & 0x03 eId = eId<<8 | ord(data[2]) - packet['eID'] = eId<<8 | ord(data[3]) - packet['rtr'] = dp5>>6 & 0x01 + eId = eId<<8 | ord(data[3]) + rtr = dp5>>6 & 0x01 + eIDmsg = " eID: %06d" %(eId) + rtrmsg = " rtr: %d" % (rtr) else: - packet['rtr'] = dp2>>4 & 0x01 - - #error check, 2nd msb of the lower nibble of byte 2 should be 0 - if( (dp2 & 0x04) == 4 ): - packet['error'] = 1 - #error check an always 0 bit - if( (dp5 & 0xf0) == 240): - packet['error'] = 1 + rtr = dp2>>4 & 0x01 + eIDmsg = "" + rtrmsg = " rtr: %d"%(rtr) # Create the standard ID. from the message - packet['sID'] = dp1<<3 | dp2>>5 - - + sID = dp1<<3 | dp2>>5 length = dp5 & 0x0f - packet['length'] = length - - if( length > 8): - packet['error'] = 1 #generate the data section + dbmsg = "" for i in range(0,length): - idx = 5+i - dbidx = 'db%d' % i - packet[dbidx] = data[idx] - return packet + dbmsg += data[idx] + msg = "sID: %04d" + eIDmsg + rtrmsg + ("length: %d"%(length)) + dbmsg + + return msg def peek8(self,adr):