RF24Network Send example program.

Dependencies:   xtoff RF24Network mbed

Fork of RF24Network_Send by Akash Vibhute

Committer:
pietor
Date:
Tue Jul 10 12:07:26 2018 +0000
Revision:
12:38c5efed7950
Parent:
11:2aa84e063c49
pom

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pietor 5:e6067799a414 1 #ifndef Verzender_h
pietor 5:e6067799a414 2 #define Verzender_h
pietor 5:e6067799a414 3 #include "mbed.h"
pietor 5:e6067799a414 4 #include <RF24Network.h>
pietor 5:e6067799a414 5 #include <RF24.h>
pietor 5:e6067799a414 6
pietor 12:38c5efed7950 7 #define nrf_CE D4
pietor 12:38c5efed7950 8 #define nrf_CSN D3
pietor 12:38c5efed7950 9 #define spi_SCK A1
pietor 12:38c5efed7950 10 #define spi_MOSI A6
pietor 12:38c5efed7950 11 #define spi_MISO A5
pietor 5:e6067799a414 12
pietor 11:2aa84e063c49 13 #define INIT '1'
pietor 11:2aa84e063c49 14 #define TARE '2'
pietor 11:2aa84e063c49 15 #define TARE_FIRST '3'
pietor 11:2aa84e063c49 16 #define TARE_COMPLETE '4'
pietor 11:2aa84e063c49 17 #define TARE_ERROR '5'
pietor 11:2aa84e063c49 18 #define POSITION '6'
pietor 11:2aa84e063c49 19 #define POSITION_WAIT '7'
pietor 11:2aa84e063c49 20 #define POSITION_ERROR '8'
pietor 12:38c5efed7950 21 #define READ '9'
pietor 12:38c5efed7950 22 #define RECEIVE 'a'
pietor 12:38c5efed7950 23 #define STARTUP 'b'
pietor 12:38c5efed7950 24 #define STARTUP_SUCCES 'c'
pietor 12:38c5efed7950 25 #define BATTERY 'd'
pietor 11:2aa84e063c49 26
pietor 11:2aa84e063c49 27
pietor 10:875812a04307 28 #ifdef PRINT_ENABLE
pietor 10:875812a04307 29 #define IF_PRINT_ENABLE(x) ({x;})
pietor 10:875812a04307 30 #else
pietor 10:875812a04307 31 #define IF_PRINT_ENABLE(x)
pietor 10:875812a04307 32 #endif
pietor 10:875812a04307 33
pietor 9:6d8c0b946259 34 //Identificatie verzender/ontvanger
pietor 5:e6067799a414 35 const uint16_t this_node = 01;
pietor 5:e6067799a414 36 const uint16_t other_node = 00;
pietor 8:62b4607c44ca 37
pietor 5:e6067799a414 38 struct payload_t {
pietor 5:e6067799a414 39 bool reedsensor;
pietor 11:2aa84e063c49 40 float gram;
pietor 11:2aa84e063c49 41 bool messageAvailable;
pietor 11:2aa84e063c49 42 char messageIndex;
pietor 5:e6067799a414 43 };
pietor 5:e6067799a414 44
pietor 6:03ba3e18ced2 45 enum State {State_init,
pietor 6:03ba3e18ced2 46 State_tare,
pietor 6:03ba3e18ced2 47 State_position,
pietor 6:03ba3e18ced2 48 State_read,
pietor 10:875812a04307 49 State_receive,
pietor 10:875812a04307 50 State_calibrate
pietor 6:03ba3e18ced2 51 };
pietor 6:03ba3e18ced2 52
pietor 6:03ba3e18ced2 53 struct state_Packet {
pietor 11:2aa84e063c49 54 char setstate;
pietor 6:03ba3e18ced2 55 };
pietor 6:03ba3e18ced2 56
pietor 6:03ba3e18ced2 57
pietor 5:e6067799a414 58 class Verzender
pietor 5:e6067799a414 59 {
pietor 5:e6067799a414 60 private:
pietor 5:e6067799a414 61
pietor 5:e6067799a414 62
pietor 5:e6067799a414 63 public:
pietor 5:e6067799a414 64 Verzender();
pietor 9:6d8c0b946259 65
pietor 9:6d8c0b946259 66 /**
pietor 9:6d8c0b946259 67 Update to receive a message available for this node
pietor 9:6d8c0b946259 68 */
pietor 5:e6067799a414 69 void update();
pietor 9:6d8c0b946259 70
pietor 9:6d8c0b946259 71
pietor 9:6d8c0b946259 72 /**
pietor 9:6d8c0b946259 73 Send a message to the receiver
pietor 9:6d8c0b946259 74
pietor 9:6d8c0b946259 75 @param message of type payload_t
pietor 9:6d8c0b946259 76 */
pietor 5:e6067799a414 77 bool write(payload_t message);
pietor 9:6d8c0b946259 78
pietor 9:6d8c0b946259 79
pietor 9:6d8c0b946259 80 /**
pietor 9:6d8c0b946259 81 Test whether there is a message available for this node
pietor 9:6d8c0b946259 82 */
pietor 6:03ba3e18ced2 83 bool available();
pietor 9:6d8c0b946259 84
pietor 9:6d8c0b946259 85
pietor 9:6d8c0b946259 86 /**
pietor 9:6d8c0b946259 87 Read a message to the receiver
pietor 9:6d8c0b946259 88
pietor 9:6d8c0b946259 89 @return message of type state_packet
pietor 9:6d8c0b946259 90 */
pietor 6:03ba3e18ced2 91 state_Packet read();
pietor 11:2aa84e063c49 92
pietor 11:2aa84e063c49 93
pietor 11:2aa84e063c49 94 /*messageIndex:
pietor 11:2aa84e063c49 95 0: Nothing wrong
pietor 11:2aa84e063c49 96 1: Tare first
pietor 11:2aa84e063c49 97 2: Error on Position
pietor 11:2aa84e063c49 98 3: Bad Tare value (<2.5V)
pietor 11:2aa84e063c49 99 */
pietor 11:2aa84e063c49 100 void sendMessage(char index);
pietor 12:38c5efed7950 101
pietor 12:38c5efed7950 102 void Verzender::printDetails();
pietor 5:e6067799a414 103 };
pietor 5:e6067799a414 104
pietor 5:e6067799a414 105 #endif
pietor 5:e6067799a414 106
pietor 5:e6067799a414 107
pietor 5:e6067799a414 108
pietor 5:e6067799a414 109
pietor 5:e6067799a414 110