Polytech school project. RICM4 students, see http://air.imag.fr/index.php/Projets-2016-2017-Station_de_pompage_connect%C3%A9e for more information
Fork of SX1276PingPong by
main.cpp@16:1643ac8ba29f, 2017-04-01 (annotated)
- Committer:
- chevamax
- Date:
- Sat Apr 01 12:14:27 2017 +0000
- Revision:
- 16:1643ac8ba29f
- Parent:
- 15:0439a7579868
Version finale
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:1ed39951ab7b | 1 | #include "mbed.h" |
GregCr | 4:5ece30264cd9 | 2 | #include "main.h" |
GregCr | 14:c7251480feb9 | 3 | #include "sx1276-hal.h" |
GregCr | 8:f956dee63a56 | 4 | #include "debug.h" |
chevamax | 16:1643ac8ba29f | 5 | #include "ordre.h" |
chevamax | 16:1643ac8ba29f | 6 | #include "trame.h" |
GregCr | 0:1ed39951ab7b | 7 | |
chevamax | 16:1643ac8ba29f | 8 | /* Set this flag to '1' to display debug messages on the console |
chevamax | 16:1643ac8ba29f | 9 | Must be 0 in order to work with the projet |
chevamax | 16:1643ac8ba29f | 10 | */ |
chevamax | 16:1643ac8ba29f | 11 | #define DEBUG_MESSAGE 0 |
chevamax | 15:0439a7579868 | 12 | |
chevamax | 16:1643ac8ba29f | 13 | #define ID_DEVICE 0x24 |
chevamax | 15:0439a7579868 | 14 | #define ID_STATION 0x55 |
chevamax | 16:1643ac8ba29f | 15 | #define TEMPS_ATTENTE_COM 20 |
GregCr | 0:1ed39951ab7b | 16 | |
GregCr | 0:1ed39951ab7b | 17 | /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ |
GregCr | 5:f2431c4fe3bb | 18 | #define USE_MODEM_LORA 1 |
GregCr | 0:1ed39951ab7b | 19 | #define USE_MODEM_FSK !USE_MODEM_LORA |
GregCr | 0:1ed39951ab7b | 20 | |
chevamax | 15:0439a7579868 | 21 | #define RF_FREQUENCY 865000000 // Hz |
GregCr | 0:1ed39951ab7b | 22 | #define TX_OUTPUT_POWER 14 // 14 dBm |
GregCr | 0:1ed39951ab7b | 23 | |
GregCr | 0:1ed39951ab7b | 24 | #if USE_MODEM_LORA == 1 |
GregCr | 0:1ed39951ab7b | 25 | |
GregCr | 1:126d70d374f6 | 26 | #define LORA_BANDWIDTH 2 // [0: 125 kHz, |
GregCr | 0:1ed39951ab7b | 27 | // 1: 250 kHz, |
GregCr | 0:1ed39951ab7b | 28 | // 2: 500 kHz, |
GregCr | 0:1ed39951ab7b | 29 | // 3: Reserved] |
GregCr | 0:1ed39951ab7b | 30 | #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] |
GregCr | 0:1ed39951ab7b | 31 | #define LORA_CODINGRATE 1 // [1: 4/5, |
GregCr | 0:1ed39951ab7b | 32 | // 2: 4/6, |
GregCr | 0:1ed39951ab7b | 33 | // 3: 4/7, |
GregCr | 0:1ed39951ab7b | 34 | // 4: 4/8] |
GregCr | 0:1ed39951ab7b | 35 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
GregCr | 0:1ed39951ab7b | 36 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
GregCr | 0:1ed39951ab7b | 37 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
GregCr | 3:8b9e2a4df4b5 | 38 | #define LORA_FHSS_ENABLED false |
GregCr | 3:8b9e2a4df4b5 | 39 | #define LORA_NB_SYMB_HOP 4 |
GregCr | 0:1ed39951ab7b | 40 | #define LORA_IQ_INVERSION_ON false |
GregCr | 3:8b9e2a4df4b5 | 41 | #define LORA_CRC_ENABLED true |
GregCr | 3:8b9e2a4df4b5 | 42 | |
GregCr | 0:1ed39951ab7b | 43 | #elif USE_MODEM_FSK == 1 |
GregCr | 0:1ed39951ab7b | 44 | |
GregCr | 2:59e108728d71 | 45 | #define FSK_FDEV 25000 // Hz |
GregCr | 2:59e108728d71 | 46 | #define FSK_DATARATE 19200 // bps |
GregCr | 2:59e108728d71 | 47 | #define FSK_BANDWIDTH 50000 // Hz |
GregCr | 2:59e108728d71 | 48 | #define FSK_AFC_BANDWIDTH 83333 // Hz |
GregCr | 0:1ed39951ab7b | 49 | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
GregCr | 0:1ed39951ab7b | 50 | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
GregCr | 3:8b9e2a4df4b5 | 51 | #define FSK_CRC_ENABLED true |
GregCr | 3:8b9e2a4df4b5 | 52 | |
GregCr | 0:1ed39951ab7b | 53 | #else |
GregCr | 0:1ed39951ab7b | 54 | #error "Please define a modem in the compiler options." |
GregCr | 0:1ed39951ab7b | 55 | #endif |
GregCr | 0:1ed39951ab7b | 56 | |
GregCr | 7:c1bbd6c56979 | 57 | #define RX_TIMEOUT_VALUE 3500000 // in us |
GregCr | 0:1ed39951ab7b | 58 | #define BUFFER_SIZE 32 // Define the payload size here |
GregCr | 0:1ed39951ab7b | 59 | |
GregCr | 8:f956dee63a56 | 60 | #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) |
GregCr | 3:8b9e2a4df4b5 | 61 | DigitalOut led(LED2); |
GregCr | 3:8b9e2a4df4b5 | 62 | #else |
GregCr | 3:8b9e2a4df4b5 | 63 | DigitalOut led(LED1); |
GregCr | 3:8b9e2a4df4b5 | 64 | #endif |
GregCr | 3:8b9e2a4df4b5 | 65 | |
GregCr | 0:1ed39951ab7b | 66 | /* |
GregCr | 0:1ed39951ab7b | 67 | * Global variables declarations |
GregCr | 0:1ed39951ab7b | 68 | */ |
mluis | 10:7af820d1e1df | 69 | typedef enum |
mluis | 10:7af820d1e1df | 70 | { |
mluis | 10:7af820d1e1df | 71 | LOWPOWER = 0, |
mluis | 10:7af820d1e1df | 72 | IDLE, |
mluis | 10:7af820d1e1df | 73 | |
mluis | 10:7af820d1e1df | 74 | RX, |
mluis | 10:7af820d1e1df | 75 | RX_TIMEOUT, |
mluis | 10:7af820d1e1df | 76 | RX_ERROR, |
mluis | 10:7af820d1e1df | 77 | |
mluis | 10:7af820d1e1df | 78 | TX, |
mluis | 10:7af820d1e1df | 79 | TX_TIMEOUT, |
mluis | 10:7af820d1e1df | 80 | |
mluis | 10:7af820d1e1df | 81 | CAD, |
mluis | 10:7af820d1e1df | 82 | CAD_DONE |
mluis | 10:7af820d1e1df | 83 | }AppStates_t; |
GregCr | 0:1ed39951ab7b | 84 | |
mluis | 10:7af820d1e1df | 85 | volatile AppStates_t State = LOWPOWER; |
mluis | 10:7af820d1e1df | 86 | |
mluis | 10:7af820d1e1df | 87 | /*! |
mluis | 10:7af820d1e1df | 88 | * Radio events function pointer |
mluis | 10:7af820d1e1df | 89 | */ |
mluis | 10:7af820d1e1df | 90 | static RadioEvents_t RadioEvents; |
mluis | 10:7af820d1e1df | 91 | |
mluis | 10:7af820d1e1df | 92 | /* |
mluis | 10:7af820d1e1df | 93 | * Global variables declarations |
mluis | 10:7af820d1e1df | 94 | */ |
GregCr | 14:c7251480feb9 | 95 | SX1276MB1xAS Radio( NULL ); |
GregCr | 0:1ed39951ab7b | 96 | |
GregCr | 0:1ed39951ab7b | 97 | uint16_t BufferSize = BUFFER_SIZE; |
GregCr | 0:1ed39951ab7b | 98 | uint8_t Buffer[BUFFER_SIZE]; |
GregCr | 0:1ed39951ab7b | 99 | |
GregCr | 5:f2431c4fe3bb | 100 | int16_t RssiValue = 0.0; |
GregCr | 5:f2431c4fe3bb | 101 | int8_t SnrValue = 0.0; |
GregCr | 0:1ed39951ab7b | 102 | |
chevamax | 16:1643ac8ba29f | 103 | //Connection serie avec le PC |
chevamax | 16:1643ac8ba29f | 104 | Serial pc(USBTX, USBRX); |
chevamax | 16:1643ac8ba29f | 105 | |
chevamax | 16:1643ac8ba29f | 106 | char portCom[3]; |
chevamax | 16:1643ac8ba29f | 107 | bool ordreRecuPortCom = false; |
chevamax | 16:1643ac8ba29f | 108 | |
chevamax | 16:1643ac8ba29f | 109 | |
GregCr | 0:1ed39951ab7b | 110 | int main() |
GregCr | 0:1ed39951ab7b | 111 | { |
GregCr | 0:1ed39951ab7b | 112 | uint8_t i; |
chevamax | 15:0439a7579868 | 113 | bool isMaster = false; |
GregCr | 0:1ed39951ab7b | 114 | |
chevamax | 16:1643ac8ba29f | 115 | debug_if( DEBUG_MESSAGE, "\n\n\r SX1276 Server Demo Application \n\n\r" ); |
mluis | 10:7af820d1e1df | 116 | |
mluis | 10:7af820d1e1df | 117 | // Initialize Radio driver |
mluis | 10:7af820d1e1df | 118 | RadioEvents.TxDone = OnTxDone; |
mluis | 10:7af820d1e1df | 119 | RadioEvents.RxDone = OnRxDone; |
mluis | 10:7af820d1e1df | 120 | RadioEvents.RxError = OnRxError; |
mluis | 10:7af820d1e1df | 121 | RadioEvents.TxTimeout = OnTxTimeout; |
mluis | 10:7af820d1e1df | 122 | RadioEvents.RxTimeout = OnRxTimeout; |
mluis | 10:7af820d1e1df | 123 | Radio.Init( &RadioEvents ); |
GregCr | 0:1ed39951ab7b | 124 | |
GregCr | 7:c1bbd6c56979 | 125 | // verify the connection with the board |
GregCr | 7:c1bbd6c56979 | 126 | while( Radio.Read( REG_VERSION ) == 0x00 ) |
GregCr | 2:59e108728d71 | 127 | { |
chevamax | 16:1643ac8ba29f | 128 | debug_if( DEBUG_MESSAGE, "Radio could not be detected!\n\r", NULL ); |
GregCr | 7:c1bbd6c56979 | 129 | wait( 1 ); |
GregCr | 2:59e108728d71 | 130 | } |
GregCr | 7:c1bbd6c56979 | 131 | |
GregCr | 14:c7251480feb9 | 132 | debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ) , "\n\r > Board Type: SX1276MB1LAS < \n\r" ); |
GregCr | 14:c7251480feb9 | 133 | debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1MAS ) ) , "\n\r > Board Type: SX1276MB1MAS < \n\r" ); |
GregCr | 14:c7251480feb9 | 134 | |
GregCr | 0:1ed39951ab7b | 135 | Radio.SetChannel( RF_FREQUENCY ); |
GregCr | 0:1ed39951ab7b | 136 | |
GregCr | 0:1ed39951ab7b | 137 | #if USE_MODEM_LORA == 1 |
GregCr | 3:8b9e2a4df4b5 | 138 | |
chevamax | 16:1643ac8ba29f | 139 | debug_if( DEBUG_MESSAGE & LORA_FHSS_ENABLED, "\n\n\r > LORA FHSS Mode < \n\n\r"); |
chevamax | 16:1643ac8ba29f | 140 | debug_if( DEBUG_MESSAGE & !LORA_FHSS_ENABLED, "\n\n\r > LORA Mode < \n\n\r"); |
GregCr | 7:c1bbd6c56979 | 141 | |
GregCr | 0:1ed39951ab7b | 142 | Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, |
GregCr | 0:1ed39951ab7b | 143 | LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
GregCr | 0:1ed39951ab7b | 144 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
GregCr | 3:8b9e2a4df4b5 | 145 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
GregCr | 7:c1bbd6c56979 | 146 | LORA_IQ_INVERSION_ON, 2000000 ); |
GregCr | 0:1ed39951ab7b | 147 | |
GregCr | 0:1ed39951ab7b | 148 | Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, |
GregCr | 0:1ed39951ab7b | 149 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
mluis | 9:e764990e45df | 150 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
GregCr | 3:8b9e2a4df4b5 | 151 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
GregCr | 3:8b9e2a4df4b5 | 152 | LORA_IQ_INVERSION_ON, true ); |
GregCr | 0:1ed39951ab7b | 153 | |
GregCr | 0:1ed39951ab7b | 154 | #elif USE_MODEM_FSK == 1 |
GregCr | 0:1ed39951ab7b | 155 | |
chevamax | 16:1643ac8ba29f | 156 | debug_if( DEBUG_MESSAGE, "\n\n\r > FSK Mode < \n\n\r"); |
GregCr | 0:1ed39951ab7b | 157 | Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, |
GregCr | 0:1ed39951ab7b | 158 | FSK_DATARATE, 0, |
GregCr | 0:1ed39951ab7b | 159 | FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, |
GregCr | 7:c1bbd6c56979 | 160 | FSK_CRC_ENABLED, 0, 0, 0, 2000000 ); |
GregCr | 0:1ed39951ab7b | 161 | |
GregCr | 0:1ed39951ab7b | 162 | Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, |
GregCr | 0:1ed39951ab7b | 163 | 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, |
mluis | 9:e764990e45df | 164 | 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED, |
GregCr | 3:8b9e2a4df4b5 | 165 | 0, 0, false, true ); |
GregCr | 0:1ed39951ab7b | 166 | |
GregCr | 0:1ed39951ab7b | 167 | #else |
GregCr | 0:1ed39951ab7b | 168 | |
GregCr | 0:1ed39951ab7b | 169 | #error "Please define a modem in the compiler options." |
GregCr | 0:1ed39951ab7b | 170 | |
GregCr | 0:1ed39951ab7b | 171 | #endif |
GregCr | 1:126d70d374f6 | 172 | |
chevamax | 15:0439a7579868 | 173 | debug_if( DEBUG_MESSAGE, "Starting Server loop\r\n" ); |
GregCr | 0:1ed39951ab7b | 174 | |
GregCr | 3:8b9e2a4df4b5 | 175 | led = 0; |
chevamax | 15:0439a7579868 | 176 | |
chevamax | 16:1643ac8ba29f | 177 | //ACK Message Par defaut |
chevamax | 16:1643ac8ba29f | 178 | char AckMsg[] = {0x24, 0x55, 0x00}; |
chevamax | 15:0439a7579868 | 179 | |
GregCr | 0:1ed39951ab7b | 180 | Radio.Rx( RX_TIMEOUT_VALUE ); |
GregCr | 0:1ed39951ab7b | 181 | |
chevamax | 16:1643ac8ba29f | 182 | //Varialbe de controle |
chevamax | 16:1643ac8ba29f | 183 | bool ackOrData = true; //true = ack, false = Data |
chevamax | 16:1643ac8ba29f | 184 | |
GregCr | 0:1ed39951ab7b | 185 | while( 1 ) |
GregCr | 0:1ed39951ab7b | 186 | { |
GregCr | 0:1ed39951ab7b | 187 | switch( State ) |
GregCr | 0:1ed39951ab7b | 188 | { |
GregCr | 0:1ed39951ab7b | 189 | case RX: |
chevamax | 15:0439a7579868 | 190 | if( BufferSize > 0 ) |
GregCr | 0:1ed39951ab7b | 191 | { |
chevamax | 16:1643ac8ba29f | 192 | TrameData trameRecue((char*)Buffer); |
chevamax | 16:1643ac8ba29f | 193 | if( trameRecue.getIdStation() == (char) ID_STATION ) |
GregCr | 0:1ed39951ab7b | 194 | { |
chevamax | 16:1643ac8ba29f | 195 | |
chevamax | 15:0439a7579868 | 196 | led = !led; |
chevamax | 16:1643ac8ba29f | 197 | debug_if( DEBUG_MESSAGE, "...DATA\r\n" ); |
chevamax | 16:1643ac8ba29f | 198 | |
chevamax | 16:1643ac8ba29f | 199 | //Envoit sur le port COM |
chevamax | 16:1643ac8ba29f | 200 | pc.printf(trameRecue.creerTrame()); |
chevamax | 16:1643ac8ba29f | 201 | |
chevamax | 16:1643ac8ba29f | 202 | // Send the ACK |
chevamax | 16:1643ac8ba29f | 203 | AckMsg[0] = trameRecue.getIdEmetteur(); |
chevamax | 16:1643ac8ba29f | 204 | |
chevamax | 16:1643ac8ba29f | 205 | strcpy( ( char* )Buffer, ( char* )AckMsg ); |
chevamax | 15:0439a7579868 | 206 | // We fill the buffer with numbers for the payload |
chevamax | 15:0439a7579868 | 207 | for( i = 3; i < BufferSize; i++ ) |
GregCr | 0:1ed39951ab7b | 208 | { |
chevamax | 15:0439a7579868 | 209 | Buffer[i] = i - 4; |
GregCr | 0:1ed39951ab7b | 210 | } |
chevamax | 16:1643ac8ba29f | 211 | wait( 5.0); |
chevamax | 16:1643ac8ba29f | 212 | ackOrData = true; |
chevamax | 15:0439a7579868 | 213 | Radio.Send( Buffer, BufferSize ); |
chevamax | 16:1643ac8ba29f | 214 | |
GregCr | 0:1ed39951ab7b | 215 | } |
chevamax | 16:1643ac8ba29f | 216 | else // valid reception but not expected |
chevamax | 16:1643ac8ba29f | 217 | { |
chevamax | 15:0439a7579868 | 218 | Radio.Rx( RX_TIMEOUT_VALUE ); |
chevamax | 15:0439a7579868 | 219 | } |
GregCr | 0:1ed39951ab7b | 220 | } |
GregCr | 0:1ed39951ab7b | 221 | State = LOWPOWER; |
GregCr | 0:1ed39951ab7b | 222 | break; |
GregCr | 3:8b9e2a4df4b5 | 223 | case TX: |
GregCr | 3:8b9e2a4df4b5 | 224 | led = !led; |
chevamax | 16:1643ac8ba29f | 225 | if(ackOrData){ |
chevamax | 16:1643ac8ba29f | 226 | debug_if( DEBUG_MESSAGE, "ACK...\r\n" ); |
chevamax | 16:1643ac8ba29f | 227 | //Après Envoie du ACK, on ecoute la réponse du PC (pour l'ordre) |
chevamax | 16:1643ac8ba29f | 228 | led = 1; |
chevamax | 16:1643ac8ba29f | 229 | pc.scanf("%s",portCom); |
chevamax | 16:1643ac8ba29f | 230 | led = 0; |
chevamax | 16:1643ac8ba29f | 231 | //Mise a jour des variables de controle |
chevamax | 16:1643ac8ba29f | 232 | ordreRecuPortCom = true; |
chevamax | 16:1643ac8ba29f | 233 | ackOrData = false; |
chevamax | 16:1643ac8ba29f | 234 | } |
chevamax | 16:1643ac8ba29f | 235 | else{ |
chevamax | 16:1643ac8ba29f | 236 | debug_if( DEBUG_MESSAGE, "ORDRE...\r\n" ); |
chevamax | 16:1643ac8ba29f | 237 | Radio.Rx( RX_TIMEOUT_VALUE ); |
chevamax | 16:1643ac8ba29f | 238 | } |
GregCr | 0:1ed39951ab7b | 239 | State = LOWPOWER; |
GregCr | 0:1ed39951ab7b | 240 | break; |
GregCr | 0:1ed39951ab7b | 241 | case RX_TIMEOUT: |
chevamax | 15:0439a7579868 | 242 | Radio.Rx( RX_TIMEOUT_VALUE ); |
GregCr | 0:1ed39951ab7b | 243 | State = LOWPOWER; |
GregCr | 0:1ed39951ab7b | 244 | break; |
GregCr | 0:1ed39951ab7b | 245 | case RX_ERROR: |
GregCr | 7:c1bbd6c56979 | 246 | // We have received a Packet with a CRC error, send reply as if packet was correct |
chevamax | 16:1643ac8ba29f | 247 | //Do nothing |
GregCr | 0:1ed39951ab7b | 248 | State = LOWPOWER; |
GregCr | 0:1ed39951ab7b | 249 | break; |
GregCr | 0:1ed39951ab7b | 250 | case TX_TIMEOUT: |
GregCr | 0:1ed39951ab7b | 251 | Radio.Rx( RX_TIMEOUT_VALUE ); |
GregCr | 0:1ed39951ab7b | 252 | State = LOWPOWER; |
GregCr | 0:1ed39951ab7b | 253 | break; |
GregCr | 0:1ed39951ab7b | 254 | case LOWPOWER: |
chevamax | 16:1643ac8ba29f | 255 | if(ordreRecuPortCom){ |
chevamax | 16:1643ac8ba29f | 256 | Ordre o((char *)portCom); |
chevamax | 16:1643ac8ba29f | 257 | debug_if( DEBUG_MESSAGE, "Ordre recu sur le port COM\r\n" ); |
chevamax | 16:1643ac8ba29f | 258 | led=!led; |
chevamax | 16:1643ac8ba29f | 259 | if(o.getOrdreAFaire() == 1){ |
chevamax | 16:1643ac8ba29f | 260 | //Envoie de l'ordre. |
chevamax | 16:1643ac8ba29f | 261 | strcpy( ( char* )Buffer, ( char* )portCom ); |
chevamax | 16:1643ac8ba29f | 262 | for( i = 3; i < BufferSize; i++ ) |
chevamax | 16:1643ac8ba29f | 263 | { |
chevamax | 16:1643ac8ba29f | 264 | Buffer[i] = i - 4; |
chevamax | 16:1643ac8ba29f | 265 | } |
chevamax | 16:1643ac8ba29f | 266 | wait_ms( 10 ); |
chevamax | 16:1643ac8ba29f | 267 | ordreRecuPortCom = false; |
chevamax | 16:1643ac8ba29f | 268 | Radio.Send( Buffer, BufferSize ); |
chevamax | 16:1643ac8ba29f | 269 | }else{ |
chevamax | 16:1643ac8ba29f | 270 | debug_if( DEBUG_MESSAGE, "Pas d'activation de la pompe\r\n" ); |
chevamax | 16:1643ac8ba29f | 271 | Radio.Rx( RX_TIMEOUT_VALUE ); |
chevamax | 16:1643ac8ba29f | 272 | } |
chevamax | 16:1643ac8ba29f | 273 | ordreRecuPortCom = false; |
chevamax | 16:1643ac8ba29f | 274 | |
GregCr | 0:1ed39951ab7b | 275 | break; |
GregCr | 0:1ed39951ab7b | 276 | default: |
GregCr | 0:1ed39951ab7b | 277 | State = LOWPOWER; |
GregCr | 0:1ed39951ab7b | 278 | break; |
GregCr | 0:1ed39951ab7b | 279 | } |
GregCr | 0:1ed39951ab7b | 280 | } |
GregCr | 0:1ed39951ab7b | 281 | } |
GregCr | 0:1ed39951ab7b | 282 | |
GregCr | 0:1ed39951ab7b | 283 | void OnTxDone( void ) |
GregCr | 0:1ed39951ab7b | 284 | { |
GregCr | 5:f2431c4fe3bb | 285 | Radio.Sleep( ); |
GregCr | 0:1ed39951ab7b | 286 | State = TX; |
GregCr | 7:c1bbd6c56979 | 287 | debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" ); |
GregCr | 0:1ed39951ab7b | 288 | } |
GregCr | 0:1ed39951ab7b | 289 | |
GregCr | 4:5ece30264cd9 | 290 | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) |
GregCr | 0:1ed39951ab7b | 291 | { |
GregCr | 0:1ed39951ab7b | 292 | Radio.Sleep( ); |
GregCr | 0:1ed39951ab7b | 293 | BufferSize = size; |
GregCr | 0:1ed39951ab7b | 294 | memcpy( Buffer, payload, BufferSize ); |
GregCr | 0:1ed39951ab7b | 295 | RssiValue = rssi; |
GregCr | 0:1ed39951ab7b | 296 | SnrValue = snr; |
GregCr | 0:1ed39951ab7b | 297 | State = RX; |
GregCr | 7:c1bbd6c56979 | 298 | debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" ); |
GregCr | 0:1ed39951ab7b | 299 | } |
GregCr | 0:1ed39951ab7b | 300 | |
GregCr | 0:1ed39951ab7b | 301 | void OnTxTimeout( void ) |
GregCr | 0:1ed39951ab7b | 302 | { |
GregCr | 0:1ed39951ab7b | 303 | Radio.Sleep( ); |
GregCr | 0:1ed39951ab7b | 304 | State = TX_TIMEOUT; |
GregCr | 7:c1bbd6c56979 | 305 | debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" ); |
GregCr | 0:1ed39951ab7b | 306 | } |
GregCr | 0:1ed39951ab7b | 307 | |
GregCr | 0:1ed39951ab7b | 308 | void OnRxTimeout( void ) |
GregCr | 0:1ed39951ab7b | 309 | { |
GregCr | 0:1ed39951ab7b | 310 | Radio.Sleep( ); |
GregCr | 1:126d70d374f6 | 311 | Buffer[ BufferSize ] = 0; |
GregCr | 0:1ed39951ab7b | 312 | State = RX_TIMEOUT; |
GregCr | 7:c1bbd6c56979 | 313 | debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" ); |
GregCr | 0:1ed39951ab7b | 314 | } |
GregCr | 0:1ed39951ab7b | 315 | |
GregCr | 0:1ed39951ab7b | 316 | void OnRxError( void ) |
GregCr | 0:1ed39951ab7b | 317 | { |
GregCr | 0:1ed39951ab7b | 318 | Radio.Sleep( ); |
GregCr | 0:1ed39951ab7b | 319 | State = RX_ERROR; |
GregCr | 7:c1bbd6c56979 | 320 | debug_if( DEBUG_MESSAGE, "> OnRxError\n\r" ); |
GregCr | 0:1ed39951ab7b | 321 | } |
GregCr | 3:8b9e2a4df4b5 | 322 |