IoT - Kubus / Mbed 2 deprecated Kubus

Dependencies:   mbed nRF24L01P

Branch:
multipipe
Revision:
51:090149c4aa28
Parent:
49:79d7eddb1f1d
Child:
56:065bd3a75d97
diff -r e83e38fece23 -r 090149c4aa28 common.cpp
--- a/common.cpp	Tue Jan 17 14:41:20 2017 +0100
+++ b/common.cpp	Wed Jan 18 16:57:05 2017 +0100
@@ -1,5 +1,11 @@
 #include "common.h"
 #include <cstring>
+#include <vector>
+
+using std::vector;
+
+const int pipes[] = {NRF24L01P_PIPE_P1, NRF24L01P_PIPE_P2, NRF24L01P_PIPE_P3, NRF24L01P_PIPE_P4};
+const unsigned long long addresses[] = {0x42424201, 0x42424202, 0x42424203};
 
 std::string Data::serialize() {
     std::string serialized;
@@ -26,8 +32,7 @@
     return ss.str();
 }
 
-void radio_init(nRF24L01P* radio, unsigned long long rx_address,
-        unsigned long long tx_address) {
+void radio_init_sensor_board(nRF24L01P* radio, unsigned long long tx_address) {
     radio->powerDown();
     radio->powerUp();
 
@@ -36,13 +41,9 @@
     radio->setRfFrequency(NRF24L01P_MIN_RF_FREQUENCY + 4 * CHANNEL);
 
     radio->setCrcWidth(NRF24L01P_CRC_8_BIT);
-    radio->enableAutoAcknowledge(NRF24L01P_PIPE_P0);
-    radio->enableAutoAcknowledge(NRF24L01P_PIPE_P1);
     radio->enableAutoRetransmit(0x0F, 0x0F);
 
     radio->setTxAddress(tx_address, 4);
-    radio->setRxAddress(tx_address, 4, NRF24L01P_PIPE_P0);
-    radio->setRxAddress(rx_address, 4, NRF24L01P_PIPE_P1);
 
     radio->setTransferSize(TRANSFER_SIZE, NRF24L01P_PIPE_P0);
     radio->setTransferSize(TRANSFER_SIZE, NRF24L01P_PIPE_P1);
@@ -50,3 +51,36 @@
     radio->setReceiveMode();
     radio->enable();
 }
+
+void radio_init_master(nRF24L01P* radio, const std::vector<unsigned long long> &rx_addresses) {
+    radio->powerDown();
+    radio->powerUp();
+
+    radio->setAirDataRate(DATA_RATE);
+    radio->setRfOutputPower(POWER);
+    radio->setRfFrequency(NRF24L01P_MIN_RF_FREQUENCY + 4 * CHANNEL);
+
+    radio->setCrcWidth(NRF24L01P_CRC_8_BIT);
+    //radio->enableAutoAcknowledge(NRF24L01P_PIPE_P0);
+    //radio->enableAutoAcknowledge(NRF24L01P_PIPE_P1);
+    radio->enableAutoRetransmit(0x0F, 0x0F);
+
+    int pipe_nr = 0;
+    for (vector<unsigned long long>::const_iterator address = rx_addresses.begin(); address != rx_addresses.end(); ++address) {
+        int pipe = pipes[pipe_nr];
+        radio->setRxAddress(*address, 4, pipe);
+        radio->enableAutoAcknowledge(pipe);
+        radio->setTransferSize(TRANSFER_SIZE, pipe);
+        ++pipe_nr;
+    }
+
+    // radio->setTxAddress(tx_address, 4);
+    // radio->setRxAddress(tx_address, 4, NRF24L01P_PIPE_P0);
+    // radio->setRxAddress(rx_address, 4, NRF24L01P_PIPE_P1);
+
+    // radio->setTransferSize(TRANSFER_SIZE, NRF24L01P_PIPE_P0);
+    // radio->setTransferSize(TRANSFER_SIZE, NRF24L01P_PIPE_P1);
+
+    radio->setReceiveMode();
+    radio->enable();
+}