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