receiving side for swimmers

Dependencies:   mbed nRF24L01P

Files at this revision

API Documentation at this revision

Comitter:
jkaderka
Date:
Fri Mar 13 21:36:14 2015 +0000
Parent:
0:210056f4d794
Child:
2:528f274c6fed
Commit message:
Data transfer changed to binary, speed increased to 2M

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Feb 28 14:47:46 2015 +0000
+++ b/main.cpp	Fri Mar 13 21:36:14 2015 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "nRF24L01P.h"
 
-#define BUFFER_SIZE 32//(sizeof(int)*4 + sizeof(float)*3)
+#define BUFFER_SIZE (sizeof(int)*4 + sizeof(float)*3)
 #define BAUDR 115200
 
 #define SAVING_START 'S'
@@ -69,21 +69,40 @@
 
 void communication(void)
 {
-    char buffer[BUFFER_SIZE+1];
+    char rxBuf[BUFFER_SIZE+1];
     int bytes;
+    int counter, acc_x, acc_y, acc_z;
+    float gyro_x, gyro_y, gyro_z;
     
     printf("\n\nReceiving data\n\r");
     while(1) {
         if (pc.readable())
             send_cmd();
 
-        bytes = rf.read(NRF24L01P_PIPE_P0, buffer, BUFFER_SIZE);
+        bytes = rf.read(NRF24L01P_PIPE_P0, rxBuf, BUFFER_SIZE);
         if (bytes <= 0)
             continue;
 
         send_ack();
-        buffer[bytes] = '\0';
-        printf("%s", buffer);
+
+        counter = *((int *) rxBuf);
+        acc_x = *((int *) &rxBuf[sizeof(int)]);
+        acc_y = *((int *) &rxBuf[sizeof(int)*2]);
+        acc_z = *((int *) &rxBuf[sizeof(int)*3]);
+        gyro_x = *((float *) &rxBuf[sizeof(int)*4]);
+        gyro_y = *((float *) &rxBuf[sizeof(int)*4 + sizeof(float)]);
+        gyro_z = *((float *) &rxBuf[sizeof(int)*4 + sizeof(float)*2]);
+        
+        /* transmission start */
+        if (counter == -1 && acc_x >= 0) {
+            printf("Swimmer id: %d\n", acc_x);
+            continue;
+        }
+        if (counter == -1 && acc_x == -1) {
+            printf("End of DATA\n");
+            continue;    
+        }
+        printf("%d %d %d %d %f %f %f\n", counter, acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z);
     }
 }
 
@@ -93,7 +112,7 @@
     
     rf.setTransferSize(BUFFER_SIZE);
     rf.setRfOutputPower(NRF24L01P_TX_PWR_ZERO_DB);
-    rf.setAirDataRate(NRF24L01P_DATARATE_1_MBPS);
+    rf.setAirDataRate(NRF24L01P_DATARATE_2_MBPS);
     rf.setReceiveMode();
     rf.enable();