+ print "Ember EM26 Z-Stack SPI Module.";
+ version=self.EM260spiversion();
+ status=self.EM260spistatus();
+ print "Version: %i" % (version);
+ print "Status: %s" % (["dead","alive"][status]);
+ print ""
+ self.setVersion();
+ print "Node ID: %04x" % (self.getNodeID());
+ print "Connected to %2i neighbors." % self.neighborCount();
+ def EM260spiversion(self):
+ """Read the SPI version number from EM260."""
+ data=self.EM260trans([0x0A,0xA7]);
+ version=ord(data[0]);
+
+ if version==0x00:
+ return self.EM260spiversion();
+ if version==0x02:
+ return self.EM260spiversion();
+ if not version&0x80:
+ print "Version misread.";
+ return 0;
+ return version&0x7F;
+
+ def EM260spistatus(self):
+ """Read the status bit."""
+ data=self.EM260trans([0x0B,0xA7]);
+ status=ord(data[0]);
+
+ if status==0x00:
+ return self.EM260spistatus();
+ if status==0x02:
+ return self.EM260spistatus();
+ if not status&0x80 and status&0x40:
+ print "Status misread.";
+ return 0;
+ return status&1;
+
+ #Everything after here is ZigBee.
+
+ def getNodeID(self):
+ """Read the EZSP node id."""
+
+ data=self.EZSPtrans([0x27]);
+ return ord(data[5])+(ord(data[6])<<8);
+ def neighborCount(self):
+ """Read the count of neighbors, used for iterating the neighbor table."""
+
+ data=self.EZSPtrans([0x7A]);
+ return ord(data[5]);
+ def setRadioChannel(self,channel):
+ """Set the radio channel."""
+
+ data=self.EZSPtrans([0x9A, channel&xFF]);
+ return ord(data[5]);
+ def setVersion(self,version=2):
+ """Set the requested EZSP protocol version."""
+
+ data=self.EZSPtrans([0x00, version]);
+ newversion=ord(data[5]);
+ if version==newversion:
+ print "Version set."
+ print "Protocol %i, stack type %i, Stack Version 0x%02x%02x." % (
+ newversion,
+ ord(data[6]),
+ ord(data[8]),
+ ord(data[7]));
+ else:
+ self.setVersion(newversion);