Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: common.cpp
- Branch:
- multipipe
- Revision:
- 51:090149c4aa28
- Parent:
- 49:79d7eddb1f1d
- Child:
- 56:065bd3a75d97
--- 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();
+}