123
Dependencies: mbed Grove_LCD_RGB_Backlight SX1272Lib
main.cpp@3:02bd846316e2, 2022-06-06 (annotated)
- Committer:
- advxolltm
- Date:
- Mon Jun 06 13:09:46 2022 +0000
- Revision:
- 3:02bd846316e2
- Parent:
- 2:2bcb1840d680
last version;
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 | 0:cc2b234b6255 | 5 | |
aizakharov | 0:cc2b234b6255 | 6 | #include "Grove_LCD_RGB_Backlight.h" |
aizakharov | 0:cc2b234b6255 | 7 | |
aizakharov | 0:cc2b234b6255 | 8 | /* Set this flag to '1' to display debug messages on the console */ |
aizakharov | 0:cc2b234b6255 | 9 | #define DEBUG_MESSAGE 1 |
aizakharov | 0:cc2b234b6255 | 10 | |
aizakharov | 0:cc2b234b6255 | 11 | /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ |
aizakharov | 0:cc2b234b6255 | 12 | #define USE_MODEM_LORA 1 |
aizakharov | 0:cc2b234b6255 | 13 | #define USE_MODEM_FSK !USE_MODEM_LORA |
aizakharov | 0:cc2b234b6255 | 14 | |
advxolltm | 3:02bd846316e2 | 15 | #define RF_FREQUENCY 864300000 // Hz |
advxolltm | 3:02bd846316e2 | 16 | #define TX_OUTPUT_POWER 70 // 14 dBm |
aizakharov | 0:cc2b234b6255 | 17 | |
aizakharov | 0:cc2b234b6255 | 18 | #if USE_MODEM_LORA == 1 |
aizakharov | 0:cc2b234b6255 | 19 | |
aizakharov | 0:cc2b234b6255 | 20 | #define LORA_BANDWIDTH 2 // [0: 125 kHz, |
aizakharov | 0:cc2b234b6255 | 21 | // 1: 250 kHz, |
aizakharov | 0:cc2b234b6255 | 22 | // 2: 500 kHz, |
aizakharov | 0:cc2b234b6255 | 23 | // 3: Reserved] |
aizakharov | 0:cc2b234b6255 | 24 | #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] |
aizakharov | 0:cc2b234b6255 | 25 | #define LORA_CODINGRATE 1 // [1: 4/5, |
aizakharov | 0:cc2b234b6255 | 26 | // 2: 4/6, |
aizakharov | 0:cc2b234b6255 | 27 | // 3: 4/7, |
aizakharov | 0:cc2b234b6255 | 28 | // 4: 4/8] |
aizakharov | 0:cc2b234b6255 | 29 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
aizakharov | 0:cc2b234b6255 | 30 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
aizakharov | 0:cc2b234b6255 | 31 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
aizakharov | 0:cc2b234b6255 | 32 | #define LORA_FHSS_ENABLED false |
aizakharov | 0:cc2b234b6255 | 33 | #define LORA_NB_SYMB_HOP 4 |
aizakharov | 0:cc2b234b6255 | 34 | #define LORA_IQ_INVERSION_ON false |
aizakharov | 0:cc2b234b6255 | 35 | #define LORA_CRC_ENABLED true |
aizakharov | 0:cc2b234b6255 | 36 | |
aizakharov | 0:cc2b234b6255 | 37 | #elif USE_MODEM_FSK == 1 |
aizakharov | 0:cc2b234b6255 | 38 | |
aizakharov | 0:cc2b234b6255 | 39 | #define FSK_FDEV 25000 // Hz |
aizakharov | 0:cc2b234b6255 | 40 | #define FSK_DATARATE 19200 // bps |
aizakharov | 0:cc2b234b6255 | 41 | #define FSK_BANDWIDTH 50000 // Hz |
aizakharov | 0:cc2b234b6255 | 42 | #define FSK_AFC_BANDWIDTH 83333 // Hz |
aizakharov | 0:cc2b234b6255 | 43 | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
aizakharov | 0:cc2b234b6255 | 44 | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
aizakharov | 0:cc2b234b6255 | 45 | #define FSK_CRC_ENABLED true |
aizakharov | 0:cc2b234b6255 | 46 | |
aizakharov | 0:cc2b234b6255 | 47 | #else |
aizakharov | 0:cc2b234b6255 | 48 | #error "Please define a modem in the compiler options." |
aizakharov | 0:cc2b234b6255 | 49 | #endif |
aizakharov | 0:cc2b234b6255 | 50 | |
aizakharov | 0:cc2b234b6255 | 51 | #define RX_TIMEOUT_VALUE 35000 // in ms |
aizakharov | 0:cc2b234b6255 | 52 | #define BUFFER_SIZE 60 // Define the payload size here |
aizakharov | 0:cc2b234b6255 | 53 | |
aizakharov | 0:cc2b234b6255 | 54 | #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) |
aizakharov | 0:cc2b234b6255 | 55 | DigitalOut led( LED2 ); |
aizakharov | 0:cc2b234b6255 | 56 | #else |
aizakharov | 0:cc2b234b6255 | 57 | DigitalOut led( LED1 ); |
aizakharov | 0:cc2b234b6255 | 58 | #endif |
aizakharov | 0:cc2b234b6255 | 59 | |
aizakharov | 0:cc2b234b6255 | 60 | Serial pc(USBTX, USBRX); // tx, rx |
aizakharov | 0:cc2b234b6255 | 61 | AnalogIn voltage(PC_5); |
aizakharov | 0:cc2b234b6255 | 62 | AnalogIn current(A1); |
aizakharov | 0:cc2b234b6255 | 63 | Ticker measure; |
aizakharov | 0:cc2b234b6255 | 64 | Ticker send; |
aizakharov | 0:cc2b234b6255 | 65 | Grove_LCD_RGB_Backlight lcd(I2C_SDA, I2C_SCL); |
aizakharov | 0:cc2b234b6255 | 66 | |
aizakharov | 0:cc2b234b6255 | 67 | //Grove_LCD_RGB_Backlight rgbLCD(I2C_SDA, I2C_SCL); |
aizakharov | 0:cc2b234b6255 | 68 | |
aizakharov | 0:cc2b234b6255 | 69 | /* |
aizakharov | 0:cc2b234b6255 | 70 | * Global variables declarations |
aizakharov | 0:cc2b234b6255 | 71 | */ |
aizakharov | 0:cc2b234b6255 | 72 | typedef enum |
aizakharov | 0:cc2b234b6255 | 73 | { |
aizakharov | 0:cc2b234b6255 | 74 | LOWPOWER = 0, |
aizakharov | 0:cc2b234b6255 | 75 | IDLE, |
aizakharov | 0:cc2b234b6255 | 76 | |
aizakharov | 0:cc2b234b6255 | 77 | RX, |
aizakharov | 0:cc2b234b6255 | 78 | RX_TIMEOUT, |
aizakharov | 0:cc2b234b6255 | 79 | RX_ERROR, |
aizakharov | 0:cc2b234b6255 | 80 | |
aizakharov | 0:cc2b234b6255 | 81 | TX, |
aizakharov | 0:cc2b234b6255 | 82 | TX_TIMEOUT, |
aizakharov | 0:cc2b234b6255 | 83 | |
aizakharov | 0:cc2b234b6255 | 84 | CAD, |
aizakharov | 0:cc2b234b6255 | 85 | CAD_DONE |
aizakharov | 0:cc2b234b6255 | 86 | }AppStates_t; |
aizakharov | 0:cc2b234b6255 | 87 | |
aizakharov | 0:cc2b234b6255 | 88 | volatile AppStates_t State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 89 | |
aizakharov | 0:cc2b234b6255 | 90 | /*! |
aizakharov | 0:cc2b234b6255 | 91 | * Radio events function pointer |
aizakharov | 0:cc2b234b6255 | 92 | */ |
aizakharov | 0:cc2b234b6255 | 93 | static RadioEvents_t RadioEvents; |
aizakharov | 0:cc2b234b6255 | 94 | |
aizakharov | 0:cc2b234b6255 | 95 | /* |
aizakharov | 0:cc2b234b6255 | 96 | * Global variables declarations |
aizakharov | 0:cc2b234b6255 | 97 | */ |
aizakharov | 0:cc2b234b6255 | 98 | SX1272MB2xAS Radio( NULL ); |
aizakharov | 0:cc2b234b6255 | 99 | |
aizakharov | 0:cc2b234b6255 | 100 | //const uint8_t Msg[]; |
aizakharov | 0:cc2b234b6255 | 101 | |
aizakharov | 0:cc2b234b6255 | 102 | uint16_t BufferSize = BUFFER_SIZE; |
aizakharov | 0:cc2b234b6255 | 103 | uint8_t Buffer[BUFFER_SIZE]; |
aizakharov | 0:cc2b234b6255 | 104 | |
aizakharov | 0:cc2b234b6255 | 105 | int16_t RssiValue = 0.0; |
aizakharov | 0:cc2b234b6255 | 106 | int8_t SnrValue = 0.0; |
aizakharov | 0:cc2b234b6255 | 107 | //float measured_sinus = 0.0; |
aizakharov | 0:cc2b234b6255 | 108 | int16_t j = 0; |
aizakharov | 1:30ce00fbab55 | 109 | float voltage_sinus, current_sinus; |
aizakharov | 1:30ce00fbab55 | 110 | volatile float Vsum = 0,Vmax =0, Vmean = 0, Imax =0, Isum = 0, Imean = 0, Ud = 0, Id = 0, cosi = 0; |
aizakharov | 1:30ce00fbab55 | 111 | volatile double P = 0, P2 = 0, S2 = 0, P1=0, S1=0; |
aizakharov | 1:30ce00fbab55 | 112 | |
aizakharov | 2:2bcb1840d680 | 113 | |
aizakharov | 0:cc2b234b6255 | 114 | uint16_t strSize = 0; |
aizakharov | 0:cc2b234b6255 | 115 | char str[BUFFER_SIZE]; |
aizakharov | 1:30ce00fbab55 | 116 | char monitor[16]="0", monitor1[16]="0"; |
aizakharov | 1:30ce00fbab55 | 117 | |
aizakharov | 1:30ce00fbab55 | 118 | |
aizakharov | 0:cc2b234b6255 | 119 | |
aizakharov | 0:cc2b234b6255 | 120 | void meas (void) |
aizakharov | 0:cc2b234b6255 | 121 | { |
aizakharov | 0:cc2b234b6255 | 122 | |
aizakharov | 1:30ce00fbab55 | 123 | j++; |
aizakharov | 2:2bcb1840d680 | 124 | |
aizakharov | 1:30ce00fbab55 | 125 | voltage_sinus = voltage*2200; |
aizakharov | 1:30ce00fbab55 | 126 | current_sinus = current*5; |
aizakharov | 1:30ce00fbab55 | 127 | Vsum+=voltage_sinus; |
aizakharov | 1:30ce00fbab55 | 128 | Isum+=current_sinus; |
aizakharov | 1:30ce00fbab55 | 129 | if (voltage_sinus>Vmax) |
aizakharov | 1:30ce00fbab55 | 130 | Vmax=voltage_sinus; |
aizakharov | 1:30ce00fbab55 | 131 | if (current_sinus>Imax) |
aizakharov | 1:30ce00fbab55 | 132 | Imax=current_sinus; |
aizakharov | 1:30ce00fbab55 | 133 | |
aizakharov | 1:30ce00fbab55 | 134 | P=P+(((voltage_sinus-Vmean)*(current_sinus-Imean))*(0.0002/3600000)); |
aizakharov | 1:30ce00fbab55 | 135 | P2=P2+((voltage_sinus-Vmean)*(current_sinus-Imean)); |
aizakharov | 1:30ce00fbab55 | 136 | if((((voltage_sinus-Vmean)*(current_sinus-Imean))*(0.0002/3600000))>0) |
aizakharov | 1:30ce00fbab55 | 137 | S2=S2+((voltage_sinus-Vmean)*(current_sinus-Imean)); |
aizakharov | 1:30ce00fbab55 | 138 | |
aizakharov | 1:30ce00fbab55 | 139 | |
aizakharov | 1:30ce00fbab55 | 140 | if (j>=300) |
aizakharov | 0:cc2b234b6255 | 141 | { |
aizakharov | 0:cc2b234b6255 | 142 | j = 0; |
aizakharov | 1:30ce00fbab55 | 143 | Vmean=Vsum/(300); |
aizakharov | 1:30ce00fbab55 | 144 | Imean = Isum/(300); |
aizakharov | 1:30ce00fbab55 | 145 | P1=P2/300; S1=S2/300; |
aizakharov | 0:cc2b234b6255 | 146 | Ud=(Vmax-Vmean)/1.41; |
aizakharov | 0:cc2b234b6255 | 147 | Id=(Imax-Imean)/1.41; |
aizakharov | 2:2bcb1840d680 | 148 | Vmax = 0; Imax = 0; Vsum=0; Isum =0; |
aizakharov | 1:30ce00fbab55 | 149 | |
aizakharov | 1:30ce00fbab55 | 150 | cosi = P2/S2; |
aizakharov | 1:30ce00fbab55 | 151 | P2=0; S2=0; |
aizakharov | 0:cc2b234b6255 | 152 | } |
aizakharov | 1:30ce00fbab55 | 153 | } |
aizakharov | 1:30ce00fbab55 | 154 | |
aizakharov | 1:30ce00fbab55 | 155 | void transmit (void) |
aizakharov | 1:30ce00fbab55 | 156 | { |
advxolltm | 3:02bd846316e2 | 157 | strSize = sprintf ( str, "0001, %10.4f, %5.4f, %5.4f, %5.4f", P, cosi, P1*1.41, S1*1.41); |
advxolltm | 3:02bd846316e2 | 158 | State=TX; |
aizakharov | 0:cc2b234b6255 | 159 | } |
aizakharov | 0:cc2b234b6255 | 160 | |
aizakharov | 0:cc2b234b6255 | 161 | |
aizakharov | 0:cc2b234b6255 | 162 | |
aizakharov | 0:cc2b234b6255 | 163 | |
aizakharov | 0:cc2b234b6255 | 164 | |
aizakharov | 0:cc2b234b6255 | 165 | int main( void ) |
aizakharov | 0:cc2b234b6255 | 166 | { |
aizakharov | 1:30ce00fbab55 | 167 | |
aizakharov | 0:cc2b234b6255 | 168 | |
aizakharov | 0:cc2b234b6255 | 169 | |
aizakharov | 0:cc2b234b6255 | 170 | |
aizakharov | 0:cc2b234b6255 | 171 | |
aizakharov | 0:cc2b234b6255 | 172 | |
aizakharov | 0:cc2b234b6255 | 173 | //uint8_t i; |
aizakharov | 0:cc2b234b6255 | 174 | //bool isMaster = true; |
aizakharov | 0:cc2b234b6255 | 175 | |
aizakharov | 0:cc2b234b6255 | 176 | debug( "\n\n\r SX1272 Ping Pong Demo Application \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 177 | |
aizakharov | 0:cc2b234b6255 | 178 | // Initialize Radio driver |
aizakharov | 0:cc2b234b6255 | 179 | RadioEvents.TxDone = OnTxDone; |
aizakharov | 0:cc2b234b6255 | 180 | RadioEvents.RxDone = OnRxDone; |
aizakharov | 0:cc2b234b6255 | 181 | RadioEvents.RxError = OnRxError; |
aizakharov | 0:cc2b234b6255 | 182 | RadioEvents.TxTimeout = OnTxTimeout; |
aizakharov | 0:cc2b234b6255 | 183 | RadioEvents.RxTimeout = OnRxTimeout; |
aizakharov | 0:cc2b234b6255 | 184 | Radio.Init( &RadioEvents ); |
aizakharov | 0:cc2b234b6255 | 185 | |
aizakharov | 0:cc2b234b6255 | 186 | // verify the connection with the board |
aizakharov | 0:cc2b234b6255 | 187 | while( Radio.Read( REG_VERSION ) == 0x00 ) |
aizakharov | 0:cc2b234b6255 | 188 | { |
aizakharov | 0:cc2b234b6255 | 189 | debug( "Radio could not be detected!\n\r", NULL ); |
aizakharov | 0:cc2b234b6255 | 190 | wait( 1 ); |
aizakharov | 0:cc2b234b6255 | 191 | } |
aizakharov | 0:cc2b234b6255 | 192 | |
aizakharov | 0:cc2b234b6255 | 193 | debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1272MB2XAS ) ), "\n\r > Board Type: SX1272MB2xAS < \n\r" ); |
aizakharov | 0:cc2b234b6255 | 194 | |
aizakharov | 0:cc2b234b6255 | 195 | Radio.SetChannel( RF_FREQUENCY ); |
aizakharov | 0:cc2b234b6255 | 196 | |
aizakharov | 0:cc2b234b6255 | 197 | #if USE_MODEM_LORA == 1 |
aizakharov | 0:cc2b234b6255 | 198 | |
aizakharov | 0:cc2b234b6255 | 199 | debug_if( LORA_FHSS_ENABLED, "\n\n\r > LORA FHSS Mode < \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 200 | debug_if( !LORA_FHSS_ENABLED, "\n\n\r > LORA Mode < \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 201 | |
aizakharov | 0:cc2b234b6255 | 202 | Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, |
aizakharov | 0:cc2b234b6255 | 203 | LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
aizakharov | 0:cc2b234b6255 | 204 | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
aizakharov | 0:cc2b234b6255 | 205 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
aizakharov | 0:cc2b234b6255 | 206 | LORA_IQ_INVERSION_ON, 2000 ); |
aizakharov | 0:cc2b234b6255 | 207 | |
aizakharov | 0:cc2b234b6255 | 208 | Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, |
aizakharov | 0:cc2b234b6255 | 209 | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
aizakharov | 0:cc2b234b6255 | 210 | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0, |
aizakharov | 0:cc2b234b6255 | 211 | LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, |
aizakharov | 0:cc2b234b6255 | 212 | LORA_IQ_INVERSION_ON, true ); |
aizakharov | 0:cc2b234b6255 | 213 | |
aizakharov | 0:cc2b234b6255 | 214 | #elif USE_MODEM_FSK == 1 |
aizakharov | 0:cc2b234b6255 | 215 | |
aizakharov | 0:cc2b234b6255 | 216 | debug("\n\n\r > FSK Mode < \n\n\r" ); |
aizakharov | 0:cc2b234b6255 | 217 | Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, |
aizakharov | 0:cc2b234b6255 | 218 | FSK_DATARATE, 0, |
aizakharov | 0:cc2b234b6255 | 219 | FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, |
aizakharov | 0:cc2b234b6255 | 220 | FSK_CRC_ENABLED, 0, 0, 0, 2000 ); |
aizakharov | 0:cc2b234b6255 | 221 | |
aizakharov | 0:cc2b234b6255 | 222 | Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, |
aizakharov | 0:cc2b234b6255 | 223 | 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, |
aizakharov | 0:cc2b234b6255 | 224 | 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED, |
aizakharov | 0:cc2b234b6255 | 225 | 0, 0, false, true ); |
aizakharov | 0:cc2b234b6255 | 226 | |
aizakharov | 0:cc2b234b6255 | 227 | #else |
aizakharov | 0:cc2b234b6255 | 228 | |
aizakharov | 0:cc2b234b6255 | 229 | #error "Please define a modem in the compiler options." |
aizakharov | 0:cc2b234b6255 | 230 | |
aizakharov | 0:cc2b234b6255 | 231 | #endif |
aizakharov | 0:cc2b234b6255 | 232 | |
aizakharov | 0:cc2b234b6255 | 233 | //debug_if( DEBUG_MESSAGE, "Starting Ping-Pong loop\r\n" ); |
aizakharov | 0:cc2b234b6255 | 234 | |
aizakharov | 0:cc2b234b6255 | 235 | led = 0; |
aizakharov | 0:cc2b234b6255 | 236 | |
aizakharov | 0:cc2b234b6255 | 237 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 238 | |
aizakharov | 0:cc2b234b6255 | 239 | |
aizakharov | 0:cc2b234b6255 | 240 | //int n = 0; |
aizakharov | 0:cc2b234b6255 | 241 | |
aizakharov | 0:cc2b234b6255 | 242 | |
aizakharov | 0:cc2b234b6255 | 243 | |
aizakharov | 0:cc2b234b6255 | 244 | |
aizakharov | 0:cc2b234b6255 | 245 | measure.attach_us(&meas, 200); |
advxolltm | 3:02bd846316e2 | 246 | send.attach(&transmit, 10); |
aizakharov | 0:cc2b234b6255 | 247 | |
aizakharov | 0:cc2b234b6255 | 248 | while( 1 ) |
aizakharov | 0:cc2b234b6255 | 249 | { |
aizakharov | 1:30ce00fbab55 | 250 | |
aizakharov | 0:cc2b234b6255 | 251 | |
aizakharov | 0:cc2b234b6255 | 252 | |
aizakharov | 0:cc2b234b6255 | 253 | lcd.setRGB(0, 255, 0); |
aizakharov | 0:cc2b234b6255 | 254 | |
aizakharov | 0:cc2b234b6255 | 255 | |
aizakharov | 0:cc2b234b6255 | 256 | |
aizakharov | 0:cc2b234b6255 | 257 | sprintf(monitor, "U=%3.0fV, I=%3.2fA", Ud, Id); |
aizakharov | 1:30ce00fbab55 | 258 | sprintf(monitor1, "P=%8.2f kWh", P); |
aizakharov | 0:cc2b234b6255 | 259 | // Print a message to the LCD. |
aizakharov | 0:cc2b234b6255 | 260 | lcd.locate(0, 0); |
aizakharov | 0:cc2b234b6255 | 261 | lcd.print(monitor); |
aizakharov | 0:cc2b234b6255 | 262 | lcd.locate(0, 1); |
aizakharov | 0:cc2b234b6255 | 263 | lcd.print(monitor1); |
aizakharov | 0:cc2b234b6255 | 264 | |
aizakharov | 1:30ce00fbab55 | 265 | switch( State ) |
aizakharov | 0:cc2b234b6255 | 266 | { |
aizakharov | 0:cc2b234b6255 | 267 | case RX: |
aizakharov | 0:cc2b234b6255 | 268 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 269 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 270 | break; |
aizakharov | 0:cc2b234b6255 | 271 | case TX: |
aizakharov | 0:cc2b234b6255 | 272 | strcpy(( char* )Buffer, ( char* ) str); |
advxolltm | 3:02bd846316e2 | 273 | Radio.Send((uint8_t *) Buffer, BufferSize ); |
aizakharov | 0:cc2b234b6255 | 274 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 275 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 276 | break; |
aizakharov | 0:cc2b234b6255 | 277 | case RX_TIMEOUT: |
advxolltm | 3:02bd846316e2 | 278 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 279 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 280 | break; |
aizakharov | 0:cc2b234b6255 | 281 | case RX_ERROR: |
aizakharov | 0:cc2b234b6255 | 282 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 283 | break; |
aizakharov | 0:cc2b234b6255 | 284 | case TX_TIMEOUT: |
advxolltm | 3:02bd846316e2 | 285 | //Radio.Rx( RX_TIMEOUT_VALUE ); |
aizakharov | 0:cc2b234b6255 | 286 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 287 | break; |
aizakharov | 0:cc2b234b6255 | 288 | case LOWPOWER: |
aizakharov | 0:cc2b234b6255 | 289 | break; |
aizakharov | 0:cc2b234b6255 | 290 | default: |
aizakharov | 0:cc2b234b6255 | 291 | State = LOWPOWER; |
aizakharov | 0:cc2b234b6255 | 292 | break; |
aizakharov | 0:cc2b234b6255 | 293 | } |
aizakharov | 1:30ce00fbab55 | 294 | |
aizakharov | 1:30ce00fbab55 | 295 | wait(5); |
aizakharov | 0:cc2b234b6255 | 296 | } |
aizakharov | 0:cc2b234b6255 | 297 | } |
aizakharov | 0:cc2b234b6255 | 298 | |
aizakharov | 0:cc2b234b6255 | 299 | void OnTxDone( void ) |
aizakharov | 0:cc2b234b6255 | 300 | { |
aizakharov | 0:cc2b234b6255 | 301 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 302 | State = TX; |
aizakharov | 0:cc2b234b6255 | 303 | debug_if( DEBUG_MESSAGE, "\r\n> OnTxDone\n\r" ); |
aizakharov | 0:cc2b234b6255 | 304 | } |
aizakharov | 0:cc2b234b6255 | 305 | |
aizakharov | 0:cc2b234b6255 | 306 | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
aizakharov | 0:cc2b234b6255 | 307 | { |
aizakharov | 0:cc2b234b6255 | 308 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 309 | BufferSize = size; |
aizakharov | 0:cc2b234b6255 | 310 | memcpy( Buffer, payload, BufferSize ); |
aizakharov | 0:cc2b234b6255 | 311 | RssiValue = rssi; |
aizakharov | 0:cc2b234b6255 | 312 | SnrValue = snr; |
aizakharov | 0:cc2b234b6255 | 313 | |
aizakharov | 0:cc2b234b6255 | 314 | State = RX; |
aizakharov | 0:cc2b234b6255 | 315 | debug_if( DEBUG_MESSAGE, "\r\n> OnRxDone\n\r" ); |
aizakharov | 0:cc2b234b6255 | 316 | } |
aizakharov | 0:cc2b234b6255 | 317 | |
aizakharov | 0:cc2b234b6255 | 318 | void OnTxTimeout( void ) |
aizakharov | 0:cc2b234b6255 | 319 | { |
aizakharov | 0:cc2b234b6255 | 320 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 321 | State = TX_TIMEOUT; |
aizakharov | 0:cc2b234b6255 | 322 | debug_if( DEBUG_MESSAGE, "\r\n> OnTxTimeout\n\r" ); |
aizakharov | 0:cc2b234b6255 | 323 | } |
aizakharov | 0:cc2b234b6255 | 324 | |
aizakharov | 0:cc2b234b6255 | 325 | void OnRxTimeout( void ) |
aizakharov | 0:cc2b234b6255 | 326 | { |
aizakharov | 0:cc2b234b6255 | 327 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 328 | Buffer[BufferSize] = 0; |
aizakharov | 0:cc2b234b6255 | 329 | State = RX_TIMEOUT; |
aizakharov | 0:cc2b234b6255 | 330 | debug_if( DEBUG_MESSAGE, "\r\n> OnRxTimeout\n\r" ); |
aizakharov | 0:cc2b234b6255 | 331 | } |
aizakharov | 0:cc2b234b6255 | 332 | |
aizakharov | 0:cc2b234b6255 | 333 | void OnRxError( void ) |
aizakharov | 0:cc2b234b6255 | 334 | { |
aizakharov | 0:cc2b234b6255 | 335 | Radio.Sleep( ); |
aizakharov | 0:cc2b234b6255 | 336 | State = RX_ERROR; |
aizakharov | 0:cc2b234b6255 | 337 | debug_if( DEBUG_MESSAGE, "\r\n> OnRxError\n\r" ); |
aizakharov | 0:cc2b234b6255 | 338 | } |