From d116d8de78feaf5c7a8bb0260c15543298e3d5d2 Mon Sep 17 00:00:00 2001 From: travisutk Date: Wed, 15 Aug 2012 22:04:57 +0000 Subject: [PATCH] Added GoodFETMCPCAN().readrxbuffer() for reading incoming packets. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1228 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- client/GoodFETMCPCAN.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/client/GoodFETMCPCAN.py b/client/GoodFETMCPCAN.py index aab98f4..c00af14 100644 --- a/client/GoodFETMCPCAN.py +++ b/client/GoodFETMCPCAN.py @@ -15,6 +15,9 @@ import sys, time, string, cStringIO, struct, glob, os; from GoodFETSPI import GoodFETSPI; class GoodFETMCPCAN(GoodFETSPI): + """This class uses the regular SPI app to implement a CAN Bus + adapter on the Goodthopter10 hardware.""" + def MCPsetup(self): """Sets up the ports.""" self.SPIsetup(); @@ -23,15 +26,18 @@ class GoodFETMCPCAN(GoodFETSPI): def MCPreset(self): """Reset the MCP2515 chip.""" self.SPItrans([0xC0]); + def MCPrxstatus(self): """Reads the RX Status by the SPI verb of the same name.""" data=self.SPItrans([0xB0,0x00]); return ord(data[1]); + def MCPreadstatus(self): """Reads the Read Status by the SPI verb of the same name.""" #See page 67 of the datasheet for the flag names. data=self.SPItrans([0xA0,0x00]); return ord(data[1]); + def MCPrts(self,TXB0=False,TXB1=False,TXB2=False): """Requests to send one of the transmit buffers.""" flags=0; @@ -42,13 +48,25 @@ class GoodFETMCPCAN(GoodFETSPI): if flags==0: print "Warning: Requesting to send no buffer."; - """Request To Send a transmission.""" self.SPItrans([0x80|flags]); + def readrxbuffer(self,packbuf=0): + """Reads the RX buffer. Might have old data.""" + data=self.SPItrans([0x90|(packbuf<<2), + 0x00,0x00, #SID + 0x00,0x00, #EID + 0x00, #DLC + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + ]); + return data[1:len(data)]; def peek8(self,adr): """Read a byte from the given address. Untested.""" data=self.SPItrans([0x03,adr&0xFF,00]); return ord(data[2]); - + def MCPbitmodify(self,adr,mask,data): + """Writes a byte with a mask. Doesn't work for many registers.""" + data=self.SPItrans([0x05,adr&0xFF,mask&0xFF,data&0xFF]); + return ord(data[2]); def poke8(self,adr,val): """Poke a value into RAM. Untested""" self.SPItrans([0x02,adr&0xFF,val&0xFF]); -- 2.20.1