This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.
Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by
This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.
How to install
- Create an account on Mbed: https://os.mbed.com/account/signup/
- Import project into Compiler
- In the Program Workspace select "Formula_Nucleo_Reader"
- Select a Platform like so:
- Click button at top-left
- Add Board
- Search "B-L072Z-LRWAN1" and then "Add to your Mbed Compiler"
- Finally click "Compile", if the build was successful, the binary would download automatically
- To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it
SX1276GenericLib/radio/radio.h@12:02d779e8c4f6, 2018-05-19 (annotated)
- Committer:
- wardm
- Date:
- Sat May 19 11:41:10 2018 +0000
- Revision:
- 12:02d779e8c4f6
Code for Technion Formula car sensors reader transmit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wardm | 12:02d779e8c4f6 | 1 | /* |
wardm | 12:02d779e8c4f6 | 2 | / _____) _ | | |
wardm | 12:02d779e8c4f6 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
wardm | 12:02d779e8c4f6 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
wardm | 12:02d779e8c4f6 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
wardm | 12:02d779e8c4f6 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
wardm | 12:02d779e8c4f6 | 7 | (C) 2014 Semtech |
wardm | 12:02d779e8c4f6 | 8 | |
wardm | 12:02d779e8c4f6 | 9 | Description: Interface for the radios, contains the main functions that a radio needs, and 5 callback functions |
wardm | 12:02d779e8c4f6 | 10 | |
wardm | 12:02d779e8c4f6 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
wardm | 12:02d779e8c4f6 | 12 | |
wardm | 12:02d779e8c4f6 | 13 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
wardm | 12:02d779e8c4f6 | 14 | */ |
wardm | 12:02d779e8c4f6 | 15 | #ifndef __RADIO_H__ |
wardm | 12:02d779e8c4f6 | 16 | #define __RADIO_H__ |
wardm | 12:02d779e8c4f6 | 17 | |
wardm | 12:02d779e8c4f6 | 18 | #ifdef __MBED__ |
wardm | 12:02d779e8c4f6 | 19 | #include "mbed.h" |
wardm | 12:02d779e8c4f6 | 20 | #endif |
wardm | 12:02d779e8c4f6 | 21 | #ifdef ARDUINO |
wardm | 12:02d779e8c4f6 | 22 | #include <arduino.h> |
wardm | 12:02d779e8c4f6 | 23 | #endif |
wardm | 12:02d779e8c4f6 | 24 | |
wardm | 12:02d779e8c4f6 | 25 | /*! |
wardm | 12:02d779e8c4f6 | 26 | * Radio driver internal state machine states definition |
wardm | 12:02d779e8c4f6 | 27 | */ |
wardm | 12:02d779e8c4f6 | 28 | typedef enum RadioState |
wardm | 12:02d779e8c4f6 | 29 | { |
wardm | 12:02d779e8c4f6 | 30 | RF_IDLE = 0, |
wardm | 12:02d779e8c4f6 | 31 | RF_RX_RUNNING, |
wardm | 12:02d779e8c4f6 | 32 | RF_TX_RUNNING, |
wardm | 12:02d779e8c4f6 | 33 | RF_CAD, |
wardm | 12:02d779e8c4f6 | 34 | } RadioState_t; |
wardm | 12:02d779e8c4f6 | 35 | |
wardm | 12:02d779e8c4f6 | 36 | |
wardm | 12:02d779e8c4f6 | 37 | /*! |
wardm | 12:02d779e8c4f6 | 38 | * Type of the modem. [LORA / FSK] |
wardm | 12:02d779e8c4f6 | 39 | */ |
wardm | 12:02d779e8c4f6 | 40 | typedef enum ModemType |
wardm | 12:02d779e8c4f6 | 41 | { |
wardm | 12:02d779e8c4f6 | 42 | MODEM_FSK = 0, |
wardm | 12:02d779e8c4f6 | 43 | MODEM_LORA |
wardm | 12:02d779e8c4f6 | 44 | }RadioModems_t; |
wardm | 12:02d779e8c4f6 | 45 | |
wardm | 12:02d779e8c4f6 | 46 | |
wardm | 12:02d779e8c4f6 | 47 | /*! |
wardm | 12:02d779e8c4f6 | 48 | * Radio LoRa modem parameters |
wardm | 12:02d779e8c4f6 | 49 | */ |
wardm | 12:02d779e8c4f6 | 50 | typedef struct |
wardm | 12:02d779e8c4f6 | 51 | { |
wardm | 12:02d779e8c4f6 | 52 | int8_t Power; |
wardm | 12:02d779e8c4f6 | 53 | uint32_t Bandwidth; |
wardm | 12:02d779e8c4f6 | 54 | uint32_t Datarate; |
wardm | 12:02d779e8c4f6 | 55 | bool LowDatarateOptimize; |
wardm | 12:02d779e8c4f6 | 56 | uint8_t Coderate; |
wardm | 12:02d779e8c4f6 | 57 | uint16_t PreambleLen; |
wardm | 12:02d779e8c4f6 | 58 | bool FixLen; |
wardm | 12:02d779e8c4f6 | 59 | uint8_t PayloadLen; |
wardm | 12:02d779e8c4f6 | 60 | bool CrcOn; |
wardm | 12:02d779e8c4f6 | 61 | bool FreqHopOn; |
wardm | 12:02d779e8c4f6 | 62 | uint8_t HopPeriod; |
wardm | 12:02d779e8c4f6 | 63 | bool IqInverted; |
wardm | 12:02d779e8c4f6 | 64 | bool RxContinuous; |
wardm | 12:02d779e8c4f6 | 65 | uint32_t TxTimeout; |
wardm | 12:02d779e8c4f6 | 66 | bool PublicNetwork; |
wardm | 12:02d779e8c4f6 | 67 | }RadioLoRaSettings_t; |
wardm | 12:02d779e8c4f6 | 68 | |
wardm | 12:02d779e8c4f6 | 69 | /*! |
wardm | 12:02d779e8c4f6 | 70 | * Radio FSK modem parameters |
wardm | 12:02d779e8c4f6 | 71 | */ |
wardm | 12:02d779e8c4f6 | 72 | typedef struct |
wardm | 12:02d779e8c4f6 | 73 | { |
wardm | 12:02d779e8c4f6 | 74 | int8_t Power; |
wardm | 12:02d779e8c4f6 | 75 | uint32_t Fdev; |
wardm | 12:02d779e8c4f6 | 76 | uint32_t Bandwidth; |
wardm | 12:02d779e8c4f6 | 77 | uint32_t BandwidthAfc; |
wardm | 12:02d779e8c4f6 | 78 | uint32_t Datarate; |
wardm | 12:02d779e8c4f6 | 79 | uint16_t PreambleLen; |
wardm | 12:02d779e8c4f6 | 80 | bool FixLen; |
wardm | 12:02d779e8c4f6 | 81 | uint8_t PayloadLen; |
wardm | 12:02d779e8c4f6 | 82 | bool CrcOn; |
wardm | 12:02d779e8c4f6 | 83 | bool IqInverted; |
wardm | 12:02d779e8c4f6 | 84 | bool RxContinuous; |
wardm | 12:02d779e8c4f6 | 85 | uint32_t TxTimeout; |
wardm | 12:02d779e8c4f6 | 86 | uint32_t RxSingleTimeout; |
wardm | 12:02d779e8c4f6 | 87 | }RadioFskSettings_t; |
wardm | 12:02d779e8c4f6 | 88 | |
wardm | 12:02d779e8c4f6 | 89 | /*! |
wardm | 12:02d779e8c4f6 | 90 | * Radio FSK packet handler state |
wardm | 12:02d779e8c4f6 | 91 | */ |
wardm | 12:02d779e8c4f6 | 92 | typedef struct |
wardm | 12:02d779e8c4f6 | 93 | { |
wardm | 12:02d779e8c4f6 | 94 | uint8_t PreambleDetected; |
wardm | 12:02d779e8c4f6 | 95 | uint8_t SyncWordDetected; |
wardm | 12:02d779e8c4f6 | 96 | int8_t RssiValue; |
wardm | 12:02d779e8c4f6 | 97 | int32_t AfcValue; |
wardm | 12:02d779e8c4f6 | 98 | uint8_t RxGain; |
wardm | 12:02d779e8c4f6 | 99 | uint16_t Size; |
wardm | 12:02d779e8c4f6 | 100 | uint16_t NbBytes; |
wardm | 12:02d779e8c4f6 | 101 | uint8_t FifoThresh; |
wardm | 12:02d779e8c4f6 | 102 | uint8_t ChunkSize; |
wardm | 12:02d779e8c4f6 | 103 | }RadioFskPacketHandler_t; |
wardm | 12:02d779e8c4f6 | 104 | |
wardm | 12:02d779e8c4f6 | 105 | /*! |
wardm | 12:02d779e8c4f6 | 106 | * Radio LoRa packet handler state |
wardm | 12:02d779e8c4f6 | 107 | */ |
wardm | 12:02d779e8c4f6 | 108 | typedef struct |
wardm | 12:02d779e8c4f6 | 109 | { |
wardm | 12:02d779e8c4f6 | 110 | int8_t SnrValue; |
wardm | 12:02d779e8c4f6 | 111 | int8_t RssiValue; |
wardm | 12:02d779e8c4f6 | 112 | uint8_t Size; |
wardm | 12:02d779e8c4f6 | 113 | }RadioLoRaPacketHandler_t; |
wardm | 12:02d779e8c4f6 | 114 | |
wardm | 12:02d779e8c4f6 | 115 | /*! |
wardm | 12:02d779e8c4f6 | 116 | * Radio Settings |
wardm | 12:02d779e8c4f6 | 117 | */ |
wardm | 12:02d779e8c4f6 | 118 | typedef struct |
wardm | 12:02d779e8c4f6 | 119 | { |
wardm | 12:02d779e8c4f6 | 120 | RadioState State; |
wardm | 12:02d779e8c4f6 | 121 | ModemType Modem; |
wardm | 12:02d779e8c4f6 | 122 | uint32_t Channel; |
wardm | 12:02d779e8c4f6 | 123 | RadioFskSettings_t Fsk; |
wardm | 12:02d779e8c4f6 | 124 | RadioFskPacketHandler_t FskPacketHandler; |
wardm | 12:02d779e8c4f6 | 125 | RadioLoRaSettings_t LoRa; |
wardm | 12:02d779e8c4f6 | 126 | RadioLoRaPacketHandler_t LoRaPacketHandler; |
wardm | 12:02d779e8c4f6 | 127 | }RadioSettings_t; |
wardm | 12:02d779e8c4f6 | 128 | |
wardm | 12:02d779e8c4f6 | 129 | /*! |
wardm | 12:02d779e8c4f6 | 130 | * @brief Radio driver callback functions |
wardm | 12:02d779e8c4f6 | 131 | */ |
wardm | 12:02d779e8c4f6 | 132 | typedef struct |
wardm | 12:02d779e8c4f6 | 133 | { |
wardm | 12:02d779e8c4f6 | 134 | /*! |
wardm | 12:02d779e8c4f6 | 135 | * @brief Tx Done callback prototype. |
wardm | 12:02d779e8c4f6 | 136 | */ |
wardm | 12:02d779e8c4f6 | 137 | void ( *TxDone )(void *radio, void *userThisPtr, void *userData); |
wardm | 12:02d779e8c4f6 | 138 | /*! |
wardm | 12:02d779e8c4f6 | 139 | * @brief Tx Timeout callback prototype. |
wardm | 12:02d779e8c4f6 | 140 | */ |
wardm | 12:02d779e8c4f6 | 141 | void ( *TxTimeout )(void *radio, void *userThisPtr, void *userData); |
wardm | 12:02d779e8c4f6 | 142 | /*! |
wardm | 12:02d779e8c4f6 | 143 | * @brief Rx Done callback prototype. |
wardm | 12:02d779e8c4f6 | 144 | * |
wardm | 12:02d779e8c4f6 | 145 | * @param [IN] payload Received buffer pointer |
wardm | 12:02d779e8c4f6 | 146 | * @param [IN] size Received buffer size |
wardm | 12:02d779e8c4f6 | 147 | * @param [IN] rssi RSSI value computed while receiving the frame [dBm] |
wardm | 12:02d779e8c4f6 | 148 | * @param [IN] snr Raw SNR value given by the radio hardware |
wardm | 12:02d779e8c4f6 | 149 | * FSK : N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 150 | * LoRa: SNR value in dB |
wardm | 12:02d779e8c4f6 | 151 | */ |
wardm | 12:02d779e8c4f6 | 152 | void ( *RxDone )(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); |
wardm | 12:02d779e8c4f6 | 153 | /*! |
wardm | 12:02d779e8c4f6 | 154 | * @brief Rx Timeout callback prototype. |
wardm | 12:02d779e8c4f6 | 155 | */ |
wardm | 12:02d779e8c4f6 | 156 | void ( *RxTimeout )(void *radio, void *userThisPtr, void *userData); |
wardm | 12:02d779e8c4f6 | 157 | /*! |
wardm | 12:02d779e8c4f6 | 158 | * @brief Rx Error callback prototype. |
wardm | 12:02d779e8c4f6 | 159 | */ |
wardm | 12:02d779e8c4f6 | 160 | void ( *RxError )(void *radio, void *userThisPtr, void *userData); |
wardm | 12:02d779e8c4f6 | 161 | /*! |
wardm | 12:02d779e8c4f6 | 162 | * \brief FHSS Change Channel callback prototype. |
wardm | 12:02d779e8c4f6 | 163 | * |
wardm | 12:02d779e8c4f6 | 164 | * \param [IN] currentChannel Index number of the current channel |
wardm | 12:02d779e8c4f6 | 165 | */ |
wardm | 12:02d779e8c4f6 | 166 | void ( *FhssChangeChannel )(void *radio, void *userThisPtr, void *userData, uint8_t currentChannel ); |
wardm | 12:02d779e8c4f6 | 167 | |
wardm | 12:02d779e8c4f6 | 168 | /*! |
wardm | 12:02d779e8c4f6 | 169 | * @brief CAD Done callback prototype. |
wardm | 12:02d779e8c4f6 | 170 | * |
wardm | 12:02d779e8c4f6 | 171 | * @param [IN] channelDetected Channel Activity detected during the CAD |
wardm | 12:02d779e8c4f6 | 172 | */ |
wardm | 12:02d779e8c4f6 | 173 | void ( *CadDone ) (void *radio, void *userThisPtr, void *userData, bool channelActivityDetected ); |
wardm | 12:02d779e8c4f6 | 174 | |
wardm | 12:02d779e8c4f6 | 175 | /* |
wardm | 12:02d779e8c4f6 | 176 | * Optional data which is being provided in callbacks |
wardm | 12:02d779e8c4f6 | 177 | * can be used e.g. for the C++ this pointer. |
wardm | 12:02d779e8c4f6 | 178 | */ |
wardm | 12:02d779e8c4f6 | 179 | void *userThisPtr; |
wardm | 12:02d779e8c4f6 | 180 | |
wardm | 12:02d779e8c4f6 | 181 | /* |
wardm | 12:02d779e8c4f6 | 182 | * Optional data which allows to bring in data structures pointer |
wardm | 12:02d779e8c4f6 | 183 | * for a given radio. As callbacks are being called in interrupt level |
wardm | 12:02d779e8c4f6 | 184 | * the userData is perfect to know the context without iterating this |
wardm | 12:02d779e8c4f6 | 185 | * data structures. |
wardm | 12:02d779e8c4f6 | 186 | */ |
wardm | 12:02d779e8c4f6 | 187 | void *userData; |
wardm | 12:02d779e8c4f6 | 188 | |
wardm | 12:02d779e8c4f6 | 189 | }RadioEvents_t; |
wardm | 12:02d779e8c4f6 | 190 | |
wardm | 12:02d779e8c4f6 | 191 | /*! |
wardm | 12:02d779e8c4f6 | 192 | * Interface for the radios, contains the main functions that a radio needs, and 5 callback functions |
wardm | 12:02d779e8c4f6 | 193 | */ |
wardm | 12:02d779e8c4f6 | 194 | class Radio |
wardm | 12:02d779e8c4f6 | 195 | { |
wardm | 12:02d779e8c4f6 | 196 | protected: |
wardm | 12:02d779e8c4f6 | 197 | RadioEvents_t* RadioEvents; |
wardm | 12:02d779e8c4f6 | 198 | |
wardm | 12:02d779e8c4f6 | 199 | public: |
wardm | 12:02d779e8c4f6 | 200 | //------------------------------------------------------------------------- |
wardm | 12:02d779e8c4f6 | 201 | // Constructor |
wardm | 12:02d779e8c4f6 | 202 | //------------------------------------------------------------------------- |
wardm | 12:02d779e8c4f6 | 203 | /*! |
wardm | 12:02d779e8c4f6 | 204 | * @brief Constructor of the radio object, the parameters are the callback functions described in the header. |
wardm | 12:02d779e8c4f6 | 205 | * |
wardm | 12:02d779e8c4f6 | 206 | * @param [IN] events Structure containing the driver callback functions |
wardm | 12:02d779e8c4f6 | 207 | */ |
wardm | 12:02d779e8c4f6 | 208 | Radio( RadioEvents_t *events ); |
wardm | 12:02d779e8c4f6 | 209 | virtual ~Radio( ) {}; |
wardm | 12:02d779e8c4f6 | 210 | |
wardm | 12:02d779e8c4f6 | 211 | //------------------------------------------------------------------------- |
wardm | 12:02d779e8c4f6 | 212 | // Pure virtual functions |
wardm | 12:02d779e8c4f6 | 213 | //------------------------------------------------------------------------- |
wardm | 12:02d779e8c4f6 | 214 | |
wardm | 12:02d779e8c4f6 | 215 | /*! |
wardm | 12:02d779e8c4f6 | 216 | * @brief Initializes the radio |
wardm | 12:02d779e8c4f6 | 217 | * |
wardm | 12:02d779e8c4f6 | 218 | * @param [IN] events Structure containing the driver callback functions |
wardm | 12:02d779e8c4f6 | 219 | */ |
wardm | 12:02d779e8c4f6 | 220 | virtual bool Init( RadioEvents_t *events ) = 0; |
wardm | 12:02d779e8c4f6 | 221 | |
wardm | 12:02d779e8c4f6 | 222 | /*! |
wardm | 12:02d779e8c4f6 | 223 | * @brief Return current radio status, returns true if a radios has been found. |
wardm | 12:02d779e8c4f6 | 224 | * |
wardm | 12:02d779e8c4f6 | 225 | * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING, CAD_RUNNING] |
wardm | 12:02d779e8c4f6 | 226 | */ |
wardm | 12:02d779e8c4f6 | 227 | virtual RadioState GetStatus( void ) = 0; |
wardm | 12:02d779e8c4f6 | 228 | |
wardm | 12:02d779e8c4f6 | 229 | /*! |
wardm | 12:02d779e8c4f6 | 230 | * @brief Configures the radio with the given modem |
wardm | 12:02d779e8c4f6 | 231 | * |
wardm | 12:02d779e8c4f6 | 232 | * @param [IN] modem Modem to be used [0: FSK, 1: LoRa] |
wardm | 12:02d779e8c4f6 | 233 | */ |
wardm | 12:02d779e8c4f6 | 234 | virtual void SetModem( RadioModems_t modem ) = 0; |
wardm | 12:02d779e8c4f6 | 235 | |
wardm | 12:02d779e8c4f6 | 236 | /*! |
wardm | 12:02d779e8c4f6 | 237 | * @brief Sets the channel frequency |
wardm | 12:02d779e8c4f6 | 238 | * |
wardm | 12:02d779e8c4f6 | 239 | * @param [IN] freq Channel RF frequency |
wardm | 12:02d779e8c4f6 | 240 | */ |
wardm | 12:02d779e8c4f6 | 241 | virtual void SetChannel( uint32_t freq ) = 0; |
wardm | 12:02d779e8c4f6 | 242 | |
wardm | 12:02d779e8c4f6 | 243 | /*! |
wardm | 12:02d779e8c4f6 | 244 | * @brief Sets the channels configuration |
wardm | 12:02d779e8c4f6 | 245 | * |
wardm | 12:02d779e8c4f6 | 246 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
wardm | 12:02d779e8c4f6 | 247 | * @param [IN] freq Channel RF frequency |
wardm | 12:02d779e8c4f6 | 248 | * @param [IN] rssiThresh RSSI threshold |
wardm | 12:02d779e8c4f6 | 249 | * |
wardm | 12:02d779e8c4f6 | 250 | * @retval isFree [true: Channel is free, false: Channel is not free] |
wardm | 12:02d779e8c4f6 | 251 | */ |
wardm | 12:02d779e8c4f6 | 252 | virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh ) = 0; |
wardm | 12:02d779e8c4f6 | 253 | |
wardm | 12:02d779e8c4f6 | 254 | /*! |
wardm | 12:02d779e8c4f6 | 255 | * @brief Generates a 32 bits random value based on the RSSI readings |
wardm | 12:02d779e8c4f6 | 256 | * |
wardm | 12:02d779e8c4f6 | 257 | * \remark This function sets the radio in LoRa modem mode and disables |
wardm | 12:02d779e8c4f6 | 258 | * all interrupts. |
wardm | 12:02d779e8c4f6 | 259 | * After calling this function either Radio.SetRxConfig or |
wardm | 12:02d779e8c4f6 | 260 | * Radio.SetTxConfig functions must be called. |
wardm | 12:02d779e8c4f6 | 261 | * |
wardm | 12:02d779e8c4f6 | 262 | * @retval randomValue 32 bits random value |
wardm | 12:02d779e8c4f6 | 263 | */ |
wardm | 12:02d779e8c4f6 | 264 | virtual uint32_t Random( void )= 0; |
wardm | 12:02d779e8c4f6 | 265 | |
wardm | 12:02d779e8c4f6 | 266 | /*! |
wardm | 12:02d779e8c4f6 | 267 | * @brief Sets the reception parameters |
wardm | 12:02d779e8c4f6 | 268 | * |
wardm | 12:02d779e8c4f6 | 269 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
wardm | 12:02d779e8c4f6 | 270 | * @param [IN] bandwidth Sets the bandwidth |
wardm | 12:02d779e8c4f6 | 271 | * FSK : >= 2600 and <= 250000 Hz |
wardm | 12:02d779e8c4f6 | 272 | * LoRa: [0: 125 kHz, 1: 250 kHz, |
wardm | 12:02d779e8c4f6 | 273 | * 2: 500 kHz, 3: Reserved] |
wardm | 12:02d779e8c4f6 | 274 | * @param [IN] datarate Sets the Datarate |
wardm | 12:02d779e8c4f6 | 275 | * FSK : 600..300000 bits/s |
wardm | 12:02d779e8c4f6 | 276 | * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, |
wardm | 12:02d779e8c4f6 | 277 | * 10: 1024, 11: 2048, 12: 4096 chips] |
wardm | 12:02d779e8c4f6 | 278 | * @param [IN] coderate Sets the coding rate ( LoRa only ) |
wardm | 12:02d779e8c4f6 | 279 | * FSK : N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 280 | * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] |
wardm | 12:02d779e8c4f6 | 281 | * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only ) |
wardm | 12:02d779e8c4f6 | 282 | * FSK : >= 2600 and <= 250000 Hz |
wardm | 12:02d779e8c4f6 | 283 | * LoRa: N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 284 | * @param [IN] preambleLen Sets the Preamble length ( LoRa only ) |
wardm | 12:02d779e8c4f6 | 285 | * FSK : N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 286 | * LoRa: Length in symbols ( the hardware adds 4 more symbols ) |
wardm | 12:02d779e8c4f6 | 287 | * @param [IN] symbTimeout Sets the RxSingle timeout value |
wardm | 12:02d779e8c4f6 | 288 | * FSK : timeout number of bytes |
wardm | 12:02d779e8c4f6 | 289 | * LoRa: timeout in symbols |
wardm | 12:02d779e8c4f6 | 290 | * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] |
wardm | 12:02d779e8c4f6 | 291 | * @param [IN] payloadLen Sets payload length when fixed lenght is used |
wardm | 12:02d779e8c4f6 | 292 | * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] |
wardm | 12:02d779e8c4f6 | 293 | * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) |
wardm | 12:02d779e8c4f6 | 294 | * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) |
wardm | 12:02d779e8c4f6 | 295 | * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) |
wardm | 12:02d779e8c4f6 | 296 | * FSK : N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 297 | * LoRa: [0: not inverted, 1: inverted] |
wardm | 12:02d779e8c4f6 | 298 | * @param [IN] rxContinuous Sets the reception in continuous mode |
wardm | 12:02d779e8c4f6 | 299 | * [false: single mode, true: continuous mode] |
wardm | 12:02d779e8c4f6 | 300 | */ |
wardm | 12:02d779e8c4f6 | 301 | virtual void SetRxConfig ( RadioModems_t modem, uint32_t bandwidth, |
wardm | 12:02d779e8c4f6 | 302 | uint32_t datarate, uint8_t coderate, |
wardm | 12:02d779e8c4f6 | 303 | uint32_t bandwidthAfc, uint16_t preambleLen, |
wardm | 12:02d779e8c4f6 | 304 | uint16_t symbTimeout, bool fixLen, |
wardm | 12:02d779e8c4f6 | 305 | uint8_t payloadLen, |
wardm | 12:02d779e8c4f6 | 306 | bool crcOn, bool freqHopOn, uint8_t hopPeriod, |
wardm | 12:02d779e8c4f6 | 307 | bool iqInverted, bool rxContinuous ) = 0; |
wardm | 12:02d779e8c4f6 | 308 | |
wardm | 12:02d779e8c4f6 | 309 | /*! |
wardm | 12:02d779e8c4f6 | 310 | * @brief Sets the transmission parameters |
wardm | 12:02d779e8c4f6 | 311 | * |
wardm | 12:02d779e8c4f6 | 312 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
wardm | 12:02d779e8c4f6 | 313 | * @param [IN] power Sets the output power [dBm] |
wardm | 12:02d779e8c4f6 | 314 | * @param [IN] fdev Sets the frequency deviation ( FSK only ) |
wardm | 12:02d779e8c4f6 | 315 | * FSK : [Hz] |
wardm | 12:02d779e8c4f6 | 316 | * LoRa: 0 |
wardm | 12:02d779e8c4f6 | 317 | * @param [IN] bandwidth Sets the bandwidth ( LoRa only ) |
wardm | 12:02d779e8c4f6 | 318 | * FSK : 0 |
wardm | 12:02d779e8c4f6 | 319 | * LoRa: [0: 125 kHz, 1: 250 kHz, |
wardm | 12:02d779e8c4f6 | 320 | * 2: 500 kHz, 3: Reserved] |
wardm | 12:02d779e8c4f6 | 321 | * @param [IN] datarate Sets the Datarate |
wardm | 12:02d779e8c4f6 | 322 | * FSK : 600..300000 bits/s |
wardm | 12:02d779e8c4f6 | 323 | * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, |
wardm | 12:02d779e8c4f6 | 324 | * 10: 1024, 11: 2048, 12: 4096 chips] |
wardm | 12:02d779e8c4f6 | 325 | * @param [IN] coderate Sets the coding rate ( LoRa only ) |
wardm | 12:02d779e8c4f6 | 326 | * FSK : N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 327 | * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] |
wardm | 12:02d779e8c4f6 | 328 | * @param [IN] preambleLen Sets the preamble length |
wardm | 12:02d779e8c4f6 | 329 | * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] |
wardm | 12:02d779e8c4f6 | 330 | * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] |
wardm | 12:02d779e8c4f6 | 331 | * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) |
wardm | 12:02d779e8c4f6 | 332 | * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) |
wardm | 12:02d779e8c4f6 | 333 | * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) |
wardm | 12:02d779e8c4f6 | 334 | * FSK : N/A ( set to 0 ) |
wardm | 12:02d779e8c4f6 | 335 | * LoRa: [0: not inverted, 1: inverted] |
wardm | 12:02d779e8c4f6 | 336 | * @param [IN] timeout Transmission timeout [us] |
wardm | 12:02d779e8c4f6 | 337 | */ |
wardm | 12:02d779e8c4f6 | 338 | virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev, |
wardm | 12:02d779e8c4f6 | 339 | uint32_t bandwidth, uint32_t datarate, |
wardm | 12:02d779e8c4f6 | 340 | uint8_t coderate, uint16_t preambleLen, |
wardm | 12:02d779e8c4f6 | 341 | bool fixLen, bool crcOn, bool freqHopOn, |
wardm | 12:02d779e8c4f6 | 342 | uint8_t hopPeriod, bool iqInverted, uint32_t timeout ) = 0; |
wardm | 12:02d779e8c4f6 | 343 | |
wardm | 12:02d779e8c4f6 | 344 | /*! |
wardm | 12:02d779e8c4f6 | 345 | * @brief Checks if the given RF frequency is supported by the hardware |
wardm | 12:02d779e8c4f6 | 346 | * |
wardm | 12:02d779e8c4f6 | 347 | * @param [IN] frequency RF frequency to be checked |
wardm | 12:02d779e8c4f6 | 348 | * @retval isSupported [true: supported, false: unsupported] |
wardm | 12:02d779e8c4f6 | 349 | */ |
wardm | 12:02d779e8c4f6 | 350 | virtual bool CheckRfFrequency( uint32_t frequency ) = 0; |
wardm | 12:02d779e8c4f6 | 351 | |
wardm | 12:02d779e8c4f6 | 352 | /*! |
wardm | 12:02d779e8c4f6 | 353 | * @brief Computes the packet time on air for the given payload |
wardm | 12:02d779e8c4f6 | 354 | * |
wardm | 12:02d779e8c4f6 | 355 | * \Remark Can only be called once SetRxConfig or SetTxConfig have been called |
wardm | 12:02d779e8c4f6 | 356 | * |
wardm | 12:02d779e8c4f6 | 357 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
wardm | 12:02d779e8c4f6 | 358 | * @param [IN] pktLen Packet payload length |
wardm | 12:02d779e8c4f6 | 359 | * |
wardm | 12:02d779e8c4f6 | 360 | * @retval airTime Computed airTime for the given packet payload length |
wardm | 12:02d779e8c4f6 | 361 | */ |
wardm | 12:02d779e8c4f6 | 362 | virtual uint32_t TimeOnAir ( RadioModems_t modem, int16_t pktLen ) = 0; |
wardm | 12:02d779e8c4f6 | 363 | |
wardm | 12:02d779e8c4f6 | 364 | /*! |
wardm | 12:02d779e8c4f6 | 365 | * @brief Sends the buffer of size. Prepares the packet to be sent and sets |
wardm | 12:02d779e8c4f6 | 366 | * the radio in transmission |
wardm | 12:02d779e8c4f6 | 367 | * |
wardm | 12:02d779e8c4f6 | 368 | * @param [IN]: buffer Buffer pointer |
wardm | 12:02d779e8c4f6 | 369 | * @param [IN]: size Buffer size |
wardm | 12:02d779e8c4f6 | 370 | * @param [IN]: buffer Header pointer |
wardm | 12:02d779e8c4f6 | 371 | * @param [IN]: size Header size |
wardm | 12:02d779e8c4f6 | 372 | */ |
wardm | 12:02d779e8c4f6 | 373 | virtual void Send( void *buffer, int16_t size, void *header = NULL, int16_t hsize = 0) = 0; |
wardm | 12:02d779e8c4f6 | 374 | |
wardm | 12:02d779e8c4f6 | 375 | /*! |
wardm | 12:02d779e8c4f6 | 376 | * @brief Sets the radio in sleep mode |
wardm | 12:02d779e8c4f6 | 377 | */ |
wardm | 12:02d779e8c4f6 | 378 | virtual void Sleep( void ) = 0; |
wardm | 12:02d779e8c4f6 | 379 | |
wardm | 12:02d779e8c4f6 | 380 | /*! |
wardm | 12:02d779e8c4f6 | 381 | * @brief Sets the radio in standby mode |
wardm | 12:02d779e8c4f6 | 382 | */ |
wardm | 12:02d779e8c4f6 | 383 | virtual void Standby( void ) = 0; |
wardm | 12:02d779e8c4f6 | 384 | |
wardm | 12:02d779e8c4f6 | 385 | /*! |
wardm | 12:02d779e8c4f6 | 386 | * @brief Sets the radio in CAD mode |
wardm | 12:02d779e8c4f6 | 387 | */ |
wardm | 12:02d779e8c4f6 | 388 | virtual void StartCad( void ) = 0; |
wardm | 12:02d779e8c4f6 | 389 | |
wardm | 12:02d779e8c4f6 | 390 | /*! |
wardm | 12:02d779e8c4f6 | 391 | * @brief Sets the radio in reception mode for the given time |
wardm | 12:02d779e8c4f6 | 392 | * @param [IN] timeout Reception timeout [us] |
wardm | 12:02d779e8c4f6 | 393 | * [0: continuous, others timeout] |
wardm | 12:02d779e8c4f6 | 394 | */ |
wardm | 12:02d779e8c4f6 | 395 | virtual void Rx( uint32_t timeout ) = 0; |
wardm | 12:02d779e8c4f6 | 396 | |
wardm | 12:02d779e8c4f6 | 397 | /*! |
wardm | 12:02d779e8c4f6 | 398 | * @brief Check is radio receives a signal |
wardm | 12:02d779e8c4f6 | 399 | */ |
wardm | 12:02d779e8c4f6 | 400 | virtual bool RxSignalPending() = 0; |
wardm | 12:02d779e8c4f6 | 401 | |
wardm | 12:02d779e8c4f6 | 402 | |
wardm | 12:02d779e8c4f6 | 403 | /*! |
wardm | 12:02d779e8c4f6 | 404 | * @brief Sets the radio in transmission mode for the given time |
wardm | 12:02d779e8c4f6 | 405 | * @param [IN] timeout Transmission timeout [us] |
wardm | 12:02d779e8c4f6 | 406 | * [0: continuous, others timeout] |
wardm | 12:02d779e8c4f6 | 407 | */ |
wardm | 12:02d779e8c4f6 | 408 | virtual void Tx( uint32_t timeout ) = 0; |
wardm | 12:02d779e8c4f6 | 409 | |
wardm | 12:02d779e8c4f6 | 410 | /*! |
wardm | 12:02d779e8c4f6 | 411 | * @brief Sets the radio in continuous wave transmission mode |
wardm | 12:02d779e8c4f6 | 412 | * |
wardm | 12:02d779e8c4f6 | 413 | * @param [IN]: freq Channel RF frequency |
wardm | 12:02d779e8c4f6 | 414 | * @param [IN]: power Sets the output power [dBm] |
wardm | 12:02d779e8c4f6 | 415 | * @param [IN]: time Transmission mode timeout [s] |
wardm | 12:02d779e8c4f6 | 416 | */ |
wardm | 12:02d779e8c4f6 | 417 | virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time ) = 0; |
wardm | 12:02d779e8c4f6 | 418 | |
wardm | 12:02d779e8c4f6 | 419 | /*! |
wardm | 12:02d779e8c4f6 | 420 | * @brief Returns the maximal transfer unit for a given modem |
wardm | 12:02d779e8c4f6 | 421 | * |
wardm | 12:02d779e8c4f6 | 422 | * @retval MTU size in bytes |
wardm | 12:02d779e8c4f6 | 423 | */ |
wardm | 12:02d779e8c4f6 | 424 | virtual int16_t MaxMTUSize( RadioModems_t modem ) = 0; |
wardm | 12:02d779e8c4f6 | 425 | |
wardm | 12:02d779e8c4f6 | 426 | /*! |
wardm | 12:02d779e8c4f6 | 427 | * @brief Reads the current RSSI value |
wardm | 12:02d779e8c4f6 | 428 | * |
wardm | 12:02d779e8c4f6 | 429 | * @retval rssiValue Current RSSI value in [dBm] |
wardm | 12:02d779e8c4f6 | 430 | */ |
wardm | 12:02d779e8c4f6 | 431 | virtual int16_t GetRssi ( RadioModems_t modem ) = 0; |
wardm | 12:02d779e8c4f6 | 432 | |
wardm | 12:02d779e8c4f6 | 433 | /*! |
wardm | 12:02d779e8c4f6 | 434 | * @brief Reads the current frequency error |
wardm | 12:02d779e8c4f6 | 435 | * |
wardm | 12:02d779e8c4f6 | 436 | * @retval frequency error value in [Hz] |
wardm | 12:02d779e8c4f6 | 437 | */ |
wardm | 12:02d779e8c4f6 | 438 | virtual int32_t GetFrequencyError( RadioModems_t modem ) = 0; |
wardm | 12:02d779e8c4f6 | 439 | |
wardm | 12:02d779e8c4f6 | 440 | /*! |
wardm | 12:02d779e8c4f6 | 441 | * @brief Writes the radio register at the specified address |
wardm | 12:02d779e8c4f6 | 442 | * |
wardm | 12:02d779e8c4f6 | 443 | * @param [IN]: addr Register address |
wardm | 12:02d779e8c4f6 | 444 | * @param [IN]: data New register value |
wardm | 12:02d779e8c4f6 | 445 | */ |
wardm | 12:02d779e8c4f6 | 446 | virtual void Write ( uint8_t addr, uint8_t data ) = 0; |
wardm | 12:02d779e8c4f6 | 447 | |
wardm | 12:02d779e8c4f6 | 448 | /*! |
wardm | 12:02d779e8c4f6 | 449 | * @brief Reads the radio register at the specified address |
wardm | 12:02d779e8c4f6 | 450 | * |
wardm | 12:02d779e8c4f6 | 451 | * @param [IN]: addr Register address |
wardm | 12:02d779e8c4f6 | 452 | * @retval data Register value |
wardm | 12:02d779e8c4f6 | 453 | */ |
wardm | 12:02d779e8c4f6 | 454 | virtual uint8_t Read ( uint8_t addr ) = 0; |
wardm | 12:02d779e8c4f6 | 455 | |
wardm | 12:02d779e8c4f6 | 456 | /*! |
wardm | 12:02d779e8c4f6 | 457 | * @brief Writes multiple radio registers starting at address |
wardm | 12:02d779e8c4f6 | 458 | * |
wardm | 12:02d779e8c4f6 | 459 | * @param [IN] addr First Radio register address |
wardm | 12:02d779e8c4f6 | 460 | * @param [IN] buffer Buffer containing the new register's values |
wardm | 12:02d779e8c4f6 | 461 | * @param [IN] size Number of registers to be written |
wardm | 12:02d779e8c4f6 | 462 | */ |
wardm | 12:02d779e8c4f6 | 463 | virtual void Write( uint8_t addr, void *buffer, uint8_t size ) = 0; |
wardm | 12:02d779e8c4f6 | 464 | |
wardm | 12:02d779e8c4f6 | 465 | /*! |
wardm | 12:02d779e8c4f6 | 466 | * @brief Reads multiple radio registers starting at address |
wardm | 12:02d779e8c4f6 | 467 | * |
wardm | 12:02d779e8c4f6 | 468 | * @param [IN] addr First Radio register address |
wardm | 12:02d779e8c4f6 | 469 | * @param [OUT] buffer Buffer where to copy the registers data |
wardm | 12:02d779e8c4f6 | 470 | * @param [IN] size Number of registers to be read |
wardm | 12:02d779e8c4f6 | 471 | */ |
wardm | 12:02d779e8c4f6 | 472 | virtual void Read ( uint8_t addr, void *buffer, uint8_t size ) = 0; |
wardm | 12:02d779e8c4f6 | 473 | |
wardm | 12:02d779e8c4f6 | 474 | /*! |
wardm | 12:02d779e8c4f6 | 475 | * @brief Writes the buffer contents to the Radio FIFO |
wardm | 12:02d779e8c4f6 | 476 | * |
wardm | 12:02d779e8c4f6 | 477 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
wardm | 12:02d779e8c4f6 | 478 | * @param [IN] size Number of bytes to be written to the FIFO |
wardm | 12:02d779e8c4f6 | 479 | */ |
wardm | 12:02d779e8c4f6 | 480 | virtual void WriteFifo( void *buffer, uint8_t size ) = 0; |
wardm | 12:02d779e8c4f6 | 481 | |
wardm | 12:02d779e8c4f6 | 482 | /*! |
wardm | 12:02d779e8c4f6 | 483 | * @brief Reads the contents of the Radio FIFO |
wardm | 12:02d779e8c4f6 | 484 | * |
wardm | 12:02d779e8c4f6 | 485 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
wardm | 12:02d779e8c4f6 | 486 | * @param [IN] size Number of bytes to be read from the FIFO |
wardm | 12:02d779e8c4f6 | 487 | */ |
wardm | 12:02d779e8c4f6 | 488 | virtual void ReadFifo( void *buffer, uint8_t size ) = 0; |
wardm | 12:02d779e8c4f6 | 489 | |
wardm | 12:02d779e8c4f6 | 490 | /*! |
wardm | 12:02d779e8c4f6 | 491 | * @brief Sets the maximum payload length. |
wardm | 12:02d779e8c4f6 | 492 | * |
wardm | 12:02d779e8c4f6 | 493 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
wardm | 12:02d779e8c4f6 | 494 | * @param [IN] max Maximum payload length in bytes |
wardm | 12:02d779e8c4f6 | 495 | */ |
wardm | 12:02d779e8c4f6 | 496 | virtual void SetMaxPayloadLength( RadioModems_t modem, uint8_t max ) = 0; |
wardm | 12:02d779e8c4f6 | 497 | |
wardm | 12:02d779e8c4f6 | 498 | /*! |
wardm | 12:02d779e8c4f6 | 499 | * @brief Sets the network to public or private. Updates the sync byte. |
wardm | 12:02d779e8c4f6 | 500 | * |
wardm | 12:02d779e8c4f6 | 501 | * @remark Applies to LoRa modem only |
wardm | 12:02d779e8c4f6 | 502 | * |
wardm | 12:02d779e8c4f6 | 503 | * @param [IN] enable if true, it enables a public network |
wardm | 12:02d779e8c4f6 | 504 | */ |
wardm | 12:02d779e8c4f6 | 505 | virtual void SetPublicNetwork( bool enable ) = 0; |
wardm | 12:02d779e8c4f6 | 506 | |
wardm | 12:02d779e8c4f6 | 507 | /*! |
wardm | 12:02d779e8c4f6 | 508 | * \brief Sets the radio output power. |
wardm | 12:02d779e8c4f6 | 509 | * |
wardm | 12:02d779e8c4f6 | 510 | * @param [IN] power Sets the RF output power |
wardm | 12:02d779e8c4f6 | 511 | */ |
wardm | 12:02d779e8c4f6 | 512 | virtual void SetRfTxPower( int8_t power ) = 0; |
wardm | 12:02d779e8c4f6 | 513 | |
wardm | 12:02d779e8c4f6 | 514 | }; |
wardm | 12:02d779e8c4f6 | 515 | |
wardm | 12:02d779e8c4f6 | 516 | #endif // __RADIO_H__ |