From: travisutk Date: Wed, 15 Aug 2012 22:38:23 +0000 (+0000) Subject: Added support for the different operating modes. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=449099caf793501a25a72a855882bb821fd7ad08 Added support for the different operating modes. Loopback will be handy for testing. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1230 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/client/GoodFETMCPCAN.py b/client/GoodFETMCPCAN.py index 0cbc090..4270b20 100644 --- a/client/GoodFETMCPCAN.py +++ b/client/GoodFETMCPCAN.py @@ -17,16 +17,45 @@ from GoodFETSPI import GoodFETSPI; class GoodFETMCPCAN(GoodFETSPI): """This class uses the regular SPI app to implement a CAN Bus adapter on the Goodthopter10 hardware.""" - + MCPMODES=["Normal","Sleep","Loopback","Listen-only","Configuration", + "UNKNOWN","UNKNOWN","PowerUp"]; def MCPsetup(self): """Sets up the ports.""" self.SPIsetup(); self.MCPreset(); #Reset the chip. - + self.MCPreqstatLoopback(); def MCPreset(self): """Reset the MCP2515 chip.""" self.SPItrans([0xC0]); - + def MCPcanstat(self): + """Get the CAN Status.""" + return self.peek8(0x0E); + def MCPreqstatNormal(self): + """Set the CAN state.""" + state=0x0; + self.MCPbitmodify(0x0F,0xE0,(state<<5)); + def MCPreqstatSleep(self): + """Set the CAN state.""" + state=0x1; + self.MCPbitmodify(0x0F,0xE0,(state<<5)); + def MCPreqstatLoopback(self): + """Set the CAN state.""" + state=0x2; + self.MCPbitmodify(0x0F,0xE0,(state<<5)); + def MCPreqstatListenOnly(self): + """Set the CAN state.""" + state=0x3; + self.MCPbitmodify(0x0F,0xE0,(state<<5)); + def MCPreqstatConfiguration(self): + """Set the CAN state.""" + state=0x4; + self.MCPbitmodify(0x0F,0xE0,(state<<5)); + + def MCPcanstatstr(self): + """Read the present status as a string.""" + status=self.MCPcanstat(); + opmod=(status&0xE0)>>5; + return self.MCPMODES[opmod]; def MCPrxstatus(self): """Reads the RX Status by the SPI verb of the same name.""" data=self.SPItrans([0xB0,0x00]); diff --git a/client/goodfet.mcpcan b/client/goodfet.mcpcan index 35fc1d4..99620a3 100755 --- a/client/goodfet.mcpcan +++ b/client/goodfet.mcpcan @@ -33,7 +33,9 @@ client.MCPsetup(); #Might read as all ones if chip has a startup delay. if(sys.argv[1]=="info"): - print "MCP2515 Info:"; + print "MCP2515 Info:\n\n"; + + print "Mode: %s" % client.MCPcanstatstr(); print "Read Status: %02x" % client.MCPreadstatus(); print "Rx Status: %02x" % client.MCPrxstatus(); print "Tx Errors: %3d" % client.peek8(0x1c);