Working Simpliciti implementation.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 12 Dec 2010 19:43:05 +0000 (19:43 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 12 Dec 2010 19:43:05 +0000 (19:43 +0000)
Call 'goodfet.cc simpliciti [us|eu|lf]' to dump accelerometer data from a Chronos watch.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@790 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETCC.py
client/goodfet.cc
shellcode/chipcon/cc1110/rxpacket.c
shellcode/chipcon/cc1110/txpacket.c
shellcode/chipcon/cc1110/txrxpacket.c

index 01b6668..9397201 100644 (file)
@@ -95,7 +95,6 @@ class GoodFETCC(GoodFET):
         self.pokebysym("TEST1",0x31);
         self.pokebysym("TEST0",0x09);
         
         self.pokebysym("TEST1",0x31);
         self.pokebysym("TEST0",0x09);
         
-        #self.pokebysym("PA_TABLE0" ,   0x60);  #above mid
         
         #self.pokebysym("FSCAL2" ,   0x2A);  #above mid
         self.pokebysym("FSCAL2" ,   0x0A);  #beneath mid
         
         #self.pokebysym("FSCAL2" ,   0x2A);  #above mid
         self.pokebysym("FSCAL2" ,   0x0A);  #beneath mid
@@ -214,7 +213,7 @@ class GoodFETCC(GoodFET):
         return;
         
     def config_simpliciti(self,band="none"):
         return;
         
     def config_simpliciti(self,band="none"):
-        self.pokebysym("FSCTRL1"  , 0x08)   # Frequency synthesizer control.
+        self.pokebysym("FSCTRL1"  , 0x0C) #08   # Frequency synthesizer control.
         self.pokebysym("FSCTRL0"  , 0x00)   # Frequency synthesizer control.
         
         #Don't change these while the radio is active.
         self.pokebysym("FSCTRL0"  , 0x00)   # Frequency synthesizer control.
         
         #Don't change these while the radio is active.
@@ -264,7 +263,7 @@ class GoodFETCC(GoodFET):
         self.pokebysym("TEST2"    , 0x81)   # Various test settings.
         self.pokebysym("TEST1"    , 0x35)   # Various test settings.
         self.pokebysym("TEST0"    , 0x09)   # Various test settings.
         self.pokebysym("TEST2"    , 0x81)   # Various test settings.
         self.pokebysym("TEST1"    , 0x35)   # Various test settings.
         self.pokebysym("TEST0"    , 0x09)   # Various test settings.
-        self.pokebysym("PA_TABLE0", 0xC0)   # PA output power setting.
+        self.pokebysym("PA_TABLE0", 0xc0)   # Max output power.
         self.pokebysym("PKTCTRL1" , 0x04)   # Packet automation control, w/ lqi
         #self.pokebysym("PKTCTRL1" , 0x00)   # Packet automation control. w/o lqi
         self.pokebysym("PKTCTRL0" , 0x05)   # Packet automation control, w/ checksum.
         self.pokebysym("PKTCTRL1" , 0x04)   # Packet automation control, w/ lqi
         #self.pokebysym("PKTCTRL1" , 0x00)   # Packet automation control. w/o lqi
         self.pokebysym("PKTCTRL0" , 0x05)   # Packet automation control, w/ checksum.
@@ -341,7 +340,7 @@ class GoodFETCC(GoodFET):
         """Get a packet from the radio.  Returns None if none is waiting."""
         self.shellcodefile("rxpacket.ihx");
         len=self.peek8(0xFE00,"xdata");
         """Get a packet from the radio.  Returns None if none is waiting."""
         self.shellcodefile("rxpacket.ihx");
         len=self.peek8(0xFE00,"xdata");
-        return self.peekblock(0xFE00,len+1,"data");
+        return self.peekblock(0xFE00,len+3,"data");
     def RF_txpacket(self,packet):
         """Transmit a packet.  Untested."""
         
     def RF_txpacket(self,packet):
         """Transmit a packet.  Untested."""
         
@@ -354,7 +353,7 @@ class GoodFETCC(GoodFET):
         self.pokeblock(0xFE00,packet,"data");
         self.shellcodefile("txrxpacket.ihx");
         len=self.peek8(0xFE00,"xdata");
         self.pokeblock(0xFE00,packet,"data");
         self.shellcodefile("txrxpacket.ihx");
         len=self.peek8(0xFE00,"xdata");
-        return self.peekblock(0xFE00,len+1,"data");
+        return self.peekblock(0xFE00,len+3,"data");
 
     def RF_getrssi(self):
         """Returns the received signal strenght, with a weird offset."""
 
     def RF_getrssi(self):
         """Returns the received signal strenght, with a weird offset."""
index 20b0405..a7a0494 100755 (executable)
@@ -16,23 +16,17 @@ from intelhex import IntelHex;
 def printpacket(packet):
     s="";
     i=0;
 def printpacket(packet):
     s="";
     i=0;
-    #print "Printing packet."
     for foo in packet:
         i=i+1;
     for foo in packet:
         i=i+1;
-        #if i>packet[0]+1: break;
         s="%s %02x" % (s,foo);
         s="%s %02x" % (s,foo);
-    print "%s" %s;
+    print "%s" %s;
 
 
+simplepacketcount=0;
 def handlesimplicitipacket(packet):
     s="";
     i=0;
 def handlesimplicitipacket(packet):
     s="";
     i=0;
-    
-    for foo in packet:
-        i=i+1;
-        #if i>packet[0]+1: break;
-        s="%s %02x" % (s,foo);
-    print "\n%s" %s;
-    
+    global simplepacketcount;
+    simplepacketcount=simplepacketcount+1;
     
     len=packet[0];
     if len<12: return;
     
     len=packet[0];
     if len<12: return;
@@ -50,13 +44,38 @@ def handlesimplicitipacket(packet):
     seq=packet[11];
     #payload begins at byte 10.
     
     seq=packet[11];
     #payload begins at byte 10.
     
-    
-    if port==0x20:
+    if packet[len+2]&0x80==0:
+        print "# Dropped broken packet.";
+    elif port==0x20:
         #data packet
         #data packet
-        x=packet[11];
-        y=packet[13];
+        counter=packet[11];
+        button=packet[12];
+        x=packet[13];
+        y=packet[14];
         z=packet[15];
         z=packet[15];
-        print "%02x: %i %i %i" % (seq,x,y,z);
+        print "%09i %03i %4i %4i %4i" % (simplepacketcount,button,x,y,z);
+        sys.stdout.flush();
+    elif port==0x02:
+        #Link request.  Gotta send a proper reply to get data.
+        tid=packet[13];
+        #14 ff ff ff ff 3c b7 e3 98 
+        #02 03 c9
+        #01 97
+        #ef be ad de 3d 00 02 
+        reply=[0x10,
+               src[0], src[1], src[2], src[3],
+               0x78,0x56,0x34,0x10, #my address.
+               port, 0x21, seq,
+               0x81, tid,         #reply, tid
+               
+               0x20,0x00,0xad,0xde, #Join token
+               0x00];             #no security
+        printpacket(reply);
+        print "#FIXME FAST: repeatedly broadcasting ACK to catch LINK on the next attempt.";
+        for foo in range(1,50):
+            client.RF_txpacket(reply);
+        
+        pass;
     elif port==0x03:
         #print "Join request.";
         if packet[12]!=1:
     elif port==0x03:
         #print "Join request.";
         if packet[12]!=1:
@@ -65,18 +84,18 @@ def handlesimplicitipacket(packet):
         tid=packet[13];
         reply=[0x12, #reply is one byte shorter
                src[0], src[1], src[2], src[3],
         tid=packet[13];
         reply=[0x12, #reply is one byte shorter
                src[0], src[1], src[2], src[3],
-               1,1,1,1,           #my address
+               0x78,0x56,0x34,0x10, #my address.
                port, 0x21, seq,
                0x81, tid,         #reply, tid
                
                port, 0x21, seq,
                0x81, tid,         #reply, tid
                
-               1,1,1,1,
-               #4,3,2,1,           #default join token
-               #8,7,6,5,          #default link token
-               #0xFF,0xFF,0xFF,0xFF,
+               0xef,0xbe,0xad,0xde, #Join token
                0x00];             #no security
         printpacket(reply);
                0x00];             #no security
         printpacket(reply);
-        client.RF_txpacket(reply);
-
+        print "#FIXME FAST: repeatedly broadcasting ACK to catch JOIN on the next attempt.";
+        for foo in range(1,50):
+            client.RF_txpacket(reply);
+        #printpacket(reply);
+        
     elif port==0x04:
         print "Security request.";
     elif port==0x05:
     elif port==0x04:
         print "Security request.";
     elif port==0x05:
@@ -231,7 +250,7 @@ if(sys.argv[1]=="simpliciti"):
     
     client.config_simpliciti(region);
     
     
     client.config_simpliciti(region);
     
-    print "Listening as %x on %f MHz" % (client.RF_getsmac(),
+    print "Listening as %x on %f MHz" % (client.RF_getsmac(),
                                            client.RF_getfreq()/10.0**6);
     #Now we're ready to get packets.
     while 1:
                                            client.RF_getfreq()/10.0**6);
     #Now we're ready to get packets.
     while 1:
index 5ba32a5..0535f0b 100644 (file)
@@ -8,31 +8,35 @@ char __xdata at 0xfe00 packet[MAXLEN] ;
 void main(){
   unsigned char len=16, i=0;
   
 void main(){
   unsigned char len=16, i=0;
   
-  //1-out the buffer.
-  for(i=0;i<64;i++)
-    packet[i]=0xFF;
-  i=0;
-  
-  //Disable interrupts.
-  RFTXRXIE=0;
-  
-  //idle a bit.
-  //RFST=RFST_SIDLE;
-  //while(MARCSTATE!=MARC_STATE_IDLE);
-  
-  //Begin to receive.
-  RFST=RFST_SRX;
-  while(MARCSTATE!=MARC_STATE_RX);
+  do{
+    //1-out the buffer.
+    for(i=0;i<64;i++)
+      packet[i]=0xFF;
+    i=0;
+    
+    //Disable interrupts.
+    RFTXRXIE=0;
+    
+    //idle a bit.
+    RFST=RFST_SIDLE;
+    while(MARCSTATE!=MARC_STATE_IDLE);
+    
+    //Begin to receive.
+    RFST=RFST_SRX;
+    while(MARCSTATE!=MARC_STATE_RX);
   
   
-  while(i<len+1){ //len+3 if status is appended.
-    while(!RFTXRXIF); //Wait for byte to be ready.
-    RFTXRXIF=0;      //Clear the flag.
+    while(i<len+3){ //len+3 if status is appended.
+      while(!RFTXRXIF); //Wait for byte to be ready.
+      RFTXRXIF=0;      //Clear the flag.
+      
+      packet[i++]=RFD; //Grab the next byte.
+      len=packet[0];   //First byte of the packet is the length.
+    }
+    RFST = RFST_SIDLE; //End receive.
     
     
-    packet[i]=RFD; //Grab the next byte.
-    i++;
-    len=packet[0];   //First byte of the packet is the length.
-  }
-  RFST = RFST_SIDLE; //End receive.
+    //This while loop can be used for filtering.  Unused for now.
+  }while(0); //packet[0]==(char) 0x0f || packet[1]==(char) 0xFF || packet[9]==(char) 0x03);
+  
   HALT;
 }
 
   HALT;
 }
 
index e41ce49..87a37b7 100644 (file)
@@ -3,9 +3,17 @@
 
 char __xdata at 0xfe00 packet[256] ;
 
 
 char __xdata at 0xfe00 packet[256] ;
 
+void sleepMillis(int ms) {
+       int j;
+       while (--ms > 0) { 
+               for (j=0; j<1200;j++); // about 1 millisecond
+       };
+}
+
 //! Transmit a packet out of the radio from 0xFE00.
 void main(){
   unsigned char len=packet[0], i=0;
 //! Transmit a packet out of the radio from 0xFE00.
 void main(){
   unsigned char len=packet[0], i=0;
+  long j;
   
   //Disable interrupts.
   RFTXRXIE=0;
   
   //Disable interrupts.
   RFTXRXIE=0;
@@ -18,12 +26,16 @@ void main(){
   RFST=RFST_STX;     //Begin transmit.
   while(MARCSTATE!=MARC_STATE_TX);
   
   RFST=RFST_STX;     //Begin transmit.
   while(MARCSTATE!=MARC_STATE_TX);
   
-  while(i!=len+1){
+  while(i<len+1){
     while(!RFTXRXIF); //Wait for byte to be ready.
     while(!RFTXRXIF); //Wait for byte to be ready.
-    
+    while(MARCSTATE!=MARC_STATE_TX); //Lockup if needed.
     RFTXRXIF=0;      //Clear the flag.
     RFD=packet[i++]; //Send the next byte.
   }
     RFTXRXIF=0;      //Clear the flag.
     RFD=packet[i++]; //Send the next byte.
   }
-  RFST = RFST_SIDLE; //End transmit.
+  
+  //Wait for transmission to complete.
+  while(MARCSTATE==MARC_STATE_TX);
+
+  //RFST = RFST_SIDLE; //End transmit.
   HALT;
 }
   HALT;
 }
index 1fdb0f1..acde9e2 100644 (file)
@@ -5,23 +5,26 @@ char __xdata at 0xfe00 packet[256] ;
 
 //! Transmit a packet out of the radio from 0xFE00.
 void main(){
 
 //! Transmit a packet out of the radio from 0xFE00.
 void main(){
-  unsigned char len=packet[0], i=0;
-  
+  unsigned char len=packet[0], i=0, j;
+
   //idle a bit.
   RFST=RFST_SIDLE;
   while(MARCSTATE!=MARC_STATE_IDLE);
   
   RFST=RFST_STX;     //Begin transmit.
   //idle a bit.
   RFST=RFST_SIDLE;
   while(MARCSTATE!=MARC_STATE_IDLE);
   
   RFST=RFST_STX;     //Begin transmit.
+  i=0;
   while(i!=len+1){
     while(!RFTXRXIF); //Wait for byte to be ready.
     
     RFTXRXIF=0;      //Clear the flag.
     RFD=packet[i++]; //Send the next byte.
   }
   while(i!=len+1){
     while(!RFTXRXIF); //Wait for byte to be ready.
     
     RFTXRXIF=0;      //Clear the flag.
     RFD=packet[i++]; //Send the next byte.
   }
-  RFST = RFST_SIDLE; //End transmit.
   
   
+  //Wait for completion.
+  while(MARCSTATE==MARC_STATE_TX);
   
   
-  while(MARCSTATE!=MARC_STATE_IDLE);
+  //RFST = RFST_SIDLE; //End transmit.
+  //while(MARCSTATE!=MARC_STATE_IDLE);
   
   //Begin to receive.
   RFST=RFST_SRX;
   
   //Begin to receive.
   RFST=RFST_SRX;