Demo HCI Implementation for WiMOD-LR Devices  V1.3.1
WiMODLoRaWAN.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 
33 
34 #ifndef ARDUINO_WIMODLORAWAN_H_
35 #define ARDUINO_WIMODLORAWAN_H_
36 
37 
38 
45 //------------------------------------------------------------------------------
46 //
47 // Section Includes Files
48 //
49 //------------------------------------------------------------------------------
50 
51 #include "Arduino.h"
52 //#include <cstddef>
53 #include <string.h>
54 
55 #include "SAP/WiMOD_SAP_LORAWAN.h"
56 #include "SAP/WiMOD_SAP_DEVMGMT.h"
57 #include "utils/ComSLIP.h"
58 #include "HCI/WiMODLRHCI.h"
59 
60 //-----------------------------------------------------------------------------
61 // common defines
62 //-----------------------------------------------------------------------------
64 #define WIMOD_LORAWAN_SERIAL_BAUDRATE 115200
65 
66 #define WiMOD_LORAWAN_TX_BUFFER_SIZE 256
67 //-----------------------------------------------------------------------------
69 // types for callback functions
70 //-----------------------------------------------------------------------------
71 
72 
73 
74 //-----------------------------------------------------------------------------
75 // API class declaration for the WiMOD LR BASE Stack
76 //
77 // note: this is NOT compliant with the WiMOD LoRaWAN Stack
78 //-----------------------------------------------------------------------------
86 class WiMODLoRaWAN : public TWiMODLRHCI {
87 public:
88  WiMODLoRaWAN(Stream& s);
89  ~WiMODLoRaWAN(void);
90 
91  void begin(void);
92  void end(void);
93 
94  /*
95  * DevMgmt SAP
96  */
97  bool Ping(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
98  bool Reset(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
99  bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfo* info, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
100  bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo* info, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
101  bool GetSystemStatus(TWiMODLR_DevMgmt_SystemStatus* info, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
102  bool GetRtc(UINT32* rtcTime,TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
103  bool SetRtc(const UINT32 rtcTime, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
104 
105  bool GetOperationMode(TWiMOD_OperationMode* opMode, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
106  bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
107 
108  bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
109  bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
110  bool ClearRtcAlarm(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
111 
114 
115 
116  /*
117  * LoRaWAN SAP
118  */
119  bool ActivateDevice(TWiMODLORAWAN_ActivateDeviceData& activationData,TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
120  bool ReactivateDevice(UINT32* devAdr, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
121  bool SetJoinParameter(TWiMODLORAWAN_JoinParams& joinParams, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
122  bool JoinNetwork(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
123 
125 
126  bool
127  convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_Data* loraWanRxData);
128  bool
130 
131  bool
132  convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_MacCmdData* loraWanMacCmdData);
133 
134  bool
136 
137  bool
139 
140  void
142 
143  void
145 
146  void
148 
149  void
151 
152  void
154 
155  void
157 
158  void
160 
161  void
163 
164  bool SendUData(const TWiMODLORAWAN_TX_Data* data, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
165  bool SendCData(const TWiMODLORAWAN_TX_Data* data,TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
166  bool SetRadioStackConfig(const TWiMODLORAWAN_RadioStackConfig* data,TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
167  bool GetRadioStackConfig(TWiMODLORAWAN_RadioStackConfig* data, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
168  bool DeactivateDevice(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
169  bool FactoryReset(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
170  bool SetDeviceEUI(const UINT8* deviceEUI, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
171  bool GetDeviceEUI(UINT8* deviceEUI, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
172 // bool GetNwkStatus(UINT8* nwkStatus, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL); // implementation for spec up to V1.13
173  bool GetNwkStatus(TWiMODLORAWAN_NwkStatus_Data* nwkStatus, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL); // new implementation for spec. V1.14
174  bool SendMacCmd(const TWiMODLORAWAN_MacCmd* cmd, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
175  bool SetCustomConfig(const INT8 txPwrOffset, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
176  bool GetCustomConfig(INT8* txPwrOffset, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
177 
179  UINT8 GetLastResponseStatus(void);
180 
181 protected:
186  virtual void ProcessUnexpectedRxMessage(TWiMODLR_HCIMessage& rxMsg);
187 
188  bool copyLoRaWanResultInfos(TWiMDLRResultCodes* hciResult, UINT8* rspStatus);
189  bool copyDevMgmtResultInfos(TWiMDLRResultCodes* hciResult, UINT8* rspStatus);
190 private:
192  UINT8 txBuffer[WiMOD_LORAWAN_TX_BUFFER_SIZE];
193 
194  UINT8 localStatusRsp;
195  bool cmdResult;
196  TWiMDLRResultCodes localHciRes;
197 
198  TWiMDLRResultCodes lastHciRes;
199  UINT8 lastStatusRsp;
201 };
202 
203 
204 #endif /* ARDUINO_WIMODLORAWAN_H_ */
bool Ping(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Ping Cmd - Checks the serial connection to the WiMOD module.
Definition: WiMODLoRaWAN.cpp:181
bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current operation mode of the WiMOD module.
Definition: WiMODLoRaWAN.cpp:498
Structure containing data of the joined network indication.
Definition: WiMOD_SAP_LORAWAN_IDs.h:592
Basic information about system status of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:208
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:481
void(* TRxCDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:133
Implementation for the ServiceAccessPoint LoRaWAN (End Node Modem firmware only)
Definition: WiMOD_SAP_LORAWAN.h:153
bool SetRtc(const UINT32 rtcTime, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current RTC values to WiMOD module.
Definition: WiMODLoRaWAN.cpp:412
Structure containing a received MAC command.
Definition: WiMOD_SAP_LORAWAN_IDs.h:575
void(* TTxCDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:124
void(* TRxMacCmdIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:136
TWiMDLRResultCodes GetLastHciResult(void)
Gets the last HCI result code from the last executed command.
Definition: WiMODLoRaWAN.cpp:2027
bool GetSystemStatus(TWiMODLR_DevMgmt_SystemStatus *info, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
GetSystemStatus Cmd - Gets the basic information about the system status of the WiMOD.
Definition: WiMODLoRaWAN.cpp:326
void(* TJoinTxIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:115
void RegisterRxAckIndicationClient(TRxAckIndicationCallback cb)
Register a callback function for the event "RX ACK (data) Indication".
Definition: WiMODLoRaWAN.cpp:1505
TWiMDLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
void RegisterRxUDataIndicationClient(TRxUDataIndicationCallback cb)
Register a callback function for the event "RX U-Data Indication".
Definition: WiMODLoRaWAN.cpp:1421
bool JoinNetwork(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Start joining the network via the OTAA procedure. Asynchronous process.
Definition: WiMODLoRaWAN.cpp:949
void begin(void)
This function must be called once before any other service can be used.
Definition: WiMODLoRaWAN.cpp:105
void(* TDevMgmtRtcAlarmCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:96
bool FactoryReset(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Reset all internal settings to default values (incl. DevEUI !!!)
Definition: WiMODLoRaWAN.cpp:1761
void RegisterRxMacCmdIndicationClient(TRxMacCmdIndicationCallback cb)
Register a callback function for the event "RX MAC Cmd Indication".
Definition: WiMODLoRaWAN.cpp:1463
bool ClearRtcAlarm(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Clears pending RTC Alarms of the WiMOD.
Definition: WiMODLoRaWAN.cpp:624
void RegisterJoinedNwkIndicationClient(TJoinedNwkIndicationCallback cb)
Register a callback function for the event "Joined Nwk Indication".
Definition: WiMODLoRaWAN.cpp:1484
bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfo *info, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
GetDeviceInfo Cmd - Gets the basic device information of the WiMOD.
Definition: WiMODLoRaWAN.cpp:241
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
bool SendMacCmd(const TWiMODLORAWAN_MacCmd *cmd, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Send a MAC command to the server; expert level only.
Definition: WiMODLoRaWAN.cpp:1929
void(* TRxAckIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:139
bool SetRadioStackConfig(const TWiMODLORAWAN_RadioStackConfig *data, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets a new radio config parameter set of the WiMOD.
Definition: WiMODLoRaWAN.cpp:1657
bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm *rtcAlarm, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets information about the RTC alarm feature of the WiMOD.
Definition: WiMODLoRaWAN.cpp:595
bool GetDeviceEUI(UINT8 *deviceEUI, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the DeviceEUI (aka. IEEE-Address) of the WiMOD.
Definition: WiMODLoRaWAN.cpp:1841
void RegisterPowerUpIndicationClient(TDevMgmtPowerUpCallback cb)
Register a callback function for the PowerUp Indication - optional -.
Definition: WiMODLoRaWAN.cpp:662
Declarations for the DeviceManagement SericeAccessPoint.
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:229
void(* TJoinedNwkIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:118
Common low level HCI message processing base.
bool GetOperationMode(TWiMOD_OperationMode *opMode, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current operation mode of the WiMOD module.
Definition: WiMODLoRaWAN.cpp:458
bool GetRadioStackConfig(TWiMODLORAWAN_RadioStackConfig *data, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current radio config parameter set of the WiMOD.
Definition: WiMODLoRaWAN.cpp:1696
void RegisterTxCDataIndicationClient(TTxCDataIndicationCallback cb)
Register a callback function for the event "TX C-Data Indication".
Definition: WiMODLoRaWAN.cpp:1352
Main class representing the interface to the WiMOD running the firmware LoRaWAN EndNode Modem...
Definition: WiMODLoRaWAN.h:86
TWiMOD_OperationMode
This enum describes the possible operation modes of the WiMOD (only for LR-BASE). ...
Definition: WiMOD_SAP_DEVMGMT_IDs.h:410
Implementation for the ServiceAccessPoint DeviceManagement.
Definition: WiMOD_SAP_DEVMGMT.h:109
void RegisterNoDataIndicationClient(TNoDataIndicationCallback cb)
Register a callback function for the event "TX Join Indication".
Definition: WiMODLoRaWAN.cpp:1305
void(* TRxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:130
bool SendUData(const TWiMODLORAWAN_TX_Data *data, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Tries to send transmit U-Data to network server via RF link.
Definition: WiMODLoRaWAN.cpp:1552
bool DeactivateDevice(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Deactivate the device (logical disconnect from lora network)
Definition: WiMODLoRaWAN.cpp:1728
WiMODLoRaWAN(Stream &s)
Constructor.
Definition: WiMODLoRaWAN.cpp:68
UINT8 GetLastResponseStatus(void)
Gets the last response code of the WiMOD of the last executed command.
Definition: WiMODLoRaWAN.cpp:2073
bool convert(TWiMODLR_HCIMessage &RxMsg, TWiMODLORAWAN_RX_Data *loraWanRxData)
Convert a received low level HCI-Msg to a high-level Rx Data structure.
Definition: WiMODLoRaWAN.cpp:1038
bool SetDeviceEUI(const UINT8 *deviceEUI, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets a new DeviceEUI (aka. IEEE-Address) to the WiMOD.
Definition: WiMODLoRaWAN.cpp:1804
JOIN data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:492
Structure containing the RTC Alarm config parameters of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:452
Basic information about the current firmware of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:194
bool SetCustomConfig(const INT8 txPwrOffset, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Setup a custom config for tx power settings; expert level only.
Definition: WiMODLoRaWAN.cpp:1952
WiMOD_SAP_DevMgmt SapDevMgmt
Definition: WiMODLoRaWAN.h:182
void RegisterRtcAlarmIndicationClient(TDevMgmtRtcAlarmCallback cb)
Register a callback function for the RTC Alarm Indication - optional -.
Definition: WiMODLoRaWAN.cpp:700
bool GetRtc(UINT32 *rtcTime, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current RTC data info from WiMOD module.
Definition: WiMODLoRaWAN.cpp:373
bool ActivateDevice(TWiMODLORAWAN_ActivateDeviceData &activationData, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Activates the device via the APB procedure.
Definition: WiMODLoRaWAN.cpp:767
Data structure for received Acknowledgment data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:634
bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm *rtcAlarm, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets and enables the RTC alarm feature of the WiMOD.
Definition: WiMODLoRaWAN.cpp:552
void RegisterRxCDataIndicationClient(TRxCDataIndicationCallback cb)
Register a callback function for the event "RX C-Data Indication".
Definition: WiMODLoRaWAN.cpp:1442
bool Reset(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Reset Cmd - Reboots the WiMOD module.
Definition: WiMODLoRaWAN.cpp:204
Declarations for the LoRaWAN SericeAccessPoint.
void end(void)
Shut shut down function.
Definition: WiMODLoRaWAN.cpp:115
bool GetNwkStatus(TWiMODLORAWAN_NwkStatus_Data *nwkStatus, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current status of the network "connection".
Definition: WiMODLoRaWAN.cpp:1888
void RegisterTxUDataIndicationClient(TTxUDataIndicationCallback cb)
Register a callback function for the event "TX U Data Indication".
Definition: WiMODLoRaWAN.cpp:1400
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:514
LoRaWAN MAC command structure.
Definition: WiMOD_SAP_LORAWAN_IDs.h:622
void(* TNoDataIndicationCallback)(void)
Definition: WiMOD_SAP_LORAWAN.h:121
bool ReactivateDevice(UINT32 *devAdr, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Re-Activates the device via the APB procedure.
Definition: WiMODLoRaWAN.cpp:834
Structure containing basic information about the WiMOD device.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:156
bool SendCData(const TWiMODLORAWAN_TX_Data *data, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Tries to send transmit C-Data to network server via RF link.
Definition: WiMODLoRaWAN.cpp:1610
Radio stack configuration related to to LoRaWAN specific options.
Definition: WiMOD_SAP_LORAWAN_IDs.h:609
void(* TTxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:127
void RegisterJoinTxIndicationClient(TJoinTxIndicationCallback cb)
Register a callback function for the event "TX Join Indication".
Definition: WiMODLoRaWAN.cpp:985
bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo *info, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
GetFirmwareInfo Cmd - Gets the basic information about the firmware of the WiMOD. ...
Definition: WiMODLoRaWAN.cpp:283
WiMOD_SAP_LoRaWAN SapLoRaWan
Definition: WiMODLoRaWAN.h:183
void(* TDevMgmtPowerUpCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:93
Structure containing all data about LoRaWAN network status.
Definition: WiMOD_SAP_LORAWAN_IDs.h:651
Structure containing all data necessary to transmitting a data message.
Definition: WiMOD_SAP_LORAWAN_IDs.h:544
bool SetJoinParameter(TWiMODLORAWAN_JoinParams &joinParams, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the parameters used for the OTAA activation procedure.
Definition: WiMODLoRaWAN.cpp:880
bool GetCustomConfig(INT8 *txPwrOffset, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Get the current offet for tx power level; expert level only.
Definition: WiMODLoRaWAN.cpp:1975
~WiMODLoRaWAN(void)
Desctructor.
Definition: WiMODLoRaWAN.cpp:85
Structure containing RX (user) payload data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:555