![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
in d mix
Dependencies: xtoff2 RF24Network mbed
Fork of RF24Network_Receive by
Ontvanger.cpp@14:3e69c8a9c730, 2018-07-12 (annotated)
- Committer:
- pietor
- Date:
- Thu Jul 12 08:56:54 2018 +0000
- Revision:
- 14:3e69c8a9c730
- Parent:
- 13:f54dfb74247e
f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pietor | 4:7ebc3b421306 | 1 | #include "Ontvanger.h" |
pietor | 4:7ebc3b421306 | 2 | |
pietor | 13:f54dfb74247e | 3 | Serial pc2(USBTX, USBRX); |
pietor | 4:7ebc3b421306 | 4 | RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN ); |
pietor | 4:7ebc3b421306 | 5 | RF24Network network(radio); |
pietor | 4:7ebc3b421306 | 6 | |
pietor | 4:7ebc3b421306 | 7 | RF24NetworkHeader header_rx; |
pietor | 4:7ebc3b421306 | 8 | |
pietor | 4:7ebc3b421306 | 9 | Ontvanger::Ontvanger() |
pietor | 4:7ebc3b421306 | 10 | { |
pietor | 4:7ebc3b421306 | 11 | radio.begin(); |
pietor | 4:7ebc3b421306 | 12 | network.begin(90, this_node); |
pietor | 4:7ebc3b421306 | 13 | wait_ms(2000); |
pietor | 10:0a4c465f7838 | 14 | radio.setPALevel(RF24_PA_MIN); |
pietor | 10:0a4c465f7838 | 15 | radio.setDataRate(RF24_250KBPS); |
pietor | 4:7ebc3b421306 | 16 | }; |
pietor | 4:7ebc3b421306 | 17 | |
pietor | 4:7ebc3b421306 | 18 | void Ontvanger::update() |
pietor | 4:7ebc3b421306 | 19 | { |
pietor | 4:7ebc3b421306 | 20 | network.update(); |
pietor | 4:7ebc3b421306 | 21 | } |
pietor | 4:7ebc3b421306 | 22 | |
pietor | 4:7ebc3b421306 | 23 | bool Ontvanger::available() |
pietor | 4:7ebc3b421306 | 24 | { |
pietor | 4:7ebc3b421306 | 25 | return network.available(); |
pietor | 4:7ebc3b421306 | 26 | } |
pietor | 4:7ebc3b421306 | 27 | |
pietor | 7:8515f205483b | 28 | |
pietor | 4:7ebc3b421306 | 29 | payload_t Ontvanger::read() |
pietor | 4:7ebc3b421306 | 30 | { |
pietor | 4:7ebc3b421306 | 31 | payload_t payload_rx; |
pietor | 4:7ebc3b421306 | 32 | network.read(header_rx,&payload_rx,sizeof(payload_rx)); |
pietor | 13:f54dfb74247e | 33 | |
pietor | 13:f54dfb74247e | 34 | if(payload_rx.messageAvailable == true) |
pietor | 13:f54dfb74247e | 35 | printMessage(payload_rx.messageIndex); |
pietor | 13:f54dfb74247e | 36 | |
pietor | 4:7ebc3b421306 | 37 | return payload_rx; |
pietor | 7:8515f205483b | 38 | } |
pietor | 7:8515f205483b | 39 | |
pietor | 7:8515f205483b | 40 | bool Ontvanger::write(state_Packet message) |
pietor | 7:8515f205483b | 41 | { |
pietor | 7:8515f205483b | 42 | RF24NetworkHeader header_tx(other_node); |
pietor | 7:8515f205483b | 43 | state_Packet packet; |
pietor | 7:8515f205483b | 44 | packet = message; |
pietor | 11:77018fac195e | 45 | |
pietor | 7:8515f205483b | 46 | return network.write(header_tx,&packet,sizeof(packet)); |
pietor | 7:8515f205483b | 47 | } |
pietor | 7:8515f205483b | 48 | |
pietor | 10:0a4c465f7838 | 49 | bool Ontvanger::isValid() |
pietor | 10:0a4c465f7838 | 50 | { |
pietor | 10:0a4c465f7838 | 51 | return radio.isValid(); |
pietor | 10:0a4c465f7838 | 52 | } |
pietor | 7:8515f205483b | 53 | |
pietor | 10:0a4c465f7838 | 54 | bool Ontvanger::testRPD() |
pietor | 10:0a4c465f7838 | 55 | { |
pietor | 10:0a4c465f7838 | 56 | return radio.testRPD(); |
pietor | 10:0a4c465f7838 | 57 | } |
pietor | 10:0a4c465f7838 | 58 | |
pietor | 13:f54dfb74247e | 59 | void Ontvanger::printMessage(char index){ |
pietor | 13:f54dfb74247e | 60 | switch (index) { |
pietor | 13:f54dfb74247e | 61 | case '1': |
pietor | 13:f54dfb74247e | 62 | pc2.printf("Message: Initializing...\n\r"); |
pietor | 13:f54dfb74247e | 63 | break; |
pietor | 13:f54dfb74247e | 64 | case '2': |
pietor | 13:f54dfb74247e | 65 | pc2.printf("Message: Taring...\n\r"); |
pietor | 13:f54dfb74247e | 66 | break; |
pietor | 13:f54dfb74247e | 67 | case '3': |
pietor | 13:f54dfb74247e | 68 | pc2.printf("Message: Error: Tare first\n\r"); |
pietor | 13:f54dfb74247e | 69 | break; |
pietor | 13:f54dfb74247e | 70 | case '4': |
pietor | 13:f54dfb74247e | 71 | pc2.printf("Message: Tare completed\n\r"); |
pietor | 13:f54dfb74247e | 72 | break; |
pietor | 13:f54dfb74247e | 73 | case '5': |
pietor | 13:f54dfb74247e | 74 | pc2.printf("Message: Error: Tare value to low... Retry\n\r"); |
pietor | 13:f54dfb74247e | 75 | break; |
pietor | 13:f54dfb74247e | 76 | case '6': |
pietor | 13:f54dfb74247e | 77 | pc2.printf("Message: Waiting on the right position...\n\r"); |
pietor | 13:f54dfb74247e | 78 | break; |
pietor | 13:f54dfb74247e | 79 | case '7': |
pietor | 13:f54dfb74247e | 80 | pc2.printf("Message: Wait 5 Seconds on POSITION...\n\r"); |
pietor | 13:f54dfb74247e | 81 | break; |
pietor | 13:f54dfb74247e | 82 | case '8': |
pietor | 13:f54dfb74247e | 83 | pc2.printf("Message: ERROR: Not on position\n\r"); |
pietor | 13:f54dfb74247e | 84 | break; |
pietor | 13:f54dfb74247e | 85 | } |
pietor | 13:f54dfb74247e | 86 | } |
pietor | 10:0a4c465f7838 | 87 | |
pietor | 13:f54dfb74247e | 88 |