SX126xDevKit

Dependencies:   mbed DmTftLibrary SX126xLib

Committer:
GregCr
Date:
Tue Sep 05 08:15:37 2017 +0000
Revision:
0:e5420f1a8a1a
Child:
1:b96176a4ccb8
Candidate Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 0:e5420f1a8a1a 1 /*
GregCr 0:e5420f1a8a1a 2 ______ _
GregCr 0:e5420f1a8a1a 3 / _____) _ | |
GregCr 0:e5420f1a8a1a 4 ( (____ _____ ____ _| |_ _____ ____| |__
GregCr 0:e5420f1a8a1a 5 \____ \| ___ | (_ _) ___ |/ ___) _ \
GregCr 0:e5420f1a8a1a 6 _____) ) ____| | | || |_| ____( (___| | | |
GregCr 0:e5420f1a8a1a 7 (______/|_____)_|_|_| \__)_____)\____)_| |_|
GregCr 0:e5420f1a8a1a 8 (C)2016 Semtech
GregCr 0:e5420f1a8a1a 9
GregCr 0:e5420f1a8a1a 10 Description: PingPong, PER demo implementation.
GregCr 0:e5420f1a8a1a 11
GregCr 0:e5420f1a8a1a 12 Maintainer: Gregory Cristian & Gilbert Menth
GregCr 0:e5420f1a8a1a 13 */
GregCr 0:e5420f1a8a1a 14
GregCr 0:e5420f1a8a1a 15 #include "mbed.h"
GregCr 0:e5420f1a8a1a 16 #include "radio.h"
GregCr 0:e5420f1a8a1a 17 #include "sx126x-hal.h"
GregCr 0:e5420f1a8a1a 18 #include "Eeprom.h"
GregCr 0:e5420f1a8a1a 19 #include "DemoApplication.h"
GregCr 0:e5420f1a8a1a 20
GregCr 0:e5420f1a8a1a 21 /*!
GregCr 0:e5420f1a8a1a 22 * \brief Defines the local payload buffer size
GregCr 0:e5420f1a8a1a 23 */
GregCr 0:e5420f1a8a1a 24 #define BUFFER_SIZE 255
GregCr 0:e5420f1a8a1a 25
GregCr 0:e5420f1a8a1a 26 /*!
GregCr 0:e5420f1a8a1a 27 * \brief Defines the size of the token defining message type in the payload
GregCr 0:e5420f1a8a1a 28 * cf. above.
GregCr 0:e5420f1a8a1a 29 */
GregCr 0:e5420f1a8a1a 30 #define PINGPONG_SIZE 4
GregCr 0:e5420f1a8a1a 31 #define PER_SIZE 3
GregCr 0:e5420f1a8a1a 32
GregCr 0:e5420f1a8a1a 33 /*!
GregCr 0:e5420f1a8a1a 34 * \brief Define time used in PingPong demo to synch with cycle
GregCr 0:e5420f1a8a1a 35 * RX_TIMEOUT_MARGIN is the free time between each cycle (time reserve)
GregCr 0:e5420f1a8a1a 36 */
GregCr 0:e5420f1a8a1a 37 #define RX_TIMEOUT_MARGIN 150 // ms
GregCr 0:e5420f1a8a1a 38 #define RX_TX_TRANSITION_WAIT 5 // ms
GregCr 0:e5420f1a8a1a 39
GregCr 0:e5420f1a8a1a 40
GregCr 0:e5420f1a8a1a 41 /*!
GregCr 0:e5420f1a8a1a 42 * \brief Define the possible message type for the Ping-Pong and PER apps
GregCr 0:e5420f1a8a1a 43 */
GregCr 0:e5420f1a8a1a 44 const uint8_t PingMsg[] = "PING";
GregCr 0:e5420f1a8a1a 45 const uint8_t PongMsg[] = "PONG";
GregCr 0:e5420f1a8a1a 46 const uint8_t PerMsg[] = "PER";
GregCr 0:e5420f1a8a1a 47
GregCr 0:e5420f1a8a1a 48 /*!
GregCr 0:e5420f1a8a1a 49 * \brief Buffer and its size
GregCr 0:e5420f1a8a1a 50 */
GregCr 0:e5420f1a8a1a 51 uint8_t BufferSize = BUFFER_SIZE;
GregCr 0:e5420f1a8a1a 52 uint8_t Buffer[BUFFER_SIZE];
GregCr 0:e5420f1a8a1a 53
GregCr 0:e5420f1a8a1a 54 /*!
GregCr 0:e5420f1a8a1a 55 * \brief Function to be executed on Radio Tx Done event
GregCr 0:e5420f1a8a1a 56 */
GregCr 0:e5420f1a8a1a 57 void OnTxDone( void );
GregCr 0:e5420f1a8a1a 58
GregCr 0:e5420f1a8a1a 59 /*!
GregCr 0:e5420f1a8a1a 60 * \brief Function to be executed on Radio Rx Done event
GregCr 0:e5420f1a8a1a 61 */
GregCr 0:e5420f1a8a1a 62 void OnRxDone( void );
GregCr 0:e5420f1a8a1a 63
GregCr 0:e5420f1a8a1a 64 /*!
GregCr 0:e5420f1a8a1a 65 * \brief Function executed on Radio Tx Timeout event
GregCr 0:e5420f1a8a1a 66 */
GregCr 0:e5420f1a8a1a 67 void OnTxTimeout( void );
GregCr 0:e5420f1a8a1a 68
GregCr 0:e5420f1a8a1a 69 /*!
GregCr 0:e5420f1a8a1a 70 * \brief Function executed on Radio Rx Timeout event
GregCr 0:e5420f1a8a1a 71 */
GregCr 0:e5420f1a8a1a 72 void OnRxTimeout( void );
GregCr 0:e5420f1a8a1a 73
GregCr 0:e5420f1a8a1a 74 /*!
GregCr 0:e5420f1a8a1a 75 * \brief Function executed on Radio Rx Error event
GregCr 0:e5420f1a8a1a 76 */
GregCr 0:e5420f1a8a1a 77 void OnRxError( IrqErrorCode_t );
GregCr 0:e5420f1a8a1a 78
GregCr 0:e5420f1a8a1a 79 /*!
GregCr 0:e5420f1a8a1a 80 * \brief Function executed on Radio CAD Done event
GregCr 0:e5420f1a8a1a 81 */
GregCr 0:e5420f1a8a1a 82 void OnCadDone( bool channelActivityDetected );
GregCr 0:e5420f1a8a1a 83
GregCr 0:e5420f1a8a1a 84 /*!
GregCr 0:e5420f1a8a1a 85 * \brief All the callbacks are stored in a structure
GregCr 0:e5420f1a8a1a 86 */
GregCr 0:e5420f1a8a1a 87 RadioCallbacks_t RadioEvents =
GregCr 0:e5420f1a8a1a 88 {
GregCr 0:e5420f1a8a1a 89 &OnTxDone, // txDone
GregCr 0:e5420f1a8a1a 90 &OnRxDone, // rxDone
GregCr 0:e5420f1a8a1a 91 NULL, // rxPreambleDetect
GregCr 0:e5420f1a8a1a 92 NULL, // rxSyncWordDone
GregCr 0:e5420f1a8a1a 93 NULL, // rxHeaderDone
GregCr 0:e5420f1a8a1a 94 &OnTxTimeout, // txTimeout
GregCr 0:e5420f1a8a1a 95 &OnRxTimeout, // rxTimeout
GregCr 0:e5420f1a8a1a 96 &OnRxError, // rxError
GregCr 0:e5420f1a8a1a 97 &OnCadDone, // cadDone
GregCr 0:e5420f1a8a1a 98 };
GregCr 0:e5420f1a8a1a 99
GregCr 0:e5420f1a8a1a 100 // SPI
GregCr 0:e5420f1a8a1a 101 // mosi, miso, sclk, nss, dio0, dio1, dio2, dio3, rst, deviceSel, antSwPower, callbacks...
GregCr 0:e5420f1a8a1a 102 SX126xHal Radio( D11, D12, D13, D7, D3, D5, NC, NC, A0, A2, D8, &RadioEvents );
GregCr 0:e5420f1a8a1a 103
GregCr 0:e5420f1a8a1a 104 /*!
GregCr 0:e5420f1a8a1a 105 * \brief Tx LED toggling on transmition success
GregCr 0:e5420f1a8a1a 106 */
GregCr 0:e5420f1a8a1a 107 DigitalOut TX_LED( A4 );
GregCr 0:e5420f1a8a1a 108
GregCr 0:e5420f1a8a1a 109 /*!
GregCr 0:e5420f1a8a1a 110 * \brief Rx LED toggling on reception success
GregCr 0:e5420f1a8a1a 111 */
GregCr 0:e5420f1a8a1a 112 DigitalOut RX_LED( A5 );
GregCr 0:e5420f1a8a1a 113
GregCr 0:e5420f1a8a1a 114 /*!
GregCr 0:e5420f1a8a1a 115 * \brief Mask of IRQs
GregCr 0:e5420f1a8a1a 116 */
GregCr 0:e5420f1a8a1a 117 uint16_t IrqMask = 0x0000;
GregCr 0:e5420f1a8a1a 118
GregCr 0:e5420f1a8a1a 119 /*!
GregCr 0:e5420f1a8a1a 120 * \brief Locals parameters and status for radio API
GregCr 0:e5420f1a8a1a 121 * NEED TO BE OPTIMIZED, COPY OF STUCTURE ALREADY EXISTING
GregCr 0:e5420f1a8a1a 122 */
GregCr 0:e5420f1a8a1a 123 PacketParams_t PacketParams;
GregCr 0:e5420f1a8a1a 124 PacketStatus_t PacketStatus;
GregCr 0:e5420f1a8a1a 125 ModulationParams_t ModulationParams;
GregCr 0:e5420f1a8a1a 126
GregCr 0:e5420f1a8a1a 127 /*!
GregCr 0:e5420f1a8a1a 128 * \brief Flag to indicate if the demo is already running
GregCr 0:e5420f1a8a1a 129 */
GregCr 0:e5420f1a8a1a 130 static bool DemoRunning = false;
GregCr 0:e5420f1a8a1a 131
GregCr 0:e5420f1a8a1a 132 /*!
GregCr 0:e5420f1a8a1a 133 * \brief Frequency Error (only LSB)
GregCr 0:e5420f1a8a1a 134 */
GregCr 0:e5420f1a8a1a 135 static double FreErrorLsb = 0.0;
GregCr 0:e5420f1a8a1a 136
GregCr 0:e5420f1a8a1a 137 /*!
GregCr 0:e5420f1a8a1a 138 * \brief Flag holding the current internal state of the demo application
GregCr 0:e5420f1a8a1a 139 */
GregCr 0:e5420f1a8a1a 140 static uint8_t DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 141
GregCr 0:e5420f1a8a1a 142 /*!
GregCr 0:e5420f1a8a1a 143 * \brief Ticker for master to synch Tx frames. Flags for PER and PingPong demo
GregCr 0:e5420f1a8a1a 144 * for Synch TX in cycle.
GregCr 0:e5420f1a8a1a 145 */
GregCr 0:e5420f1a8a1a 146 Ticker SendNextPacket;
GregCr 0:e5420f1a8a1a 147 static bool SendNext = false;
GregCr 0:e5420f1a8a1a 148
GregCr 0:e5420f1a8a1a 149 /*!
GregCr 0:e5420f1a8a1a 150 * \brief Hold last Rx packet number to compute PER in PER and PingPong demo
GregCr 0:e5420f1a8a1a 151 */
GregCr 0:e5420f1a8a1a 152 static uint32_t PacketRxSequence = 0;
GregCr 0:e5420f1a8a1a 153 static uint32_t PacketRxSequencePrev = 0;
GregCr 0:e5420f1a8a1a 154
GregCr 0:e5420f1a8a1a 155 void LedBlink( void );
GregCr 0:e5420f1a8a1a 156 void InitializeDemoParameters( uint8_t modulation );
GregCr 0:e5420f1a8a1a 157 uint16_t GetTimeOnAir( uint8_t modulation );
GregCr 0:e5420f1a8a1a 158 void SendNextPacketEvent( void );
GregCr 0:e5420f1a8a1a 159
GregCr 0:e5420f1a8a1a 160 // ************************** RF Test Demo ******************************
GregCr 0:e5420f1a8a1a 161 // * *
GregCr 0:e5420f1a8a1a 162 // * *
GregCr 0:e5420f1a8a1a 163 // * *
GregCr 0:e5420f1a8a1a 164 // *****************************************************************************
GregCr 0:e5420f1a8a1a 165
GregCr 0:e5420f1a8a1a 166 uint8_t RunDemoSleepMode( void )
GregCr 0:e5420f1a8a1a 167 {
GregCr 0:e5420f1a8a1a 168 SleepParams_t SleepParam;
GregCr 0:e5420f1a8a1a 169
GregCr 0:e5420f1a8a1a 170 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 171 {
GregCr 0:e5420f1a8a1a 172 return 0;
GregCr 0:e5420f1a8a1a 173 }
GregCr 0:e5420f1a8a1a 174
GregCr 0:e5420f1a8a1a 175 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 176 {
GregCr 0:e5420f1a8a1a 177 DemoRunning = true;
GregCr 0:e5420f1a8a1a 178 InitializeDemoParameters( PACKET_TYPE_LORA );
GregCr 0:e5420f1a8a1a 179 TX_LED = 0;
GregCr 0:e5420f1a8a1a 180 RX_LED = 0;
GregCr 0:e5420f1a8a1a 181
GregCr 0:e5420f1a8a1a 182 SleepParam.Fields.WakeUpRTC = 0; //!< Get out of sleep mode if wakeup signal received from RTC
GregCr 0:e5420f1a8a1a 183 SleepParam.Fields.Reset = 0; //!<
GregCr 0:e5420f1a8a1a 184 SleepParam.Fields.WarmStart = 1; //!<
GregCr 0:e5420f1a8a1a 185 Radio.SetSleep( SleepParam );
GregCr 0:e5420f1a8a1a 186 }
GregCr 0:e5420f1a8a1a 187 else
GregCr 0:e5420f1a8a1a 188 {
GregCr 0:e5420f1a8a1a 189 LedBlink( );
GregCr 0:e5420f1a8a1a 190 }
GregCr 0:e5420f1a8a1a 191 return 0;
GregCr 0:e5420f1a8a1a 192 }
GregCr 0:e5420f1a8a1a 193
GregCr 0:e5420f1a8a1a 194 uint8_t RunDemoStandbyRcMode( void )
GregCr 0:e5420f1a8a1a 195 {
GregCr 0:e5420f1a8a1a 196 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 197 {
GregCr 0:e5420f1a8a1a 198 return 0;
GregCr 0:e5420f1a8a1a 199 }
GregCr 0:e5420f1a8a1a 200
GregCr 0:e5420f1a8a1a 201 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 202 {
GregCr 0:e5420f1a8a1a 203 DemoRunning = true;
GregCr 0:e5420f1a8a1a 204 InitializeDemoParameters( PACKET_TYPE_LORA );
GregCr 0:e5420f1a8a1a 205 TX_LED = 0;
GregCr 0:e5420f1a8a1a 206 RX_LED = 0;
GregCr 0:e5420f1a8a1a 207 Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
GregCr 0:e5420f1a8a1a 208 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 209 DemoRunning = true;
GregCr 0:e5420f1a8a1a 210 }
GregCr 0:e5420f1a8a1a 211 else
GregCr 0:e5420f1a8a1a 212 {
GregCr 0:e5420f1a8a1a 213 LedBlink( );
GregCr 0:e5420f1a8a1a 214 }
GregCr 0:e5420f1a8a1a 215 return 0;
GregCr 0:e5420f1a8a1a 216 }
GregCr 0:e5420f1a8a1a 217
GregCr 0:e5420f1a8a1a 218 uint8_t RunDemoStandbyXoscMode( void )
GregCr 0:e5420f1a8a1a 219 {
GregCr 0:e5420f1a8a1a 220 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 221 {
GregCr 0:e5420f1a8a1a 222 return 0;
GregCr 0:e5420f1a8a1a 223 }
GregCr 0:e5420f1a8a1a 224 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 225 {
GregCr 0:e5420f1a8a1a 226 DemoRunning = true;
GregCr 0:e5420f1a8a1a 227 InitializeDemoParameters( PACKET_TYPE_LORA );
GregCr 0:e5420f1a8a1a 228 TX_LED = 0;
GregCr 0:e5420f1a8a1a 229 RX_LED = 0;
GregCr 0:e5420f1a8a1a 230 Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
GregCr 0:e5420f1a8a1a 231 Radio.SetStandby( STDBY_XOSC );
GregCr 0:e5420f1a8a1a 232 DemoRunning = true;
GregCr 0:e5420f1a8a1a 233 }
GregCr 0:e5420f1a8a1a 234 else
GregCr 0:e5420f1a8a1a 235 {
GregCr 0:e5420f1a8a1a 236 LedBlink( );
GregCr 0:e5420f1a8a1a 237 }
GregCr 0:e5420f1a8a1a 238 return 0;
GregCr 0:e5420f1a8a1a 239 }
GregCr 0:e5420f1a8a1a 240
GregCr 0:e5420f1a8a1a 241 uint8_t RunDemoTxCw( void )
GregCr 0:e5420f1a8a1a 242 {
GregCr 0:e5420f1a8a1a 243 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 244 {
GregCr 0:e5420f1a8a1a 245 return 0;
GregCr 0:e5420f1a8a1a 246 }
GregCr 0:e5420f1a8a1a 247
GregCr 0:e5420f1a8a1a 248 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 249 {
GregCr 0:e5420f1a8a1a 250 DemoRunning = true;
GregCr 0:e5420f1a8a1a 251 InitializeDemoParameters( PACKET_TYPE_LORA );
GregCr 0:e5420f1a8a1a 252 TX_LED = 0;
GregCr 0:e5420f1a8a1a 253 RX_LED = 0;
GregCr 0:e5420f1a8a1a 254 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 255 Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
GregCr 0:e5420f1a8a1a 256 Radio.SetRfFrequency( Eeprom.EepromData.DemoSettings.Frequency );
GregCr 0:e5420f1a8a1a 257 Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_40_US );
GregCr 0:e5420f1a8a1a 258 Radio.SetTxContinuousWave( );
GregCr 0:e5420f1a8a1a 259 DemoRunning = true;
GregCr 0:e5420f1a8a1a 260 }
GregCr 0:e5420f1a8a1a 261 else
GregCr 0:e5420f1a8a1a 262 {
GregCr 0:e5420f1a8a1a 263 LedBlink( );
GregCr 0:e5420f1a8a1a 264 }
GregCr 0:e5420f1a8a1a 265 return 0;
GregCr 0:e5420f1a8a1a 266 }
GregCr 0:e5420f1a8a1a 267
GregCr 0:e5420f1a8a1a 268 uint8_t RunDemoTxContinuousModulation( void )
GregCr 0:e5420f1a8a1a 269 {
GregCr 0:e5420f1a8a1a 270 uint8_t localPayloadSize = 250;
GregCr 0:e5420f1a8a1a 271 uint8_t i = 0;
GregCr 0:e5420f1a8a1a 272
GregCr 0:e5420f1a8a1a 273 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 274 {
GregCr 0:e5420f1a8a1a 275 return 0;
GregCr 0:e5420f1a8a1a 276 }
GregCr 0:e5420f1a8a1a 277
GregCr 0:e5420f1a8a1a 278 Radio.ProcessIrqs( );
GregCr 0:e5420f1a8a1a 279
GregCr 0:e5420f1a8a1a 280 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 281 {
GregCr 0:e5420f1a8a1a 282 DemoRunning = true;
GregCr 0:e5420f1a8a1a 283 InitializeDemoParameters( Eeprom.EepromData.DemoSettings.ModulationType );
GregCr 0:e5420f1a8a1a 284 Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_3400_US );
GregCr 0:e5420f1a8a1a 285 TX_LED = 0;
GregCr 0:e5420f1a8a1a 286 RX_LED = 0;
GregCr 0:e5420f1a8a1a 287 IrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 288 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 289 for( i = 0; i < localPayloadSize; i++ )
GregCr 0:e5420f1a8a1a 290 {
GregCr 0:e5420f1a8a1a 291 Buffer[i] = ( uint8_t )rand( );
GregCr 0:e5420f1a8a1a 292 }
GregCr 0:e5420f1a8a1a 293 Radio.SendPayload( Buffer, localPayloadSize, 0xFFFFFF );
GregCr 0:e5420f1a8a1a 294 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 295 }
GregCr 0:e5420f1a8a1a 296 else
GregCr 0:e5420f1a8a1a 297 {
GregCr 0:e5420f1a8a1a 298 switch( DemoInternalState )
GregCr 0:e5420f1a8a1a 299 {
GregCr 0:e5420f1a8a1a 300 case APP_RX:
GregCr 0:e5420f1a8a1a 301 break;
GregCr 0:e5420f1a8a1a 302
GregCr 0:e5420f1a8a1a 303 case APP_TX:
GregCr 0:e5420f1a8a1a 304 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 305 LedBlink( );
GregCr 0:e5420f1a8a1a 306 // Send the next frame
GregCr 0:e5420f1a8a1a 307 IrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 308 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 309
GregCr 0:e5420f1a8a1a 310 Radio.SendPayload( Buffer, localPayloadSize, 0xFFFFFF );
GregCr 0:e5420f1a8a1a 311 // we prepare next payload during transmission
GregCr 0:e5420f1a8a1a 312 for( i = 0; i < localPayloadSize; i++ )
GregCr 0:e5420f1a8a1a 313 {
GregCr 0:e5420f1a8a1a 314 Buffer[i] = ( uint8_t )rand( );
GregCr 0:e5420f1a8a1a 315 }
GregCr 0:e5420f1a8a1a 316 break;
GregCr 0:e5420f1a8a1a 317
GregCr 0:e5420f1a8a1a 318 case APP_RX_TIMEOUT:
GregCr 0:e5420f1a8a1a 319 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 320 break;
GregCr 0:e5420f1a8a1a 321
GregCr 0:e5420f1a8a1a 322 case APP_RX_ERROR:
GregCr 0:e5420f1a8a1a 323 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 324 break;
GregCr 0:e5420f1a8a1a 325
GregCr 0:e5420f1a8a1a 326 case APP_TX_TIMEOUT:
GregCr 0:e5420f1a8a1a 327 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 328 break;
GregCr 0:e5420f1a8a1a 329
GregCr 0:e5420f1a8a1a 330 case APP_IDLE:
GregCr 0:e5420f1a8a1a 331 break;
GregCr 0:e5420f1a8a1a 332
GregCr 0:e5420f1a8a1a 333 default:
GregCr 0:e5420f1a8a1a 334 break;
GregCr 0:e5420f1a8a1a 335 }
GregCr 0:e5420f1a8a1a 336 }
GregCr 0:e5420f1a8a1a 337
GregCr 0:e5420f1a8a1a 338 return 0;
GregCr 0:e5420f1a8a1a 339 }
GregCr 0:e5420f1a8a1a 340
GregCr 0:e5420f1a8a1a 341 uint8_t RunDemoRxContinuous( void )
GregCr 0:e5420f1a8a1a 342 {
GregCr 0:e5420f1a8a1a 343 uint8_t refreshDisplay = 0;
GregCr 0:e5420f1a8a1a 344
GregCr 0:e5420f1a8a1a 345 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 346 {
GregCr 0:e5420f1a8a1a 347 return 0;
GregCr 0:e5420f1a8a1a 348 }
GregCr 0:e5420f1a8a1a 349
GregCr 0:e5420f1a8a1a 350 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 351 {
GregCr 0:e5420f1a8a1a 352 DemoRunning = true;
GregCr 0:e5420f1a8a1a 353
GregCr 0:e5420f1a8a1a 354 printf( "Start RunDemoRxContinuous\n\r" );
GregCr 0:e5420f1a8a1a 355
GregCr 0:e5420f1a8a1a 356 TX_LED = 0;
GregCr 0:e5420f1a8a1a 357 RX_LED = 0;
GregCr 0:e5420f1a8a1a 358
GregCr 0:e5420f1a8a1a 359 Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
GregCr 0:e5420f1a8a1a 360 Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
GregCr 0:e5420f1a8a1a 361 Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
GregCr 0:e5420f1a8a1a 362
GregCr 0:e5420f1a8a1a 363 InitializeDemoParameters( Eeprom.EepromData.DemoSettings.ModulationType );
GregCr 0:e5420f1a8a1a 364
GregCr 0:e5420f1a8a1a 365 // set preamble to max size to avoid filtering of the receiver on preamble lenght
GregCr 0:e5420f1a8a1a 366 if( Eeprom.EepromData.DemoSettings.ModulationType == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 367 {
GregCr 0:e5420f1a8a1a 368 PacketParams.Params.LoRa.PreambleLength = 0xFFFF;
GregCr 0:e5420f1a8a1a 369 PacketParams.Params.LoRa.HeaderType = ( RadioLoRaPacketLengthsMode_t )Eeprom.EepromData.DemoSettings.PacketParam2;
GregCr 0:e5420f1a8a1a 370 PacketParams.Params.LoRa.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam3;
GregCr 0:e5420f1a8a1a 371 PacketParams.Params.LoRa.CrcMode = ( RadioLoRaCrcModes_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
GregCr 0:e5420f1a8a1a 372 PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5;
GregCr 0:e5420f1a8a1a 373 Radio.SetPacketParams( &PacketParams );
GregCr 0:e5420f1a8a1a 374 }
GregCr 0:e5420f1a8a1a 375
GregCr 0:e5420f1a8a1a 376 IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 377 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 378 // Rx Continuous
GregCr 0:e5420f1a8a1a 379 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 380 {
GregCr 0:e5420f1a8a1a 381 Radio.SetRx( 0xFFFFFF );
GregCr 0:e5420f1a8a1a 382 }
GregCr 0:e5420f1a8a1a 383 else
GregCr 0:e5420f1a8a1a 384 {
GregCr 0:e5420f1a8a1a 385 Radio.SetRxBoosted( 0xFFFFFF );
GregCr 0:e5420f1a8a1a 386 }
GregCr 0:e5420f1a8a1a 387 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 388
GregCr 0:e5420f1a8a1a 389 }
GregCr 0:e5420f1a8a1a 390
GregCr 0:e5420f1a8a1a 391 if( Eeprom.EepromData.DemoSettings.MaxNumPacket > 0 ) // != Infinite
GregCr 0:e5420f1a8a1a 392 {
GregCr 0:e5420f1a8a1a 393 if( ( Eeprom.EepromData.DemoSettings.CntPacketRxOK + \
GregCr 0:e5420f1a8a1a 394 Eeprom.EepromData.DemoSettings.CntPacketRxKO ) >= \
GregCr 0:e5420f1a8a1a 395 Eeprom.EepromData.DemoSettings.MaxNumPacket )
GregCr 0:e5420f1a8a1a 396 {
GregCr 0:e5420f1a8a1a 397 RX_LED = 0;
GregCr 0:e5420f1a8a1a 398 TX_LED = 0;
GregCr 0:e5420f1a8a1a 399 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 400 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 401 SendNextPacket.detach( );
GregCr 0:e5420f1a8a1a 402 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 403 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 404 }
GregCr 0:e5420f1a8a1a 405 }
GregCr 0:e5420f1a8a1a 406
GregCr 0:e5420f1a8a1a 407 Radio.ProcessIrqs( );
GregCr 0:e5420f1a8a1a 408
GregCr 0:e5420f1a8a1a 409 switch( DemoInternalState )
GregCr 0:e5420f1a8a1a 410 {
GregCr 0:e5420f1a8a1a 411 case APP_TX:
GregCr 0:e5420f1a8a1a 412 break;
GregCr 0:e5420f1a8a1a 413
GregCr 0:e5420f1a8a1a 414 case APP_RX:
GregCr 0:e5420f1a8a1a 415 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 416 Radio.GetPayload( Buffer, &BufferSize, BUFFER_SIZE );
GregCr 0:e5420f1a8a1a 417 Radio.GetPacketStatus( &PacketStatus );
GregCr 0:e5420f1a8a1a 418 if( Eeprom.EepromData.DemoSettings.ModulationType == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 419 {
GregCr 0:e5420f1a8a1a 420 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.LoRa.RssiPkt;
GregCr 0:e5420f1a8a1a 421 Eeprom.EepromData.DemoSettings.SnrValue = PacketStatus.Params.LoRa.SnrPkt;
GregCr 0:e5420f1a8a1a 422 if( ( PacketStatus.Params.LoRa.FreqError & 0x00080000 ) == 0x00080000 )
GregCr 0:e5420f1a8a1a 423 {
GregCr 0:e5420f1a8a1a 424 PacketStatus.Params.LoRa.FreqError = 0xFFFFF - PacketStatus.Params.LoRa.FreqError;
GregCr 0:e5420f1a8a1a 425 }
GregCr 0:e5420f1a8a1a 426 Eeprom.EepromData.DemoSettings.FreqErrorEst = ( double )PacketStatus.Params.LoRa.FreqError * FreErrorLsb;
GregCr 0:e5420f1a8a1a 427 }
GregCr 0:e5420f1a8a1a 428 else // Eeprom.EepromData.DemoSettings.ModulationType == PACKET_TYPE_GFSK
GregCr 0:e5420f1a8a1a 429 {
GregCr 0:e5420f1a8a1a 430 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.Gfsk.RssiAvg;
GregCr 0:e5420f1a8a1a 431 Eeprom.EepromData.DemoSettings.SnrValue = 0;
GregCr 0:e5420f1a8a1a 432 }
GregCr 0:e5420f1a8a1a 433
GregCr 0:e5420f1a8a1a 434 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 435 Eeprom.EepromData.DemoSettings.CntPacketRxOK ++;
GregCr 0:e5420f1a8a1a 436 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 437 break;
GregCr 0:e5420f1a8a1a 438
GregCr 0:e5420f1a8a1a 439 case APP_RX_ERROR:
GregCr 0:e5420f1a8a1a 440 case APP_RX_TIMEOUT:
GregCr 0:e5420f1a8a1a 441 Eeprom.EepromData.DemoSettings.CntPacketRxKO ++;
GregCr 0:e5420f1a8a1a 442 DemoInternalState = PER_RX_START;
GregCr 0:e5420f1a8a1a 443 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 444 break;
GregCr 0:e5420f1a8a1a 445
GregCr 0:e5420f1a8a1a 446 case APP_TX_TIMEOUT:
GregCr 0:e5420f1a8a1a 447 break;
GregCr 0:e5420f1a8a1a 448
GregCr 0:e5420f1a8a1a 449 case APP_IDLE:
GregCr 0:e5420f1a8a1a 450 break;
GregCr 0:e5420f1a8a1a 451
GregCr 0:e5420f1a8a1a 452 default:
GregCr 0:e5420f1a8a1a 453 break;
GregCr 0:e5420f1a8a1a 454 }
GregCr 0:e5420f1a8a1a 455 return refreshDisplay;
GregCr 0:e5420f1a8a1a 456 }
GregCr 0:e5420f1a8a1a 457
GregCr 0:e5420f1a8a1a 458 // ************************* PER Demo ******************************
GregCr 0:e5420f1a8a1a 459 // * *
GregCr 0:e5420f1a8a1a 460 // * *
GregCr 0:e5420f1a8a1a 461 // * *
GregCr 0:e5420f1a8a1a 462 // *****************************************************************************
GregCr 0:e5420f1a8a1a 463 uint8_t RunDemoApplicationPer( void )
GregCr 0:e5420f1a8a1a 464 {
GregCr 0:e5420f1a8a1a 465 uint8_t i = 0;
GregCr 0:e5420f1a8a1a 466 uint8_t refreshDisplay = 0;
GregCr 0:e5420f1a8a1a 467
GregCr 0:e5420f1a8a1a 468 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 469 {
GregCr 0:e5420f1a8a1a 470 return 0;
GregCr 0:e5420f1a8a1a 471 }
GregCr 0:e5420f1a8a1a 472
GregCr 0:e5420f1a8a1a 473 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 474 {
GregCr 0:e5420f1a8a1a 475 DemoRunning = true;
GregCr 0:e5420f1a8a1a 476
GregCr 0:e5420f1a8a1a 477 printf( "Start RunDemoApplicationPer\n\r" );
GregCr 0:e5420f1a8a1a 478
GregCr 0:e5420f1a8a1a 479 TX_LED = 0;
GregCr 0:e5420f1a8a1a 480 RX_LED = 0;
GregCr 0:e5420f1a8a1a 481
GregCr 0:e5420f1a8a1a 482 Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
GregCr 0:e5420f1a8a1a 483 Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
GregCr 0:e5420f1a8a1a 484 Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
GregCr 0:e5420f1a8a1a 485 Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
GregCr 0:e5420f1a8a1a 486
GregCr 0:e5420f1a8a1a 487 InitializeDemoParameters( Eeprom.EepromData.DemoSettings.ModulationType );
GregCr 0:e5420f1a8a1a 488
GregCr 0:e5420f1a8a1a 489 Eeprom.EepromData.DemoSettings.InterPacketDelay = GetTimeOnAir( Eeprom.EepromData.DemoSettings.ModulationType ) + RX_TX_TRANSITION_WAIT;
GregCr 0:e5420f1a8a1a 490
GregCr 0:e5420f1a8a1a 491 if( Eeprom.EepromData.DemoSettings.Entity == MASTER )
GregCr 0:e5420f1a8a1a 492 {
GregCr 0:e5420f1a8a1a 493 SendNextPacket.attach_us( &SendNextPacketEvent, ( uint32_t )( ( Eeprom.EepromData.DemoSettings.InterPacketDelay + RX_TIMEOUT_MARGIN ) * 1000 ) );
GregCr 0:e5420f1a8a1a 494 DemoInternalState = APP_TX;
GregCr 0:e5420f1a8a1a 495 }
GregCr 0:e5420f1a8a1a 496 else
GregCr 0:e5420f1a8a1a 497 {
GregCr 0:e5420f1a8a1a 498 IrqMask = /*0xFFFF; IRQ_HEADER_VALID |*/ IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 499 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 500 // Rx Single without timeout for the start
GregCr 0:e5420f1a8a1a 501 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 502 {
GregCr 0:e5420f1a8a1a 503 Radio.SetRx( 0x0000 );
GregCr 0:e5420f1a8a1a 504 }
GregCr 0:e5420f1a8a1a 505 else
GregCr 0:e5420f1a8a1a 506 {
GregCr 0:e5420f1a8a1a 507 Radio.SetRxBoosted( 0x0000 );
GregCr 0:e5420f1a8a1a 508 }
GregCr 0:e5420f1a8a1a 509 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 510 }
GregCr 0:e5420f1a8a1a 511 }
GregCr 0:e5420f1a8a1a 512
GregCr 0:e5420f1a8a1a 513 Radio.ProcessIrqs( );
GregCr 0:e5420f1a8a1a 514
GregCr 0:e5420f1a8a1a 515 if( Eeprom.EepromData.DemoSettings.MaxNumPacket > 0 ) // != Infinite
GregCr 0:e5420f1a8a1a 516 {
GregCr 0:e5420f1a8a1a 517 if( ( Eeprom.EepromData.DemoSettings.CntPacketRxOK + \
GregCr 0:e5420f1a8a1a 518 Eeprom.EepromData.DemoSettings.CntPacketRxKO + \
GregCr 0:e5420f1a8a1a 519 Eeprom.EepromData.DemoSettings.RxTimeOutCount) >= \
GregCr 0:e5420f1a8a1a 520 Eeprom.EepromData.DemoSettings.MaxNumPacket )
GregCr 0:e5420f1a8a1a 521 {
GregCr 0:e5420f1a8a1a 522 RX_LED = 0;
GregCr 0:e5420f1a8a1a 523 TX_LED = 0;
GregCr 0:e5420f1a8a1a 524 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 525 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 526 SendNextPacket.detach( );
GregCr 0:e5420f1a8a1a 527 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 528 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 529 }
GregCr 0:e5420f1a8a1a 530 }
GregCr 0:e5420f1a8a1a 531
GregCr 0:e5420f1a8a1a 532 switch( DemoInternalState )
GregCr 0:e5420f1a8a1a 533 {
GregCr 0:e5420f1a8a1a 534 case PER_TX_START:
GregCr 0:e5420f1a8a1a 535 Eeprom.EepromData.DemoSettings.CntPacketTx++;
GregCr 0:e5420f1a8a1a 536 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 537
GregCr 0:e5420f1a8a1a 538 Buffer[0] = 0x00;
GregCr 0:e5420f1a8a1a 539 Buffer[1] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 24 ) & 0xFF;
GregCr 0:e5420f1a8a1a 540 Buffer[2] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 16 ) & 0xFF;
GregCr 0:e5420f1a8a1a 541 Buffer[3] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 8 ) & 0xFF;
GregCr 0:e5420f1a8a1a 542 Buffer[4] = Eeprom.EepromData.DemoSettings.CntPacketTx & 0xFF;
GregCr 0:e5420f1a8a1a 543 Buffer[5] = PerMsg[0];
GregCr 0:e5420f1a8a1a 544 Buffer[6] = PerMsg[1];
GregCr 0:e5420f1a8a1a 545 Buffer[7] = PerMsg[2];
GregCr 0:e5420f1a8a1a 546 for( i = 8; i < Eeprom.EepromData.DemoSettings.PayloadLength; i++ )
GregCr 0:e5420f1a8a1a 547 {
GregCr 0:e5420f1a8a1a 548 Buffer[i] = i;
GregCr 0:e5420f1a8a1a 549 }
GregCr 0:e5420f1a8a1a 550 TX_LED = !TX_LED;
GregCr 0:e5420f1a8a1a 551 IrqMask = 0xFFFF; //IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 552 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 553 Radio.SendPayload( Buffer, Eeprom.EepromData.DemoSettings.PayloadLength, ( Eeprom.EepromData.DemoSettings.InterPacketDelay ) << 6 );
GregCr 0:e5420f1a8a1a 554 break;
GregCr 0:e5420f1a8a1a 555
GregCr 0:e5420f1a8a1a 556 case PER_RX_START:
GregCr 0:e5420f1a8a1a 557 IrqMask = /*0xFFFF;*/ IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 558 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 559 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 560 {
GregCr 0:e5420f1a8a1a 561 Radio.SetRx( ( Eeprom.EepromData.DemoSettings.InterPacketDelay + RX_TIMEOUT_MARGIN ) << 6 );
GregCr 0:e5420f1a8a1a 562 }
GregCr 0:e5420f1a8a1a 563 else
GregCr 0:e5420f1a8a1a 564 {
GregCr 0:e5420f1a8a1a 565 Radio.SetRxBoosted( ( Eeprom.EepromData.DemoSettings.InterPacketDelay + RX_TIMEOUT_MARGIN ) << 6 );
GregCr 0:e5420f1a8a1a 566 }
GregCr 0:e5420f1a8a1a 567 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 568 break;
GregCr 0:e5420f1a8a1a 569
GregCr 0:e5420f1a8a1a 570 case APP_TX:
GregCr 0:e5420f1a8a1a 571 if( SendNext == true )
GregCr 0:e5420f1a8a1a 572 {
GregCr 0:e5420f1a8a1a 573 SendNext = false;
GregCr 0:e5420f1a8a1a 574 if( Eeprom.EepromData.DemoSettings.MaxNumPacket == 0 )
GregCr 0:e5420f1a8a1a 575 {
GregCr 0:e5420f1a8a1a 576 DemoInternalState = PER_TX_START; // Infinite -> send next
GregCr 0:e5420f1a8a1a 577 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 578 }
GregCr 0:e5420f1a8a1a 579 else if( Eeprom.EepromData.DemoSettings.CntPacketTx < \
GregCr 0:e5420f1a8a1a 580 Eeprom.EepromData.DemoSettings.MaxNumPacket )
GregCr 0:e5420f1a8a1a 581 {
GregCr 0:e5420f1a8a1a 582 DemoInternalState = PER_TX_START; // MaxNumPacket not sent
GregCr 0:e5420f1a8a1a 583 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 584 }
GregCr 0:e5420f1a8a1a 585 else // MaxNumPacket sent -> end of demo
GregCr 0:e5420f1a8a1a 586 {
GregCr 0:e5420f1a8a1a 587 RX_LED = 0;
GregCr 0:e5420f1a8a1a 588 TX_LED = 0;
GregCr 0:e5420f1a8a1a 589 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 590 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 591 SendNextPacket.detach( );
GregCr 0:e5420f1a8a1a 592 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 593 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 594 }
GregCr 0:e5420f1a8a1a 595 }
GregCr 0:e5420f1a8a1a 596 break;
GregCr 0:e5420f1a8a1a 597
GregCr 0:e5420f1a8a1a 598 case APP_RX:
GregCr 0:e5420f1a8a1a 599 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 600 Radio.GetPayload( Buffer, &BufferSize, BUFFER_SIZE );
GregCr 0:e5420f1a8a1a 601 Radio.GetPacketStatus( &PacketStatus );
GregCr 0:e5420f1a8a1a 602 if( Eeprom.EepromData.DemoSettings.ModulationType == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 603 {
GregCr 0:e5420f1a8a1a 604 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.LoRa.RssiPkt;
GregCr 0:e5420f1a8a1a 605 Eeprom.EepromData.DemoSettings.SnrValue = PacketStatus.Params.LoRa.SnrPkt;
GregCr 0:e5420f1a8a1a 606 if( ( PacketStatus.Params.LoRa.FreqError & 0x00080000 ) == 0x00080000 )
GregCr 0:e5420f1a8a1a 607 {
GregCr 0:e5420f1a8a1a 608 PacketStatus.Params.LoRa.FreqError = 0xFFFFF - PacketStatus.Params.LoRa.FreqError;
GregCr 0:e5420f1a8a1a 609 }
GregCr 0:e5420f1a8a1a 610 Eeprom.EepromData.DemoSettings.FreqErrorEst = ( double )PacketStatus.Params.LoRa.FreqError * FreErrorLsb;
GregCr 0:e5420f1a8a1a 611 }
GregCr 0:e5420f1a8a1a 612 else // Eeprom.EepromData.DemoSettings.ModulationType == PACKET_TYPE_GFSK
GregCr 0:e5420f1a8a1a 613 {
GregCr 0:e5420f1a8a1a 614 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.Gfsk.RssiAvg;
GregCr 0:e5420f1a8a1a 615 Eeprom.EepromData.DemoSettings.SnrValue = 0;
GregCr 0:e5420f1a8a1a 616 if( ( PacketStatus.Params.Gfsk.FreqError & 0x00000800 ) == 0x00000800 )
GregCr 0:e5420f1a8a1a 617 {
GregCr 0:e5420f1a8a1a 618 PacketStatus.Params.Gfsk.FreqError = 0x00000FFF - PacketStatus.Params.Gfsk.FreqError;
GregCr 0:e5420f1a8a1a 619 }
GregCr 0:e5420f1a8a1a 620 PacketStatus.Params.LoRa.FreqError = PacketStatus.Params.LoRa.FreqError / 2048;
GregCr 0:e5420f1a8a1a 621 Eeprom.EepromData.DemoSettings.FreqErrorEst = ( ( double )PacketStatus.Params.Gfsk.FreqError / 2048.0 );
GregCr 0:e5420f1a8a1a 622 }
GregCr 0:e5420f1a8a1a 623
GregCr 0:e5420f1a8a1a 624 DemoInternalState = PER_RX_START;
GregCr 0:e5420f1a8a1a 625 if( ( BufferSize >= PER_SIZE ) && ( strncmp( ( const char* )( Buffer + 5 ), ( const char* )PerMsg, PER_SIZE ) == 0 ) )
GregCr 0:e5420f1a8a1a 626 {
GregCr 0:e5420f1a8a1a 627 ComputePerPayload( Buffer, BufferSize );
GregCr 0:e5420f1a8a1a 628 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 629 }
GregCr 0:e5420f1a8a1a 630 else
GregCr 0:e5420f1a8a1a 631 {
GregCr 0:e5420f1a8a1a 632 Eeprom.EepromData.DemoSettings.RxTimeOutCount++;
GregCr 0:e5420f1a8a1a 633 }
GregCr 0:e5420f1a8a1a 634 break;
GregCr 0:e5420f1a8a1a 635
GregCr 0:e5420f1a8a1a 636 case APP_RX_ERROR:
GregCr 0:e5420f1a8a1a 637 case APP_RX_TIMEOUT:
GregCr 0:e5420f1a8a1a 638 Eeprom.EepromData.DemoSettings.RxTimeOutCount++;
GregCr 0:e5420f1a8a1a 639 DemoInternalState = PER_RX_START;
GregCr 0:e5420f1a8a1a 640 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 641 break;
GregCr 0:e5420f1a8a1a 642
GregCr 0:e5420f1a8a1a 643 case APP_TX_TIMEOUT:
GregCr 0:e5420f1a8a1a 644 printf( "Failure: timeout in Tx is shorter than the packet time on air\n\r" );
GregCr 0:e5420f1a8a1a 645 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 646 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 647 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 648 break;
GregCr 0:e5420f1a8a1a 649
GregCr 0:e5420f1a8a1a 650 case APP_IDLE: // do nothing
GregCr 0:e5420f1a8a1a 651 /*
GregCr 0:e5420f1a8a1a 652 val = Radio.GetSysErrors( );
GregCr 0:e5420f1a8a1a 653 if( val.Value != 0x0000 )
GregCr 0:e5420f1a8a1a 654 {
GregCr 0:e5420f1a8a1a 655 printf(" Dev Error = 0x%04x \n\r", val.Value );
GregCr 0:e5420f1a8a1a 656 }
GregCr 0:e5420f1a8a1a 657 */
GregCr 0:e5420f1a8a1a 658 break;
GregCr 0:e5420f1a8a1a 659
GregCr 0:e5420f1a8a1a 660 default:
GregCr 0:e5420f1a8a1a 661 break;
GregCr 0:e5420f1a8a1a 662 }
GregCr 0:e5420f1a8a1a 663 return refreshDisplay;
GregCr 0:e5420f1a8a1a 664 }
GregCr 0:e5420f1a8a1a 665
GregCr 0:e5420f1a8a1a 666 void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize )
GregCr 0:e5420f1a8a1a 667 {
GregCr 0:e5420f1a8a1a 668 uint32_t i = 0;
GregCr 0:e5420f1a8a1a 669
GregCr 0:e5420f1a8a1a 670 Eeprom.EepromData.DemoSettings.CntPacketRxOK++;
GregCr 0:e5420f1a8a1a 671 PacketRxSequence = ( ( uint32_t )buffer[1] << 24 ) | \
GregCr 0:e5420f1a8a1a 672 ( ( uint32_t )buffer[2] << 16 ) | \
GregCr 0:e5420f1a8a1a 673 ( ( uint32_t )buffer[3] << 8 ) | \
GregCr 0:e5420f1a8a1a 674 buffer[4];
GregCr 0:e5420f1a8a1a 675
GregCr 0:e5420f1a8a1a 676 if( ( PacketRxSequence <= PacketRxSequencePrev ) || \
GregCr 0:e5420f1a8a1a 677 ( PacketRxSequencePrev == 0xFFFFFFFF ) )
GregCr 0:e5420f1a8a1a 678 {
GregCr 0:e5420f1a8a1a 679 // Sequence went back => resynchronization
GregCr 0:e5420f1a8a1a 680 // Don't count missed packets this time
GregCr 0:e5420f1a8a1a 681 i = 0;
GregCr 0:e5420f1a8a1a 682 }
GregCr 0:e5420f1a8a1a 683 else
GregCr 0:e5420f1a8a1a 684 {
GregCr 0:e5420f1a8a1a 685 // Determine number of missed packets
GregCr 0:e5420f1a8a1a 686 i = PacketRxSequence - PacketRxSequencePrev - 1;
GregCr 0:e5420f1a8a1a 687 }
GregCr 0:e5420f1a8a1a 688 // Be ready for the next
GregCr 0:e5420f1a8a1a 689 PacketRxSequencePrev = PacketRxSequence;
GregCr 0:e5420f1a8a1a 690 // increment 'missed' counter for the RX session
GregCr 0:e5420f1a8a1a 691 Eeprom.EepromData.DemoSettings.CntPacketRxKO += i;
GregCr 0:e5420f1a8a1a 692 Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
GregCr 0:e5420f1a8a1a 693 }
GregCr 0:e5420f1a8a1a 694
GregCr 0:e5420f1a8a1a 695 // ************************ Ping Pong Demo *****************************
GregCr 0:e5420f1a8a1a 696 // * *
GregCr 0:e5420f1a8a1a 697 // * *
GregCr 0:e5420f1a8a1a 698 // * *
GregCr 0:e5420f1a8a1a 699 // *****************************************************************************
GregCr 0:e5420f1a8a1a 700 uint8_t RunDemoApplicationPingPong( void )
GregCr 0:e5420f1a8a1a 701 {
GregCr 0:e5420f1a8a1a 702 uint8_t i = 0;
GregCr 0:e5420f1a8a1a 703 uint8_t refreshDisplay = 0;
GregCr 0:e5420f1a8a1a 704
GregCr 0:e5420f1a8a1a 705 if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
GregCr 0:e5420f1a8a1a 706 {
GregCr 0:e5420f1a8a1a 707 return 0; // quit without refresh display
GregCr 0:e5420f1a8a1a 708 }
GregCr 0:e5420f1a8a1a 709
GregCr 0:e5420f1a8a1a 710 if( DemoRunning == false )
GregCr 0:e5420f1a8a1a 711 {
GregCr 0:e5420f1a8a1a 712 DemoRunning = true;
GregCr 0:e5420f1a8a1a 713 TX_LED = 0;
GregCr 0:e5420f1a8a1a 714 RX_LED = 0;
GregCr 0:e5420f1a8a1a 715 Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
GregCr 0:e5420f1a8a1a 716 Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
GregCr 0:e5420f1a8a1a 717 Eeprom.EepromData.DemoSettings.CntPacketRxOKSlave = 0;
GregCr 0:e5420f1a8a1a 718 Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
GregCr 0:e5420f1a8a1a 719 Eeprom.EepromData.DemoSettings.CntPacketRxKOSlave = 0;
GregCr 0:e5420f1a8a1a 720 Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
GregCr 0:e5420f1a8a1a 721
GregCr 0:e5420f1a8a1a 722 InitializeDemoParameters( Eeprom.EepromData.DemoSettings.ModulationType );
GregCr 0:e5420f1a8a1a 723
GregCr 0:e5420f1a8a1a 724 Eeprom.EepromData.DemoSettings.InterPacketDelay = GetTimeOnAir( Eeprom.EepromData.DemoSettings.ModulationType ) + RX_TX_TRANSITION_WAIT;
GregCr 0:e5420f1a8a1a 725
GregCr 0:e5420f1a8a1a 726 printf( "Start RunDemoApplicationPingPong.\n\r" );
GregCr 0:e5420f1a8a1a 727
GregCr 0:e5420f1a8a1a 728 if( Eeprom.EepromData.DemoSettings.Entity == MASTER )
GregCr 0:e5420f1a8a1a 729 {
GregCr 0:e5420f1a8a1a 730 DemoInternalState = SEND_PING_MSG;
GregCr 0:e5420f1a8a1a 731 uint32_t temp = ( Eeprom.EepromData.DemoSettings.InterPacketDelay << 1 ) + RX_TIMEOUT_MARGIN;
GregCr 0:e5420f1a8a1a 732 float val = ( float )temp / ( float )( 1000.0 );
GregCr 0:e5420f1a8a1a 733 SendNextPacket.attach( &SendNextPacketEvent, val );
GregCr 0:e5420f1a8a1a 734 }
GregCr 0:e5420f1a8a1a 735 else
GregCr 0:e5420f1a8a1a 736 {
GregCr 0:e5420f1a8a1a 737 IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 738 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 739 // Rx Single without timeout for the start
GregCr 0:e5420f1a8a1a 740 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 741
GregCr 0:e5420f1a8a1a 742 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 743 {
GregCr 0:e5420f1a8a1a 744 Radio.SetRx( 0x0000 );
GregCr 0:e5420f1a8a1a 745 }
GregCr 0:e5420f1a8a1a 746 else
GregCr 0:e5420f1a8a1a 747 {
GregCr 0:e5420f1a8a1a 748 Radio.SetRxBoosted( 0x0000 );
GregCr 0:e5420f1a8a1a 749 }
GregCr 0:e5420f1a8a1a 750 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 751 }
GregCr 0:e5420f1a8a1a 752 }
GregCr 0:e5420f1a8a1a 753
GregCr 0:e5420f1a8a1a 754 Radio.ProcessIrqs( );
GregCr 0:e5420f1a8a1a 755
GregCr 0:e5420f1a8a1a 756 if( Eeprom.EepromData.DemoSettings.Entity == MASTER )
GregCr 0:e5420f1a8a1a 757 {
GregCr 0:e5420f1a8a1a 758 switch( DemoInternalState )
GregCr 0:e5420f1a8a1a 759 {
GregCr 0:e5420f1a8a1a 760 case SEND_PING_MSG:
GregCr 0:e5420f1a8a1a 761 if( ( Eeprom.EepromData.DemoSettings.MaxNumPacket != 0 ) \
GregCr 0:e5420f1a8a1a 762 && ( Eeprom.EepromData.DemoSettings.CntPacketTx >= Eeprom.EepromData.DemoSettings.MaxNumPacket ) )
GregCr 0:e5420f1a8a1a 763 {
GregCr 0:e5420f1a8a1a 764 SendNextPacket.detach( );
GregCr 0:e5420f1a8a1a 765 SendNext = false;
GregCr 0:e5420f1a8a1a 766 RX_LED = 0;
GregCr 0:e5420f1a8a1a 767 TX_LED = 0;
GregCr 0:e5420f1a8a1a 768 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 769 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 770 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 771 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 772 }
GregCr 0:e5420f1a8a1a 773 else
GregCr 0:e5420f1a8a1a 774 {
GregCr 0:e5420f1a8a1a 775 if( SendNext == true )
GregCr 0:e5420f1a8a1a 776 {
GregCr 0:e5420f1a8a1a 777 SendNext = false;
GregCr 0:e5420f1a8a1a 778 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 779 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 780 Eeprom.EepromData.DemoSettings.CntPacketTx++;
GregCr 0:e5420f1a8a1a 781 // Send the next PING frame
GregCr 0:e5420f1a8a1a 782 Buffer[0] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 24 ) & 0xFF;
GregCr 0:e5420f1a8a1a 783 Buffer[1] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 16 ) & 0xFF;
GregCr 0:e5420f1a8a1a 784 Buffer[2] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 8 ) & 0xFF;
GregCr 0:e5420f1a8a1a 785 Buffer[3] = ( Eeprom.EepromData.DemoSettings.CntPacketTx & 0xFF );
GregCr 0:e5420f1a8a1a 786 Buffer[4] = PingMsg[0];
GregCr 0:e5420f1a8a1a 787 Buffer[5] = PingMsg[1];
GregCr 0:e5420f1a8a1a 788 Buffer[6] = PingMsg[2];
GregCr 0:e5420f1a8a1a 789 Buffer[7] = PingMsg[3];
GregCr 0:e5420f1a8a1a 790 for( i = 8; i < Eeprom.EepromData.DemoSettings.PayloadLength; i++ )
GregCr 0:e5420f1a8a1a 791 {
GregCr 0:e5420f1a8a1a 792 Buffer[i] = i;
GregCr 0:e5420f1a8a1a 793 }
GregCr 0:e5420f1a8a1a 794 TX_LED = !TX_LED;
GregCr 0:e5420f1a8a1a 795 IrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 796 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 797 Radio.SendPayload( Buffer, Eeprom.EepromData.DemoSettings.PayloadLength, \
GregCr 0:e5420f1a8a1a 798 Eeprom.EepromData.DemoSettings.InterPacketDelay << 6 );
GregCr 0:e5420f1a8a1a 799 }
GregCr 0:e5420f1a8a1a 800 }
GregCr 0:e5420f1a8a1a 801 break;
GregCr 0:e5420f1a8a1a 802
GregCr 0:e5420f1a8a1a 803 case APP_TX:
GregCr 0:e5420f1a8a1a 804 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 805 TX_LED = !TX_LED;
GregCr 0:e5420f1a8a1a 806 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 807 IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 808 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 809
GregCr 0:e5420f1a8a1a 810 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 811 {
GregCr 0:e5420f1a8a1a 812 Radio.SetRx( ( ( Eeprom.EepromData.DemoSettings.InterPacketDelay << 1 ) + RX_TIMEOUT_MARGIN ) << 6 );
GregCr 0:e5420f1a8a1a 813 }
GregCr 0:e5420f1a8a1a 814 else
GregCr 0:e5420f1a8a1a 815 {
GregCr 0:e5420f1a8a1a 816 Radio.SetRxBoosted( ( ( Eeprom.EepromData.DemoSettings.InterPacketDelay << 1 ) + RX_TIMEOUT_MARGIN ) << 6 );
GregCr 0:e5420f1a8a1a 817 }
GregCr 0:e5420f1a8a1a 818 break;
GregCr 0:e5420f1a8a1a 819
GregCr 0:e5420f1a8a1a 820 case APP_RX:
GregCr 0:e5420f1a8a1a 821 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 822 Radio.GetPayload( Buffer, &BufferSize, BUFFER_SIZE );
GregCr 0:e5420f1a8a1a 823 Radio.GetPacketStatus( &PacketStatus );
GregCr 0:e5420f1a8a1a 824 if( Eeprom.EepromData.ModulationParams.PacketType == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 825 {
GregCr 0:e5420f1a8a1a 826 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.LoRa.RssiPkt;
GregCr 0:e5420f1a8a1a 827 Eeprom.EepromData.DemoSettings.SnrValue = PacketStatus.Params.LoRa.SnrPkt;
GregCr 0:e5420f1a8a1a 828 }
GregCr 0:e5420f1a8a1a 829 else // Eeprom.EepromData.ModulationParams.PacketType == PACKET_TYPE_GFSK
GregCr 0:e5420f1a8a1a 830 {
GregCr 0:e5420f1a8a1a 831 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.Gfsk.RssiAvg;
GregCr 0:e5420f1a8a1a 832 Eeprom.EepromData.DemoSettings.SnrValue = 0;
GregCr 0:e5420f1a8a1a 833 }
GregCr 0:e5420f1a8a1a 834
GregCr 0:e5420f1a8a1a 835 if( ( BufferSize >= PINGPONG_SIZE ) && ( strncmp( ( const char* )( Buffer + 8 ), ( const char* )PongMsg, PINGPONG_SIZE ) == 0 ) )
GregCr 0:e5420f1a8a1a 836 {
GregCr 0:e5420f1a8a1a 837 ComputePingPongPayload( Buffer, BufferSize );
GregCr 0:e5420f1a8a1a 838 }
GregCr 0:e5420f1a8a1a 839 else
GregCr 0:e5420f1a8a1a 840 {
GregCr 0:e5420f1a8a1a 841 Eeprom.EepromData.DemoSettings.CntPacketRxKO++;
GregCr 0:e5420f1a8a1a 842 }
GregCr 0:e5420f1a8a1a 843 DemoInternalState = SEND_PING_MSG;
GregCr 0:e5420f1a8a1a 844 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 845 break;
GregCr 0:e5420f1a8a1a 846
GregCr 0:e5420f1a8a1a 847 case APP_RX_TIMEOUT:
GregCr 0:e5420f1a8a1a 848 case APP_RX_ERROR:
GregCr 0:e5420f1a8a1a 849 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 850 Eeprom.EepromData.DemoSettings.CntPacketRxKO++;
GregCr 0:e5420f1a8a1a 851 DemoInternalState = SEND_PING_MSG;
GregCr 0:e5420f1a8a1a 852 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 853 break;
GregCr 0:e5420f1a8a1a 854
GregCr 0:e5420f1a8a1a 855 case APP_TX_TIMEOUT:
GregCr 0:e5420f1a8a1a 856 printf( "Failure: timeout in Tx is shorter than the packet time on air\n\r" );
GregCr 0:e5420f1a8a1a 857 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 858 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 859 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 860 break;
GregCr 0:e5420f1a8a1a 861
GregCr 0:e5420f1a8a1a 862 case APP_IDLE: // do nothing
GregCr 0:e5420f1a8a1a 863 break;
GregCr 0:e5420f1a8a1a 864
GregCr 0:e5420f1a8a1a 865 default:
GregCr 0:e5420f1a8a1a 866 break;
GregCr 0:e5420f1a8a1a 867 }
GregCr 0:e5420f1a8a1a 868 }
GregCr 0:e5420f1a8a1a 869 else // SLAVE
GregCr 0:e5420f1a8a1a 870 {
GregCr 0:e5420f1a8a1a 871 switch( DemoInternalState )
GregCr 0:e5420f1a8a1a 872 {
GregCr 0:e5420f1a8a1a 873 case SEND_PONG_MSG:
GregCr 0:e5420f1a8a1a 874 wait_ms( RX_TX_TRANSITION_WAIT );
GregCr 0:e5420f1a8a1a 875
GregCr 0:e5420f1a8a1a 876 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 877 // Send the next PING frame
GregCr 0:e5420f1a8a1a 878 Buffer[0] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 24 ) & 0xFF;
GregCr 0:e5420f1a8a1a 879 Buffer[1] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 16 ) & 0xFF;
GregCr 0:e5420f1a8a1a 880 Buffer[2] = ( Eeprom.EepromData.DemoSettings.CntPacketTx >> 8 ) & 0xFF;
GregCr 0:e5420f1a8a1a 881 Buffer[3] = ( Eeprom.EepromData.DemoSettings.CntPacketTx & 0xFF );
GregCr 0:e5420f1a8a1a 882 Buffer[4] = ( ( Eeprom.EepromData.DemoSettings.CntPacketRxKO + \
GregCr 0:e5420f1a8a1a 883 Eeprom.EepromData.DemoSettings.RxTimeOutCount ) >> 24 ) & 0xFF;
GregCr 0:e5420f1a8a1a 884 Buffer[5] = ( ( Eeprom.EepromData.DemoSettings.CntPacketRxKO + \
GregCr 0:e5420f1a8a1a 885 Eeprom.EepromData.DemoSettings.RxTimeOutCount ) >> 16 ) & 0xFF;
GregCr 0:e5420f1a8a1a 886 Buffer[6] = ( ( Eeprom.EepromData.DemoSettings.CntPacketRxKO + \
GregCr 0:e5420f1a8a1a 887 Eeprom.EepromData.DemoSettings.RxTimeOutCount ) >> 8 ) & 0xFF;
GregCr 0:e5420f1a8a1a 888 Buffer[7] = ( ( Eeprom.EepromData.DemoSettings.CntPacketRxKO + \
GregCr 0:e5420f1a8a1a 889 Eeprom.EepromData.DemoSettings.RxTimeOutCount ) & 0xFF );
GregCr 0:e5420f1a8a1a 890 Buffer[8] = PongMsg[0];
GregCr 0:e5420f1a8a1a 891 Buffer[9] = PongMsg[1];
GregCr 0:e5420f1a8a1a 892 Buffer[10] = PongMsg[2];
GregCr 0:e5420f1a8a1a 893 Buffer[11] = PongMsg[3];
GregCr 0:e5420f1a8a1a 894 for( i = 12; i < Eeprom.EepromData.DemoSettings.PayloadLength; i++ )
GregCr 0:e5420f1a8a1a 895 {
GregCr 0:e5420f1a8a1a 896 Buffer[i] = i;
GregCr 0:e5420f1a8a1a 897 }
GregCr 0:e5420f1a8a1a 898 TX_LED = !TX_LED;
GregCr 0:e5420f1a8a1a 899 IrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 900 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 901 Radio.SendPayload( Buffer, Eeprom.EepromData.DemoSettings.PayloadLength, \
GregCr 0:e5420f1a8a1a 902 ( Eeprom.EepromData.DemoSettings.InterPacketDelay ) << 6 );
GregCr 0:e5420f1a8a1a 903 break;
GregCr 0:e5420f1a8a1a 904
GregCr 0:e5420f1a8a1a 905 case APP_TX:
GregCr 0:e5420f1a8a1a 906 if( ( Eeprom.EepromData.DemoSettings.MaxNumPacket != 0 ) \
GregCr 0:e5420f1a8a1a 907 && ( ( Eeprom.EepromData.DemoSettings.CntPacketRxOK + Eeprom.EepromData.DemoSettings.CntPacketRxKO + \
GregCr 0:e5420f1a8a1a 908 Eeprom.EepromData.DemoSettings.RxTimeOutCount ) >= Eeprom.EepromData.DemoSettings.MaxNumPacket ) )
GregCr 0:e5420f1a8a1a 909 {
GregCr 0:e5420f1a8a1a 910 SendNextPacket.detach( );
GregCr 0:e5420f1a8a1a 911 SendNext = false;
GregCr 0:e5420f1a8a1a 912 RX_LED = 0;
GregCr 0:e5420f1a8a1a 913 TX_LED = 0;
GregCr 0:e5420f1a8a1a 914 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 915 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 916 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 917 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 918 }
GregCr 0:e5420f1a8a1a 919 else
GregCr 0:e5420f1a8a1a 920 {
GregCr 0:e5420f1a8a1a 921 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 922 TX_LED = !TX_LED;
GregCr 0:e5420f1a8a1a 923 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 924 IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 925 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 926 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 927 {
GregCr 0:e5420f1a8a1a 928 Radio.SetRx( ( ( Eeprom.EepromData.DemoSettings.InterPacketDelay << 1 ) + RX_TIMEOUT_MARGIN ) << 6 );
GregCr 0:e5420f1a8a1a 929 }
GregCr 0:e5420f1a8a1a 930 else
GregCr 0:e5420f1a8a1a 931 {
GregCr 0:e5420f1a8a1a 932 Radio.SetRxBoosted( ( ( Eeprom.EepromData.DemoSettings.InterPacketDelay << 1 ) + RX_TIMEOUT_MARGIN) << 6 );
GregCr 0:e5420f1a8a1a 933 }
GregCr 0:e5420f1a8a1a 934 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 935 }
GregCr 0:e5420f1a8a1a 936 break;
GregCr 0:e5420f1a8a1a 937
GregCr 0:e5420f1a8a1a 938 case APP_RX:
GregCr 0:e5420f1a8a1a 939 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 940 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 941 Radio.GetPayload( Buffer, &BufferSize, BUFFER_SIZE );
GregCr 0:e5420f1a8a1a 942 Radio.GetPacketStatus( &PacketStatus );
GregCr 0:e5420f1a8a1a 943 if( Eeprom.EepromData.ModulationParams.PacketType == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 944 {
GregCr 0:e5420f1a8a1a 945 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.LoRa.RssiPkt;
GregCr 0:e5420f1a8a1a 946 Eeprom.EepromData.DemoSettings.SnrValue = PacketStatus.Params.LoRa.SnrPkt;
GregCr 0:e5420f1a8a1a 947 }
GregCr 0:e5420f1a8a1a 948 else // Eeprom.EepromData.ModulationParams.PacketType == PACKET_TYPE_GFSK
GregCr 0:e5420f1a8a1a 949 {
GregCr 0:e5420f1a8a1a 950 Eeprom.EepromData.DemoSettings.RssiValue = PacketStatus.Params.Gfsk.RssiAvg;
GregCr 0:e5420f1a8a1a 951 Eeprom.EepromData.DemoSettings.SnrValue = 0;
GregCr 0:e5420f1a8a1a 952 }
GregCr 0:e5420f1a8a1a 953
GregCr 0:e5420f1a8a1a 954 if( ( BufferSize >= PINGPONG_SIZE ) && ( strncmp( ( const char* )( Buffer + 4 ), ( const char* )PingMsg, PINGPONG_SIZE ) == 0 ) )
GregCr 0:e5420f1a8a1a 955 {
GregCr 0:e5420f1a8a1a 956 ComputePingPongPayload( Buffer, BufferSize );
GregCr 0:e5420f1a8a1a 957 DemoInternalState = SEND_PONG_MSG;
GregCr 0:e5420f1a8a1a 958 }
GregCr 0:e5420f1a8a1a 959 else
GregCr 0:e5420f1a8a1a 960 {
GregCr 0:e5420f1a8a1a 961 Eeprom.EepromData.DemoSettings.CntPacketRxKO++;
GregCr 0:e5420f1a8a1a 962 RX_LED = !RX_LED;
GregCr 0:e5420f1a8a1a 963 IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 964 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 965 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 966 {
GregCr 0:e5420f1a8a1a 967 Radio.SetRx( ( Eeprom.EepromData.DemoSettings.InterPacketDelay ) << 6 );
GregCr 0:e5420f1a8a1a 968 }
GregCr 0:e5420f1a8a1a 969 else
GregCr 0:e5420f1a8a1a 970 {
GregCr 0:e5420f1a8a1a 971 Radio.SetRxBoosted( ( Eeprom.EepromData.DemoSettings.InterPacketDelay ) << 6 );
GregCr 0:e5420f1a8a1a 972 }
GregCr 0:e5420f1a8a1a 973 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 974 }
GregCr 0:e5420f1a8a1a 975 break;
GregCr 0:e5420f1a8a1a 976
GregCr 0:e5420f1a8a1a 977 case APP_RX_TIMEOUT:
GregCr 0:e5420f1a8a1a 978 case APP_RX_ERROR:
GregCr 0:e5420f1a8a1a 979 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 980 Eeprom.EepromData.DemoSettings.RxTimeOutCount++;
GregCr 0:e5420f1a8a1a 981 IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 982 Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
GregCr 0:e5420f1a8a1a 983 if( Eeprom.EepromData.DemoSettings.BoostedRx == false )
GregCr 0:e5420f1a8a1a 984 {
GregCr 0:e5420f1a8a1a 985 Radio.SetRx( ( Eeprom.EepromData.DemoSettings.InterPacketDelay ) << 6 );
GregCr 0:e5420f1a8a1a 986 }
GregCr 0:e5420f1a8a1a 987 else
GregCr 0:e5420f1a8a1a 988 {
GregCr 0:e5420f1a8a1a 989 Radio.SetRxBoosted( ( Eeprom.EepromData.DemoSettings.InterPacketDelay ) << 6 );
GregCr 0:e5420f1a8a1a 990 }
GregCr 0:e5420f1a8a1a 991 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 992 break;
GregCr 0:e5420f1a8a1a 993
GregCr 0:e5420f1a8a1a 994 case APP_TX_TIMEOUT:
GregCr 0:e5420f1a8a1a 995 printf( "Failure: timeout in Tx is shorter than the packet time on air\n\r" );
GregCr 0:e5420f1a8a1a 996 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 997 Eeprom.EepromData.DemoSettings.HoldDemo = true;
GregCr 0:e5420f1a8a1a 998 refreshDisplay = 1;
GregCr 0:e5420f1a8a1a 999 break;
GregCr 0:e5420f1a8a1a 1000
GregCr 0:e5420f1a8a1a 1001 case APP_IDLE: // do nothing
GregCr 0:e5420f1a8a1a 1002 break;
GregCr 0:e5420f1a8a1a 1003
GregCr 0:e5420f1a8a1a 1004 default:
GregCr 0:e5420f1a8a1a 1005 break;
GregCr 0:e5420f1a8a1a 1006 }
GregCr 0:e5420f1a8a1a 1007 }
GregCr 0:e5420f1a8a1a 1008 return refreshDisplay;
GregCr 0:e5420f1a8a1a 1009 }
GregCr 0:e5420f1a8a1a 1010
GregCr 0:e5420f1a8a1a 1011 void ComputePingPongPayload( uint8_t *buffer, uint8_t bufferSize )
GregCr 0:e5420f1a8a1a 1012 {
GregCr 0:e5420f1a8a1a 1013 uint32_t i = 0;
GregCr 0:e5420f1a8a1a 1014
GregCr 0:e5420f1a8a1a 1015 PacketRxSequence = ( ( uint32_t )buffer[0] << 24 ) | \
GregCr 0:e5420f1a8a1a 1016 ( ( uint32_t )buffer[1] << 16 ) | \
GregCr 0:e5420f1a8a1a 1017 ( ( uint32_t )buffer[2] << 8 ) | \
GregCr 0:e5420f1a8a1a 1018 buffer[3];
GregCr 0:e5420f1a8a1a 1019
GregCr 0:e5420f1a8a1a 1020 if( Eeprom.EepromData.DemoSettings.Entity == MASTER )
GregCr 0:e5420f1a8a1a 1021 {
GregCr 0:e5420f1a8a1a 1022 Eeprom.EepromData.DemoSettings.CntPacketRxKOSlave =
GregCr 0:e5420f1a8a1a 1023 ( ( uint32_t )buffer[4] << 24 ) | \
GregCr 0:e5420f1a8a1a 1024 ( ( uint32_t )buffer[5] << 16 ) | \
GregCr 0:e5420f1a8a1a 1025 ( ( uint32_t )buffer[6] << 8 ) | \
GregCr 0:e5420f1a8a1a 1026 buffer[7];
GregCr 0:e5420f1a8a1a 1027 if( PacketRxSequence > Eeprom.EepromData.DemoSettings.CntPacketRxKOSlave )
GregCr 0:e5420f1a8a1a 1028 {
GregCr 0:e5420f1a8a1a 1029 Eeprom.EepromData.DemoSettings.CntPacketRxOKSlave = PacketRxSequence - \
GregCr 0:e5420f1a8a1a 1030 Eeprom.EepromData.DemoSettings.CntPacketRxKOSlave;
GregCr 0:e5420f1a8a1a 1031 }
GregCr 0:e5420f1a8a1a 1032 else
GregCr 0:e5420f1a8a1a 1033 {
GregCr 0:e5420f1a8a1a 1034 Eeprom.EepromData.DemoSettings.CntPacketRxOKSlave = 0;
GregCr 0:e5420f1a8a1a 1035 }
GregCr 0:e5420f1a8a1a 1036
GregCr 0:e5420f1a8a1a 1037 if( PacketRxSequence == Eeprom.EepromData.DemoSettings.CntPacketTx )
GregCr 0:e5420f1a8a1a 1038 {
GregCr 0:e5420f1a8a1a 1039 Eeprom.EepromData.DemoSettings.CntPacketRxOK += 1;
GregCr 0:e5420f1a8a1a 1040 }
GregCr 0:e5420f1a8a1a 1041 else
GregCr 0:e5420f1a8a1a 1042 {
GregCr 0:e5420f1a8a1a 1043 Eeprom.EepromData.DemoSettings.CntPacketRxKO += 1;
GregCr 0:e5420f1a8a1a 1044 }
GregCr 0:e5420f1a8a1a 1045 }
GregCr 0:e5420f1a8a1a 1046 else
GregCr 0:e5420f1a8a1a 1047 {
GregCr 0:e5420f1a8a1a 1048 Eeprom.EepromData.DemoSettings.CntPacketRxOK += 1;
GregCr 0:e5420f1a8a1a 1049 if( ( PacketRxSequence <= PacketRxSequencePrev ) || \
GregCr 0:e5420f1a8a1a 1050 ( PacketRxSequencePrev == 0 ) )
GregCr 0:e5420f1a8a1a 1051 {
GregCr 0:e5420f1a8a1a 1052 // Sequence went back => resynchronization
GregCr 0:e5420f1a8a1a 1053 // Don't count missed packets this time
GregCr 0:e5420f1a8a1a 1054 i = 0;
GregCr 0:e5420f1a8a1a 1055 }
GregCr 0:e5420f1a8a1a 1056 else
GregCr 0:e5420f1a8a1a 1057 {
GregCr 0:e5420f1a8a1a 1058 // Determine number of missed packets
GregCr 0:e5420f1a8a1a 1059 i = PacketRxSequence - PacketRxSequencePrev - 1;
GregCr 0:e5420f1a8a1a 1060 }
GregCr 0:e5420f1a8a1a 1061 // Be ready for the next
GregCr 0:e5420f1a8a1a 1062 PacketRxSequencePrev = PacketRxSequence;
GregCr 0:e5420f1a8a1a 1063 Eeprom.EepromData.DemoSettings.CntPacketTx = PacketRxSequence;
GregCr 0:e5420f1a8a1a 1064 // increment 'missed' counter for the RX session
GregCr 0:e5420f1a8a1a 1065 Eeprom.EepromData.DemoSettings.CntPacketRxKO += i;
GregCr 0:e5420f1a8a1a 1066 Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
GregCr 0:e5420f1a8a1a 1067 }
GregCr 0:e5420f1a8a1a 1068 }
GregCr 0:e5420f1a8a1a 1069
GregCr 0:e5420f1a8a1a 1070 // ************************ Utils ****************************
GregCr 0:e5420f1a8a1a 1071 // * *
GregCr 0:e5420f1a8a1a 1072 // * *
GregCr 0:e5420f1a8a1a 1073 // * *
GregCr 0:e5420f1a8a1a 1074 // *****************************************************************************
GregCr 0:e5420f1a8a1a 1075
GregCr 0:e5420f1a8a1a 1076 uint8_t GetConnectedDevice( void )
GregCr 0:e5420f1a8a1a 1077 {
GregCr 0:e5420f1a8a1a 1078 return( Radio.GetDeviceType( ) );
GregCr 0:e5420f1a8a1a 1079 }
GregCr 0:e5420f1a8a1a 1080
GregCr 0:e5420f1a8a1a 1081 void InitDemoApplication( void )
GregCr 0:e5420f1a8a1a 1082 {
GregCr 0:e5420f1a8a1a 1083 RX_LED = 1;
GregCr 0:e5420f1a8a1a 1084 TX_LED = 1;
GregCr 0:e5420f1a8a1a 1085
GregCr 0:e5420f1a8a1a 1086 Radio.Init( );
GregCr 0:e5420f1a8a1a 1087
GregCr 0:e5420f1a8a1a 1088 // Can also be set in LDO mode but consume more power
GregCr 0:e5420f1a8a1a 1089 Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
GregCr 0:e5420f1a8a1a 1090 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 1091
GregCr 0:e5420f1a8a1a 1092 memset( &Buffer, 0x00, BufferSize );
GregCr 0:e5420f1a8a1a 1093
GregCr 0:e5420f1a8a1a 1094 RX_LED = 0;
GregCr 0:e5420f1a8a1a 1095 TX_LED = 0;
GregCr 0:e5420f1a8a1a 1096
GregCr 0:e5420f1a8a1a 1097 PacketRxSequence = 0;
GregCr 0:e5420f1a8a1a 1098 PacketRxSequencePrev = 0;
GregCr 0:e5420f1a8a1a 1099 Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
GregCr 0:e5420f1a8a1a 1100 Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
GregCr 0:e5420f1a8a1a 1101 Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
GregCr 0:e5420f1a8a1a 1102 Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
GregCr 0:e5420f1a8a1a 1103 }
GregCr 0:e5420f1a8a1a 1104
GregCr 0:e5420f1a8a1a 1105 void StopDemoApplication( void )
GregCr 0:e5420f1a8a1a 1106 {
GregCr 0:e5420f1a8a1a 1107 if( DemoRunning == true )
GregCr 0:e5420f1a8a1a 1108 {
GregCr 0:e5420f1a8a1a 1109 Radio.CheckDeviceReady( );
GregCr 0:e5420f1a8a1a 1110
GregCr 0:e5420f1a8a1a 1111 RX_LED = 0;
GregCr 0:e5420f1a8a1a 1112 TX_LED = 0;
GregCr 0:e5420f1a8a1a 1113 DemoRunning = false;
GregCr 0:e5420f1a8a1a 1114 SendNext = false;
GregCr 0:e5420f1a8a1a 1115 PacketRxSequence = 0;
GregCr 0:e5420f1a8a1a 1116 PacketRxSequencePrev = 0;
GregCr 0:e5420f1a8a1a 1117 Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
GregCr 0:e5420f1a8a1a 1118 Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
GregCr 0:e5420f1a8a1a 1119 Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
GregCr 0:e5420f1a8a1a 1120 Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
GregCr 0:e5420f1a8a1a 1121
GregCr 0:e5420f1a8a1a 1122 DemoInternalState = APP_IDLE;
GregCr 0:e5420f1a8a1a 1123 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 1124 Radio.ClearIrqStatus( IRQ_RADIO_ALL );
GregCr 0:e5420f1a8a1a 1125 SendNextPacket.detach( );
GregCr 0:e5420f1a8a1a 1126 }
GregCr 0:e5420f1a8a1a 1127 }
GregCr 0:e5420f1a8a1a 1128
GregCr 0:e5420f1a8a1a 1129 /*
GregCr 0:e5420f1a8a1a 1130 * Function still being implemented >>> To be completed
GregCr 0:e5420f1a8a1a 1131 * WARNING: Computation is in float and his really slow
GregCr 0:e5420f1a8a1a 1132 * LongInterLeaving vs LegacyInterLeaving has no influence on TimeOnAir.
GregCr 0:e5420f1a8a1a 1133 */
GregCr 0:e5420f1a8a1a 1134 uint16_t GetTimeOnAir( uint8_t modulation )
GregCr 0:e5420f1a8a1a 1135 {
GregCr 0:e5420f1a8a1a 1136 uint16_t result = 2000;
GregCr 0:e5420f1a8a1a 1137 uint8_t LowDatarateOptimize = 0;
GregCr 0:e5420f1a8a1a 1138
GregCr 0:e5420f1a8a1a 1139 if( modulation == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 1140 {
GregCr 0:e5420f1a8a1a 1141 volatile double loraBw = 0.0;
GregCr 0:e5420f1a8a1a 1142 volatile double FreqErrorUnits = 0.0;
GregCr 0:e5420f1a8a1a 1143
GregCr 0:e5420f1a8a1a 1144 switch( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth )
GregCr 0:e5420f1a8a1a 1145 {
GregCr 0:e5420f1a8a1a 1146 case LORA_BW_500:
GregCr 0:e5420f1a8a1a 1147 loraBw = 500e3;
GregCr 0:e5420f1a8a1a 1148 break;
GregCr 0:e5420f1a8a1a 1149
GregCr 0:e5420f1a8a1a 1150 case LORA_BW_250:
GregCr 0:e5420f1a8a1a 1151 loraBw = 250e3;
GregCr 0:e5420f1a8a1a 1152 break;
GregCr 0:e5420f1a8a1a 1153
GregCr 0:e5420f1a8a1a 1154 case LORA_BW_125:
GregCr 0:e5420f1a8a1a 1155 loraBw = 125e3;
GregCr 0:e5420f1a8a1a 1156 break;
GregCr 0:e5420f1a8a1a 1157
GregCr 0:e5420f1a8a1a 1158 case LORA_BW_062:
GregCr 0:e5420f1a8a1a 1159 loraBw = 62e3;
GregCr 0:e5420f1a8a1a 1160 break;
GregCr 0:e5420f1a8a1a 1161
GregCr 0:e5420f1a8a1a 1162 case LORA_BW_041:
GregCr 0:e5420f1a8a1a 1163 loraBw = 41e3;
GregCr 0:e5420f1a8a1a 1164 break;
GregCr 0:e5420f1a8a1a 1165
GregCr 0:e5420f1a8a1a 1166 case LORA_BW_031:
GregCr 0:e5420f1a8a1a 1167 loraBw = 31e3;
GregCr 0:e5420f1a8a1a 1168 break;
GregCr 0:e5420f1a8a1a 1169
GregCr 0:e5420f1a8a1a 1170 case LORA_BW_020:
GregCr 0:e5420f1a8a1a 1171 loraBw = 20e3;
GregCr 0:e5420f1a8a1a 1172 break;
GregCr 0:e5420f1a8a1a 1173
GregCr 0:e5420f1a8a1a 1174 case LORA_BW_015:
GregCr 0:e5420f1a8a1a 1175 loraBw = 15e3;
GregCr 0:e5420f1a8a1a 1176 break;
GregCr 0:e5420f1a8a1a 1177
GregCr 0:e5420f1a8a1a 1178 case LORA_BW_010:
GregCr 0:e5420f1a8a1a 1179 loraBw = 10e3;
GregCr 0:e5420f1a8a1a 1180 break;
GregCr 0:e5420f1a8a1a 1181
GregCr 0:e5420f1a8a1a 1182 case LORA_BW_007:
GregCr 0:e5420f1a8a1a 1183 loraBw = 7e3;
GregCr 0:e5420f1a8a1a 1184 break;
GregCr 0:e5420f1a8a1a 1185
GregCr 0:e5420f1a8a1a 1186 default:
GregCr 0:e5420f1a8a1a 1187 loraBw = 7e3;
GregCr 0:e5420f1a8a1a 1188 break;
GregCr 0:e5420f1a8a1a 1189 }
GregCr 0:e5420f1a8a1a 1190
GregCr 0:e5420f1a8a1a 1191 /* Used to compute the freq Error */
GregCr 0:e5420f1a8a1a 1192 FreqErrorUnits = FREQ_ERR;
GregCr 0:e5420f1a8a1a 1193 FreErrorLsb = FreqErrorUnits * ( ( double )loraBw / 1000 ) / 500;
GregCr 0:e5420f1a8a1a 1194
GregCr 0:e5420f1a8a1a 1195 float ts = 1 << Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor; // time for one symbol in ms
GregCr 0:e5420f1a8a1a 1196 ts = (float)ts / (float)loraBw;
GregCr 0:e5420f1a8a1a 1197 ts = ts * 1000; // from seconds to miliseconds
GregCr 0:e5420f1a8a1a 1198
GregCr 0:e5420f1a8a1a 1199 float tPreamble = ( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength + 4.25 + ( ( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor > 6 ) ? 2 : 0 )) * ts; // time of preamble
GregCr 0:e5420f1a8a1a 1200
GregCr 0:e5420f1a8a1a 1201 switch( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth )
GregCr 0:e5420f1a8a1a 1202 {
GregCr 0:e5420f1a8a1a 1203 case LORA_BW_500:
GregCr 0:e5420f1a8a1a 1204 break;
GregCr 0:e5420f1a8a1a 1205
GregCr 0:e5420f1a8a1a 1206 case LORA_BW_250:
GregCr 0:e5420f1a8a1a 1207 if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF12 )
GregCr 0:e5420f1a8a1a 1208 {
GregCr 0:e5420f1a8a1a 1209 LowDatarateOptimize = 1;
GregCr 0:e5420f1a8a1a 1210 }
GregCr 0:e5420f1a8a1a 1211 break;
GregCr 0:e5420f1a8a1a 1212
GregCr 0:e5420f1a8a1a 1213 case LORA_BW_125:
GregCr 0:e5420f1a8a1a 1214 if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF11 )
GregCr 0:e5420f1a8a1a 1215 {
GregCr 0:e5420f1a8a1a 1216 LowDatarateOptimize = 1;
GregCr 0:e5420f1a8a1a 1217 }
GregCr 0:e5420f1a8a1a 1218 break;
GregCr 0:e5420f1a8a1a 1219
GregCr 0:e5420f1a8a1a 1220 case LORA_BW_062:
GregCr 0:e5420f1a8a1a 1221 if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF10 )
GregCr 0:e5420f1a8a1a 1222 {
GregCr 0:e5420f1a8a1a 1223 LowDatarateOptimize = 1;
GregCr 0:e5420f1a8a1a 1224 }
GregCr 0:e5420f1a8a1a 1225 break;
GregCr 0:e5420f1a8a1a 1226
GregCr 0:e5420f1a8a1a 1227 case LORA_BW_041:
GregCr 0:e5420f1a8a1a 1228 case LORA_BW_031:
GregCr 0:e5420f1a8a1a 1229 if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF9 )
GregCr 0:e5420f1a8a1a 1230 {
GregCr 0:e5420f1a8a1a 1231 LowDatarateOptimize = 1;
GregCr 0:e5420f1a8a1a 1232 }
GregCr 0:e5420f1a8a1a 1233 break;
GregCr 0:e5420f1a8a1a 1234
GregCr 0:e5420f1a8a1a 1235 case LORA_BW_020:
GregCr 0:e5420f1a8a1a 1236 case LORA_BW_015:
GregCr 0:e5420f1a8a1a 1237 if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF8 )
GregCr 0:e5420f1a8a1a 1238 {
GregCr 0:e5420f1a8a1a 1239 LowDatarateOptimize = 1;
GregCr 0:e5420f1a8a1a 1240 }
GregCr 0:e5420f1a8a1a 1241 break;
GregCr 0:e5420f1a8a1a 1242
GregCr 0:e5420f1a8a1a 1243 case LORA_BW_010:
GregCr 0:e5420f1a8a1a 1244 case LORA_BW_007:
GregCr 0:e5420f1a8a1a 1245 if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF7 )
GregCr 0:e5420f1a8a1a 1246 {
GregCr 0:e5420f1a8a1a 1247 LowDatarateOptimize = 1;
GregCr 0:e5420f1a8a1a 1248 }
GregCr 0:e5420f1a8a1a 1249 break;
GregCr 0:e5420f1a8a1a 1250 }
GregCr 0:e5420f1a8a1a 1251
GregCr 0:e5420f1a8a1a 1252 float nData = ceil( ( float )( ( 8 * Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength + \
GregCr 0:e5420f1a8a1a 1253 16 * ( ( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode == LORA_CRC_OFF ) ? 0 : 1 ) + \
GregCr 0:e5420f1a8a1a 1254 ( ( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType == LORA_PACKET_VARIABLE_LENGTH ) ? 20 : 0 ) - \
GregCr 0:e5420f1a8a1a 1255 ( 4 * Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ) + 8 - \
GregCr 0:e5420f1a8a1a 1256 ( 8 *( ( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor > 6 ) ? 1 : 0 ) ) ) / 4 ) );
GregCr 0:e5420f1a8a1a 1257
GregCr 0:e5420f1a8a1a 1258 nData = ceil( ( float )nData / ( ( float )( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor - \
GregCr 0:e5420f1a8a1a 1259 ( LowDatarateOptimize * 2 ) ) ) * ( ( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate % 4 ) + 4 ) );
GregCr 0:e5420f1a8a1a 1260
GregCr 0:e5420f1a8a1a 1261 float tPayload = nData * ts;
GregCr 0:e5420f1a8a1a 1262
GregCr 0:e5420f1a8a1a 1263 float tHeader = 8 * ts;
GregCr 0:e5420f1a8a1a 1264 // Time on air [ms]
GregCr 0:e5420f1a8a1a 1265 float ToA = ceil( tPreamble + tPayload + tHeader );
GregCr 0:e5420f1a8a1a 1266
GregCr 0:e5420f1a8a1a 1267 result = ( uint16_t )ToA + ( ( uint16_t )ToA >> 1 ); // Set some margin
GregCr 0:e5420f1a8a1a 1268 }
GregCr 0:e5420f1a8a1a 1269 else if( modulation == PACKET_TYPE_GFSK )
GregCr 0:e5420f1a8a1a 1270 {
GregCr 0:e5420f1a8a1a 1271 uint16_t packetBitCount = Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength;
GregCr 0:e5420f1a8a1a 1272
GregCr 0:e5420f1a8a1a 1273 packetBitCount += ( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength + 1 );
GregCr 0:e5420f1a8a1a 1274 packetBitCount += Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength + 3;
GregCr 0:e5420f1a8a1a 1275 packetBitCount *= 8;
GregCr 0:e5420f1a8a1a 1276 // 1500 = 1000 * 1.5 : 1000 for translate s in ms and 1.5 is some margin
GregCr 0:e5420f1a8a1a 1277 result = ( uint16_t )( ceil( 1500 * ( float )packetBitCount / Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ) );
GregCr 0:e5420f1a8a1a 1278 }
GregCr 0:e5420f1a8a1a 1279 return result;
GregCr 0:e5420f1a8a1a 1280 }
GregCr 0:e5420f1a8a1a 1281
GregCr 0:e5420f1a8a1a 1282 void InitializeDemoParameters( uint8_t modulation )
GregCr 0:e5420f1a8a1a 1283 {
GregCr 0:e5420f1a8a1a 1284 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 1285
GregCr 0:e5420f1a8a1a 1286 Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
GregCr 0:e5420f1a8a1a 1287
GregCr 0:e5420f1a8a1a 1288 printf("> InitializeDemoParameters\n\r");
GregCr 0:e5420f1a8a1a 1289 if( modulation == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 1290 {
GregCr 0:e5420f1a8a1a 1291 printf("set param LORA for demo\n\r");
GregCr 0:e5420f1a8a1a 1292 ModulationParams.PacketType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 1293 PacketParams.PacketType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 1294
GregCr 0:e5420f1a8a1a 1295 ModulationParams.Params.LoRa.SpreadingFactor = ( RadioLoRaSpreadingFactors_t ) Eeprom.EepromData.DemoSettings.ModulationParam1;
GregCr 0:e5420f1a8a1a 1296 ModulationParams.Params.LoRa.Bandwidth = ( RadioLoRaBandwidths_t ) Eeprom.EepromData.DemoSettings.ModulationParam2;
GregCr 0:e5420f1a8a1a 1297 ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
GregCr 0:e5420f1a8a1a 1298
GregCr 0:e5420f1a8a1a 1299 PacketParams.Params.LoRa.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
GregCr 0:e5420f1a8a1a 1300 PacketParams.Params.LoRa.HeaderType = ( RadioLoRaPacketLengthsMode_t )Eeprom.EepromData.DemoSettings.PacketParam2;
GregCr 0:e5420f1a8a1a 1301 PacketParams.Params.LoRa.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam3;
GregCr 0:e5420f1a8a1a 1302 PacketParams.Params.LoRa.CrcMode = ( RadioLoRaCrcModes_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
GregCr 0:e5420f1a8a1a 1303 PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5;
GregCr 0:e5420f1a8a1a 1304
GregCr 0:e5420f1a8a1a 1305 Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.LoRa.PayloadLength;
GregCr 0:e5420f1a8a1a 1306 }
GregCr 0:e5420f1a8a1a 1307 else// if( modulation == PACKET_TYPE_GFSK )
GregCr 0:e5420f1a8a1a 1308 {
GregCr 0:e5420f1a8a1a 1309 printf("set param GFSK for demo\n\r");
GregCr 0:e5420f1a8a1a 1310 ModulationParams.PacketType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 1311 PacketParams.PacketType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 1312
GregCr 0:e5420f1a8a1a 1313 ModulationParams.Params.Gfsk.BitRate = Eeprom.EepromData.DemoSettings.ModulationParam1;
GregCr 0:e5420f1a8a1a 1314 ModulationParams.Params.Gfsk.Fdev = Eeprom.EepromData.DemoSettings.ModulationParam2;
GregCr 0:e5420f1a8a1a 1315 ModulationParams.Params.Gfsk.ModulationShaping = ( RadioModShapings_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
GregCr 0:e5420f1a8a1a 1316 ModulationParams.Params.Gfsk.Bandwidth = ( RadioRxBandwidth_t ) Eeprom.EepromData.DemoSettings.ModulationParam4;
GregCr 0:e5420f1a8a1a 1317 PacketParams.Params.Gfsk.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
GregCr 0:e5420f1a8a1a 1318 PacketParams.Params.Gfsk.PreambleMinDetect = ( RadioPreambleDetection_t )Eeprom.EepromData.DemoSettings.PacketParam2;
GregCr 0:e5420f1a8a1a 1319 PacketParams.Params.Gfsk.SyncWordLength = Eeprom.EepromData.DemoSettings.PacketParam3;
GregCr 0:e5420f1a8a1a 1320 PacketParams.Params.Gfsk.AddrComp = ( RadioAddressComp_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
GregCr 0:e5420f1a8a1a 1321 PacketParams.Params.Gfsk.HeaderType = ( RadioPacketLengthModes_t )Eeprom.EepromData.DemoSettings.PacketParam5;
GregCr 0:e5420f1a8a1a 1322 PacketParams.Params.Gfsk.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam6;
GregCr 0:e5420f1a8a1a 1323
GregCr 0:e5420f1a8a1a 1324 PacketParams.Params.Gfsk.CrcLength = ( RadioCrcTypes_t ) Eeprom.EepromData.DemoSettings.PacketParam7;
GregCr 0:e5420f1a8a1a 1325 PacketParams.Params.Gfsk.DcFree = ( RadioDcFree_t ) Eeprom.EepromData.DemoSettings.PacketParam8;
GregCr 0:e5420f1a8a1a 1326
GregCr 0:e5420f1a8a1a 1327 Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.Gfsk.PayloadLength;
GregCr 0:e5420f1a8a1a 1328 }
GregCr 0:e5420f1a8a1a 1329
GregCr 0:e5420f1a8a1a 1330 Radio.SetStandby( STDBY_RC );
GregCr 0:e5420f1a8a1a 1331 Radio.ClearIrqStatus( IRQ_RADIO_ALL );
GregCr 0:e5420f1a8a1a 1332 Radio.SetPacketType( ModulationParams.PacketType );
GregCr 0:e5420f1a8a1a 1333 Radio.SetModulationParams( &ModulationParams );
GregCr 0:e5420f1a8a1a 1334 Radio.SetPacketParams( &PacketParams );
GregCr 0:e5420f1a8a1a 1335
GregCr 0:e5420f1a8a1a 1336 Radio.SetRfFrequency( Eeprom.EepromData.DemoSettings.Frequency );
GregCr 0:e5420f1a8a1a 1337 Radio.SetBufferBaseAddresses( 0x00, 0x00 );
GregCr 0:e5420f1a8a1a 1338
GregCr 0:e5420f1a8a1a 1339
GregCr 0:e5420f1a8a1a 1340 Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_40_US );
GregCr 0:e5420f1a8a1a 1341
GregCr 0:e5420f1a8a1a 1342 // only used in GFSK
GregCr 0:e5420f1a8a1a 1343 Radio.SetSyncWord( ( uint8_t[] ){ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 } );
GregCr 0:e5420f1a8a1a 1344 Radio.SetWhiteningSeed( 0x01FF );
GregCr 0:e5420f1a8a1a 1345
GregCr 0:e5420f1a8a1a 1346 RX_LED = 0;
GregCr 0:e5420f1a8a1a 1347 TX_LED = 0;
GregCr 0:e5420f1a8a1a 1348 }
GregCr 0:e5420f1a8a1a 1349
GregCr 0:e5420f1a8a1a 1350 /*!
GregCr 0:e5420f1a8a1a 1351 * \brief Callback of ticker PerSendNextPacket
GregCr 0:e5420f1a8a1a 1352 */
GregCr 0:e5420f1a8a1a 1353 void SendNextPacketEvent( void )
GregCr 0:e5420f1a8a1a 1354 {
GregCr 0:e5420f1a8a1a 1355 SendNext = true;
GregCr 0:e5420f1a8a1a 1356 }
GregCr 0:e5420f1a8a1a 1357
GregCr 0:e5420f1a8a1a 1358 void LedBlink( void )
GregCr 0:e5420f1a8a1a 1359 {
GregCr 0:e5420f1a8a1a 1360 if( ( TX_LED == 0 ) && ( RX_LED == 0 ) )
GregCr 0:e5420f1a8a1a 1361 {
GregCr 0:e5420f1a8a1a 1362 TX_LED = 1;
GregCr 0:e5420f1a8a1a 1363 }
GregCr 0:e5420f1a8a1a 1364 else if( ( TX_LED == 1 ) && ( RX_LED == 0 ) )
GregCr 0:e5420f1a8a1a 1365 {
GregCr 0:e5420f1a8a1a 1366 RX_LED = 1;
GregCr 0:e5420f1a8a1a 1367 }
GregCr 0:e5420f1a8a1a 1368 else if( ( TX_LED == 1 ) && ( RX_LED == 1 ) )
GregCr 0:e5420f1a8a1a 1369 {
GregCr 0:e5420f1a8a1a 1370 TX_LED = 0;
GregCr 0:e5420f1a8a1a 1371 }
GregCr 0:e5420f1a8a1a 1372 else
GregCr 0:e5420f1a8a1a 1373 {
GregCr 0:e5420f1a8a1a 1374 RX_LED = 0;
GregCr 0:e5420f1a8a1a 1375 }
GregCr 0:e5420f1a8a1a 1376 }
GregCr 0:e5420f1a8a1a 1377
GregCr 0:e5420f1a8a1a 1378 // ************************ Radio Callbacks ****************************
GregCr 0:e5420f1a8a1a 1379 // * *
GregCr 0:e5420f1a8a1a 1380 // * These functions are called through function pointer by the Radio low *
GregCr 0:e5420f1a8a1a 1381 // * level drivers *
GregCr 0:e5420f1a8a1a 1382 // * *
GregCr 0:e5420f1a8a1a 1383 // *****************************************************************************
GregCr 0:e5420f1a8a1a 1384 void OnTxDone( void )
GregCr 0:e5420f1a8a1a 1385 {
GregCr 0:e5420f1a8a1a 1386 DemoInternalState = APP_TX;
GregCr 0:e5420f1a8a1a 1387 }
GregCr 0:e5420f1a8a1a 1388
GregCr 0:e5420f1a8a1a 1389 void OnRxDone( void )
GregCr 0:e5420f1a8a1a 1390 {
GregCr 0:e5420f1a8a1a 1391 DemoInternalState = APP_RX;
GregCr 0:e5420f1a8a1a 1392 }
GregCr 0:e5420f1a8a1a 1393
GregCr 0:e5420f1a8a1a 1394 void OnTxTimeout( void )
GregCr 0:e5420f1a8a1a 1395 {
GregCr 0:e5420f1a8a1a 1396 DemoInternalState = APP_TX_TIMEOUT;
GregCr 0:e5420f1a8a1a 1397 }
GregCr 0:e5420f1a8a1a 1398
GregCr 0:e5420f1a8a1a 1399 void OnRxTimeout( void )
GregCr 0:e5420f1a8a1a 1400 {
GregCr 0:e5420f1a8a1a 1401 DemoInternalState = APP_RX_TIMEOUT;
GregCr 0:e5420f1a8a1a 1402 }
GregCr 0:e5420f1a8a1a 1403
GregCr 0:e5420f1a8a1a 1404 void OnRxError( IrqErrorCode_t errorCode )
GregCr 0:e5420f1a8a1a 1405 {
GregCr 0:e5420f1a8a1a 1406 DemoInternalState = APP_RX_ERROR;
GregCr 0:e5420f1a8a1a 1407
GregCr 0:e5420f1a8a1a 1408 if( errorCode == IRQ_HEADER_ERROR_CODE )
GregCr 0:e5420f1a8a1a 1409 {
GregCr 0:e5420f1a8a1a 1410 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 1411 printf( ">> IRQ_HEADER_ERROR_CODE\n\r" );
GregCr 0:e5420f1a8a1a 1412 #endif
GregCr 0:e5420f1a8a1a 1413 }
GregCr 0:e5420f1a8a1a 1414 else if( errorCode == IRQ_SYNCWORD_ERROR_CODE )
GregCr 0:e5420f1a8a1a 1415 {
GregCr 0:e5420f1a8a1a 1416 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 1417 printf( ">> IRQ_SYNCWORD_ERROR_CODE\n\r" );
GregCr 0:e5420f1a8a1a 1418 #endif
GregCr 0:e5420f1a8a1a 1419 }
GregCr 0:e5420f1a8a1a 1420 else if( errorCode == IRQ_CRC_ERROR_CODE )
GregCr 0:e5420f1a8a1a 1421 {
GregCr 0:e5420f1a8a1a 1422 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 1423 printf( ">> IRQ_CRC_ERROR_CODE\n\r" );
GregCr 0:e5420f1a8a1a 1424 #endif
GregCr 0:e5420f1a8a1a 1425 }
GregCr 0:e5420f1a8a1a 1426 else
GregCr 0:e5420f1a8a1a 1427 {
GregCr 0:e5420f1a8a1a 1428 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 1429 printf( "unknown error\n\r" );
GregCr 0:e5420f1a8a1a 1430 #endif
GregCr 0:e5420f1a8a1a 1431 }
GregCr 0:e5420f1a8a1a 1432 Radio.GetPacketStatus( &PacketStatus );
GregCr 0:e5420f1a8a1a 1433 }
GregCr 0:e5420f1a8a1a 1434
GregCr 0:e5420f1a8a1a 1435 void OnCadDone( bool channelActivityDetected )
GregCr 0:e5420f1a8a1a 1436 {
GregCr 0:e5420f1a8a1a 1437 if( channelActivityDetected == true )
GregCr 0:e5420f1a8a1a 1438 {
GregCr 0:e5420f1a8a1a 1439 DemoInternalState = CAD_DONE_CHANNEL_DETECTED;
GregCr 0:e5420f1a8a1a 1440 }
GregCr 0:e5420f1a8a1a 1441 else
GregCr 0:e5420f1a8a1a 1442 {
GregCr 0:e5420f1a8a1a 1443 DemoInternalState = CAD_DONE;
GregCr 0:e5420f1a8a1a 1444 }
GregCr 0:e5420f1a8a1a 1445 }