testing

Dependencies:   mbed nRF24L01P

Fork of nRF24L01P_Hello_World by Owen Edwards

Revision:
2:653be5496b69
Parent:
1:5be2682710c6
--- a/main.cpp	Wed Jan 19 23:53:19 2011 +0000
+++ b/main.cpp	Tue Mar 31 01:38:31 2015 +0000
@@ -8,6 +8,8 @@
 DigitalOut myled1(LED1);
 DigitalOut myled2(LED2);
 
+Timer t;
+
 int main() {
 
 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
@@ -18,6 +20,8 @@
     char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
     int txDataCnt = 0;
     int rxDataCnt = 0;
+    int tmpDataCnt = 0;
+    char tmpData[TRANSFER_SIZE+1];
 
     my_nrf24l01p.powerUp();
 
@@ -46,9 +50,11 @@
             // If the transmit buffer is full
             if ( txDataCnt >= sizeof( txData ) ) {
 
+                t.start();
+                
                 // Send the transmitbuffer via the nRF24L01+
                 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
-
+                
                 txDataCnt = 0;
             }
 
@@ -58,14 +64,38 @@
 
         // If we've received anything in the nRF24L01+...
         if ( my_nrf24l01p.readable() ) {
-
+                
             // ...read the data into the receive buffer
             rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
 
             // Display the receive buffer contents via the host serial link
             for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
-
+            
                 pc.putc( rxData[i] );
+                tmpData[tmpDataCnt++] = rxData[i]; 
+            }
+            
+            if ( tmpDataCnt >= TRANSFER_SIZE ) {
+                tmpData[TRANSFER_SIZE] = '\0';
+                //pc.printf( "Received data : %s \r\n", tmpData);
+                if (strcmp(tmpData, "ackn"))
+                {
+                    tmpData[0] = 'a';
+                    tmpData[1] = 'c';
+                    tmpData[2] = 'k';
+                    tmpData[3] = 'n';
+                    //pc.printf( "Sending data : %s \r\n", "ackn");
+                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, tmpData, tmpDataCnt );  
+                }
+                else
+                {
+                    t.stop();
+                    pc.printf("\r\nThe time taken was %f seconds \r\n", t.read());
+                    t.reset();
+                }
+                
+                 
+                tmpDataCnt = 0;   
             }
 
             // Toggle LED2 (to help debug nRF24L01+ -> Host communication)