print "Status=%02x" % status;
#Radio stuff begins here.
- def RF_freq(self,frequency):
+ def RF_setfreq(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);
+ chan=frequency/1000000-2400;
+ self.poke(0x05,chan);
+ def RF_getfreq(self):
+ """Get the frequency in Hz."""
+
+ #On the NRF24L01+, register 0x05 is the offset in
+ #MHz above 2400.
+
+ return (2400+self.peek(0x05))*10**6
+ self.poke(0x05,chan);
def RF_getsmac(self):
"""Return the source MAC address."""
"""Set the number of bytes in the expected payload."""
self.poke(0x11,len);
self.packetlen=len;
+
s="";
i=0;
for foo in packet:
- if i>client.packetlen: break;
i=i+1;
+ if i>client.packetlen: break;
s="%s %02x" % (s,ord(foo));
print "Got %s" %s;
#Initialize FET and set baud rate
client=GoodFETNRF();
-print "Connecting."
client.serInit()
-print "Connected."
client.NRFsetup();
-print "Setup."
-client.status();
if(sys.argv[1]=="test"):
#Delay of 1.5ms by round-trip.
# Set CONT_WAVE, PLL_LOCK, and 0dBm in RF_SETUP
client.poke(0x06,8+10+4+2);
- client.RF_freq(2480 * 10**6);
+ client.RF_setfreq(2480 * 10**6);
#Print registers, just for fun.
print "SMAC was %010x" % client.RF_getsmac();
client.poke(0x01,0x00); #Disable Shockburst
client.poke(0x02,0x01); #Set RX Pipe 0
client.poke(0x03,0x03); #SETUP_AW for 5-byte addresses.
- client.RF_freq(2481 * 10**6);
- #client.RF_freq(2490 * 10**6);
+ client.RF_setfreq(2481 * 10**6);
+ #client.RF_setfreq(2490 * 10**6);
client.poke(0x06,0x09); #2MBps, -18dBm in RF_SETUP
client.poke(0x07,0x78); #Reset status register
#client.poke(0x11,16);
client.RF_setpacketlen(16);
- client.status();
#Power radio, prime for RX, checksum.
client.poke(0x00,0x70|0x03|0x08);
- print "Listening as %010x on channel %03i" % (client.RF_getsmac(),client.peek(0x05));
+ print "Listening as %010x on %i MHz" % (client.RF_getsmac(),
+ client.RF_getfreq()/10**6);
#Now we're ready to get packets.
while 1: