FN
Dependencies: mbed RF24Network RF24
main.cpp@4:93d0253a8a32, 2019-01-21 (annotated)
- Committer:
- wesleytiem
- Date:
- Mon Jan 21 15:03:09 2019 +0000
- Revision:
- 4:93d0253a8a32
- Parent:
- 3:e9c4d66da50c
- Child:
- 5:ddab03ae19aa
c'est bon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:3982c0e9eda1 | 1 | #include "mbed.h" |
akashvibhute | 0:3982c0e9eda1 | 2 | #include <RF24Network.h> |
akashvibhute | 2:608cf8c5c55e | 3 | #include <RF24.h> |
akashvibhute | 0:3982c0e9eda1 | 4 | |
akashvibhute | 0:3982c0e9eda1 | 5 | Serial pc(USBTX, USBRX); |
akashvibhute | 0:3982c0e9eda1 | 6 | |
wesleytiem | 4:93d0253a8a32 | 7 | RF24 radio(SPI_MOSI, SPI_MISO, SPI_SCK, D9, SPI_CS ); |
akashvibhute | 0:3982c0e9eda1 | 8 | |
akashvibhute | 0:3982c0e9eda1 | 9 | // Network uses that radio |
akashvibhute | 0:3982c0e9eda1 | 10 | RF24Network network(radio); |
akashvibhute | 0:3982c0e9eda1 | 11 | |
akashvibhute | 0:3982c0e9eda1 | 12 | // Address of our node |
akashvibhute | 3:e9c4d66da50c | 13 | const uint16_t this_node = 00; |
akashvibhute | 0:3982c0e9eda1 | 14 | |
akashvibhute | 0:3982c0e9eda1 | 15 | // Address of the other node |
akashvibhute | 3:e9c4d66da50c | 16 | const uint16_t other_node = 01; |
akashvibhute | 0:3982c0e9eda1 | 17 | |
akashvibhute | 0:3982c0e9eda1 | 18 | // When did we last send? |
akashvibhute | 0:3982c0e9eda1 | 19 | unsigned long last_sent; |
akashvibhute | 0:3982c0e9eda1 | 20 | |
akashvibhute | 0:3982c0e9eda1 | 21 | // How many have we sent already |
akashvibhute | 0:3982c0e9eda1 | 22 | unsigned long packets_sent; |
akashvibhute | 0:3982c0e9eda1 | 23 | |
akashvibhute | 0:3982c0e9eda1 | 24 | // Structure of our payload |
akashvibhute | 2:608cf8c5c55e | 25 | struct payload_t |
akashvibhute | 0:3982c0e9eda1 | 26 | { |
akashvibhute | 2:608cf8c5c55e | 27 | unsigned long ms; |
akashvibhute | 2:608cf8c5c55e | 28 | unsigned long counter; |
akashvibhute | 0:3982c0e9eda1 | 29 | }; |
akashvibhute | 0:3982c0e9eda1 | 30 | |
akashvibhute | 0:3982c0e9eda1 | 31 | |
akashvibhute | 2:608cf8c5c55e | 32 | int main() |
akashvibhute | 0:3982c0e9eda1 | 33 | { |
wesleytiem | 4:93d0253a8a32 | 34 | pc.baud(115200); |
akashvibhute | 0:3982c0e9eda1 | 35 | wait_ms(1000); |
akashvibhute | 2:608cf8c5c55e | 36 | |
akashvibhute | 2:608cf8c5c55e | 37 | pc.printf("mBed RF24Network node\n"); |
akashvibhute | 0:3982c0e9eda1 | 38 | radio.begin(); |
akashvibhute | 0:3982c0e9eda1 | 39 | network.begin(/*channel*/ 90, /*node address*/ this_node); |
akashvibhute | 0:3982c0e9eda1 | 40 | wait_ms(2000); |
akashvibhute | 2:608cf8c5c55e | 41 | |
akashvibhute | 2:608cf8c5c55e | 42 | while(1) |
akashvibhute | 0:3982c0e9eda1 | 43 | { |
akashvibhute | 0:3982c0e9eda1 | 44 | // Pump the network regularly |
akashvibhute | 0:3982c0e9eda1 | 45 | network.update(); |
wesleytiem | 4:93d0253a8a32 | 46 | |
akashvibhute | 0:3982c0e9eda1 | 47 | // Is there anything ready for us? |
akashvibhute | 2:608cf8c5c55e | 48 | while ( network.available() ) |
akashvibhute | 0:3982c0e9eda1 | 49 | { |
akashvibhute | 0:3982c0e9eda1 | 50 | // If so, grab it and print it out |
akashvibhute | 0:3982c0e9eda1 | 51 | RF24NetworkHeader header_rx; |
akashvibhute | 0:3982c0e9eda1 | 52 | payload_t payload_rx; |
akashvibhute | 0:3982c0e9eda1 | 53 | network.read(header_rx,&payload_rx,sizeof(payload_rx)); |
wesleytiem | 4:93d0253a8a32 | 54 | pc.printf("Received packet # %d at %d ms\r\n",payload_rx.counter,payload_rx.ms); |
akashvibhute | 0:3982c0e9eda1 | 55 | } |
akashvibhute | 1:5be48a9550c3 | 56 | |
akashvibhute | 0:3982c0e9eda1 | 57 | } |
akashvibhute | 2:608cf8c5c55e | 58 | |
akashvibhute | 0:3982c0e9eda1 | 59 | } |