![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
hg
Dependencies: LoRaTransmitter mbed BME280 SX1272Lib
main.cpp@3:4e51739d3a97, 2022-06-11 (annotated)
- Committer:
- aizakharov
- Date:
- Sat Jun 11 14:20:20 2022 +0000
- Revision:
- 3:4e51739d3a97
- Parent:
- 1:30ce00fbab55
hhjjhkxkhn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aizakharov | 0:cc2b234b6255 | 1 | #include "mbed.h" |
aizakharov | 0:cc2b234b6255 | 2 | #include "main.h" |
aizakharov | 0:cc2b234b6255 | 3 | #include "sx1272-hal.h" |
aizakharov | 0:cc2b234b6255 | 4 | #include "debug.h" |
aizakharov | 3:4e51739d3a97 | 5 | #include "BME280.h" |
aizakharov | 0:cc2b234b6255 | 6 | |
aizakharov | 3:4e51739d3a97 | 7 | |
aizakharov | 0:cc2b234b6255 | 8 | |
aizakharov | 0:cc2b234b6255 | 9 | /* Set this flag to '1' to display debug messages on the console */ |
aizakharov | 0:cc2b234b6255 | 10 | #define DEBUG_MESSAGE 1 |
aizakharov | 0:cc2b234b6255 | 11 | |
aizakharov | 0:cc2b234b6255 | 12 | /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ |
aizakharov | 0:cc2b234b6255 | 13 | #define USE_MODEM_LORA 1 |
aizakharov | 0:cc2b234b6255 | 14 | #define USE_MODEM_FSK !USE_MODEM_LORA |
aizakharov | 0:cc2b234b6255 | 15 | |
aizakharov | 0:cc2b234b6255 | 16 | #define RF_FREQUENCY 868000000 // Hz |
aizakharov | 0:cc2b234b6255 | 17 | #define TX_OUTPUT_POWER 14 // 14 dBm |
aizakharov | 0:cc2b234b6255 | 18 | |
aizakharov | 0:cc2b234b6255 | 19 | #if USE_MODEM_LORA == 1 |
aizakharov | 0:cc2b234b6255 | 20 | |
aizakharov | 0:cc2b234b6255 | 21 | #define LORA_BANDWIDTH 2 // [0: 125 kHz, |
aizakharov | 0:cc2b234b6255 | 22 | // 1: 250 kHz, |
aizakharov | 0:cc2b234b6255 | 23 | // 2: 500 kHz, |
aizakharov | 0:cc2b234b6255 | 24 | // 3: Reserved] |
aizakharov | 0:cc2b234b6255 | 25 | #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] |
aizakharov | 0:cc2b234b6255 | 26 | #define LORA_CODINGRATE 1 // [1: 4/5, |
aizakharov | 0:cc2b234b6255 | 27 | // 2: 4/6, |
aizakharov | 0:cc2b234b6255 | 28 | // 3: 4/7, |
aizakharov | 0:cc2b234b6255 | 29 | // 4: 4/8] |
aizakharov | 0:cc2b234b6255 | 30 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
aizakharov | 0:cc2b234b6255 | 31 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
aizakharov | 0:cc2b234b6255 | 32 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
aizakharov | 0:cc2b234b6255 | 33 | #define LORA_FHSS_ENABLED false |
aizakharov | 0:cc2b234b6255 | 34 | #define LORA_NB_SYMB_HOP 4 |
aizakharov | 0:cc2b234b6255 | 35 | #define LORA_IQ_INVERSION_ON false |
aizakharov | 0:cc2b234b6255 | 36 | #define LORA_CRC_ENABLED true |
aizakharov | 0:cc2b234b6255 | 37 | |
aizakharov | 0:cc2b234b6255 | 38 | #elif USE_MODEM_FSK == 1 |
aizakharov | 0:cc2b234b6255 | 39 | |
aizakharov | 0:cc2b234b6255 | 40 | #define FSK_FDEV 25000 // Hz |
aizakharov | 0:cc2b234b6255 | 41 | #define FSK_DATARATE 19200 // bps |
aizakharov | 0:cc2b234b6255 | 42 | #define FSK_BANDWIDTH 50000 // Hz |
aizakharov | 0:cc2b234b6255 | 43 | #define FSK_AFC_BANDWIDTH 83333 // Hz |
aizakharov | 0:cc2b234b6255 | 44 | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
aizakharov | 0:cc2b234b6255 | 45 | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
aizakharov | 0:cc2b234b6255 | 46 | #define FSK_CRC_ENABLED true |
aizakharov | 0:cc2b234b6255 | 47 | |
aizakharov | 0:cc2b234b6255 | 48 | #else |
aizakharov | 0:cc2b234b6255 | 49 | #error "Please define a modem in the compiler options." |
aizakharov | 0:cc2b234b6255 | 50 | #endif |
aizakharov | 0:cc2b234b6255 | 51 | |
aizakharov | 0:cc2b234b6255 | 52 | #define RX_TIMEOUT_VALUE 35000 // in ms |
aizakharov | 0:cc2b234b6255 | 53 | #define BUFFER_SIZE 60 // Define the payload size here |
aizakharov | 0:cc2b234b6255 | 54 | |
aizakharov | 0:cc2b234b6255 | 55 | #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) |
aizakharov | 0:cc2b234b6255 | 56 | DigitalOut led( LED2 ); |
aizakharov | 0:cc2b234b6255 | 57 | #else |
aizakharov | 0:cc2b234b6255 | 58 | DigitalOut led( LED1 ); |
aizakharov | 0:cc2b234b6255 | 59 | #endif |
aizakharov | 0:cc2b234b6255 | 60 | |
aizakharov | 3:4e51739d3a97 | 61 | //Serial pc(USBTX, USBRX); // tx, rx |
aizakharov | 3:4e51739d3a97 | 62 | AnalogIn ground(A1); |
aizakharov | 3:4e51739d3a97 | 63 | BME280 sensor(I2C_SDA, I2C_SCL); |
aizakharov | 0:cc2b234b6255 | 64 | Ticker measure; |
aizakharov | 3:4e51739d3a97 | 65 | |
aizakharov | 0:cc2b234b6255 | 66 | |
aizakharov | 3:4e51739d3a97 | 67 | |
aizakharov | 3:4e51739d3a97 | 68 | |
aizakharov | 0:cc2b234b6255 | 69 | |
aizakharov | 0:cc2b234b6255 | 70 | /* |
aizakharov | 0:cc2b234b6255 | 71 | * Global variables declarations |
aizakharov | 0:cc2b234b6255 | 72 | */ |
aizakharov | 0:cc2b234b6255 | 73 | typedef enum |
aizakharov | 0:cc2b234b6255 | 74 | { |
aizakharov | 0:cc2b234b6255 | 75 | LOWPOWER = 0, |
aizakharov | 0:cc2b234b6255 | 76 | IDLE, |
aizakharov | 0:cc2b234b6255 | 77 | |
aizakharov | 0:cc2b234b6255 | 78 | RX, |
aizakharov | 0:cc2b234b6255 | 79 | RX_TIMEOUT, |
aizakharov | 0:cc2b234b6255 | 80 | RX_ERROR, |
aizakharov | 0:cc2b234b6255 | 81 | |
aizakharov | 0:cc2b234b6255 | 82 | TX, |
aizakharov | 0:cc2b234b6255 | 83 | TX_TIMEOUT, |
aizakharov | 0:cc2b234b6255 | 84 | |
aizakharov | 0:cc2b234b6255 | 85 | CAD, |
aizakharov | 0:cc2b234b6255 | 86 | CAD_DONE |
aizakharov | 0:cc2b234b6255 | 87 | }AppStates_t; |
aizakharov | 0:cc2b234b6255 | 88 | |
aizakharov | 0:cc2b234b6255 | 89 | volatile AppStates_t State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 90 | |
aizakharov | 0:cc2b234b6255 | 91 | /*! |
aizakharov | 0:cc2b234b6255 | 92 | * Radio events function pointer |
aizakharov | 0:cc2b234b6255 | 93 | */ |
aizakharov | 0:cc2b234b6255 | 94 | static RadioEvents_t RadioEvents; |
aizakharov | 0:cc2b234b6255 | 95 | |
aizakharov | 0:cc2b234b6255 | 96 | /* |
aizakharov | 0:cc2b234b6255 | 97 | * Global variables declarations |
aizakharov | 0:cc2b234b6255 | 98 | */ |
aizakharov | 0:cc2b234b6255 | 99 | SX1272MB2xAS Radio( NULL ); |
aizakharov | 0:cc2b234b6255 | 100 | |
aizakharov | 0:cc2b234b6255 | 101 | //const uint8_t Msg[]; |
aizakharov | 0:cc2b234b6255 | 102 | |
aizakharov | 0:cc2b234b6255 | 103 | uint16_t BufferSize = BUFFER_SIZE; |
aizakharov | 0:cc2b234b6255 | 104 | uint8_t Buffer[BUFFER_SIZE]; |
aizakharov | 0:cc2b234b6255 | 105 | |
aizakharov | 0:cc2b234b6255 | 106 | int16_t RssiValue = 0.0; |
aizakharov | 0:cc2b234b6255 | 107 | int8_t SnrValue = 0.0; |
aizakharov | 0:cc2b234b6255 | 108 | //float measured_sinus = 0.0; |
aizakharov | 0:cc2b234b6255 | 109 | int16_t j = 0; |
aizakharov | 3:4e51739d3a97 | 110 | float ground_hum, temperature, pressure, humidity; |
aizakharov | 1:30ce00fbab55 | 111 | |
aizakharov | 0:cc2b234b6255 | 112 | uint16_t strSize = 0; |
aizakharov | 0:cc2b234b6255 | 113 | char str[BUFFER_SIZE]; |
aizakharov | 3:4e51739d3a97 | 114 | |
aizakharov | 1:30ce00fbab55 | 115 | |
aizakharov | 1:30ce00fbab55 | 116 | |
aizakharov | 0:cc2b234b6255 | 117 | |
aizakharov | 0:cc2b234b6255 | 118 | void meas (void) |
aizakharov | 0:cc2b234b6255 | 119 | { |
aizakharov | 0:cc2b234b6255 | 120 | |
aizakharov | 3:4e51739d3a97 | 121 | ground_hum = ground; |
aizakharov | 3:4e51739d3a97 | 122 | printf("Ground humidity is %5.2f%%\n\r", ground_hum*100); |
aizakharov | 3:4e51739d3a97 | 123 | printf("%2.2f degC, %04.2f hPa, %2.2f %%\n\r", temperature, pressure, humidity); |
aizakharov | 3:4e51739d3a97 | 124 | strSize = sprintf ( str, "%5.2f%%, %5.2f degC, %5.2f hPa, %5.2f %%", ground_hum*100, temperature, pressure, humidity); |
aizakharov | 3:4e51739d3a97 | 125 | State = TX; |
aizakharov | 1:30ce00fbab55 | 126 | |
aizakharov | 3:4e51739d3a97 | 127 | |
aizakharov | 1:30ce00fbab55 | 128 | } |
aizakharov | 1:30ce00fbab55 | 129 | |
aizakharov | 3:4e51739d3a97 | 130 | |
aizakharov | 0:cc2b234b6255 | 131 | |
aizakharov | 0:cc2b234b6255 | 132 | |
aizakharov | 0:cc2b234b6255 | 133 | |
aizakharov | 0:cc2b234b6255 | 134 | |
aizakharov | 0:cc2b234b6255 | 135 | |
aizakharov | 0:cc2b234b6255 | 136 | int main( void ) |
aizakharov | 0:cc2b234b6255 | 137 | { |
aizakharov | 1:30ce00fbab55 | 138 | |
aizakharov | 0:cc2b234b6255 | 139 | |
aizakharov | 0:cc2b234b6255 | 140 | |
aizakharov | 0:cc2b234b6255 | 141 | |
aizakharov | 0:cc2b234b6255 | 142 | |
aizakharov | 0:cc2b234b6255 | 143 | |
aizakharov | 0:cc2b234b6255 | 144 | //uint8_t i; |
aizakharov | 0:cc2b234b6255 | 145 | //bool isMaster = true; |
aizakharov | 0:cc2b234b6255 | 146 | |
aizakharov | 0:cc2b234b6255 | 147 | debug( "\n\n\r SX1272 Ping Pong Demo Application \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 148 | |
aizakharov | 0:cc2b234b6255 | 149 | // Initialize Radio driver |
aizakharov | 0:cc2b234b6255 | 150 | RadioEvents.TxDone = OnTxDone; |
aizakharov | 0:cc2b234b6255 | 151 | RadioEvents.RxDone = OnRxDone; |
aizakharov | 0:cc2b234b6255 | 152 | RadioEvents.RxError = OnRxError; |
aizakharov | 0:cc2b234b6255 | 153 | RadioEvents.TxTimeout = OnTxTimeout; |
aizakharov | 0:cc2b234b6255 | 154 | RadioEvents.RxTimeout = OnRxTimeout; |
aizakharov | 0:cc2b234b6255 | 155 | Radio.Init( &RadioEvents ); |
aizakharov | 0:cc2b234b6255 | 156 | |
aizakharov | 0:cc2b234b6255 | 157 | // verify the connection with the board |
aizakharov | 0:cc2b234b6255 | 158 | while( Radio.Read( REG_VERSION ) == 0x00 ) |
aizakharov | 0:cc2b234b6255 | 159 | { |
aizakharov | 0:cc2b234b6255 | 160 | debug( "Radio could not be detected!\n\r", NULL ); |
aizakharov | 0:cc2b234b6255 | 161 | wait( 1 ); |
aizakharov | 0:cc2b234b6255 | 162 | } |
aizakharov | 0:cc2b234b6255 | 163 | |
aizakharov | 0:cc2b234b6255 | 164 | debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1272MB2XAS ) ), "\n\r > Board Type: SX1272MB2xAS < \n\r" ); |
aizakharov | 0:cc2b234b6255 | 165 | |
aizakharov | 0:cc2b234b6255 | 166 | Radio.SetChannel( RF_FREQUENCY ); |
aizakharov | 0:cc2b234b6255 | 167 | |
aizakharov | 0:cc2b234b6255 | 168 | #if USE_MODEM_LORA == 1 |
aizakharov | 0:cc2b234b6255 | 169 | |
aizakharov | 0:cc2b234b6255 | 170 | debug_if( LORA_FHSS_ENABLED, "\n\n\r > LORA FHSS Mode < \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 171 | debug_if( !LORA_FHSS_ENABLED, "\n\n\r > LORA Mode < \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 172 | |
aizakharov | 0:cc2b234b6255 | 173 | Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, |
aizakharov | 0:cc2b234b6255 | 174 | LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
aizakharov | 0:cc2b234b6255 | 175 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
aizakharov | 0:cc2b234b6255 | 176 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
aizakharov | 0:cc2b234b6255 | 177 | LORA_IQ_INVERSION_ON, 2000 ); |
aizakharov | 0:cc2b234b6255 | 178 | |
aizakharov | 0:cc2b234b6255 | 179 | Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, |
aizakharov | 0:cc2b234b6255 | 180 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
aizakharov | 0:cc2b234b6255 | 181 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
aizakharov | 0:cc2b234b6255 | 182 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
aizakharov | 0:cc2b234b6255 | 183 | LORA_IQ_INVERSION_ON, true ); |
aizakharov | 0:cc2b234b6255 | 184 | |
aizakharov | 0:cc2b234b6255 | 185 | #elif USE_MODEM_FSK == 1 |
aizakharov | 0:cc2b234b6255 | 186 | |
aizakharov | 0:cc2b234b6255 | 187 | debug("\n\n\r > FSK Mode < \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 188 | Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, |
aizakharov | 0:cc2b234b6255 | 189 | FSK_DATARATE, 0, |
aizakharov | 0:cc2b234b6255 | 190 | FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, |
aizakharov | 0:cc2b234b6255 | 191 | FSK_CRC_ENABLED, 0, 0, 0, 2000 ); |
aizakharov | 0:cc2b234b6255 | 192 | |
aizakharov | 0:cc2b234b6255 | 193 | Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, |
aizakharov | 0:cc2b234b6255 | 194 | 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, |
aizakharov | 0:cc2b234b6255 | 195 | 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED, |
aizakharov | 0:cc2b234b6255 | 196 | 0, 0, false, true ); |
aizakharov | 0:cc2b234b6255 | 197 | |
aizakharov | 0:cc2b234b6255 | 198 | #else |
aizakharov | 0:cc2b234b6255 | 199 | |
aizakharov | 0:cc2b234b6255 | 200 | #error "Please define a modem in the compiler options." |
aizakharov | 0:cc2b234b6255 | 201 | |
aizakharov | 0:cc2b234b6255 | 202 | #endif |
aizakharov | 0:cc2b234b6255 | 203 | |
aizakharov | 0:cc2b234b6255 | 204 | //debug_if( DEBUG_MESSAGE, "Starting Ping-Pong loop\r\n" ); |
aizakharov | 0:cc2b234b6255 | 205 | |
aizakharov | 0:cc2b234b6255 | 206 | led = 0; |
aizakharov | 0:cc2b234b6255 | 207 | |
aizakharov | 0:cc2b234b6255 | 208 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 209 | |
aizakharov | 0:cc2b234b6255 | 210 | |
aizakharov | 0:cc2b234b6255 | 211 | //int n = 0; |
aizakharov | 0:cc2b234b6255 | 212 | |
aizakharov | 0:cc2b234b6255 | 213 | |
aizakharov | 0:cc2b234b6255 | 214 | |
aizakharov | 0:cc2b234b6255 | 215 | |
aizakharov | 3:4e51739d3a97 | 216 | measure.attach(&meas, 5); |
aizakharov | 0:cc2b234b6255 | 217 | |
aizakharov | 0:cc2b234b6255 | 218 | while( 1 ) |
aizakharov | 0:cc2b234b6255 | 219 | { |
aizakharov | 1:30ce00fbab55 | 220 | |
aizakharov | 0:cc2b234b6255 | 221 | |
aizakharov | 0:cc2b234b6255 | 222 | |
aizakharov | 0:cc2b234b6255 | 223 | |
aizakharov | 0:cc2b234b6255 | 224 | |
aizakharov | 1:30ce00fbab55 | 225 | switch( State ) |
aizakharov | 0:cc2b234b6255 | 226 | { |
aizakharov | 0:cc2b234b6255 | 227 | case RX: |
aizakharov | 1:30ce00fbab55 | 228 | |
aizakharov | 0:cc2b234b6255 | 229 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 230 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 231 | break; |
aizakharov | 0:cc2b234b6255 | 232 | case TX: |
aizakharov | 0:cc2b234b6255 | 233 | |
aizakharov | 0:cc2b234b6255 | 234 | strcpy(( char* )Buffer, ( char* ) str); |
aizakharov | 1:30ce00fbab55 | 235 | Radio.Send((uint8_t *) Buffer, BufferSize ); |
aizakharov | 0:cc2b234b6255 | 236 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 237 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 238 | break; |
aizakharov | 0:cc2b234b6255 | 239 | case RX_TIMEOUT: |
aizakharov | 0:cc2b234b6255 | 240 | Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 241 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 242 | break; |
aizakharov | 0:cc2b234b6255 | 243 | case RX_ERROR: |
aizakharov | 3:4e51739d3a97 | 244 | Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 245 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 246 | break; |
aizakharov | 0:cc2b234b6255 | 247 | case TX_TIMEOUT: |
aizakharov | 1:30ce00fbab55 | 248 | Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 249 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 250 | break; |
aizakharov | 0:cc2b234b6255 | 251 | case LOWPOWER: |
aizakharov | 0:cc2b234b6255 | 252 | break; |
aizakharov | 0:cc2b234b6255 | 253 | default: |
aizakharov | 0:cc2b234b6255 | 254 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 255 | break; |
aizakharov | 0:cc2b234b6255 | 256 | } |
aizakharov | 3:4e51739d3a97 | 257 | temperature = sensor.getTemperature(); |
aizakharov | 3:4e51739d3a97 | 258 | pressure = sensor.getPressure(); |
aizakharov | 3:4e51739d3a97 | 259 | humidity = sensor.getHumidity(); |
aizakharov | 3:4e51739d3a97 | 260 | |
aizakharov | 1:30ce00fbab55 | 261 | wait(5); |
aizakharov | 0:cc2b234b6255 | 262 | } |
aizakharov | 0:cc2b234b6255 | 263 | } |
aizakharov | 0:cc2b234b6255 | 264 | |
aizakharov | 0:cc2b234b6255 | 265 | void OnTxDone( void ) |
aizakharov | 0:cc2b234b6255 | 266 | { |
aizakharov | 0:cc2b234b6255 | 267 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 268 | State = TX; |
aizakharov | 0:cc2b234b6255 | 269 | debug_if( DEBUG_MESSAGE, "\r\n> OnTxDone\n\r" ); |
aizakharov | 0:cc2b234b6255 | 270 | } |
aizakharov | 0:cc2b234b6255 | 271 | |
aizakharov | 0:cc2b234b6255 | 272 | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
aizakharov | 0:cc2b234b6255 | 273 | { |
aizakharov | 0:cc2b234b6255 | 274 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 275 | BufferSize = size; |
aizakharov | 0:cc2b234b6255 | 276 | memcpy( Buffer, payload, BufferSize ); |
aizakharov | 0:cc2b234b6255 | 277 | RssiValue = rssi; |
aizakharov | 0:cc2b234b6255 | 278 | SnrValue = snr; |
aizakharov | 0:cc2b234b6255 | 279 | |
aizakharov | 0:cc2b234b6255 | 280 | State = RX; |
aizakharov | 0:cc2b234b6255 | 281 | debug_if( DEBUG_MESSAGE, "\r\n> OnRxDone\n\r" ); |
aizakharov | 0:cc2b234b6255 | 282 | } |
aizakharov | 0:cc2b234b6255 | 283 | |
aizakharov | 0:cc2b234b6255 | 284 | void OnTxTimeout( void ) |
aizakharov | 0:cc2b234b6255 | 285 | { |
aizakharov | 0:cc2b234b6255 | 286 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 287 | State = TX_TIMEOUT; |
aizakharov | 0:cc2b234b6255 | 288 | debug_if( DEBUG_MESSAGE, "\r\n> OnTxTimeout\n\r" ); |
aizakharov | 0:cc2b234b6255 | 289 | } |
aizakharov | 0:cc2b234b6255 | 290 | |
aizakharov | 0:cc2b234b6255 | 291 | void OnRxTimeout( void ) |
aizakharov | 0:cc2b234b6255 | 292 | { |
aizakharov | 0:cc2b234b6255 | 293 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 294 | Buffer[BufferSize] = 0; |
aizakharov | 0:cc2b234b6255 | 295 | State = RX_TIMEOUT; |
aizakharov | 0:cc2b234b6255 | 296 | debug_if( DEBUG_MESSAGE, "\r\n> OnRxTimeout\n\r" ); |
aizakharov | 0:cc2b234b6255 | 297 | } |
aizakharov | 0:cc2b234b6255 | 298 | |
aizakharov | 0:cc2b234b6255 | 299 | void OnRxError( void ) |
aizakharov | 0:cc2b234b6255 | 300 | { |
aizakharov | 0:cc2b234b6255 | 301 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 302 | State = RX_ERROR; |
aizakharov | 0:cc2b234b6255 | 303 | debug_if( DEBUG_MESSAGE, "\r\n> OnRxError\n\r" ); |
aizakharov | 0:cc2b234b6255 | 304 | } |