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