Better sniffing of 802.15.4 in CCSPI, but the length is still wrong.
[goodfet] / firmware / apps / radios / ccspi.c
index dd86e8c..d7fba81 100644 (file)
@@ -139,14 +139,32 @@ void ccspi_handle_fn( uint8_t const app,
     txdata(app,verb,0);
     break;
   case CCSPI_RX:
-    //Get the packet.
-    CLRSS;
-    ccspitrans8(CCSPI_RXFIFO);
-    for(i=0;i<32;i++)
-      cmddata[i]=ccspitrans8(0xde);
-    SETSS;
-    //no break
-    txdata(app,verb,32);
+    #ifdef FIFOP
+    //Wait for any incoming packet to finish.
+    //while(!SFD);
+    while(SFD);
+    delay(1000);
+    
+    
+    //Is there a packet?
+    if((!SFD)){
+      //Get the packet.
+      CLRSS;
+      //ccspitrans8(CCSPI_RXFIFO);
+      ccspitrans8(0x3F|0x40);
+      cmddata[1]=0xff; //to be replaced with length
+      for(i=0;i<cmddata[1];i++)
+       cmddata[i]=ccspitrans8(0xde);
+      SETSS;
+      txdata(app,verb,cmddata[0]);
+    }else{
+      //No packet.
+      txdata(app,verb,0);
+    }
+    #else
+    debugstr("Can't RX a packet with SFD and FIFOP definitions.");
+    txdata(app,NOK,0);
+    #endif
     break;
   case CCSPI_RX_FLUSH:
     //Flush the buffer.
@@ -154,11 +172,21 @@ void ccspi_handle_fn( uint8_t const app,
     ccspitrans8(CCSPI_SFLUSHRX);
     SETSS;
     
-    //Return the packet.
-    txdata(app,verb,32);
+    txdata(app,verb,0);
+    break;
+  case CCSPI_REFLEX:
+    debugstr("Coming soon.");
+    txdata(app,verb,0);
     break;
-  case CCSPI_TX:
   case CCSPI_TX_FLUSH:
+     //Flush the buffer.
+    CLRSS;
+    ccspitrans8(CCSPI_SFLUSHTX);
+    SETSS;
+    
+    txdata(app,verb,0);
+    break;
+  case CCSPI_TX:
   default:
     debugstr("Not yet supported.");
     txdata(app,verb,0);