This code holds the complete demo set for the sx1280: PingPong, PER and Ranging Outdoor demo application. >>>>> This code MUST run on the mbed library release 127 or everything will be painfully slow.

Dependencies:   mbed SX1280Lib DmTftLibrary

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DemoApplication.h Source File

DemoApplication.h

00001 /*
00002   ______                              _
00003  / _____)             _              | |
00004 ( (____  _____ ____ _| |_ _____  ____| |__
00005  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00006  _____) ) ____| | | || |_| ____( (___| | | |
00007 (______/|_____)_|_|_| \__)_____)\____)_| |_|
00008     (C)2016 Semtech
00009 
00010 Description: Display driver header
00011 
00012 Maintainer: Gregory Cristian & Gilbert Menth
00013 */
00014 
00015 #ifndef DEMO_APPLICATION_H
00016 #define DEMO_APPLICATION_H
00017 
00018 
00019 /*!
00020  * \brief Used to display firmware version on TFT (Utilities menu)
00021  */
00022 #define FIRMWARE_VERSION    ( ( char* )"v1.5.2" )
00023 #define FIRMWARE_DATE       ( ( char* )"2018-10-15" )
00024 
00025 /*!
00026  * \brief Define range of central frequency [Hz]
00027  */
00028 #define DEMO_CENTRAL_FREQ_MIN       2400000000UL
00029 #define DEMO_CENTRAL_FREQ_MAX       2483500000UL
00030 
00031 /*!
00032  * \brief Define 3 preset central frequencies [Hz]
00033  */
00034 #define DEMO_CENTRAL_FREQ_PRESET1   2402000000UL
00035 #define DEMO_CENTRAL_FREQ_PRESET2   2450000000UL
00036 #define DEMO_CENTRAL_FREQ_PRESET3   2480000000UL
00037 
00038 /*!
00039  * \brief Define 5 preset ranging addresses
00040  */
00041 #define DEMO_RNG_ADDR_1             0x10000000
00042 #define DEMO_RNG_ADDR_2             0x32100000
00043 #define DEMO_RNG_ADDR_3             0x20012301
00044 #define DEMO_RNG_ADDR_4             0x20000abc
00045 #define DEMO_RNG_ADDR_5             0x32101230
00046 
00047 /*!
00048  * \brief Define antenna selection for ranging
00049  */
00050 #define DEMO_RNG_ANT_1              1
00051 #define DEMO_RNG_ANT_0              2
00052 #define DEMO_RNG_ANT_BOTH           0
00053 
00054 /*!
00055  * \brief Define units for ranging distances
00056  */
00057 #define DEMO_RNG_UNIT_CONV_M        1.0 // not used
00058 #define DEMO_RNG_UNIT_CONV_YD       1.0936
00059 #define DEMO_RNG_UNIT_CONV_MI       6.2137e-4
00060 #define DEMO_RNG_UNIT_SEL_M         0
00061 #define DEMO_RNG_UNIT_SEL_YD        1
00062 #define DEMO_RNG_UNIT_SEL_MI        2
00063 
00064 /*!
00065  * \brief Define min and max Tx power [dBm]
00066  */
00067 #define DEMO_POWER_TX_MIN           -18
00068 #define DEMO_POWER_TX_MAX           13
00069 
00070 /*!
00071  * \brief Define min and max ranging channels count
00072  */
00073 const uint16_t DEMO_RNG_CHANNELS_COUNT_MAX = 255;
00074 const uint16_t DEMO_RNG_CHANNELS_COUNT_MIN = 10;
00075 
00076 /*!
00077  * \brief Define min and max Z Score for ranging filtered results
00078  */
00079 #define DEMO_RNG_ZSCORE_MIN         1
00080 #define DEMO_RNG_ZSCORE_MAX         5
00081 
00082 /*!
00083  * \brief Define min and max payload length for demo applications
00084  */
00085 #define DEMO_MIN_PAYLOAD            12
00086 #define DEMO_FLRC_MAX_PAYLOAD       127
00087 #define DEMO_GFS_LORA_MAX_PAYLOAD   255
00088 
00089 
00090 /*!
00091  * \brief Define current demo mode
00092  */
00093 enum DemoMode
00094 {
00095     MASTER = 0,
00096     SLAVE
00097 };
00098 
00099 /*!
00100  * \brief Status of ranging distance
00101  */
00102 enum RangingStatus
00103 {
00104     RNG_INIT = 0,
00105     RNG_PROCESS,
00106     RNG_VALID,
00107     RNG_TIMEOUT,
00108     RNG_PER_ERROR
00109 };
00110 
00111 /*!
00112  * \brief List of states for demo state machine
00113  */
00114 enum DemoInternalStates
00115 {
00116     APP_IDLE = 0,               // nothing to do (or wait a radio interrupt)
00117     APP_RANGING_DONE,
00118     APP_RANGING_TIMEOUT,
00119     APP_RANGING_CONFIG,
00120     APP_RNG,
00121     SEND_PING_MSG,
00122     SEND_PONG_MSG,
00123     APP_RX,                     // Rx done
00124     APP_RX_TIMEOUT,             // Rx timeout
00125     APP_RX_ERROR,               // Rx error
00126     APP_TX,                     // Tx done
00127     APP_TX_TIMEOUT,             // Tx error
00128     PER_TX_START,               // PER master
00129     PER_RX_START                // PER slave
00130 };
00131 
00132 /*!
00133  * \brief Demo Settings structure of Eeprom structure
00134  */
00135 typedef struct
00136 {
00137     uint8_t Entity;              // Master or Slave
00138     uint8_t HoldDemo;            // Put demo in hold status
00139     uint8_t AntennaSwitch;       // Witch antenna connected
00140     uint32_t Frequency;          // Demo frequency
00141     int8_t TxPower;              // Demo Tx power
00142     uint8_t RadioPowerMode;      // Radio Power Mode [0: LDO, 1:DC_DC]
00143     uint8_t PayloadLength;       // Demo payload length
00144     uint8_t ModulationType;      // Demo modulation type (LORA, GFSK, FLRC)
00145     uint8_t ModulationParam1;    // Demo Mod. Param1 (depend on modulation type)
00146     uint8_t ModulationParam2;    // Demo Mod. Param2 (depend on modulation type)
00147     uint8_t ModulationParam3;    // Demo Mod. Param3 (depend on modulation type)
00148     uint8_t PacketParam1;        // Demo Pack. Param1 (depend on packet type)
00149     uint8_t PacketParam2;        // Demo Pack. Param2 (depend on packet type)
00150     uint8_t PacketParam3;        // Demo Pack. Param3 (depend on packet type)
00151     uint8_t PacketParam4;        // Demo Pack. Param4 (depend on packet type)
00152     uint8_t PacketParam5;        // Demo Pack. Param5 (depend on packet type)
00153     uint8_t PacketParam6;        // Demo Pack. Param6 (depend on packet type)
00154     uint8_t PacketParam7;        // Demo Pack. Param7 (depend on packet type)
00155     uint32_t MaxNumPacket;       // Demo Max Num Packet for PingPong and PER
00156     uint16_t TimeOnAir;          // Computed time on air of the current packet
00157     uint32_t CntPacketTx;        // Tx packet transmitted
00158     uint32_t CntPacketRxOK;      // Rx packet received OK
00159     uint32_t CntPacketRxOKSlave; // Rx packet received OK (slave side)
00160     uint32_t CntPacketRxKO;      // Rx packet received KO
00161     uint32_t CntPacketRxKOSlave; // Rx packet received KO (slave side)
00162     uint16_t RxTimeOutCount;     // Rx packet received KO (by timeout)
00163     double RngDistance;          // Distance measured by ranging demo
00164     double RngRawDistance;       // Uncorrected measured distance [m]
00165     uint32_t RngAddress;         // Ranging Address
00166     uint16_t RngFullScale;       // Full range of measuring distance (Ranging)
00167     uint8_t RngRequestCount;     // Ranging Request Count
00168     uint8_t RngUnit;             // Ranging distance unit [m]/[mi]
00169     uint8_t RngStatus;           // Status of ranging distance
00170     double RngFei;               // Ranging Frequency Error Indicator
00171     uint8_t RngAntenna;          // Ranging antenna selection
00172     double RngFeiFactor;         // Ranging frequency correction factor
00173     uint16_t RngReqDelay;        // Time between ranging request
00174     uint16_t RngCalib;           // Ranging Calibration
00175     uint8_t RFU;                 // -------------------------
00176     int8_t RssiValue;            // Demo Rssi Value
00177     int8_t SnrValue;             // Demo Snr Value (only for LORA mod. type)
00178 }DemoSettings_t;
00179 
00180 /*!
00181  * \brief Define freq offset for config central freq in "Radio Config Freq" menu
00182  */
00183 enum FreqBase
00184 {
00185     FB1     = 1,            //   1 Hz
00186     FB10    = 10,           //  10 Hz
00187     FB100   = 100,          // 100 Hz
00188     FB1K    = 1000,         //   1 kHz
00189     FB10K   = 10000,        //  10 kHz
00190     FB100K  = 100000,       // 100 kHz
00191     FB1M    = 1000000,      //   1 MHz
00192     FB10M   = 10000000      //  10 MHz
00193 };
00194 
00195 
00196 /*!
00197  * \brief Init RAM copy of Eeprom structure and init radio with it.
00198  */
00199 void InitDemoApplication( void );
00200 
00201 /*!
00202  * \brief Init vars of demo and fix APP_IDLE state to demo state machine.
00203  */
00204 void StopDemoApplication( void );
00205 
00206 /*!
00207  * \brief Run Demo in sleep mode.
00208  *
00209  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00210  */
00211 uint8_t RunDemoSleepMode( void );
00212 
00213 /*!
00214  * \brief Run Demo in standby RC mode.
00215  *
00216  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00217  */
00218 uint8_t RunDemoStandbyRcMode( void );
00219 
00220 /*!
00221  * \brief Run Demo in standby XOSC mode.
00222  *
00223  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00224  */
00225 uint8_t RunDemoStandbyXoscMode( void );
00226 
00227 /*!
00228  * \brief Run Demo Tx in continuous mode without modulation.
00229  *
00230  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00231  */
00232 uint8_t RunDemoTxCw( void );
00233 
00234 /*!
00235  * \brief Run Demo Tx in continuous modulation.
00236  *
00237  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00238  */
00239 uint8_t RunDemoTxContinuousModulation( void );
00240 
00241 /*!
00242  * \brief Run demo PingPong.
00243  *
00244  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00245  */
00246 uint8_t RunDemoApplicationPingPong( void );
00247 
00248 /*!
00249  * \brief Compute payload of Rx frame and update current counts and indicators.
00250  *
00251  * \param [in]  buffer        buffer with frame to compute
00252  * \param [in]  buffersize    size of frame data in the buffer
00253  */
00254 void ComputePingPongPayload( uint8_t *buffer, uint8_t bufferSize );
00255 
00256 /*!
00257  * \brief Run demo PER.
00258  *
00259  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00260  */
00261 uint8_t RunDemoApplicationPer( void );
00262 
00263 /*!
00264  * \brief Compute payload of Rx frame and update current counts and indicators.
00265  *
00266  * \param [in]  buffer        buffer with frame to compute
00267  * \param [in]  buffersize    size of frame data in the buffer
00268  */
00269 void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize );
00270 
00271 /*!
00272  * \brief Run ranging demo.
00273  *
00274  * \retval      demoStatusUpdate    page refresh status ( >0 : refresh)
00275  */
00276 uint8_t RunDemoApplicationRanging( void );
00277 
00278 #endif // DEMO_APPLICATION_H