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: master.cpp
- Branch:
- multipipe
- Revision:
- 51:090149c4aa28
- Parent:
- 50:e83e38fece23
- Child:
- 54:2551a3c781cf
diff -r e83e38fece23 -r 090149c4aa28 master.cpp
--- a/master.cpp Tue Jan 17 14:41:20 2017 +0100
+++ b/master.cpp Wed Jan 18 16:57:05 2017 +0100
@@ -4,20 +4,22 @@
#include "cantcoap.h"
#include <sstream>
+const int boards_count = 3;
+
+
int master_loop() {
Serial pc(USBTX, USBRX); // tx, rx
Serial wifi(PA_9, PA_10);
nRF24L01P radio(PB_15, PB_14, PB_13, PB_12, PB_1, PB_2); // mosi, miso, sck, csn, ce, irq
- const unsigned long long RX_ADDRESS = MASTER_ADDRESS;
- const unsigned long long TX_ADDRESS = BOARD1_ADDRESS;
-
char rxData[TRANSFER_SIZE];
pc.baud(115200);
wifi.baud(115200);
- radio_init(&radio, RX_ADDRESS, TX_ADDRESS);
+ vector<unsigned long long> rx_addresses(addresses, addresses + boards_count);
+
+ radio_init_master(&radio, rx_addresses);
// Display the (default) setup of the nRF24L01+ chip
pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", radio.getRfFrequency() );
@@ -26,6 +28,8 @@
pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", radio.getTxAddress() );
pc.printf( "nRF24L01+ RX0 Address : 0x%010llX\r\n", radio.getRxAddress(NRF24L01P_PIPE_P0) );
pc.printf( "nRF24L01+ RX1 Address : 0x%010llX\r\n", radio.getRxAddress(NRF24L01P_PIPE_P1) );
+ pc.printf( "nRF24L01+ RX2 Address : 0x%010llX\r\n", radio.getRxAddress(NRF24L01P_PIPE_P2) );
+ pc.printf( "nRF24L01+ RX3 Address : 0x%010llX\r\n", radio.getRxAddress(NRF24L01P_PIPE_P3) );
CoapPDU *pdu = new CoapPDU();
pdu->setType(CoapPDU::COAP_NON_CONFIRMABLE);
@@ -33,11 +37,15 @@
pdu->setURI((char*)"pir1",4);
while (1) {
- if(radio.readable(NRF24L01P_PIPE_P1)){
- int rx_bytes = radio.read(NRF24L01P_PIPE_P1, rxData, sizeof(rxData));
- std::string output = str_hex(rxData, rx_bytes);
- wifi.printf("received: %s\r\n", output.c_str());
- pc.printf("received: %s\r\n", output.c_str());
+ for (int board = 0; board < boards_count; ++board) {
+ int pipe = pipes[board];
+ //pc.printf("pipe: %x\r\n", pipe);
+ if(radio.readable(pipe)){
+ int rx_bytes = radio.read(pipe, rxData, sizeof(rxData));
+ std::string output = str_hex(rxData, rx_bytes);
+ wifi.printf("received: %s\r\n", output.c_str());
+ pc.printf("received: %s\r\n", output.c_str());
+ }
}
}
}