+ # and now return to whatever state we were in before
+ self.MCPreqstat(oldstatus);
+ #print "Reverted to %s." % self.MCPcanstatstr();
+
+
+ ################# STATE MANAGEMENT ##################
+
+ def MCPcanstat(self):
+ """Get the CAN Status."""
+ return self.peek8(0x0E);
+ def MCPcanstatstr(self):
+ """Read the present status as a string."""
+ opmod=self.MCPcanstatint();
+ return self.MCPMODES[opmod];
+ def MCPcanstatint(self):
+ """Read present status as an int."""
+ return self.MCPcanstat()>>5;
+
+
+ def MCPreqstat(self, state):
+ """Set the CAN state."""
+ if state==0:
+ self.MCPreqstatNormal();
+ elif state==1:
+ self.MCPreqstatSleep();
+ elif state==2:
+ self.MCPreqstatLoopback();
+ elif state==3:
+ self.MCPreqstatListenOnly();
+ elif state==4:
+ self.MCPreqstatConfiguration();
+ else:
+ print "Invalid state entered; defaulting to Listen-Only"
+ self.MCPreqstatListenOnly();
+ 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));
+
+ #################### RX MANAGEMENT #####################
+