Demo HCI Implementation for WiMOD-LR Devices  V2.0.3
WiMODProLink.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 
33 /*
34  * THIS IS AN EXAMPLE IMPLEMENTATION ACCORDING THE THE HCI SPEC: V1.3
35  * FOR FIRMWARE: LoRaWAN PROLINK
36  *
37  * SEE FILE: ProLink_LoRaWAN_EndNode_Modem_HCI_Spec_v1_3.pdf for detailed information
38  */
39 
40 #ifndef ARDUINO_WIMODPROLINK_H_
41 #define ARDUINO_WIMODPROLINK_H_
42 
43 //------------------------------------------------------------------------------
44 //
45 // Section Includes Files
46 //
47 //------------------------------------------------------------------------------
48 
49 #include "Arduino.h"
50 /************
51  * BUG in ardunino.h ?
52  * -> https://stackoverflow.com/questions/41093090/esp8266-error-macro-min-passed-3-arguments-but-takes-just-2
53  */
54 #undef min
55 #undef max
56 
57 #include <string.h>
58 
62 
63 #include "SAP/WiMOD_SAP_Generic.h"
64 #include "utils/ComSLIP.h"
65 #include "HCI/WiMODLRHCI.h"
66 #include "utils/FreqCalc_SX127x.h"
67 
68 //-----------------------------------------------------------------------------
69 // common defines
70 //-----------------------------------------------------------------------------
72 #define WIMOD_PROLINK_SERIAL_BAUDRATE 115200
73 
74 #define WiMOD_PROLINK_TX_BUFFER_SIZE 256
75 //-----------------------------------------------------------------------------
77 // types for callback functions
78 //-----------------------------------------------------------------------------
79 
80 
81 
82 //-----------------------------------------------------------------------------
83 // API class declaration for the WiMOD ProLink LoRaWAN Stack
84 //
85 //-----------------------------------------------------------------------------
93 class WiMODProLink : public TWiMODLRHCI {
94 public:
95  /*explicit*/ WiMODProLink(Stream& s);
96  ~WiMODProLink(void);
98  void end(void);
99 
101  void beginAndAutoSetup(void);
102  void autoSetupSupportedRegion(void);
104 
105  /*
106  * DevMgmt SAP
107  */
108  bool Ping(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
109  bool Reset(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
110  bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfoLoRaWan* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
111  bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
112  bool GetRtc(UINT32* rtcTime,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
113  bool SetRtc(const UINT32 rtcTime, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
114 
115  bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
116  bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
117  bool ClearRtcAlarm(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
118 
119  bool GetOperationMode(TWiMOD_OperationMode* opMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
120  bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
121 
124 
125  bool GetHciConfig(TWiMODLR_DevMgmt_HciConfig* hciConfig, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
126  bool SetHciConfig(TWiMODLR_DevMgmt_HciConfig& hciConfig, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
127 
128 
129  bool GetRadioStack(TRadioStack_Mode* stackMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
130  bool SetRadioStack(const TRadioStack_Mode& stackMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
131 
132 
133  bool SetDeviceConfig(const TProLinkDeviceConfig& config, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
134  bool GetDeviceConfig(TProLinkDeviceConfig* config, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
135  bool ResetDeviceConfig(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
136 
137  bool GetDeviceStatus(TProLinkDeviceStatus* devStatus, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
138 
139  /*
140  * LoRaWAN SAP
141  */
142  bool ActivateDevice(TWiMODLORAWAN_ActivateDeviceData& activationData,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
143  bool ReactivateDevice(UINT32* devAdr, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
144  bool SetJoinParameter(TWiMODLORAWAN_JoinParams& joinParams, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
145  bool JoinNetwork(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
146 
148 
149  bool
150  convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_Data* loraWanRxData);
151  bool
153 
154  bool
155  convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_MacCmdData* loraWanMacCmdData);
156 
157  bool
159 
160  bool
162 
163  bool
165 
166  void
168 
169  void
171 
172  void
174 
175  void
177 
178  void
180 
181  void
183 
184  void
186 
187  void
189 
190  bool SendUData(TWiMODProLinkLORAWAN_TX_Data* data, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
191  bool SendCData(TWiMODProLinkLORAWAN_TX_Data* data,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
192  bool SetRadioStackConfig(TWiMODProLinkLORAWAN_RadioStackConfig* data,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
193  bool GetRadioStackConfig(TWiMODProLinkLORAWAN_RadioStackConfig* data, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
194  bool DeactivateDevice(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
195  bool FactoryReset(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
196  bool SetDeviceEUI(const UINT8* deviceEUI, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
197  bool GetDeviceEUI(UINT8* deviceEUI, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
198  bool GetNwkStatus(TWiMODLORAWAN_NwkStatus_Data* nwkStatus, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL); // new implementation for spec. V1.14
199  bool SendMacCmd(const TWiMODLORAWAN_MacCmd* cmd, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
200  bool SetCustomConfig(const INT8 rfGain, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
201  bool GetCustomConfig(INT8* rfGain, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
202  bool GetSupportedBands(TWiMODLORAWAN_SupportedBands* supportedBands, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
203  bool GetTxPowerLimitConfig(TWiMODLORAWAN_TxPwrLimitConfig* txPwrLimitCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
204  bool SetTxPowerLimitConfig(TWiMODLORAWAN_TxPwrLimitConfig& txPwrLimitCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
205 
206  bool SetBatteryLevelStatus(UINT8 battStatus, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
207 
208  bool SetDeviceNonce(const UINT16 devNonce, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
209  bool GetDeviceNonce(UINT16* devNonce, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
210 
211 
212  bool SetMulticastConfig(TWiMODLORAWAN_McastConfig& mcastCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
213  bool GetMulticastConfig(TWiMODLORAWAN_McastConfig* mcastCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
214  bool RemoveMulticastConfig(const UINT8 mcastIndex, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
215 
216  void
218 
219  bool SetJoinNonce(const UINT16 joinNonce, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
220  bool GetJoinNonce(UINT16* joinNonce, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
221 
222  void
224 
225  bool SendNwkTimeRequest(TWiMODLORAWAN_DevTimeReqInfo* devTimeInfo, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
226 
227  void
229 
230  void
232 
233  void
235 
236  bool
238  bool
240  bool
242 
243 
244  /*
245  * proprietary RadioLink SAP (LR-BASE)
246  */
247  bool GetRadioLinkRadioConfig(TWiMODLR_ProLinkRadioLink_RadioConfig* radioCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
248  bool SetRadioLinkRadioConfig(const TWiMODLR_ProLinkRadioLink_RadioConfig* radioCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
249  bool ResetRadioLinkRadioConfig(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
250 
251  bool SetRadioLinkAesKey(const UINT8* key, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
252  bool GetRadioLinkAesKey( UINT8* key,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
253 
254  bool SendRadioLinkUData(const TWiMODLR_RadioLink_Msg* data,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
255 
257 
259 
260  void calcFreqToRegister(uint32_t freq, uint8_t* msb, uint8_t* mid, uint8_t* lsb);
261  uint32_t calcRegisterToFreq(uint8_t msb, uint8_t mid, uint8_t lsb);
262 
263  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_Msg* radioLinkMsg);
264  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_UdataInd* uDataTxInfo);
265 
266 
267  /*
268  * Generic Cmd
269  */
270  bool ExecuteGenericCmd(TWiMODLR_Generic_CmdInfo* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
271 
272  /*
273  * Info & QuickStart Cmds
274  */
275  void PrintBasicDeviceInfo(Stream& s);
276  void ConnectViaOTAA(const uint8_t* appEUI = NULL, const uint8_t* appKey = NULL);
277  void ConvertAppEuiStrToArray(char* appEuiStr, uint8_t* appEuiArray);
278  void ConvertAppKeyStrToArray(char* appKeyStr, uint8_t* appKeyArray);
279 
280  void ConvertNwkSKeyStrToArray(char* nwkSKeyStr, uint8_t* nwkSKeyArray);
281  void ConvertAppSKeyStrToArray(char* appSKeyStr, uint8_t* appSKeyArray);
282 
284  UINT8 GetLastResponseStatus(void);
285 
286 protected:
293  virtual void ProcessUnexpectedRxMessage(TWiMODLR_HCIMessage& rxMsg);
294 
295 
296  bool copyLoRaWanResultInfos(TWiMODLRResultCodes* hciResult, UINT8* rspStatus);
297  bool copyDevMgmtResultInfos(TWiMODLRResultCodes* hciResult, UINT8* rspStatus);
298  bool copyProLinkRadioLinkResultInfos(TWiMODLRResultCodes* hciResult, UINT8* rspStatus);
299 private:
301  UINT8 txBuffer[WiMOD_PROLINK_TX_BUFFER_SIZE];
302 
303  UINT8 localStatusRsp;
304  bool cmdResult;
305  TWiMODLRResultCodes localHciRes;
306 
307  TWiMODLRResultCodes lastHciRes;
308  UINT8 lastStatusRsp;
310 };
311 
312 
313 
314 
315 
316 
317 
318 
319 
320 
321 #endif /* ARDUINO_WIMODPROLINK_H_ */
WiMOD_SAP_Generic
Implementation for the ServiceAccessPoint DeviceManagement.
Definition: WiMOD_SAP_Generic.h:78
TJoinedNwkIndicationCallback
void(* TJoinedNwkIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:154
TWiMODLORAWAN_DevTimeAnsInfo
info data structure for LoRa device time request MAC command
Definition: WiMOD_SAP_LORAWAN_ProLink_IDs.h:114
TWiMODLORAWAN_RX_JoinedNwkData
Structure containing data of the joined network indication.
Definition: WiMOD_SAP_LORAWAN_IDs.h:551
TRxUDataIndicationCallback
void(* TRxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:166
TWiMODLORAWAN_RX_Data
Structure containing RX (user) payload data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:514
TWiMODLORAWAN_McastNoData
Structure containing a MultiCast Data.
Definition: WiMOD_SAP_LORAWAN_ProLink_IDs.h:176
TWiMODLORAWAN_NoData_Data
Structure containing infos of a NoData Indication message.
Definition: WiMOD_SAP_LORAWAN_IDs.h:648
TWiMODLORAWAN_TxIndData
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:472
TWiMODLRHCI
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:235
TWiMODLORAWAN_McastData
Structure containing a MultiCast Data.
Definition: WiMOD_SAP_LORAWAN_ProLink_IDs.h:139
TWiMODLORAWAN_NwkStatus_Data
Structure containing all data about LoRaWAN network status.
Definition: WiMOD_SAP_LORAWAN_IDs.h:619
TWiMODLR_DevMgmt_FwInfo
Basic information about the current firmware of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:220
TWiMODLR_DevMgmt_DevInfoLoRaWan
Structure containing basic information about the WiMOD device.
Definition: WiMOD_SAP_DEVMGMT_Lorawan_IDs.h:64
TWiMODLR_HCIMessage
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
TWiMODLR_DevMgmt_RtcAlarm
Structure containing the RTC Alarm config parameters of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:484
TWiMODLORAWAN_SupportedBands
data structure for supported bands
Definition: WiMOD_SAP_LORAWAN_IDs.h:663
WiMODLRHCI.h
TWiMOD_OperationMode
TWiMOD_OperationMode
This enum describes the possible operation modes of the WiMOD (only for LR-BASE).
Definition: WiMOD_SAP_DEVMGMT_IDs.h:440
TWiMODLORAWAN_JoinParams
JOIN data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:450
TTxUDataIndicationCallback
void(* TTxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:163
TWiMODLORAWAN_TxPwrLimitConfig
data structure for TX Power Limits
Definition: WiMOD_SAP_LORAWAN_IDs.h:674
TRxAckIndicationCallback
void(* TRxAckIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:175
TWiMODLORAWAN_RX_ACK_Data
Data structure for received Acknowledgment data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:602
ComSLIP.h
TRxMacCmdIndicationCallback
void(* TRxMacCmdIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:172
TNwkDeviceTimeAnsIndicationCallback
void(* TNwkDeviceTimeAnsIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:148
TTxCDataIndicationCallback
void(* TTxCDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:160
TWiMODLORAWAN_DevTimeReqInfo
info data structure for LoRa device time request MAC command
Definition: WiMOD_SAP_LORAWAN_ProLink_IDs.h:104
TWiMODLORAWAN_MacCmd
LoRaWAN MAC command structure.
Definition: WiMOD_SAP_LORAWAN_IDs.h:590
TWiMODLORAWAN_McastConfig
Definition: WiMOD_SAP_LORAWAN_ProLink_IDs.h:121
TJoinTxIndicationCallback
void(* TJoinTxIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:151
TNoDataIndicationCallback
void(* TNoDataIndicationCallback)(void)
Definition: WiMOD_SAP_LORAWAN.h:157
TRxCDataIndicationCallback
void(* TRxCDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:169
TResetDevNonceIndicationCallback
void(* TResetDevNonceIndicationCallback)(void)
Definition: WiMOD_SAP_LORAWAN.h:142
TWiMODLORAWAN_RX_MacCmdData
Structure containing a received MAC command.
Definition: WiMOD_SAP_LORAWAN_IDs.h:534
TWiMODLRResultCodes
TWiMODLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
WiMOD_SAP_Generic.h
TWiMODLORAWAN_ActivateDeviceData
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:439
TWiMODLR_DevMgmt_HciConfig
HCI Configuration Parameters.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:519
TWiMODLRHCI::begin
virtual void begin(void)
Init function of the generic HCI message handler.
Definition: WiMODLRHCI.cpp:92
TDevMgmtRtcAlarmCallback
void(* TDevMgmtRtcAlarmCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:96
TDevMgmtPowerUpCallback
void(* TDevMgmtPowerUpCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:93
FreqCalc_SX127x.h
TLinkDisconnectIndicationCallback
void(* TLinkDisconnectIndicationCallback)(void)
Definition: WiMOD_SAP_LORAWAN.h:145