#Radio stuff begins here.
def RF_setenc(self,code="802.15.4"):
"""Set the encoding type."""
- return;
+ return code;
def RF_getenc(self):
"""Get the encoding type."""
return "802.15.4";
self.poke(0x14,sync);
return;
+ def RF_setkey(self,key):
+ """Sets the first key for encryption to the given argument."""
+ print "ERROR: Forgot to set the key.";
+
+ return;
def RF_setfreq(self,frequency):
"""Set the frequency in Hz."""
mhz=frequency/1000000;
"""Returns the received signal strength, with a weird offset."""
rssival=self.peek(0x13)&0xFF; #raw RSSI register
return rssival^0x80;
+
+ def peekram(self,adr,count):
+ """Peeks data from CC2420 RAM."""
+ data=[
+ adr&0xFF,adr>>8, # Address first.
+ count&0xFF,count>>8 # Then length.
+ ];
+ self.writecmd(self.CCSPIAPP,0x84,len(data),data);
+ return self.data;
+ def pokeram(self,adr,data):
+ """Pokes data into CC2420 RAM."""
+ data=[adr&0xFF, adr>>8]+data;
+ self.writecmd(self.CCSPIAPP,0x85,len(data),data);
+ return;
+
lastpacket=range(0,0xff);
def RF_rxpacket(self):
- """Get a packet from the radio. Returns None if none is waiting. In
- order to not require the SFD, FIFO, or FIFOP lines, this
- implementation works by comparing the buffer to the older
- contents.
- """
+ """Get a packet from the radio. Returns None if none is
+ waiting."""
data="\0";
self.data=data;
self.lastpacket=buffer;
if(len(buffer)==0):
return None;
- #self.strobe(0x08); #SFLUSHRX
return buffer;
+ def RF_rxpacketdec(self):
+ """Get and decrypt a packet from the radio. Returns None if
+ none is waiting."""
+
+ data="\0";
+ self.data=data;
+ self.writecmd(self.CCSPIAPP,0x90,len(data),data);
+ buffer=self.data;
+
+ self.lastpacket=buffer;
+ if(len(buffer)==0):
+ return None;
+
+ return buffer;
+
def RF_txpacket(self,packet):
"""Send a packet through the radio."""
self.writecmd(self.CCSPIAPP,0x81,len(packet),packet);