# The delay is mandatory.
-import sys, time, string, cStringIO, struct, glob, serial, os;
+import sys, time, string, cStringIO, struct, glob, os;
from GoodFETSPI import GoodFETSPI;
self.seq&0xFF,0x00,
]+frame+[
0xA7]);
- #s="EZSP< ";
- #for foo in data:
- # s=s+"%02x " % ord(foo);
- #print s;
+ s="EZSP< ";
+ for foo in data:
+ s=s+"%02x " % ord(foo);
+ print s;
if ord(data[0])!=0xFE:
print "EZSP error: 0x%02x" % ord(data[0]);
if ord(data[4])==0x58:
- print "EZSP Invalid Command";
- return None;
+ print "EZSP Invalid Command because 0x%02x" % ord(data[5]);
+ return data;
if frame[0]!=ord(data[4]):
print "EZSP warning: Command 0x%02x returned type 0x%02x." % (
frame[0],ord(data[4]));
self.EZSPtrans([0x46,adr&0xFF,1,val&0xFF]);
return val;
def rand16(self):
- """Read a byte from the given address."""
+ """Read a random 16-bit word."""
data=self.EZSPtrans([0x49]);
if data==None:
print "Insufficient random data.";
return 0;
return ord(data[6])+(ord(data[7])<<8);
-
+
def info(self):
"""Read the info bytes."""
print "Ember EM26 Z-Stack SPI Module.";
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]);
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);