X-Git-Url: http://git.rot13.org//?a=blobdiff_plain;f=client%2FGoodFETMCPCAN.py;h=0cbc0904c2e461199a5ac3091c1ecad3477b504e;hb=43f50970e78843e02cfa981005165ef0b64381a0;hp=c00af14307fc509c33ed4599fc140bbd4546818a;hpb=d116d8de78feaf5c7a8bb0260c15543298e3d5d2;p=goodfet diff --git a/client/GoodFETMCPCAN.py b/client/GoodFETMCPCAN.py index c00af14..0cbc090 100644 --- a/client/GoodFETMCPCAN.py +++ b/client/GoodFETMCPCAN.py @@ -59,6 +59,24 @@ class GoodFETMCPCAN(GoodFETSPI): 0x00, 0x00, 0x00, 0x00 ]); return data[1:len(data)]; + def rxpacket(self): + """Reads the next incoming packet from either buffer. + Returns None immediately if no packet is waiting.""" + status=self.MCPrxstatus()&0xC0; + if status&0x40: + #Buffer 0 has higher priority. + return self.rxbuffer(0); + elif status&0x80: + #Buffer 1 has lower priority. + return self.rxbuffer(1); + else: + return None; + def packet2str(self,packet): + """Converts a packet from the internal format to a string.""" + toprint=""; + for bar in packet: + toprint=toprint+("%02x "%ord(bar)) + return toprint; def peek8(self,adr): """Read a byte from the given address. Untested.""" data=self.SPItrans([0x03,adr&0xFF,00]);