#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
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);
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);
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.";
packet=client.RF_rxpacket();
printpacket(packet);
sys.stdout.flush();
+if(sys.argv[1]=="txtest"):
+ if len(sys.argv)>2:
+ freq=eval(sys.argv[2]);
+ if freq>100:
+ client.RF_setfreq(freq);
+ else:
+ print "Channels not yet supported."
+ print "Transmitting as %010x on %i MHz" % (
+ client.RF_getsmac(),
+ client.RF_getfreq()/10**6);
+
+ while 1:
+ client.RF_txpacket([0x0f, 0x01, 0x08, 0x82,
+ 0xff, 0xff, 0xff, 0xff,
+ 0x4d, 0x7d, 0x09, 0x00,
+ 0x1f, 0x00, 0xc0]);
+ print client.status();
+ print;
+
if(sys.argv[1]=="peek"):
start=0x0000;
if(len(sys.argv)>2):
txdata(app,verb,0);
break;
case CCSPI_RX:
- #ifdef FIFOP
-
+#ifdef FIFOP
//Has there been an overflow?
if((!FIFO)&&FIFOP){
debugstr("Clearing overflow");
ccspitrans8(CCSPI_RXFIFO | 0x40);
//ccspitrans8(0x3F|0x40);
cmddata[0]=0xff; //to be replaced with length
- for(i=0;i<cmddata[0];i++)
+ for(i=0;i<cmddata[0]+2;i++)
cmddata[i]=ccspitrans8(0xde);
SETSS;
CLRSS;
ccspitrans8(0x08); //SFLUSHRX
SETSS;
- txdata(app,verb,i);
+ txdata(app,verb,cmddata[0]+2);
}else{
//No packet.
txdata(app,verb,0);
}
- #else
+#else
debugstr("Can't RX a packet with SFD and FIFOP definitions.");
txdata(app,NOK,0);
- #endif
+#endif
break;
case CCSPI_RX_FLUSH:
//Flush the buffer.
txdata(app,verb,0);
break;
case CCSPI_TX:
+#ifdef FIFOP
+
+ /* //Has there been an overflow?
+ if(ccspi_status()&BIT5){
+ debugstr("Clearing underflow");
+ CLRSS;
+ ccspitrans8(0x09); //SFLUSHTX
+ SETSS;
+ }
+ */
+
+
+ //Wait for last packet to TX.
+ //while(ccspi_status()&BIT3);
+
+ //Load the packet.
+ CLRSS;
+ ccspitrans8(CCSPI_TXFIFO);
+ for(i=0;i<cmddata[0];i++)
+ ccspitrans8(cmddata[i]);
+ SETSS;
+
+ //Transmit the packet.
+ CLRSS;
+ ccspitrans8(0x04); //STXON
+ SETSS;
+
+
+ txdata(app,verb,0);
+#else
+ debugstr("Can't TX a packet with SFD and FIFOP definitions.");
+ txdata(app,NOK,0);
+#endif
+ break;
default:
- debugstr("Not yet supported.");
+ debugstr("Not yet supported in CCSPI");
txdata(app,verb,0);
break;
}