SX1272 LoRa RF module PingPong Demo
Dependencies: SX1272Lib XRange_mbed_src
XRange SX1272 LoRa RF module https://www.netblocks.eu/xrange-sx1272-lora-datasheet/
Application demonstrating simple Tx/Rx between two boards. By default, each board starts as a "master" and will transmit a "Ping" message, and then wait for an answer. The first board receiving a "Ping" message will become a slave and answer the "master" with a "Pong". The Ping-Pong is then started
main.cpp@0:5ff027a21ffb, 2015-05-31 (annotated)
- Committer:
- netblocks
- Date:
- Sun May 31 13:08:43 2015 +0000
- Revision:
- 0:5ff027a21ffb
SX1272 LoRa RF module PingPong Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
netblocks | 0:5ff027a21ffb | 1 | #include "mbed.h" |
netblocks | 0:5ff027a21ffb | 2 | |
netblocks | 0:5ff027a21ffb | 3 | /* |
netblocks | 0:5ff027a21ffb | 4 | Maintainers: www.netblocks.eu |
netblocks | 0:5ff027a21ffb | 5 | SX1272 LoRa RF module : http://www.netblocks.eu/xrange-sx1272-lora-datasheet/ |
netblocks | 0:5ff027a21ffb | 6 | */ |
netblocks | 0:5ff027a21ffb | 7 | |
netblocks | 0:5ff027a21ffb | 8 | #include "main.h" |
netblocks | 0:5ff027a21ffb | 9 | #include "sx1272-hal.h" |
netblocks | 0:5ff027a21ffb | 10 | #include "debug.h" |
netblocks | 0:5ff027a21ffb | 11 | |
netblocks | 0:5ff027a21ffb | 12 | /* Set this flag to '1' to display debug messages on the console */ |
netblocks | 0:5ff027a21ffb | 13 | #define DEBUG_MESSAGE 0 |
netblocks | 0:5ff027a21ffb | 14 | |
netblocks | 0:5ff027a21ffb | 15 | /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ |
netblocks | 0:5ff027a21ffb | 16 | #define USE_MODEM_LORA 1 |
netblocks | 0:5ff027a21ffb | 17 | #define USE_MODEM_FSK !USE_MODEM_LORA |
netblocks | 0:5ff027a21ffb | 18 | |
netblocks | 0:5ff027a21ffb | 19 | #define RF_FREQUENCY 868000000 // Hz |
netblocks | 0:5ff027a21ffb | 20 | #define TX_OUTPUT_POWER 20 // 14 dBm |
netblocks | 0:5ff027a21ffb | 21 | |
netblocks | 0:5ff027a21ffb | 22 | #if USE_MODEM_LORA == 1 |
netblocks | 0:5ff027a21ffb | 23 | |
netblocks | 0:5ff027a21ffb | 24 | #define LORA_BANDWIDTH 2 // [0: 125 kHz, |
netblocks | 0:5ff027a21ffb | 25 | // 1: 250 kHz, |
netblocks | 0:5ff027a21ffb | 26 | // 2: 500 kHz, |
netblocks | 0:5ff027a21ffb | 27 | // 3: Reserved] |
netblocks | 0:5ff027a21ffb | 28 | #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] |
netblocks | 0:5ff027a21ffb | 29 | #define LORA_CODINGRATE 1 // [1: 4/5, |
netblocks | 0:5ff027a21ffb | 30 | // 2: 4/6, |
netblocks | 0:5ff027a21ffb | 31 | // 3: 4/7, |
netblocks | 0:5ff027a21ffb | 32 | // 4: 4/8] |
netblocks | 0:5ff027a21ffb | 33 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
netblocks | 0:5ff027a21ffb | 34 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
netblocks | 0:5ff027a21ffb | 35 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
netblocks | 0:5ff027a21ffb | 36 | #define LORA_FHSS_ENABLED false |
netblocks | 0:5ff027a21ffb | 37 | #define LORA_NB_SYMB_HOP 4 |
netblocks | 0:5ff027a21ffb | 38 | #define LORA_IQ_INVERSION_ON false |
netblocks | 0:5ff027a21ffb | 39 | #define LORA_CRC_ENABLED true |
netblocks | 0:5ff027a21ffb | 40 | |
netblocks | 0:5ff027a21ffb | 41 | #elif USE_MODEM_FSK == 1 |
netblocks | 0:5ff027a21ffb | 42 | |
netblocks | 0:5ff027a21ffb | 43 | #define FSK_FDEV 25000 // Hz |
netblocks | 0:5ff027a21ffb | 44 | #define FSK_DATARATE 19200 // bps |
netblocks | 0:5ff027a21ffb | 45 | #define FSK_BANDWIDTH 50000 // Hz |
netblocks | 0:5ff027a21ffb | 46 | #define FSK_AFC_BANDWIDTH 83333 // Hz |
netblocks | 0:5ff027a21ffb | 47 | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
netblocks | 0:5ff027a21ffb | 48 | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
netblocks | 0:5ff027a21ffb | 49 | #define FSK_CRC_ENABLED true |
netblocks | 0:5ff027a21ffb | 50 | |
netblocks | 0:5ff027a21ffb | 51 | #else |
netblocks | 0:5ff027a21ffb | 52 | #error "Please define a modem in the compiler options." |
netblocks | 0:5ff027a21ffb | 53 | #endif |
netblocks | 0:5ff027a21ffb | 54 | |
netblocks | 0:5ff027a21ffb | 55 | #define RX_TIMEOUT_VALUE 3500000 // in us |
netblocks | 0:5ff027a21ffb | 56 | #define BUFFER_SIZE 32 // Define the payload size here |
netblocks | 0:5ff027a21ffb | 57 | |
netblocks | 0:5ff027a21ffb | 58 | DigitalOut led(PA_8); |
netblocks | 0:5ff027a21ffb | 59 | |
netblocks | 0:5ff027a21ffb | 60 | |
netblocks | 0:5ff027a21ffb | 61 | /* |
netblocks | 0:5ff027a21ffb | 62 | * Global variables declarations |
netblocks | 0:5ff027a21ffb | 63 | */ |
netblocks | 0:5ff027a21ffb | 64 | typedef RadioState States_t; |
netblocks | 0:5ff027a21ffb | 65 | volatile States_t State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 66 | |
netblocks | 0:5ff027a21ffb | 67 | XRange Radio( OnTxDone, OnTxTimeout, OnRxDone, OnRxTimeout, OnRxError, NULL, NULL ); |
netblocks | 0:5ff027a21ffb | 68 | |
netblocks | 0:5ff027a21ffb | 69 | const uint8_t PingMsg[] = "PING"; |
netblocks | 0:5ff027a21ffb | 70 | const uint8_t PongMsg[] = "PONG"; |
netblocks | 0:5ff027a21ffb | 71 | |
netblocks | 0:5ff027a21ffb | 72 | uint16_t BufferSize = BUFFER_SIZE; |
netblocks | 0:5ff027a21ffb | 73 | uint8_t Buffer[BUFFER_SIZE]; |
netblocks | 0:5ff027a21ffb | 74 | |
netblocks | 0:5ff027a21ffb | 75 | int16_t RssiValue = 0.0; |
netblocks | 0:5ff027a21ffb | 76 | int8_t SnrValue = 0.0; |
netblocks | 0:5ff027a21ffb | 77 | |
netblocks | 0:5ff027a21ffb | 78 | int main() |
netblocks | 0:5ff027a21ffb | 79 | { |
netblocks | 0:5ff027a21ffb | 80 | uint8_t i; |
netblocks | 0:5ff027a21ffb | 81 | bool isMaster = true; |
netblocks | 0:5ff027a21ffb | 82 | |
netblocks | 0:5ff027a21ffb | 83 | debug( "\n\n\r SX1276 Ping Pong Demo Application \n\n\r" ); |
netblocks | 0:5ff027a21ffb | 84 | |
netblocks | 0:5ff027a21ffb | 85 | // verify the connection with the board |
netblocks | 0:5ff027a21ffb | 86 | |
netblocks | 0:5ff027a21ffb | 87 | |
netblocks | 0:5ff027a21ffb | 88 | Radio.SetChannel( RF_FREQUENCY ); |
netblocks | 0:5ff027a21ffb | 89 | |
netblocks | 0:5ff027a21ffb | 90 | #if USE_MODEM_LORA == 1 |
netblocks | 0:5ff027a21ffb | 91 | |
netblocks | 0:5ff027a21ffb | 92 | debug_if( LORA_FHSS_ENABLED, "\n\n\r > LORA FHSS Mode < \n\n\r"); |
netblocks | 0:5ff027a21ffb | 93 | debug_if( !LORA_FHSS_ENABLED, "\n\n\r > LORA Mode < \n\n\r"); |
netblocks | 0:5ff027a21ffb | 94 | |
netblocks | 0:5ff027a21ffb | 95 | Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, |
netblocks | 0:5ff027a21ffb | 96 | LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
netblocks | 0:5ff027a21ffb | 97 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
netblocks | 0:5ff027a21ffb | 98 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
netblocks | 0:5ff027a21ffb | 99 | LORA_IQ_INVERSION_ON, 2000000 ); |
netblocks | 0:5ff027a21ffb | 100 | |
netblocks | 0:5ff027a21ffb | 101 | Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, |
netblocks | 0:5ff027a21ffb | 102 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
netblocks | 0:5ff027a21ffb | 103 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
netblocks | 0:5ff027a21ffb | 104 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
netblocks | 0:5ff027a21ffb | 105 | LORA_IQ_INVERSION_ON, true ); |
netblocks | 0:5ff027a21ffb | 106 | |
netblocks | 0:5ff027a21ffb | 107 | #elif USE_MODEM_FSK == 1 |
netblocks | 0:5ff027a21ffb | 108 | |
netblocks | 0:5ff027a21ffb | 109 | debug("\n\n\r > FSK Mode < \n\n\r"); |
netblocks | 0:5ff027a21ffb | 110 | Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, |
netblocks | 0:5ff027a21ffb | 111 | FSK_DATARATE, 0, |
netblocks | 0:5ff027a21ffb | 112 | FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, |
netblocks | 0:5ff027a21ffb | 113 | FSK_CRC_ENABLED, 0, 0, 0, 2000000 ); |
netblocks | 0:5ff027a21ffb | 114 | |
netblocks | 0:5ff027a21ffb | 115 | Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, |
netblocks | 0:5ff027a21ffb | 116 | 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, |
netblocks | 0:5ff027a21ffb | 117 | 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED, |
netblocks | 0:5ff027a21ffb | 118 | 0, 0, false, true ); |
netblocks | 0:5ff027a21ffb | 119 | |
netblocks | 0:5ff027a21ffb | 120 | #else |
netblocks | 0:5ff027a21ffb | 121 | |
netblocks | 0:5ff027a21ffb | 122 | #error "Please define a modem in the compiler options." |
netblocks | 0:5ff027a21ffb | 123 | |
netblocks | 0:5ff027a21ffb | 124 | #endif |
netblocks | 0:5ff027a21ffb | 125 | |
netblocks | 0:5ff027a21ffb | 126 | debug_if( DEBUG_MESSAGE, "Starting Ping-Pong loop\r\n" ); |
netblocks | 0:5ff027a21ffb | 127 | |
netblocks | 0:5ff027a21ffb | 128 | led = 0; |
netblocks | 0:5ff027a21ffb | 129 | |
netblocks | 0:5ff027a21ffb | 130 | Radio.Rx( RX_TIMEOUT_VALUE ); |
netblocks | 0:5ff027a21ffb | 131 | |
netblocks | 0:5ff027a21ffb | 132 | while( 1 ) |
netblocks | 0:5ff027a21ffb | 133 | { |
netblocks | 0:5ff027a21ffb | 134 | switch( State ) |
netblocks | 0:5ff027a21ffb | 135 | { |
netblocks | 0:5ff027a21ffb | 136 | case RX: |
netblocks | 0:5ff027a21ffb | 137 | if( isMaster == true ) |
netblocks | 0:5ff027a21ffb | 138 | { |
netblocks | 0:5ff027a21ffb | 139 | if( BufferSize > 0 ) |
netblocks | 0:5ff027a21ffb | 140 | { |
netblocks | 0:5ff027a21ffb | 141 | if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) |
netblocks | 0:5ff027a21ffb | 142 | { |
netblocks | 0:5ff027a21ffb | 143 | led = !led; |
netblocks | 0:5ff027a21ffb | 144 | debug( "...Pong\r\n" ); |
netblocks | 0:5ff027a21ffb | 145 | // Send the next PING frame |
netblocks | 0:5ff027a21ffb | 146 | strcpy( ( char* )Buffer, ( char* )PingMsg ); |
netblocks | 0:5ff027a21ffb | 147 | // We fill the buffer with numbers for the payload |
netblocks | 0:5ff027a21ffb | 148 | for( i = 4; i < BufferSize; i++ ) |
netblocks | 0:5ff027a21ffb | 149 | { |
netblocks | 0:5ff027a21ffb | 150 | Buffer[i] = i - 4; |
netblocks | 0:5ff027a21ffb | 151 | } |
netblocks | 0:5ff027a21ffb | 152 | wait_ms( 10 ); |
netblocks | 0:5ff027a21ffb | 153 | Radio.Send( Buffer, BufferSize ); |
netblocks | 0:5ff027a21ffb | 154 | } |
netblocks | 0:5ff027a21ffb | 155 | else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) |
netblocks | 0:5ff027a21ffb | 156 | { // A master already exists then become a slave |
netblocks | 0:5ff027a21ffb | 157 | debug( "...Ping\r\n" ); |
netblocks | 0:5ff027a21ffb | 158 | led = !led; |
netblocks | 0:5ff027a21ffb | 159 | isMaster = false; |
netblocks | 0:5ff027a21ffb | 160 | // Send the next PONG frame |
netblocks | 0:5ff027a21ffb | 161 | strcpy( ( char* )Buffer, ( char* )PongMsg ); |
netblocks | 0:5ff027a21ffb | 162 | // We fill the buffer with numbers for the payload |
netblocks | 0:5ff027a21ffb | 163 | for( i = 4; i < BufferSize; i++ ) |
netblocks | 0:5ff027a21ffb | 164 | { |
netblocks | 0:5ff027a21ffb | 165 | Buffer[i] = i - 4; |
netblocks | 0:5ff027a21ffb | 166 | } |
netblocks | 0:5ff027a21ffb | 167 | wait_ms( 10 ); |
netblocks | 0:5ff027a21ffb | 168 | Radio.Send( Buffer, BufferSize ); |
netblocks | 0:5ff027a21ffb | 169 | } |
netblocks | 0:5ff027a21ffb | 170 | else // valid reception but neither a PING or a PONG message |
netblocks | 0:5ff027a21ffb | 171 | { // Set device as master ans start again |
netblocks | 0:5ff027a21ffb | 172 | isMaster = true; |
netblocks | 0:5ff027a21ffb | 173 | Radio.Rx( RX_TIMEOUT_VALUE ); |
netblocks | 0:5ff027a21ffb | 174 | } |
netblocks | 0:5ff027a21ffb | 175 | } |
netblocks | 0:5ff027a21ffb | 176 | } |
netblocks | 0:5ff027a21ffb | 177 | else |
netblocks | 0:5ff027a21ffb | 178 | { |
netblocks | 0:5ff027a21ffb | 179 | if( BufferSize > 0 ) |
netblocks | 0:5ff027a21ffb | 180 | { |
netblocks | 0:5ff027a21ffb | 181 | if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) |
netblocks | 0:5ff027a21ffb | 182 | { |
netblocks | 0:5ff027a21ffb | 183 | led = !led; |
netblocks | 0:5ff027a21ffb | 184 | debug( "...Ping\r\n" ); |
netblocks | 0:5ff027a21ffb | 185 | // Send the reply to the PING string |
netblocks | 0:5ff027a21ffb | 186 | strcpy( ( char* )Buffer, ( char* )PongMsg ); |
netblocks | 0:5ff027a21ffb | 187 | // We fill the buffer with numbers for the payload |
netblocks | 0:5ff027a21ffb | 188 | for( i = 4; i < BufferSize; i++ ) |
netblocks | 0:5ff027a21ffb | 189 | { |
netblocks | 0:5ff027a21ffb | 190 | Buffer[i] = i - 4; |
netblocks | 0:5ff027a21ffb | 191 | } |
netblocks | 0:5ff027a21ffb | 192 | wait_ms( 10 ); |
netblocks | 0:5ff027a21ffb | 193 | Radio.Send( Buffer, BufferSize ); |
netblocks | 0:5ff027a21ffb | 194 | } |
netblocks | 0:5ff027a21ffb | 195 | else // valid reception but not a PING as expected |
netblocks | 0:5ff027a21ffb | 196 | { // Set device as master and start again |
netblocks | 0:5ff027a21ffb | 197 | isMaster = true; |
netblocks | 0:5ff027a21ffb | 198 | Radio.Rx( RX_TIMEOUT_VALUE ); |
netblocks | 0:5ff027a21ffb | 199 | } |
netblocks | 0:5ff027a21ffb | 200 | } |
netblocks | 0:5ff027a21ffb | 201 | } |
netblocks | 0:5ff027a21ffb | 202 | State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 203 | break; |
netblocks | 0:5ff027a21ffb | 204 | case TX: |
netblocks | 0:5ff027a21ffb | 205 | led = !led; |
netblocks | 0:5ff027a21ffb | 206 | if( isMaster == true ) |
netblocks | 0:5ff027a21ffb | 207 | { |
netblocks | 0:5ff027a21ffb | 208 | debug( "Ping...\r\n" ); |
netblocks | 0:5ff027a21ffb | 209 | } |
netblocks | 0:5ff027a21ffb | 210 | else |
netblocks | 0:5ff027a21ffb | 211 | { |
netblocks | 0:5ff027a21ffb | 212 | debug( "Pong...\r\n" ); |
netblocks | 0:5ff027a21ffb | 213 | } |
netblocks | 0:5ff027a21ffb | 214 | Radio.Rx( RX_TIMEOUT_VALUE ); |
netblocks | 0:5ff027a21ffb | 215 | State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 216 | break; |
netblocks | 0:5ff027a21ffb | 217 | case RX_TIMEOUT: |
netblocks | 0:5ff027a21ffb | 218 | if( isMaster == true ) |
netblocks | 0:5ff027a21ffb | 219 | { |
netblocks | 0:5ff027a21ffb | 220 | // Send the next PING frame |
netblocks | 0:5ff027a21ffb | 221 | strcpy( ( char* )Buffer, ( char* )PingMsg ); |
netblocks | 0:5ff027a21ffb | 222 | for( i = 4; i < BufferSize; i++ ) |
netblocks | 0:5ff027a21ffb | 223 | { |
netblocks | 0:5ff027a21ffb | 224 | Buffer[i] = i - 4; |
netblocks | 0:5ff027a21ffb | 225 | } |
netblocks | 0:5ff027a21ffb | 226 | wait_ms( 10 ); |
netblocks | 0:5ff027a21ffb | 227 | Radio.Send( Buffer, BufferSize ); |
netblocks | 0:5ff027a21ffb | 228 | } |
netblocks | 0:5ff027a21ffb | 229 | else |
netblocks | 0:5ff027a21ffb | 230 | { |
netblocks | 0:5ff027a21ffb | 231 | Radio.Rx( RX_TIMEOUT_VALUE ); |
netblocks | 0:5ff027a21ffb | 232 | } |
netblocks | 0:5ff027a21ffb | 233 | State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 234 | break; |
netblocks | 0:5ff027a21ffb | 235 | case RX_ERROR: |
netblocks | 0:5ff027a21ffb | 236 | // We have received a Packet with a CRC error, send reply as if packet was correct |
netblocks | 0:5ff027a21ffb | 237 | if( isMaster == true ) |
netblocks | 0:5ff027a21ffb | 238 | { |
netblocks | 0:5ff027a21ffb | 239 | // Send the next PING frame |
netblocks | 0:5ff027a21ffb | 240 | strcpy( ( char* )Buffer, ( char* )PingMsg ); |
netblocks | 0:5ff027a21ffb | 241 | for( i = 4; i < BufferSize; i++ ) |
netblocks | 0:5ff027a21ffb | 242 | { |
netblocks | 0:5ff027a21ffb | 243 | Buffer[i] = i - 4; |
netblocks | 0:5ff027a21ffb | 244 | } |
netblocks | 0:5ff027a21ffb | 245 | wait_ms( 10 ); |
netblocks | 0:5ff027a21ffb | 246 | Radio.Send( Buffer, BufferSize ); |
netblocks | 0:5ff027a21ffb | 247 | } |
netblocks | 0:5ff027a21ffb | 248 | else |
netblocks | 0:5ff027a21ffb | 249 | { |
netblocks | 0:5ff027a21ffb | 250 | // Send the next PONG frame |
netblocks | 0:5ff027a21ffb | 251 | strcpy( ( char* )Buffer, ( char* )PongMsg ); |
netblocks | 0:5ff027a21ffb | 252 | for( i = 4; i < BufferSize; i++ ) |
netblocks | 0:5ff027a21ffb | 253 | { |
netblocks | 0:5ff027a21ffb | 254 | Buffer[i] = i - 4; |
netblocks | 0:5ff027a21ffb | 255 | } |
netblocks | 0:5ff027a21ffb | 256 | wait_ms( 10 ); |
netblocks | 0:5ff027a21ffb | 257 | Radio.Send( Buffer, BufferSize ); |
netblocks | 0:5ff027a21ffb | 258 | } |
netblocks | 0:5ff027a21ffb | 259 | State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 260 | break; |
netblocks | 0:5ff027a21ffb | 261 | case TX_TIMEOUT: |
netblocks | 0:5ff027a21ffb | 262 | Radio.Rx( RX_TIMEOUT_VALUE ); |
netblocks | 0:5ff027a21ffb | 263 | State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 264 | break; |
netblocks | 0:5ff027a21ffb | 265 | case LOWPOWER: |
netblocks | 0:5ff027a21ffb | 266 | break; |
netblocks | 0:5ff027a21ffb | 267 | default: |
netblocks | 0:5ff027a21ffb | 268 | State = LOWPOWER; |
netblocks | 0:5ff027a21ffb | 269 | break; |
netblocks | 0:5ff027a21ffb | 270 | } |
netblocks | 0:5ff027a21ffb | 271 | } |
netblocks | 0:5ff027a21ffb | 272 | } |
netblocks | 0:5ff027a21ffb | 273 | |
netblocks | 0:5ff027a21ffb | 274 | void OnTxDone( void ) |
netblocks | 0:5ff027a21ffb | 275 | { |
netblocks | 0:5ff027a21ffb | 276 | Radio.Sleep( ); |
netblocks | 0:5ff027a21ffb | 277 | State = TX; |
netblocks | 0:5ff027a21ffb | 278 | debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" ); |
netblocks | 0:5ff027a21ffb | 279 | } |
netblocks | 0:5ff027a21ffb | 280 | |
netblocks | 0:5ff027a21ffb | 281 | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) |
netblocks | 0:5ff027a21ffb | 282 | { |
netblocks | 0:5ff027a21ffb | 283 | Radio.Sleep( ); |
netblocks | 0:5ff027a21ffb | 284 | BufferSize = size; |
netblocks | 0:5ff027a21ffb | 285 | memcpy( Buffer, payload, BufferSize ); |
netblocks | 0:5ff027a21ffb | 286 | RssiValue = rssi; |
netblocks | 0:5ff027a21ffb | 287 | SnrValue = snr; |
netblocks | 0:5ff027a21ffb | 288 | State = RX; |
netblocks | 0:5ff027a21ffb | 289 | debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" ); |
netblocks | 0:5ff027a21ffb | 290 | } |
netblocks | 0:5ff027a21ffb | 291 | |
netblocks | 0:5ff027a21ffb | 292 | void OnTxTimeout( void ) |
netblocks | 0:5ff027a21ffb | 293 | { |
netblocks | 0:5ff027a21ffb | 294 | Radio.Sleep( ); |
netblocks | 0:5ff027a21ffb | 295 | State = TX_TIMEOUT; |
netblocks | 0:5ff027a21ffb | 296 | debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" ); |
netblocks | 0:5ff027a21ffb | 297 | } |
netblocks | 0:5ff027a21ffb | 298 | |
netblocks | 0:5ff027a21ffb | 299 | void OnRxTimeout( void ) |
netblocks | 0:5ff027a21ffb | 300 | { |
netblocks | 0:5ff027a21ffb | 301 | Radio.Sleep( ); |
netblocks | 0:5ff027a21ffb | 302 | Buffer[ BufferSize ] = 0; |
netblocks | 0:5ff027a21ffb | 303 | State = RX_TIMEOUT; |
netblocks | 0:5ff027a21ffb | 304 | debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" ); |
netblocks | 0:5ff027a21ffb | 305 | debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" ); |
netblocks | 0:5ff027a21ffb | 306 | |
netblocks | 0:5ff027a21ffb | 307 | } |
netblocks | 0:5ff027a21ffb | 308 | |
netblocks | 0:5ff027a21ffb | 309 | void OnRxError( void ) |
netblocks | 0:5ff027a21ffb | 310 | { |
netblocks | 0:5ff027a21ffb | 311 | Radio.Sleep( ); |
netblocks | 0:5ff027a21ffb | 312 | State = RX_ERROR; |
netblocks | 0:5ff027a21ffb | 313 | debug_if( DEBUG_MESSAGE, "> OnRxError\n\r" ); |
netblocks | 0:5ff027a21ffb | 314 | } |