receiving side for swimmers

Dependencies:   mbed nRF24L01P

Files at this revision

API Documentation at this revision

Comitter:
jkaderka
Date:
Sat Feb 28 14:47:46 2015 +0000
Child:
1:29fdc2c617f8
Commit message:
first commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF24L01P.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 28 14:47:46 2015 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "nRF24L01P.h"
+
+#define BUFFER_SIZE 32//(sizeof(int)*4 + sizeof(float)*3)
+#define BAUDR 115200
+
+#define SAVING_START 'S'
+#define SAVING_STOP 'E'
+#define TRANSFER_START 'T'
+#define CHECK_READY 'R'
+#define SEND_ACK 'A'
+
+#define NACK 'N'
+#define ACK 'A'
+
+Serial pc(USBTX, USBRX);
+nRF24L01P rf(p5, p6, p7, p8, p9);
+//nRF24L01P rf(p11, p12, p13, p14, p15);
+DigitalOut led(LED1);
+
+
+void send_ack()
+{
+    char buffer[BUFFER_SIZE];
+    buffer[0] = 0x00;
+    buffer[1] = SEND_ACK;
+    
+    rf.write(NRF24L01P_PIPE_P0, buffer, BUFFER_SIZE);    
+}
+
+void check_ack()
+{
+    char buffer[BUFFER_SIZE];
+    wait_ms(10);
+    if (!rf.readable()) { 
+        printf("#%c\n", NACK);
+        return;
+    }
+
+    rf.read(NRF24L01P_PIPE_P0, buffer, BUFFER_SIZE);
+    if (buffer[0] != 0x00 || buffer[1] != SEND_ACK)
+        printf("#%c\n", NACK);
+    
+    printf("#%c\n", ACK);
+}
+
+int send_cmd(void)
+{
+    char buffer[BUFFER_SIZE];
+    char c;
+    static char last = 0;
+    
+    c = pc.getc();
+    if (c != '#' && last != 1)
+        return -1;
+    if (c == '#') {
+        last = 1;
+        return 0;    
+    }
+    
+    last = 0;
+
+    buffer[0] = 0x00;
+    buffer[1] = c;
+    rf.write(NRF24L01P_PIPE_P0, buffer, BUFFER_SIZE);
+    check_ack();
+    return 0;
+}
+
+void communication(void)
+{
+    char buffer[BUFFER_SIZE+1];
+    int bytes;
+    
+    printf("\n\nReceiving data\n\r");
+    while(1) {
+        if (pc.readable())
+            send_cmd();
+
+        bytes = rf.read(NRF24L01P_PIPE_P0, buffer, BUFFER_SIZE);
+        if (bytes <= 0)
+            continue;
+
+        send_ack();
+        buffer[bytes] = '\0';
+        printf("%s", buffer);
+    }
+}
+
+int main(void)
+{
+    pc.baud(BAUDR);
+    
+    rf.setTransferSize(BUFFER_SIZE);
+    rf.setRfOutputPower(NRF24L01P_TX_PWR_ZERO_DB);
+    rf.setAirDataRate(NRF24L01P_DATARATE_1_MBPS);
+    rf.setReceiveMode();
+    rf.enable();
+    
+    printf("Freq: %d MHz\n\r", rf.getRfFrequency());
+    printf("Power: %d dBm\n\r", rf.getRfOutputPower());
+    printf("TX Address: %llu\n\r", rf.getTxAddress());
+    printf("RX Address: %llu\n\r", rf.getRxAddress());
+    
+    communication();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Feb 28 14:47:46 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24L01P.lib	Sat Feb 28 14:47:46 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Owen/code/nRF24L01P/#8ae48233b4e4