+ if self.addresses[addr]>1 or rate>0.01:
+ print "'%s' looks valid\t%i\t%0.5f" % (
+ addr,count,rate);
+ return addr;
+ tunecount=0;
+ def selftune(self,threshold=2,forever=False,
+ delay=5.0):
+ """Tunes to the first strong signal.
+ It's important that this not get triggered by false positives."""
+
+ while 1:
+ self.retune();
+ start=time.mktime(time.localtime());
+ sys.stdout.flush();
+ while (time.mktime(time.localtime())-start) < delay:
+ packet=None;
+ while packet==None:
+ packet=client.RF_rxpacket();
+ addr=guesser.handle(packet);
+ try:
+ count=self.addresses[addr];
+ except:
+ count=0;
+ if count>threshold and forever==False:
+ #Tune it in here?
+ client.tune(addr);
+ return addr;
+
+
+ def retune(self):
+ """Tunes to another channel or preamble looking for the next packet."""
+ count=self.tunecount;
+ self.tunecount=count+1;
+
+ #Swap the SYNC value most often.
+ if self.sync:
+ sync=0x00AA;
+ if count&1:
+ sync=0x0055;
+ self.client.RF_setsmac(sync);
+ count=(count>>1);
+
+ if self.rate:
+ #Then the data rate.
+ rate=0;
+
+ #This swaps between 1Mbps and 2Mbps.
+ #TODO add support for 256kbps, if anyone uses it.
+ if count&1:
+ rate=rate|0x08;
+ #print "Setting rate to 0x%02x" % rate;
+ if(rate==0x20):
+ rate=0x08;
+ self.client.poke(0x06,rate);
+ count=(count>>1);
+
+ if self.chan:
+ self.client.poke(0x05,
+ (count+self.startch)&0x7f);
+ print "Tuned to %i MHz" % (
+ self.client.RF_getfreq()
+ /(10**6));
+ #Grab two packets to clear buffers.
+ #Should retune only after a few packets to reduce this delay.
+ packet=client.RF_rxpacket();
+ packet=client.RF_rxpacket();