| Demo HCI Implementation for WiMOD-LR Devices V1.3.1

- Main Page
- Classes
- Files

- File List
- File Members

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
115 typedef void (*TJoinTxIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
116
118 typedef void (*TJoinedNwkIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
119
121 typedef void (*TNoDataIndicationCallback)(void);
122
124 typedef void (*TTxCDataIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
125
127 typedef void (*TTxUDataIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
128
130 typedef void (*TRxUDataIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
131
133 typedef void (*TRxCDataIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
134
136 typedef void (*TRxMacCmdIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
137
139 typedef void (*TRxAckIndicationCallback)(TWiMODLR_HCIMessage& rxMsg);
140
141 #endif
142
143
144 //------------------------------------------------------------------------------
145 //
146 // Section class
147 //
148 //------------------------------------------------------------------------------
149
153 class WiMOD_SAP_LoRaWAN {
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
165 void RegisterJoinTxIndicationClient(TJoinTxIndicationCallback cb);
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);
173 bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLORAWAN_RX_ACK_Data* ackData);
174
175
176 void RegisterNoDataIndicationClient(TNoDataIndicationCallback cb);
177 void RegisterTxCDataIndicationClient(TTxCDataIndicationCallback cb);
178 void RegisterTxUDataIndicationClient(TTxUDataIndicationCallback cb);
179 void RegisterRxUDataIndicationClient(TRxUDataIndicationCallback cb);
180 void RegisterRxCDataIndicationClient(TRxCDataIndicationCallback cb);
181 void RegisterRxMacCmdIndicationClient(TRxMacCmdIndicationCallback cb);
182 void RegisterJoinedNwkIndicationClient(TJoinedNwkIndicationCallback cb);
183 void RegisterRxAckIndicationClient(TRxAckIndicationCallback cb);
184
185
186 TWiMDLRResultCodes SendUData(const TWiMODLORAWAN_TX_Data* data, UINT8* statusRsp);
187 TWiMDLRResultCodes SendCData(const TWiMODLORAWAN_TX_Data* data, UINT8* statusRsp);
188 TWiMDLRResultCodes SetRadioStackConfig(const TWiMODLORAWAN_RadioStackConfig* data, UINT8* statusRsp);
189 TWiMDLRResultCodes GetRadioStackConfig(TWiMODLORAWAN_RadioStackConfig* 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_ */
TWiMODLORAWAN_RX_JoinedNwkData
Structure containing data of the joined network indication.
Definition: WiMOD_SAP_LORAWAN_IDs.h:592
TWiMODLORAWAN_ActivateDeviceData
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:481
WiMOD_SAP_LORAWAN_IDs.h
Supporting IDs and definitions for the LoRaWAN ServiceAccessPoint.
TRxCDataIndicationCallback
void(* TRxCDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:133
WiMOD_SAP_LoRaWAN
Implementation for the ServiceAccessPoint LoRaWAN (End Node Modem firmware only)
Definition: WiMOD_SAP_LORAWAN.h:153
WiMOD_SAP_LoRaWAN::~WiMOD_SAP_LoRaWAN
~WiMOD_SAP_LoRaWAN(void)
Destructor.
Definition: WiMOD_SAP_LORAWAN.cpp:90
TWiMODLORAWAN_RX_MacCmdData
Structure containing a received MAC command.
Definition: WiMOD_SAP_LORAWAN_IDs.h:575
TTxCDataIndicationCallback
void(* TTxCDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:124
TRxMacCmdIndicationCallback
void(* TRxMacCmdIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:136
WiMOD_SAP_LoRaWAN::RegisterNoDataIndicationClient
void RegisterNoDataIndicationClient(TNoDataIndicationCallback cb)
Register a callback function for the event "TX Join Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:657
WiMOD_SAP_LoRaWAN::RegisterRxAckIndicationClient
void RegisterRxAckIndicationClient(TRxAckIndicationCallback cb)
Register a callback function for the event "RX ACK (data) Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:762
TJoinTxIndicationCallback
void(* TJoinTxIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:115
TWiMDLRResultCodes
TWiMDLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
WiMOD_SAP_LoRaWAN::GetNwkStatus
TWiMDLRResultCodes GetNwkStatus(TWiMODLORAWAN_NwkStatus_Data *nwkStatus, UINT8 *statusRsp)
Gets the current status of the network "connection".
Definition: WiMOD_SAP_LORAWAN.cpp:1036
WiMOD_SAP_LoRaWAN::SendMacCmd
TWiMDLRResultCodes SendMacCmd(const TWiMODLORAWAN_MacCmd *cmd, UINT8 *statusRsp)
Send a MAC command to the server; expert level only.
Definition: WiMOD_SAP_LORAWAN.cpp:1088
WiMOD_SAP_LoRaWAN::convert
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
WiMOD_SAP_LoRaWAN::SetJoinParameter
TWiMDLRResultCodes SetJoinParameter(TWiMODLORAWAN_JoinParams &joinParams, UINT8 *statusRsp)
Sets the parameters used for the OTAA activation procedure.
Definition: WiMOD_SAP_LORAWAN.cpp:190
TWiMODLR_HCIMessage
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
WiMOD_SAP_LoRaWAN::RegisterJoinedNwkIndicationClient
void RegisterJoinedNwkIndicationClient(TJoinedNwkIndicationCallback cb)
Register a callback function for the event "Joined Nwk Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:747
TRxAckIndicationCallback
void(* TRxAckIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:139
WiMOD_SAP_LoRaWAN::SetRadioStackConfig
TWiMDLRResultCodes SetRadioStackConfig(const TWiMODLORAWAN_RadioStackConfig *data, UINT8 *statusRsp)
Sets a new radio config parameter set of the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:780
TWiMODLRHCI
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:229
WiMOD_SAP_LoRaWAN::RegisterTxCDataIndicationClient
void RegisterTxCDataIndicationClient(TTxCDataIndicationCallback cb)
Register a callback function for the event "TX C-Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:672
TJoinedNwkIndicationCallback
void(* TJoinedNwkIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:118
WiMOD_SAP_LoRaWAN::ActivateDevice
TWiMDLRResultCodes ActivateDevice(TWiMODLORAWAN_ActivateDeviceData &activationData, UINT8 *statusRsp)
Activates the device via the APB procedure.
Definition: WiMOD_SAP_LORAWAN.cpp:108
WiMOD_SAP_LoRaWAN::SendUData
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::WiMOD_SAP_LoRaWAN
WiMOD_SAP_LoRaWAN(TWiMODLRHCI *hci, UINT8 *buffer, UINT16 bufferSize)
Constructor.
Definition: WiMOD_SAP_LORAWAN.cpp:68
WiMOD_SAP_LoRaWAN::RegisterRxCDataIndicationClient
void RegisterRxCDataIndicationClient(TRxCDataIndicationCallback cb)
Register a callback function for the event "RX C-Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:717
WiMOD_SAP_LoRaWAN::SetDeviceEUI
TWiMDLRResultCodes SetDeviceEUI(const UINT8 *deviceEUI, UINT8 *statusRsp)
Sets a new DeviceEUI (aka. IEEE-Address) to the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:925
WiMOD_SAP_LoRaWAN::SendCData
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
TRxUDataIndicationCallback
void(* TRxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:130
TWiMODLORAWAN_JoinParams
JOIN data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:492
WiMOD_SAP_LoRaWAN::JoinNetwork
TWiMDLRResultCodes JoinNetwork(UINT8 *statusRsp)
Start joining the network via the OTAA procedure. Asynchronous process.
Definition: WiMOD_SAP_LORAWAN.cpp:228
WiMOD_SAP_LoRaWAN::RegisterJoinTxIndicationClient
void RegisterJoinTxIndicationClient(TJoinTxIndicationCallback cb)
Register a callback function for the event "TX Join Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:342
WiMOD_SAP_LoRaWAN::RegisterRxMacCmdIndicationClient
void RegisterRxMacCmdIndicationClient(TRxMacCmdIndicationCallback cb)
Register a callback function for the event "RX MAC Cmd Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:732
WiMOD_SAP_LoRaWAN::RegisterRxUDataIndicationClient
void RegisterRxUDataIndicationClient(TRxUDataIndicationCallback cb)
Register a callback function for the event "RX U-Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:702
WiMOD_SAP_LoRaWAN::DeactivateDevice
TWiMDLRResultCodes DeactivateDevice(UINT8 *statusRsp)
Deactivate the device (logical disconnect from lora network)
Definition: WiMOD_SAP_LORAWAN.cpp:864
TWiMODLORAWAN_RX_ACK_Data
Data structure for received Acknowledgment data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:634
WiMOD_SAP_LoRaWAN::GetDeviceEUI
TWiMDLRResultCodes GetDeviceEUI(UINT8 *deviceEUI, UINT8 *statusRsp)
Gets the DeviceEUI (aka. IEEE-Address) of the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:962
WiMOD_SAP_LoRaWAN::RegisterTxUDataIndicationClient
void RegisterTxUDataIndicationClient(TTxUDataIndicationCallback cb)
Register a callback function for the event "TX U Data Indication".
Definition: WiMOD_SAP_LORAWAN.cpp:687
WiMOD_SAP_LoRaWAN::ReactivateDevice
TWiMDLRResultCodes ReactivateDevice(UINT32 *devAdr, UINT8 *statusRsp)
Re-Activates the device via the APB procedure.
Definition: WiMOD_SAP_LORAWAN.cpp:149
TWiMODLORAWAN_TxIndData
Activation data structure for LoRa network activation.
Definition: WiMOD_SAP_LORAWAN_IDs.h:514
TWiMODLORAWAN_MacCmd
LoRaWAN MAC command structure.
Definition: WiMOD_SAP_LORAWAN_IDs.h:622
TNoDataIndicationCallback
void(* TNoDataIndicationCallback)(void)
Definition: WiMOD_SAP_LORAWAN.h:121
TWiMODLORAWAN_RadioStackConfig
Radio stack configuration related to to LoRaWAN specific options.
Definition: WiMOD_SAP_LORAWAN_IDs.h:609
TTxUDataIndicationCallback
void(* TTxUDataIndicationCallback)(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMOD_SAP_LORAWAN.h:127
WiMOD_SAP_LoRaWAN::GetCustomConfig
TWiMDLRResultCodes GetCustomConfig(INT8 *txPwrOffset, UINT8 *statusRsp)
Get the current offet for tx power level; expert level only.
Definition: WiMOD_SAP_LORAWAN.cpp:1169
WiMOD_SAP_LoRaWAN::FactoryReset
TWiMDLRResultCodes FactoryReset(UINT8 *statusRsp)
Reset all internal settings to default values (incl. DevEUI)
Definition: WiMOD_SAP_LORAWAN.cpp:892
WiMOD_SAP_LoRaWAN::SetCustomConfig
TWiMDLRResultCodes SetCustomConfig(const INT8 txPwrOffset, UINT8 *statusRsp)
Setup a custom config for tx power settings; expert level only.
Definition: WiMOD_SAP_LORAWAN.cpp:1135
TWiMODLORAWAN_NwkStatus_Data
Structure containing all data about LoRaWAN network status.
Definition: WiMOD_SAP_LORAWAN_IDs.h:651
TWiMODLORAWAN_TX_Data
Structure containing all data necessary to transmitting a data message.
Definition: WiMOD_SAP_LORAWAN_IDs.h:544
WiMOD_SAP_LoRaWAN::GetRadioStackConfig
TWiMDLRResultCodes GetRadioStackConfig(TWiMODLORAWAN_RadioStackConfig *data, UINT8 *statusRsp)
Gets the current radio config parameter set of the WiMOD.
Definition: WiMOD_SAP_LORAWAN.cpp:824
TWiMODLORAWAN_RX_Data
Structure containing RX (user) payload data.
Definition: WiMOD_SAP_LORAWAN_IDs.h:555