X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFETCCSPI.py;h=36c8bd7ed1ad4c5fa9c4926a58a8cdaf069986d7;hp=612ce3e685ca2f4bb2f9c0ae2946db9114179e06;hb=ca4deae50d7d2098d372d903d33879f9f951c75c;hpb=73a31780aab1bea70e6e201dad4c752a3e253536 diff --git a/client/GoodFETCCSPI.py b/client/GoodFETCCSPI.py index 612ce3e..36c8bd7 100644 --- a/client/GoodFETCCSPI.py +++ b/client/GoodFETCCSPI.py @@ -19,6 +19,7 @@ class GoodFETCCSPI(GoodFET): #Set up the radio for ZigBee self.strobe(0x01); #SXOSCON + self.strobe(0x02); #SCAL self.poke(0x11, 0x0AC2); #MDMCTRL0 self.poke(0x12, 0x0500); #MDMCTRL1 self.poke(0x1C, 0x007F); #IOCFG0 @@ -91,8 +92,22 @@ class GoodFETCCSPI(GoodFET): def status(self): """Read the status byte.""" + statusbits={0x80: "?", + 0x40: "XOSC16M_STABLE", + 0x20: "TX_UNDERFLOW", + 0x10: "ENC_BUSY", + 0x08: "TX_ACTIVE", + 0x04: "LOCK", + 0x02: "RSSI_VALID", + 0x01: "?"}; status=self.strobe(0x00); - print "Status=%02x" % status; + i=1; + str=""; + while i<0x100: + if status&i: + str="%s %s" % (statusbits[i],str); + i*=2; + return str; #Radio stuff begins here. def RF_setenc(self,code="802.15.4"): @@ -111,6 +126,7 @@ class GoodFETCCSPI(GoodFET): fsctrl=self.peek(0x18)&~0x3FF; fsctrl=fsctrl+int(mhz-2048) self.poke(0x18,fsctrl); + self.strobe(0x02); def RF_getfreq(self): """Get the frequency in Hz.""" fsctrl=self.peek(0x18); @@ -140,9 +156,6 @@ class GoodFETCCSPI(GoodFET): contents. """ - # TODO -- Flush only if there's an overflow. - #self.strobe(0x08); #SFLUSHRX - data="\0"; self.data=data; self.writecmd(self.CCSPIAPP,0x80,len(data),data); @@ -152,37 +165,21 @@ class GoodFETCCSPI(GoodFET): if(len(buffer)==0): return None; return buffer; - def RF_rxpacket_old(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. - """ - self.strobe(0x03); #SRXON - self.strobe(0x08); #SFLUSHRX - - buffer=range(0,0xff); - buffer[0]=0x3F | 0x40; #RXFIFO - buffer=self.trans(buffer); - - new=False; - for foo in range(0,ord(buffer[0])): - if buffer[foo]!=self.lastpacket[foo]: - new=True; - if not new: - return None; - - - self.lastpacket=buffer; - return buffer; + def RF_txpacket(self,packet): + """Send a packet through the radio.""" + self.writecmd(self.CCSPIAPP,0x81,len(packet),packet); + #time.sleep(1); + #self.strobe(0x09); + return; + def RF_carrier(self): """Hold a carrier wave on the present frequency.""" print "Don't know how to hold a carrier."; def RF_promiscuity(self,promiscuous=1): mdmctrl0=self.peek(0x11); - print "mdmctrl0 was %04x" % mdmctrl0; + #print "mdmctrl0 was %04x" % mdmctrl0; mdmctrl0=mdmctrl0&(~0x800); - print "mdmctrl0 is now %04x" % mdmctrl0; + #print "mdmctrl0 is now %04x" % mdmctrl0; self.poke(0x11,mdmctrl0); return;