Simple example Ping Pong from Semtech, updated new lib

Dependencies:   SX1276Lib mbed

Fork of SX1276PingPong by Semtech

i'm using stm32 nucleo l46rg and stm32 nucleo l073 with sx1276mb1mas.

Committer:
NguyenNguyenQuocHuy1
Date:
Tue Aug 16 04:03:12 2016 +0000
Revision:
15:565259e9e94a
Parent:
14:c7251480feb9
updated lib

Who changed what in which revision?

UserRevisionLine numberNew 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"
GregCr 0:1ed39951ab7b 5
GregCr 0:1ed39951ab7b 6 /* Set this flag to '1' to display debug messages on the console */
NguyenNguyenQuocHuy1 15:565259e9e94a 7 #define DEBUG_MESSAGE 1
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
NguyenNguyenQuocHuy1 15:565259e9e94a 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
NguyenNguyenQuocHuy1 15:565259e9e94a 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
NguyenNguyenQuocHuy1 15:565259e9e94a 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
NguyenNguyenQuocHuy1 15:565259e9e94a 49 #define RX_TIMEOUT_VALUE 35000000 // DU 1 SO 0
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 */
mluis 10:7af820d1e1df 61 typedef enum
mluis 10:7af820d1e1df 62 {
mluis 10:7af820d1e1df 63 LOWPOWER = 0,
mluis 10:7af820d1e1df 64 IDLE,
mluis 10:7af820d1e1df 65
mluis 10:7af820d1e1df 66 RX,
mluis 10:7af820d1e1df 67 RX_TIMEOUT,
mluis 10:7af820d1e1df 68 RX_ERROR,
mluis 10:7af820d1e1df 69
mluis 10:7af820d1e1df 70 TX,
mluis 10:7af820d1e1df 71 TX_TIMEOUT,
mluis 10:7af820d1e1df 72
mluis 10:7af820d1e1df 73 CAD,
mluis 10:7af820d1e1df 74 CAD_DONE
mluis 10:7af820d1e1df 75 }AppStates_t;
GregCr 0:1ed39951ab7b 76
mluis 10:7af820d1e1df 77 volatile AppStates_t State = LOWPOWER;
mluis 10:7af820d1e1df 78
mluis 10:7af820d1e1df 79 /*!
mluis 10:7af820d1e1df 80 * Radio events function pointer
mluis 10:7af820d1e1df 81 */
mluis 10:7af820d1e1df 82 static RadioEvents_t RadioEvents;
mluis 10:7af820d1e1df 83
mluis 10:7af820d1e1df 84 /*
mluis 10:7af820d1e1df 85 * Global variables declarations
mluis 10:7af820d1e1df 86 */
GregCr 14:c7251480feb9 87 SX1276MB1xAS Radio( NULL );
GregCr 0:1ed39951ab7b 88
GregCr 0:1ed39951ab7b 89 const uint8_t PingMsg[] = "PING";
GregCr 0:1ed39951ab7b 90 const uint8_t PongMsg[] = "PONG";
GregCr 0:1ed39951ab7b 91
GregCr 0:1ed39951ab7b 92 uint16_t BufferSize = BUFFER_SIZE;
GregCr 0:1ed39951ab7b 93 uint8_t Buffer[BUFFER_SIZE];
GregCr 0:1ed39951ab7b 94
GregCr 5:f2431c4fe3bb 95 int16_t RssiValue = 0.0;
GregCr 5:f2431c4fe3bb 96 int8_t SnrValue = 0.0;
GregCr 0:1ed39951ab7b 97
GregCr 0:1ed39951ab7b 98 int main()
GregCr 0:1ed39951ab7b 99 {
GregCr 0:1ed39951ab7b 100 uint8_t i;
GregCr 0:1ed39951ab7b 101 bool isMaster = true;
GregCr 0:1ed39951ab7b 102
NguyenNguyenQuocHuy1 15:565259e9e94a 103 debug ("\n\r HUY \n\r");
NguyenNguyenQuocHuy1 15:565259e9e94a 104
GregCr 14:c7251480feb9 105 debug( "\n\n\r SX1276 Ping Pong Demo Application \n\n\r" );
mluis 10:7af820d1e1df 106
mluis 10:7af820d1e1df 107 // Initialize Radio driver
mluis 10:7af820d1e1df 108 RadioEvents.TxDone = OnTxDone;
mluis 10:7af820d1e1df 109 RadioEvents.RxDone = OnRxDone;
mluis 10:7af820d1e1df 110 RadioEvents.RxError = OnRxError;
mluis 10:7af820d1e1df 111 RadioEvents.TxTimeout = OnTxTimeout;
mluis 10:7af820d1e1df 112 RadioEvents.RxTimeout = OnRxTimeout;
mluis 10:7af820d1e1df 113 Radio.Init( &RadioEvents );
NguyenNguyenQuocHuy1 15:565259e9e94a 114 debug ("\n\r HUY HUY \n\r");
GregCr 0:1ed39951ab7b 115
GregCr 7:c1bbd6c56979 116 // verify the connection with the board
GregCr 7:c1bbd6c56979 117 while( Radio.Read( REG_VERSION ) == 0x00 )
GregCr 2:59e108728d71 118 {
GregCr 7:c1bbd6c56979 119 debug( "Radio could not be detected!\n\r", NULL );
GregCr 7:c1bbd6c56979 120 wait( 1 );
GregCr 2:59e108728d71 121 }
GregCr 7:c1bbd6c56979 122
NguyenNguyenQuocHuy1 15:565259e9e94a 123 //debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ) , "\n\r > Board Type: SX1276MB1LAS < \n\r" );
GregCr 14:c7251480feb9 124 debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1MAS ) ) , "\n\r > Board Type: SX1276MB1MAS < \n\r" );
NguyenNguyenQuocHuy1 15:565259e9e94a 125 debug ("\n\r HUY HUY HUY \n\r");
GregCr 0:1ed39951ab7b 126 Radio.SetChannel( RF_FREQUENCY );
GregCr 0:1ed39951ab7b 127
GregCr 0:1ed39951ab7b 128 #if USE_MODEM_LORA == 1
GregCr 3:8b9e2a4df4b5 129
GregCr 7:c1bbd6c56979 130 debug_if( LORA_FHSS_ENABLED, "\n\n\r > LORA FHSS Mode < \n\n\r");
GregCr 7:c1bbd6c56979 131 debug_if( !LORA_FHSS_ENABLED, "\n\n\r > LORA Mode < \n\n\r");
NguyenNguyenQuocHuy1 15:565259e9e94a 132
NguyenNguyenQuocHuy1 15:565259e9e94a 133 debug ("\n\r HUY HUY HUY HUY \n\r");
GregCr 7:c1bbd6c56979 134
GregCr 0:1ed39951ab7b 135 Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
GregCr 0:1ed39951ab7b 136 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
GregCr 0:1ed39951ab7b 137 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
GregCr 3:8b9e2a4df4b5 138 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
GregCr 7:c1bbd6c56979 139 LORA_IQ_INVERSION_ON, 2000000 );
GregCr 0:1ed39951ab7b 140
GregCr 0:1ed39951ab7b 141 Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
GregCr 0:1ed39951ab7b 142 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
mluis 9:e764990e45df 143 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
GregCr 3:8b9e2a4df4b5 144 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
GregCr 3:8b9e2a4df4b5 145 LORA_IQ_INVERSION_ON, true );
GregCr 0:1ed39951ab7b 146
NguyenNguyenQuocHuy1 15:565259e9e94a 147 /*#elif USE_MODEM_FSK == 1
GregCr 0:1ed39951ab7b 148
GregCr 7:c1bbd6c56979 149 debug("\n\n\r > FSK Mode < \n\n\r");
GregCr 0:1ed39951ab7b 150 Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
GregCr 0:1ed39951ab7b 151 FSK_DATARATE, 0,
GregCr 0:1ed39951ab7b 152 FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
GregCr 7:c1bbd6c56979 153 FSK_CRC_ENABLED, 0, 0, 0, 2000000 );
GregCr 0:1ed39951ab7b 154
GregCr 0:1ed39951ab7b 155 Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
GregCr 0:1ed39951ab7b 156 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
mluis 9:e764990e45df 157 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED,
NguyenNguyenQuocHuy1 15:565259e9e94a 158 0, 0, false, true );*/
GregCr 0:1ed39951ab7b 159
GregCr 0:1ed39951ab7b 160 #else
GregCr 0:1ed39951ab7b 161
GregCr 0:1ed39951ab7b 162 #error "Please define a modem in the compiler options."
GregCr 0:1ed39951ab7b 163
GregCr 0:1ed39951ab7b 164 #endif
GregCr 1:126d70d374f6 165
NguyenNguyenQuocHuy1 15:565259e9e94a 166
NguyenNguyenQuocHuy1 15:565259e9e94a 167
GregCr 7:c1bbd6c56979 168 debug_if( DEBUG_MESSAGE, "Starting Ping-Pong loop\r\n" );
NguyenNguyenQuocHuy1 15:565259e9e94a 169
NguyenNguyenQuocHuy1 15:565259e9e94a 170 debug ("\n\r HUY PING PONG \n\r");
GregCr 0:1ed39951ab7b 171
GregCr 3:8b9e2a4df4b5 172 led = 0;
GregCr 3:8b9e2a4df4b5 173
GregCr 0:1ed39951ab7b 174 Radio.Rx( RX_TIMEOUT_VALUE );
GregCr 0:1ed39951ab7b 175
GregCr 0:1ed39951ab7b 176 while( 1 )
GregCr 0:1ed39951ab7b 177 {
GregCr 0:1ed39951ab7b 178 switch( State )
GregCr 0:1ed39951ab7b 179 {
GregCr 0:1ed39951ab7b 180 case RX:
GregCr 0:1ed39951ab7b 181 if( isMaster == true )
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* )PongMsg, 4 ) == 0 )
GregCr 0:1ed39951ab7b 186 {
GregCr 3:8b9e2a4df4b5 187 led = !led;
GregCr 2:59e108728d71 188 debug( "...Pong\r\n" );
NguyenNguyenQuocHuy1 15:565259e9e94a 189 debug ("\n\r HUY PONG \n\r");
GregCr 0:1ed39951ab7b 190 // Send the next PING frame
GregCr 7:c1bbd6c56979 191 strcpy( ( char* )Buffer, ( char* )PingMsg );
GregCr 0:1ed39951ab7b 192 // We fill the buffer with numbers for the payload
GregCr 0:1ed39951ab7b 193 for( i = 4; i < BufferSize; i++ )
GregCr 0:1ed39951ab7b 194 {
GregCr 0:1ed39951ab7b 195 Buffer[i] = i - 4;
GregCr 0:1ed39951ab7b 196 }
GregCr 0:1ed39951ab7b 197 wait_ms( 10 );
GregCr 0:1ed39951ab7b 198 Radio.Send( Buffer, BufferSize );
GregCr 0:1ed39951ab7b 199 }
GregCr 2:59e108728d71 200 else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
GregCr 0:1ed39951ab7b 201 { // A master already exists then become a slave
GregCr 2:59e108728d71 202 debug( "...Ping\r\n" );
NguyenNguyenQuocHuy1 15:565259e9e94a 203 debug ("\n\r HUY PING \n\r");
GregCr 3:8b9e2a4df4b5 204 led = !led;
GregCr 0:1ed39951ab7b 205 isMaster = false;
GregCr 7:c1bbd6c56979 206 // Send the next PONG frame
GregCr 7:c1bbd6c56979 207 strcpy( ( char* )Buffer, ( char* )PongMsg );
GregCr 2:59e108728d71 208 // We fill the buffer with numbers for the payload
GregCr 2:59e108728d71 209 for( i = 4; i < BufferSize; i++ )
GregCr 2:59e108728d71 210 {
GregCr 2:59e108728d71 211 Buffer[i] = i - 4;
GregCr 2:59e108728d71 212 }
GregCr 3:8b9e2a4df4b5 213 wait_ms( 10 );
GregCr 2:59e108728d71 214 Radio.Send( Buffer, BufferSize );
GregCr 2:59e108728d71 215 }
GregCr 2:59e108728d71 216 else // valid reception but neither a PING or a PONG message
GregCr 2:59e108728d71 217 { // Set device as master ans start again
GregCr 2:59e108728d71 218 isMaster = true;
GregCr 0:1ed39951ab7b 219 Radio.Rx( RX_TIMEOUT_VALUE );
GregCr 2:59e108728d71 220 }
GregCr 0:1ed39951ab7b 221 }
GregCr 0:1ed39951ab7b 222 }
GregCr 0:1ed39951ab7b 223 else
GregCr 0:1ed39951ab7b 224 {
GregCr 0:1ed39951ab7b 225 if( BufferSize > 0 )
GregCr 0:1ed39951ab7b 226 {
GregCr 0:1ed39951ab7b 227 if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
GregCr 0:1ed39951ab7b 228 {
GregCr 3:8b9e2a4df4b5 229 led = !led;
GregCr 2:59e108728d71 230 debug( "...Ping\r\n" );
NguyenNguyenQuocHuy1 15:565259e9e94a 231 debug ("\n\r HUY PING 2 \n\r");
GregCr 2:59e108728d71 232 // Send the reply to the PING string
GregCr 7:c1bbd6c56979 233 strcpy( ( char* )Buffer, ( char* )PongMsg );
GregCr 0:1ed39951ab7b 234 // We fill the buffer with numbers for the payload
GregCr 0:1ed39951ab7b 235 for( i = 4; i < BufferSize; i++ )
GregCr 0:1ed39951ab7b 236 {
GregCr 0:1ed39951ab7b 237 Buffer[i] = i - 4;
GregCr 0:1ed39951ab7b 238 }
GregCr 0:1ed39951ab7b 239 wait_ms( 10 );
GregCr 0:1ed39951ab7b 240 Radio.Send( Buffer, BufferSize );
GregCr 0:1ed39951ab7b 241 }
GregCr 2:59e108728d71 242 else // valid reception but not a PING as expected
GregCr 2:59e108728d71 243 { // Set device as master and start again
GregCr 2:59e108728d71 244 isMaster = true;
GregCr 2:59e108728d71 245 Radio.Rx( RX_TIMEOUT_VALUE );
GregCr 2:59e108728d71 246 }
GregCr 0:1ed39951ab7b 247 }
GregCr 0:1ed39951ab7b 248 }
GregCr 0:1ed39951ab7b 249 State = LOWPOWER;
GregCr 0:1ed39951ab7b 250 break;
GregCr 3:8b9e2a4df4b5 251 case TX:
GregCr 3:8b9e2a4df4b5 252 led = !led;
GregCr 2:59e108728d71 253 if( isMaster == true )
GregCr 0:1ed39951ab7b 254 {
GregCr 2:59e108728d71 255 debug( "Ping...\r\n" );
NguyenNguyenQuocHuy1 15:565259e9e94a 256 debug ("\n\r HUY PING 3 \n\r");
GregCr 0:1ed39951ab7b 257 }
GregCr 0:1ed39951ab7b 258 else
GregCr 0:1ed39951ab7b 259 {
GregCr 2:59e108728d71 260 debug( "Pong...\r\n" );
NguyenNguyenQuocHuy1 15:565259e9e94a 261 debug ("\n\r HUY PONG 2 \n\r");
GregCr 0:1ed39951ab7b 262 }
GregCr 0:1ed39951ab7b 263 Radio.Rx( RX_TIMEOUT_VALUE );
GregCr 0:1ed39951ab7b 264 State = LOWPOWER;
GregCr 0:1ed39951ab7b 265 break;
GregCr 0:1ed39951ab7b 266 case RX_TIMEOUT:
GregCr 0:1ed39951ab7b 267 if( isMaster == true )
GregCr 0:1ed39951ab7b 268 {
GregCr 0:1ed39951ab7b 269 // Send the next PING frame
GregCr 7:c1bbd6c56979 270 strcpy( ( char* )Buffer, ( char* )PingMsg );
GregCr 0:1ed39951ab7b 271 for( i = 4; i < BufferSize; i++ )
GregCr 0:1ed39951ab7b 272 {
GregCr 0:1ed39951ab7b 273 Buffer[i] = i - 4;
GregCr 0:1ed39951ab7b 274 }
GregCr 0:1ed39951ab7b 275 wait_ms( 10 );
GregCr 0:1ed39951ab7b 276 Radio.Send( Buffer, BufferSize );
GregCr 0:1ed39951ab7b 277 }
GregCr 0:1ed39951ab7b 278 else
GregCr 0:1ed39951ab7b 279 {
GregCr 0:1ed39951ab7b 280 Radio.Rx( RX_TIMEOUT_VALUE );
GregCr 0:1ed39951ab7b 281 }
GregCr 0:1ed39951ab7b 282 State = LOWPOWER;
GregCr 0:1ed39951ab7b 283 break;
GregCr 0:1ed39951ab7b 284 case RX_ERROR:
GregCr 7:c1bbd6c56979 285 // We have received a Packet with a CRC error, send reply as if packet was correct
GregCr 0:1ed39951ab7b 286 if( isMaster == true )
GregCr 0:1ed39951ab7b 287 {
GregCr 0:1ed39951ab7b 288 // Send the next PING frame
GregCr 7:c1bbd6c56979 289 strcpy( ( char* )Buffer, ( char* )PingMsg );
GregCr 0:1ed39951ab7b 290 for( i = 4; i < BufferSize; i++ )
GregCr 0:1ed39951ab7b 291 {
GregCr 0:1ed39951ab7b 292 Buffer[i] = i - 4;
GregCr 0:1ed39951ab7b 293 }
GregCr 0:1ed39951ab7b 294 wait_ms( 10 );
GregCr 0:1ed39951ab7b 295 Radio.Send( Buffer, BufferSize );
GregCr 0:1ed39951ab7b 296 }
GregCr 0:1ed39951ab7b 297 else
GregCr 0:1ed39951ab7b 298 {
GregCr 2:59e108728d71 299 // Send the next PONG frame
GregCr 7:c1bbd6c56979 300 strcpy( ( char* )Buffer, ( char* )PongMsg );
GregCr 2:59e108728d71 301 for( i = 4; i < BufferSize; i++ )
GregCr 2:59e108728d71 302 {
GregCr 2:59e108728d71 303 Buffer[i] = i - 4;
GregCr 2:59e108728d71 304 }
GregCr 2:59e108728d71 305 wait_ms( 10 );
GregCr 2:59e108728d71 306 Radio.Send( Buffer, BufferSize );
GregCr 0:1ed39951ab7b 307 }
GregCr 0:1ed39951ab7b 308 State = LOWPOWER;
GregCr 0:1ed39951ab7b 309 break;
GregCr 0:1ed39951ab7b 310 case TX_TIMEOUT:
GregCr 0:1ed39951ab7b 311 Radio.Rx( RX_TIMEOUT_VALUE );
GregCr 0:1ed39951ab7b 312 State = LOWPOWER;
GregCr 0:1ed39951ab7b 313 break;
GregCr 0:1ed39951ab7b 314 case LOWPOWER:
GregCr 0:1ed39951ab7b 315 break;
GregCr 0:1ed39951ab7b 316 default:
GregCr 0:1ed39951ab7b 317 State = LOWPOWER;
GregCr 0:1ed39951ab7b 318 break;
GregCr 0:1ed39951ab7b 319 }
GregCr 0:1ed39951ab7b 320 }
GregCr 0:1ed39951ab7b 321 }
GregCr 0:1ed39951ab7b 322
GregCr 0:1ed39951ab7b 323 void OnTxDone( void )
GregCr 0:1ed39951ab7b 324 {
GregCr 5:f2431c4fe3bb 325 Radio.Sleep( );
GregCr 0:1ed39951ab7b 326 State = TX;
GregCr 7:c1bbd6c56979 327 debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" );
NguyenNguyenQuocHuy1 15:565259e9e94a 328 debug ("\n\r HUY ONTXDONE \n\r");
GregCr 0:1ed39951ab7b 329 }
GregCr 0:1ed39951ab7b 330
GregCr 4:5ece30264cd9 331 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
GregCr 0:1ed39951ab7b 332 {
GregCr 0:1ed39951ab7b 333 Radio.Sleep( );
GregCr 0:1ed39951ab7b 334 BufferSize = size;
GregCr 0:1ed39951ab7b 335 memcpy( Buffer, payload, BufferSize );
GregCr 0:1ed39951ab7b 336 RssiValue = rssi;
GregCr 0:1ed39951ab7b 337 SnrValue = snr;
GregCr 0:1ed39951ab7b 338 State = RX;
GregCr 7:c1bbd6c56979 339 debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" );
NguyenNguyenQuocHuy1 15:565259e9e94a 340 debug ("\n\r HUY RXDONE \n\r");
GregCr 0:1ed39951ab7b 341 }
GregCr 0:1ed39951ab7b 342
GregCr 0:1ed39951ab7b 343 void OnTxTimeout( void )
GregCr 0:1ed39951ab7b 344 {
GregCr 0:1ed39951ab7b 345 Radio.Sleep( );
GregCr 0:1ed39951ab7b 346 State = TX_TIMEOUT;
GregCr 7:c1bbd6c56979 347 debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" );
NguyenNguyenQuocHuy1 15:565259e9e94a 348 debug ("\n\r HUYTX_TIMEOUT \n\r");
GregCr 0:1ed39951ab7b 349 }
GregCr 0:1ed39951ab7b 350
GregCr 0:1ed39951ab7b 351 void OnRxTimeout( void )
GregCr 0:1ed39951ab7b 352 {
GregCr 0:1ed39951ab7b 353 Radio.Sleep( );
GregCr 1:126d70d374f6 354 Buffer[ BufferSize ] = 0;
GregCr 0:1ed39951ab7b 355 State = RX_TIMEOUT;
GregCr 7:c1bbd6c56979 356 debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" );
NguyenNguyenQuocHuy1 15:565259e9e94a 357 debug ("\n\r HUY RX_TIMEOUT \n\r");
GregCr 0:1ed39951ab7b 358 }
GregCr 0:1ed39951ab7b 359
GregCr 0:1ed39951ab7b 360 void OnRxError( void )
GregCr 0:1ed39951ab7b 361 {
GregCr 0:1ed39951ab7b 362 Radio.Sleep( );
GregCr 0:1ed39951ab7b 363 State = RX_ERROR;
GregCr 7:c1bbd6c56979 364 debug_if( DEBUG_MESSAGE, "> OnRxError\n\r" );
GregCr 0:1ed39951ab7b 365 }
GregCr 3:8b9e2a4df4b5 366