![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
RF24Network Send example program.
Dependencies: xtoff RF24Network mbed
Fork of RF24Network_Send by
Verzender.cpp@12:38c5efed7950, 2018-07-10 (annotated)
- Committer:
- pietor
- Date:
- Tue Jul 10 12:07:26 2018 +0000
- Revision:
- 12:38c5efed7950
- Parent:
- 11:2aa84e063c49
pom
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pietor | 5:e6067799a414 | 1 | #include "Verzender.h" |
pietor | 5:e6067799a414 | 2 | |
pietor | 5:e6067799a414 | 3 | RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN ); |
pietor | 5:e6067799a414 | 4 | RF24Network network(radio); |
pietor | 5:e6067799a414 | 5 | unsigned long packets_sent; |
pietor | 6:03ba3e18ced2 | 6 | RF24NetworkHeader header_rx; |
pietor | 12:38c5efed7950 | 7 | char previous_char; |
pietor | 8:62b4607c44ca | 8 | |
pietor | 8:62b4607c44ca | 9 | /** |
pietor | 8:62b4607c44ca | 10 | Constructor: Initialize RF24 and RF24Network |
pietor | 8:62b4607c44ca | 11 | */ |
pietor | 5:e6067799a414 | 12 | Verzender::Verzender() |
pietor | 5:e6067799a414 | 13 | { |
pietor | 9:6d8c0b946259 | 14 | wait_ms(2000); |
pietor | 5:e6067799a414 | 15 | radio.begin(); |
pietor | 8:62b4607c44ca | 16 | network.begin(90, this_node); |
pietor | 5:e6067799a414 | 17 | wait_ms(2000); |
pietor | 9:6d8c0b946259 | 18 | radio.setPALevel(RF24_PA_MIN); |
pietor | 9:6d8c0b946259 | 19 | radio.setDataRate(RF24_250KBPS); |
pietor | 12:38c5efed7950 | 20 | |
pietor | 5:e6067799a414 | 21 | } |
pietor | 5:e6067799a414 | 22 | |
pietor | 5:e6067799a414 | 23 | void Verzender::update() |
pietor | 5:e6067799a414 | 24 | { |
pietor | 5:e6067799a414 | 25 | network.update(); |
pietor | 5:e6067799a414 | 26 | } |
pietor | 5:e6067799a414 | 27 | |
pietor | 11:2aa84e063c49 | 28 | bool Verzender::write(payload_t packet) |
pietor | 5:e6067799a414 | 29 | { |
pietor | 5:e6067799a414 | 30 | RF24NetworkHeader header_tx(other_node); |
pietor | 5:e6067799a414 | 31 | payload_t payload_tx; |
pietor | 11:2aa84e063c49 | 32 | payload_tx = packet; |
pietor | 11:2aa84e063c49 | 33 | |
pietor | 11:2aa84e063c49 | 34 | payload_tx.messageIndex = 0; |
pietor | 11:2aa84e063c49 | 35 | payload_tx.messageAvailable = false; |
pietor | 11:2aa84e063c49 | 36 | |
pietor | 5:e6067799a414 | 37 | return network.write(header_tx,&payload_tx,sizeof(payload_tx)); |
pietor | 5:e6067799a414 | 38 | } |
pietor | 6:03ba3e18ced2 | 39 | |
pietor | 11:2aa84e063c49 | 40 | void Verzender::sendMessage(char index){ |
pietor | 12:38c5efed7950 | 41 | |
pietor | 12:38c5efed7950 | 42 | if(previous_char != index){ |
pietor | 11:2aa84e063c49 | 43 | RF24NetworkHeader header_tx(other_node); |
pietor | 11:2aa84e063c49 | 44 | payload_t payload_message; |
pietor | 11:2aa84e063c49 | 45 | payload_message.messageIndex = index; |
pietor | 11:2aa84e063c49 | 46 | payload_message.messageAvailable = true; |
pietor | 11:2aa84e063c49 | 47 | bool test = network.write(header_tx,&payload_message,sizeof(payload_message)); |
pietor | 12:38c5efed7950 | 48 | } |
pietor | 12:38c5efed7950 | 49 | previous_char = index; |
pietor | 11:2aa84e063c49 | 50 | } |
pietor | 8:62b4607c44ca | 51 | |
pietor | 6:03ba3e18ced2 | 52 | state_Packet Verzender::read() |
pietor | 6:03ba3e18ced2 | 53 | { |
pietor | 6:03ba3e18ced2 | 54 | state_Packet packet; |
pietor | 6:03ba3e18ced2 | 55 | network.read(header_rx,&packet,sizeof(packet)); |
pietor | 11:2aa84e063c49 | 56 | |
pietor | 6:03ba3e18ced2 | 57 | return packet; |
pietor | 6:03ba3e18ced2 | 58 | } |
pietor | 6:03ba3e18ced2 | 59 | |
pietor | 6:03ba3e18ced2 | 60 | bool Verzender::available() |
pietor | 6:03ba3e18ced2 | 61 | { |
pietor | 6:03ba3e18ced2 | 62 | return network.available(); |
pietor | 11:2aa84e063c49 | 63 | } |
pietor | 12:38c5efed7950 | 64 | |
pietor | 12:38c5efed7950 | 65 | void Verzender::printDetails(){ |
pietor | 12:38c5efed7950 | 66 | radio.printDetails(); |
pietor | 12:38c5efed7950 | 67 | } |