Demo HCI Implementation for WiMOD-LR Devices  V1.3.1
WiMOD_SAP_LORAWAN.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 
33 
34 #ifndef ARDUINO_WIMOD_SAP_LORAWAN_H_
35 #define ARDUINO_WIMOD_SAP_LORAWAN_H_
36 
37 /*
38  * THIS IS AN EXAMPLE IMPLEMENTATION ACCORDING THE THE HCI SPEC: V1.11
39  * FOR FIRMWARE: LoRaWAN_EndNode_Modem
40  *
41  * SEE FILE: WiMOD_LoRaWAN_EndNode_Modem_HCI_Spec_V1_11.pdf
42  * for detailed information
43  *
44  */
45 
46 
47 //------------------------------------------------------------------------------
48 //
49 // Section Includes Files
50 //
51 //------------------------------------------------------------------------------
52 
53 #include "WiMOD_SAP_LORAWAN_IDs.h"
54 #include "../HCI/WiMODLRHCI.h"
55 
56 /*
57  * C++11 supports a better way for function pointers / function objects
58  * But C++11 mode is not supported by all platforms.
59  */
60 #ifdef WIMOD_USE_CPP11
61 #include <functional>
62 #endif
63 //------------------------------------------------------------------------------
64 //
65 // Section defines
66 //
67 //------------------------------------------------------------------------------
68 
70 #define WiMOD_LORAWAN_TX_PAYLOAD_SIZE (WiMODLORAWAN_APP_PAYLOAD_LEN + 5)
71 
73 
74 //-----------------------------------------------------------------------------
75 //
76 // types for callback functions
77 //
78 //-----------------------------------------------------------------------------
79 
80 // C++11 check
81 #ifdef WIMOD_USE_CPP11
82 /* C++11 function callback definitions */
83 
85  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TJoinTxIndicationCallback;
86 
88  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TJoinedNwkIndicationCallback;
89 
91  typedef std::function<void (void)> TNoDataIndicationCallback;
92 
94  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TTxCDataIndicationCallback;
95 
97  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TTxUDataIndicationCallback;
98 
100  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TRxUDataIndicationCallback;
101 
103  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TRxCDataIndicationCallback;
104 
106  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TRxMacCmdIndicationCallback;
107 
109  typedef std::function<void (TWiMODLR_HCIMessage& rxMsg)> TRxAckIndicationCallback;
110 
111 #else
112  /* pre C++11 function callback definitions */
113 
116 
119 
121  typedef void (*TNoDataIndicationCallback)(void);
122 
125 
128 
131 
134 
137 
140 
141 #endif
142 
143 
144 //------------------------------------------------------------------------------
145 //
146 // Section class
147 //
148 //------------------------------------------------------------------------------
149 
154 public:
155 
156  WiMOD_SAP_LoRaWAN(TWiMODLRHCI* hci, UINT8* buffer, UINT16 bufferSize);
157  ~WiMOD_SAP_LoRaWAN(void);
158 
159 
160  TWiMDLRResultCodes ActivateDevice(TWiMODLORAWAN_ActivateDeviceData& activationData, UINT8* statusRsp);
161  TWiMDLRResultCodes ReactivateDevice(UINT32* devAdr, UINT8* statusRsp);
162  TWiMDLRResultCodes SetJoinParameter(TWiMODLORAWAN_JoinParams& joinParams, UINT8* statusRsp);
163  TWiMDLRResultCodes JoinNetwork(UINT8* statusRsp);
164 
166 
167 // bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_JoinNwkTxIndData* indicationData);
168  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_Data* loraWanRxData);
169 // bool convert(TWiMODLR_HCIMessage& rxMsg, TWiMODLORAWAN_SendDataTxInd_Data* sendIndData);
170  bool convert(TWiMODLR_HCIMessage& rxMsg, TWiMODLORAWAN_TxIndData* sendIndData);
171  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_MacCmdData* loraWanMacCmdData);
172  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_JoinedNwkData* joinedNwkData);
174 
175 
184 
185 
186  TWiMDLRResultCodes SendUData(const TWiMODLORAWAN_TX_Data* data, UINT8* statusRsp);
187  TWiMDLRResultCodes SendCData(const TWiMODLORAWAN_TX_Data* data, UINT8* statusRsp);
190  TWiMDLRResultCodes DeactivateDevice(UINT8* statusRsp);
191  TWiMDLRResultCodes FactoryReset(UINT8* statusRsp);
192  TWiMDLRResultCodes SetDeviceEUI(const UINT8* deviceEUI, UINT8* statusRsp);
193  TWiMDLRResultCodes GetDeviceEUI(UINT8* deviceEUI, UINT8* statusRsp);
194 // TWiMDLRResultCodes GetNwkStatus(UINT8* nwkStatus, UINT8* statusRsp); // implementation up to spec V1.13
195  TWiMDLRResultCodes GetNwkStatus(TWiMODLORAWAN_NwkStatus_Data* nwkStatus, UINT8* statusRsp); // new implemation for spec. V1.14
196 
197  TWiMDLRResultCodes SendMacCmd(const TWiMODLORAWAN_MacCmd* cmd, UINT8* statusRsp);
198  TWiMDLRResultCodes SetCustomConfig(const INT8 txPwrOffset, UINT8* statusRsp);
199  TWiMDLRResultCodes GetCustomConfig(INT8* txPwrOffset, UINT8* statusRsp);
200 
201  void DispatchLoRaWANMessage(TWiMODLR_HCIMessage& rxMsg);
202 protected:
204  TJoinTxIndicationCallback JoinTxIndCallback;
205  TNoDataIndicationCallback NoDataIndCallback;
206  TTxCDataIndicationCallback TxCDataIndCallback;
207  TTxUDataIndicationCallback TxUDataIndCallback;
208  TRxUDataIndicationCallback RxUDataIndCallback;
209  TRxCDataIndicationCallback RxCDataIndCallback;
210  TRxMacCmdIndicationCallback RxMacCmdIndCallback;
211  TJoinedNwkIndicationCallback JoinedNwkIndCallback;
212  TRxAckIndicationCallback RxAckIndCallback;
214 private:
216  UINT8* txPayload;
217  UINT16 txPayloadSize;
218  TWiMODLRHCI* HciParser;
220 
221 };
222 
223 
224 #endif /* ARDUINO_WIMOD_SAP_LORAWAN_H_ */
Structure containing data of the joined network indication.
Definition: WiMOD_SAP_LORAWAN_IDs.h:592
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:481
Supporting IDs and definitions for the LoRaWAN ServiceAccessPoint.
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
~WiMOD_SAP_LoRaWAN(void)
Destructor.
Definition: WiMOD_SAP_LORAWAN.cpp:90
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
void RegisterNoDataIndicationClient(TNoDataIndicationCallback cb)
Register a callback function for the event "TX Join Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:657
void RegisterRxAckIndicationClient(TRxAckIndicationCallback cb)
Register a callback function for the event "RX ACK (data) Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:762
void(* TJoinTxIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:115
TWiMDLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
TWiMDLRResultCodes GetNwkStatus(TWiMODLORAWAN_NwkStatus_Data *nwkStatus, UINT8 *statusRsp)
Gets the current status of the network "connection".
Definition: WiMOD_SAP_LORAWAN.cpp:1036
TWiMDLRResultCodes SendMacCmd(const TWiMODLORAWAN_MacCmd *cmd, UINT8 *statusRsp)
Send a MAC command to the server; expert level only.
Definition: WiMOD_SAP_LORAWAN.cpp:1088
bool convert(TWiMODLR_HCIMessage &RxMsg, TWiMODLORAWAN_RX_Data *loraWanRxData)
Convert a received low level HCI-Msg to a high-level Rx Data structure.
Definition: WiMOD_SAP_LORAWAN.cpp:426
TWiMDLRResultCodes SetJoinParameter(TWiMODLORAWAN_JoinParams &joinParams, UINT8 *statusRsp)
Sets the parameters used for the OTAA activation procedure.
Definition: WiMOD_SAP_LORAWAN.cpp:190
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
void RegisterJoinedNwkIndicationClient(TJoinedNwkIndicationCallback cb)
Register a callback function for the event "Joined Nwk Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:747
void(* TRxAckIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:139
TWiMDLRResultCodes SetRadioStackConfig(const TWiMODLORAWAN_RadioStackConfig *data, UINT8 *statusRsp)
Sets a new radio config parameter set of the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:780
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:229
void RegisterTxCDataIndicationClient(TTxCDataIndicationCallback cb)
Register a callback function for the event "TX C-Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:672
void(* TJoinedNwkIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:118
TWiMDLRResultCodes ActivateDevice(TWiMODLORAWAN_ActivateDeviceData &activationData, UINT8 *statusRsp)
Activates the device via the APB procedure.
Definition: WiMOD_SAP_LORAWAN.cpp:108
TWiMDLRResultCodes SendUData(const TWiMODLORAWAN_TX_Data *data, UINT8 *statusRsp)
Tries to send transmit U-Data to network server via RF link.
Definition: WiMOD_SAP_LORAWAN.cpp:257
WiMOD_SAP_LoRaWAN(TWiMODLRHCI *hci, UINT8 *buffer, UINT16 bufferSize)
Constructor.
Definition: WiMOD_SAP_LORAWAN.cpp:68
void RegisterRxCDataIndicationClient(TRxCDataIndicationCallback cb)
Register a callback function for the event "RX C-Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:717
TWiMDLRResultCodes SetDeviceEUI(const UINT8 *deviceEUI, UINT8 *statusRsp)
Sets a new DeviceEUI (aka. IEEE-Address) to the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:925
TWiMDLRResultCodes SendCData(const TWiMODLORAWAN_TX_Data *data, UINT8 *statusRsp)
Tries to send transmit C-Data to network server via RF link.
Definition: WiMOD_SAP_LORAWAN.cpp:304
void(* TRxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:130
JOIN data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:492
TWiMDLRResultCodes JoinNetwork(UINT8 *statusRsp)
Start joining the network via the OTAA procedure. Asynchronous process.
Definition: WiMOD_SAP_LORAWAN.cpp:228
void RegisterJoinTxIndicationClient(TJoinTxIndicationCallback cb)
Register a callback function for the event "TX Join Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:342
void RegisterRxMacCmdIndicationClient(TRxMacCmdIndicationCallback cb)
Register a callback function for the event "RX MAC Cmd Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:732
void RegisterRxUDataIndicationClient(TRxUDataIndicationCallback cb)
Register a callback function for the event "RX U-Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:702
TWiMDLRResultCodes DeactivateDevice(UINT8 *statusRsp)
Deactivate the device (logical disconnect from lora network)
Definition: WiMOD_SAP_LORAWAN.cpp:864
Data structure for received Acknowledgment data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:634
TWiMDLRResultCodes GetDeviceEUI(UINT8 *deviceEUI, UINT8 *statusRsp)
Gets the DeviceEUI (aka. IEEE-Address) of the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:962
void RegisterTxUDataIndicationClient(TTxUDataIndicationCallback cb)
Register a callback function for the event "TX U Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:687
TWiMDLRResultCodes ReactivateDevice(UINT32 *devAdr, UINT8 *statusRsp)
Re-Activates the device via the APB procedure.
Definition: WiMOD_SAP_LORAWAN.cpp:149
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
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
TWiMDLRResultCodes GetCustomConfig(INT8 *txPwrOffset, UINT8 *statusRsp)
Get the current offet for tx power level; expert level only.
Definition: WiMOD_SAP_LORAWAN.cpp:1169
TWiMDLRResultCodes FactoryReset(UINT8 *statusRsp)
Reset all internal settings to default values (incl. DevEUI)
Definition: WiMOD_SAP_LORAWAN.cpp:892
TWiMDLRResultCodes SetCustomConfig(const INT8 txPwrOffset, UINT8 *statusRsp)
Setup a custom config for tx power settings; expert level only.
Definition: WiMOD_SAP_LORAWAN.cpp:1135
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
TWiMDLRResultCodes GetRadioStackConfig(TWiMODLORAWAN_RadioStackConfig *data, UINT8 *statusRsp)
Gets the current radio config parameter set of the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:824
Structure containing RX (user) payload data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:555