Cleaned up frequency settings, packet sniffer.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 May 2010 07:46:42 +0000 (07:46 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 May 2010 07:46:42 +0000 (07:46 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@537 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETNRF.py
client/goodfet.nrf

index 459b71f..e9c44c1 100644 (file)
@@ -50,15 +50,22 @@ class GoodFETNRF(GoodFET):
         print "Status=%02x" % status;
     
     #Radio stuff begins here.
         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.
         
         """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."""
         
     def RF_getsmac(self):
         """Return the source MAC address."""
         
@@ -100,3 +107,4 @@ class GoodFETNRF(GoodFET):
         """Set the number of bytes in the expected payload."""
         self.poke(0x11,len);
         self.packetlen=len;
         """Set the number of bytes in the expected payload."""
         self.poke(0x11,len);
         self.packetlen=len;
+    
index 65bface..7e0721f 100755 (executable)
@@ -15,8 +15,8 @@ def printpacket(packet):
     s="";
     i=0;
     for foo in packet:
     s="";
     i=0;
     for foo in packet:
-        if i>client.packetlen: break;
         i=i+1;
         i=i+1;
+        if i>client.packetlen: break;
         s="%s %02x" % (s,ord(foo));
     print "Got %s" %s;
         
         s="%s %02x" % (s,ord(foo));
     print "Got %s" %s;
         
@@ -29,13 +29,9 @@ if(len(sys.argv)==1):
 
 #Initialize FET and set baud rate
 client=GoodFETNRF();
 
 #Initialize FET and set baud rate
 client=GoodFETNRF();
-print "Connecting."
 client.serInit()
 
 client.serInit()
 
-print "Connected."
 client.NRFsetup();
 client.NRFsetup();
-print "Setup."
-client.status();
 
 
 if(sys.argv[1]=="test"):
 
 
 if(sys.argv[1]=="test"):
@@ -44,7 +40,7 @@ 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); 
     #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();
     
     #Print registers, just for fun.
     print "SMAC was %010x" % client.RF_getsmac();
@@ -64,8 +60,8 @@ if(sys.argv[1]=="sniffob"):
     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.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(0x06,0x09); #2MBps, -18dBm in RF_SETUP
     client.poke(0x07,0x78); #Reset status register
     
@@ -79,12 +75,12 @@ if(sys.argv[1]=="sniffob"):
     #client.poke(0x11,16);
     client.RF_setpacketlen(16);
     
     #client.poke(0x11,16);
     client.RF_setpacketlen(16);
     
-    client.status();
     #Power radio, prime for RX, checksum.
     client.poke(0x00,0x70|0x03|0x08);
     
     
     #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:
     #Now we're ready to get packets.
     
     while 1: