X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFETMCPCAN.py;h=0232b287e79dc0b3bfc78efe1121fc626525943f;hp=d99e07c29654f11d1febff6a7608e4d087a70620;hb=3a68664f8b47dd3aff108a22d5156f8747a24ee5;hpb=c1945b6830167f16f8e37b55cab3935283d7d2cc diff --git a/client/GoodFETMCPCAN.py b/client/GoodFETMCPCAN.py index d99e07c..0232b28 100644 --- a/client/GoodFETMCPCAN.py +++ b/client/GoodFETMCPCAN.py @@ -227,24 +227,12 @@ class GoodFETMCPCAN(GoodFETSPI): if flags==0: print "Warning: Requesting to send no buffer."; - if self.MCPcanstat()>>5!=0: - print "Warning: currently in %s mode. NOT in normal mode! May not transmit." %self.MCPcanstatstr(); self.SPItrans([0x80|flags]); def writetxbuffer(self,packet,packbuf=0): """Writes the transmit buffer.""" self.SPItrans([0x40|(packbuf<<1)]+packet); - #READ BACK BUFFER 0 to check what we're about to send out - data=self.SPItrans([0x03, 0x31, - 0x00,0x00, #SID - 0x00,0x00, #EID - 0x00, #DLC - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - ]); - print "about to transmit:" + self.packet2str(data[2:len(data)]); - def simpleParse(self,packet): dataPt = ord(packet[0]); @@ -290,8 +278,6 @@ class GoodFETMCPCAN(GoodFETSPI): For now, only TXB0 is supported.""" self.writetxbuffer(packet,0); - - #self.SPItrans([0x81]); self.MCPrts(TXB0=True); @@ -304,18 +290,14 @@ class GoodFETMCPCAN(GoodFETSPI): toprint=toprint+("%02x "%ord(bar)) return toprint; + + ## This code could be drastica def packet2parsed(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} - + packet = {} #get the ide bit. allows us to check to see if we have an extended #frame packet['ide'] = (dp2 & 0x0f)>>3 @@ -324,36 +306,41 @@ class GoodFETMCPCAN(GoodFETSPI): #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 + packet['eID'] = " eID: %06d" %(eId) + packet['rtr'] = " 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 + # Create the standard ID. from the message packet['sID'] = dp1<<3 | dp2>>5 - - - length = dp5 & 0x0f - packet['length'] = length - - if( length > 8): - packet['error'] = 1 + packet['length'] = dp5 & 0x0f #generate the data section - for i in range(0,length): - idx = 5+i - dbidx = 'db%d' % i - packet[dbidx] = data[idx] + for i in range(0,packet['length']): + idx = 5 + i + dbidx = 'db%d'%i + packet[dbidx] = data[idx] + return packet - + + def packet2parsedstr(self,data): + packet = self.packet2parsed(data) + msg = "sID: %04d" %sId + if( packetParsed.get('eID')): + msg += " eID: %d" %packetParsed.get('eID') + msg += " rtr: %d"%packetParsed['rtr'] + length = packetParsed['length'] + msg += " length: %d"%length + msg += " data:" + for i in range(0,length): + dbidx = 'db%d'%i + msg +=" %03d"% ord(packetParsed[dbidx]) + #msg = self.client.packet2parsedstr(packet) + print msg def peek8(self,adr): @@ -398,4 +385,4 @@ class GoodFETMCPCAN(GoodFETSPI): # TXRTSCTRL = x0D - \ No newline at end of file +