--- /dev/null
+#!/usr/bin/env python
+# GoodFET Nordic RF Radio Client
+#
+# (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
+#
+# This code is being rewritten and refactored. You've been warned!
+
+import sys, time, string, cStringIO, struct, glob, serial, os;
+
+from GoodFET import GoodFET;
+
+class GoodFETNRF(GoodFET):
+ NRFAPP=0x50;
+ def NRFsetup(self):
+ """Move the FET into the NRF application."""
+ self.writecmd(self.NRFAPP,0x10,0,self.data); #NRF/SETUP
+
+ def NRFtrans8(self,byte):
+ """Read and write 8 bits by NRF."""
+ data=self.NRFtrans([byte]);
+ return ord(data[0]);
+
+ def NRFtrans(self,data):
+ """Exchange data by NRF."""
+ self.data=data;
+ self.writecmd(self.NRFAPP,0x00,len(data),data);
+ return self.data;
+
+ def peek(self,reg,bytes=1):
+ """Read an NRF Register. For long regs, result is flipped."""
+ data=[reg,0,0,0,0,0];
+ self.writecmd(self.NRFAPP,0x02,len(data),data);
+ toret=0;
+ for i in range(0,bytes):
+ toret=toret|(ord(self.data[i+1])<<(8*i));
+ return toret;
+ def poke(self,reg,val,bytes=1):
+ """Write an NRF Register."""
+ data=[reg];
+ for i in range(0,bytes):
+ data=data+[(val>>(8*i))&0xFF];
+ self.writecmd(self.NRFAPP,0x03,len(data),data);
+ if self.peek(reg,bytes)!=val:
+ print "Warning, failed to set register %02x." %reg;
+ return;
+
+ def status(self):
+ """Read the status byte."""
+ self.poke(0x07,0x78); #Reset status
+ status=self.peek(0x07);
+ print "Status=%02x" % status;
+
+ #Radio stuff begins here.
+ def RF_freq(self,frequency):
+ """Set the frequency in Hz."""
+
+ #On the NRF24L01+, register 0x05 is the offset in
+ #MHz above 2400.
+
+ mhz=frequency/1000000-2400;
+ print "Setting channel %i." % mhz
+ self.poke(0x05,mhz);
+ def RF_getsmac(self):
+ """Return the source MAC address."""
+
+ #Register 0A is RX_ADDR_P0, five bytes.
+ mac=self.peek(0x0A, 5);
+ return mac;
client.poke(0x06,8+10+4+2);
client.RF_freq(2480 * 10**6);
- #Print register, no idea why.
- for r in range(0,30):
- print "r[0x%02x]=0x%02x" % (r,client.peek(r));
- print "SMAC=%010x" % client.RF_getsmac();
+ #Print registers, just for fun.
+ print "SMAC was %010x" % client.RF_getsmac();
+
+ client.poke(0x0A,0xDEADBEEF,5);
+ print "SMAC set to %010x" % client.RF_getsmac();
+ if client.RF_getsmac()!=0xdeadbeef:
+ print "ERROR: Failed to set MAC address.";
if(sys.argv[1]=="regs"):
for r in range(0,30):
print "r[0x%02x]=0x%02x" % (r,client.peek(r));
+
+