Demo HCI Implementation for WiMOD-LR Devices  V2.0.3
WiMODLR_BASE.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 
33 
39 /*
40  * THIS FILE IMPLEMENTS THE HIGH LEVEL API FOR THE WiMOD LR BASE STACK
41  */
42 
43 
44 #ifndef WIMODLR_BASE_H_
45 #define WIMODLR_BASE_H_
46 
47 //-----------------------------------------------------------------------------
48 // Include files needed by this module
49 //-----------------------------------------------------------------------------
50 #include "Arduino.h"
51 /************
52  * BUG in ardunino.h ?
53  * -> https://stackoverflow.com/questions/41093090/esp8266-error-macro-min-passed-3-arguments-but-takes-just-2
54  */
55 
56 #include <string.h>
57 
58 #include "utils/WMDefs.h"
59 #include "utils/ComSLIP.h"
60 #include "HCI/WiMODLRHCI.h"
61 #include "utils/FreqCalc_SX127x.h"
62 
63 #include "SAP/WiMOD_SAP_DEVMGMT.h"
65 #include "SAP/WiMOD_SAP_Generic.h"
66 #include "SAP/WiMOD_SAP_HWTest.h"
67 
68 
69 /*
70  * C++11 supports a better way for function pointers / function objects
71  * But C++11 mode is not supported by all platforms.
72  */
73 #ifdef WIMOD_USE_CPP11
74 #include <functional>
75 #endif
76 //-----------------------------------------------------------------------------
77 // common defines
78 //-----------------------------------------------------------------------------
80 #define WIMOD_LR_BASE_SERIAL_BAUDRATE 115200
81 
82 #define WiMOD_LR_BASE_TX_BUFFER_SIZE 100
83 //-----------------------------------------------------------------------------
85 // types for callback functions
86 //-----------------------------------------------------------------------------
87 
88 // C++11 check
89 #ifdef WIMOD_USE_CPP11
90  /* C++11 function callback definitions */
91 
93  typedef std::function<void (UINT8* data, UINT16 length)> TDataLinkRxUDataIndClient;
94 
96  typedef std::function<void (UINT8 status)> TDataLinkSendUdataIndClient;
97 
98 #else
99  /* pre C++11 function callback definitions */
100 
102  typedef void (*TDataLinkRxUDataIndClient)(UINT8* data, UINT16 length);
103 
105  typedef void (*TDataLinkSendUdataIndClient)(UINT8 status);
106 
107 #endif
108 
109 //-----------------------------------------------------------------------------
110 // API class declaration for the WiMOD LR BASE Stack
111 //
112 // note: this is NOT compliant with the WiMOD LoRaWAN Stack
113 //-----------------------------------------------------------------------------
114 
122 class WiMODLRBASE : public TWiMODLRHCI {
123 public:
124  /*explicit*/ WiMODLRBASE(Stream& s);
125  ~WiMODLRBASE(void);
126 
127  void begin(void);
128  void end(void);
129 
130  /*
131  * DevMgmt SAP
132  */
133  bool Ping(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
134  bool Reset(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
135  bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfo* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
136  bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
137  bool GetSystemStatus(TWiMODLR_DevMgmt_SystemStatus* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
138  bool GetRtc(UINT32* rtcTime,TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
139  bool SetRtc(const UINT32 rtcTime, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
140 
141  bool GetRadioConfig(TWiMODLR_DevMgmt_RadioConfig* radioCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
142  bool SetRadioConfig(const TWiMODLR_DevMgmt_RadioConfig* radioCfg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
143  bool ResetRadioConfig(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
144 
145  bool GetOperationMode(TWiMOD_OperationMode* opMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
146  bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
147 
148  bool SetRadioMode(const TRadioCfg_RadioMode radioMode, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
149 
150  bool SetAesKey(const UINT8* key, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
151  bool GetAesKey(UINT8* key, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
152 
153  bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
154  bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
155  bool ClearRtcAlarm(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
156 
159 
160  /*
161  * Radio Link SAP
162  */
163  bool SendUData(const TWiMODLR_RadioLink_Msg* txMsg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
164  bool SendCData(const TWiMODLR_RadioLink_Msg* txMsg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
165 
166  bool SetAckData(const TWiMODLR_RadioLink_Msg* txMsg, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
167 
168  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_Msg* radioLinkMsg);
169  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_CdataInd* cDataTxInfo);
170  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_UdataInd* cDataTxInfo);
171  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_AckTxInd_Msg* txAckIndInfo);
172  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_RawMsg* radioLinkRawMsg);
173 
176  void RegisterRawDataRxClient(TRadioLinkRawDataRxIndicationCallback cb);
182 
183 
184  /*
185  * Generic Cmd
186  */
187  bool ExecuteGenericCmd(TWiMODLR_Generic_CmdInfo* info, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
188 
189  /*
190  * Hardware Test SAP
191  */
192 // bool StartRadioTest(const TWiMODLR_HWTestParameter* testParams, TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
193 // bool StopRadioTest(TWiMODLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
194 
195 
196  void calcFreqToRegister(uint32_t freq, uint8_t* msb, uint8_t* mid, uint8_t* lsb);
197  uint32_t calcRegisterToFreq(uint8_t msb, uint8_t mid, uint8_t lsb);
198 
199 
201  UINT8 GetLastResponseStatus(void);
202 
203 protected:
204 
205  bool copyResultInfos(TWiMODLRResultCodes* hciResult, UINT8* rspStatus, UINT8 successValue);
206 
207 
208  virtual void ProcessUnexpectedRxMessage(TWiMODLR_HCIMessage& rxMsg);
209 
213 // WiMOD_SAP_HWTest SapHwTest; /*!< Service Access Point for 'HW Test' */
214 private:
216  UINT8 txBuffer[WiMOD_LR_BASE_TX_BUFFER_SIZE];
217 
218  UINT8 localStatusRsp;
219  bool cmdResult;
220 
221  TWiMODLRResultCodes localHciRes;
222 
223  TWiMODLRResultCodes lastHciRes;
224  UINT8 lastStatusRsp;
226 };
227 
228 
229 
230 #endif /* WIMODLR_BASE_H_ */
WiMOD_SAP_Generic
Implementation for the ServiceAccessPoint DeviceManagement.
Definition: WiMOD_SAP_Generic.h:78
WiMODLRBASE::Reset
bool Reset(TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Reset Cmd - Do a local reboot of the WiMOD module.
Definition: WiMODLR_BASE.cpp:220
TDataLinkSendUdataIndClient
void(* TDataLinkSendUdataIndClient)(UINT8 status)
Definition: WiMODLR_BASE.h:105
WiMODLRBASE::SetRadioConfig
bool SetRadioConfig(const TWiMODLR_DevMgmt_RadioConfig *radioCfg, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current configuration for the radio of the WiMOD module.
Definition: WiMODLR_BASE.cpp:521
WiMODLRBASE::GetRadioConfig
bool GetRadioConfig(TWiMODLR_DevMgmt_RadioConfig *radioCfg, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current configuration of the radio of the WiMOD module.
Definition: WiMODLR_BASE.cpp:471
WiMODLRBASE::GetLastResponseStatus
UINT8 GetLastResponseStatus(void)
Gets the value of the last status response value of the WiMOD.
Definition: WiMODLR_BASE.cpp:1838
WiMODLRBASE::~WiMODLRBASE
~WiMODLRBASE(void)
Destructor.
Definition: WiMODLR_BASE.cpp:88
WiMODLRBASE::Ping
bool Ping(TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Ping Cmd - Checks serial connetion to WiMOD module.
Definition: WiMODLR_BASE.cpp:187
WiMOD_SAP_DevMgmt
Implementation for the ServiceAccessPoint DeviceManagement.
Definition: WiMOD_SAP_DEVMGMT.h:109
TWiMODLRHCI
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:235
WiMODLRBASE::SetRtcAlarm
bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm *rtcAlarm, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets and enables the RTC alarm feature of the WiMOD.
Definition: WiMODLR_BASE.cpp:796
WiMODLRBASE::RegisterUDataTxClient
void RegisterUDataTxClient(TRadioLinkUDataTxIndicationCallback cb)
Register a callback function for the TX U-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1460
WiMODLRBASE::WiMODLRBASE
WiMODLRBASE(Stream &s)
Constructor.
Definition: WiMODLR_BASE.cpp:69
WiMODLRBASE::RegisterCDataTxClient
void RegisterCDataTxClient(TRadioLinkCDataTxIndicationCallback cb)
Register a callback function for the TX C-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1575
WiMODLRBASE::SapDevMgmt
WiMOD_SAP_DevMgmt SapDevMgmt
Definition: WiMODLR_BASE.h:210
WiMODLRBASE::SetRtc
bool SetRtc(const UINT32 rtcTime, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current RTC values to WiMOD module.
Definition: WiMODLR_BASE.cpp:425
WiMODLRBASE::RegisterUDataRxClient
void RegisterUDataRxClient(TRadioLinkUDataRxIndicationCallback cb)
Register a callback function for the RX U-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1418
WiMODLRBASE::GetDeviceInfo
bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfo *info, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the basic DeviceInfo from WiMOD module.
Definition: WiMODLR_BASE.cpp:259
TWiMODLR_DevMgmt_FwInfo
Basic information about the current firmware of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:220
WiMODLRBASE::RegisterRtcAlarmIndicationClient
void RegisterRtcAlarmIndicationClient(TDevMgmtRtcAlarmCallback cb)
Register a callback function for the RTC Alarm Indication - optional -.
Definition: WiMODLR_BASE.cpp:947
TWiMODLR_AckTxInd_Msg
Structure containing information about an acknowledgment transmission.
Definition: WiMOD_SAP_RadioLink_IDs.h:243
TWiMODLR_HCIMessage
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
WiMODLRBASE::SetRadioMode
bool SetRadioMode(const TRadioCfg_RadioMode radioMode, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
SetRadioMode - Set the current radio mode of the WiMOD.
Definition: WiMODLR_BASE.cpp:583
WiMODLRBASE::GetOperationMode
bool GetOperationMode(TWiMOD_OperationMode *opMode, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current operation mode of the WiMOD module.
Definition: WiMODLR_BASE.cpp:625
WiMODLRBASE::RegisterPowerUpIndicationClient
void RegisterPowerUpIndicationClient(TDevMgmtPowerUpCallback cb)
Register a callback function for the PowerUp Indication - optional -.
Definition: WiMODLR_BASE.cpp:910
WiMOD_SAP_DEVMGMT.h
TWiMODLR_DevMgmt_RtcAlarm
Structure containing the RTC Alarm config parameters of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:484
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
WiMODLRBASE::convert
bool convert(TWiMODLR_HCIMessage &RxMsg, TWiMODLR_RadioLink_Msg *radioLinkMsg)
Convert a received low level HCI-Msg to a high-level RadioLink-Msg.
Definition: WiMODLR_BASE.cpp:1129
WiMODLRBASE
Main class representing the interface to the WiMOD running the firmware WiMODLR-BASE.
Definition: WiMODLR_BASE.h:122
TDataLinkRxUDataIndClient
void(* TDataLinkRxUDataIndClient)(UINT8 *data, UINT16 length)
Definition: WiMODLR_BASE.h:102
WiMODLRBASE::SapRadioLink
WiMOD_SAP_RadioLink SapRadioLink
Definition: WiMODLR_BASE.h:211
WiMODLRBASE::SendUData
bool SendUData(const TWiMODLR_RadioLink_Msg *txMsg, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Tries to send transmit U-Data to peer module via RF link.
Definition: WiMODLR_BASE.cpp:1002
WiMODLRBASE::end
void end(void)
De-Setup internal things.
Definition: WiMODLR_BASE.cpp:122
TRadioCfg_RadioMode
TRadioCfg_RadioMode
general operation mode of the radio part (only for LR-BASE)
Definition: WiMOD_SAP_DEVMGMT_IDs.h:255
WiMODLRBASE::RegisterAckRxTimeoutClient
void RegisterAckRxTimeoutClient(TRadioLinkAckRxTimeoutIndicationCallback cb)
Register a callback function for the Ack Timeout Indication - optional -.
Definition: WiMODLR_BASE.cpp:1671
WiMODLRBASE::GetRtc
bool GetRtc(UINT32 *rtcTime, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current RTC data info from WiMOD module.
Definition: WiMODLR_BASE.cpp:386
WiMODLRBASE::GetFirmwareInfo
bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo *info, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the basic FirmwareInfo from WiMOD module.
Definition: WiMODLR_BASE.cpp:298
ComSLIP.h
WiMODLRBASE::SetAesKey
bool SetAesKey(const UINT8 *key, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the security 128bit AES key to use for RF communication.
Definition: WiMODLR_BASE.cpp:703
WiMODLRBASE::GetAesKey
bool GetAesKey(UINT8 *key, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the used security 128bit AES key.
Definition: WiMODLR_BASE.cpp:742
WiMODLRBASE::GetSystemStatus
bool GetSystemStatus(TWiMODLR_DevMgmt_SystemStatus *info, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the bas SystemStatus info from WiMOD module.
Definition: WiMODLR_BASE.cpp:339
TWiMODLR_DevMgmt_DevInfo
Structure containing basic information about the WiMOD device.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:172
WiMODLRBASE::calcRegisterToFreq
uint32_t calcRegisterToFreq(uint8_t msb, uint8_t mid, uint8_t lsb)
Convert a frequency registers to frequency in Hz.
Definition: WiMODLR_BASE.cpp:1747
WiMODLRBASE::RegisterCDataRxClient
void RegisterCDataRxClient(TRadioLinkCDataRxIndicationCallback cb)
Register a callback function for the RX C-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1528
WiMODLRBASE::RegisterAckRxClient
void RegisterAckRxClient(TRadioLinkAckRxIndicationCallback cb)
Register a callback function for the RX Ack (+data) Indication - optional -.
Definition: WiMODLR_BASE.cpp:1623
WiMODLRBASE::begin
void begin(void)
Setup internal things.
Definition: WiMODLR_BASE.cpp:111
WiMODLRBASE::SetAckData
bool SetAckData(const TWiMODLR_RadioLink_Msg *txMsg, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets additional user payload for the next ack frame to send.
Definition: WiMODLR_BASE.cpp:1368
WiMODLRBASE::SapGeneric
WiMOD_SAP_Generic SapGeneric
Definition: WiMODLR_BASE.h:212
WiMODLRBASE::ClearRtcAlarm
bool ClearRtcAlarm(TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Clears pending RTC Alarms of the WiMOD.
Definition: WiMODLR_BASE.cpp:868
WiMODLRBASE::calcFreqToRegister
void calcFreqToRegister(uint32_t freq, uint8_t *msb, uint8_t *mid, uint8_t *lsb)
Convert a frequency in Hz to the corresponding low level register values.
Definition: WiMODLR_BASE.cpp:1731
WiMODLRBASE::SendCData
bool SendCData(const TWiMODLR_RadioLink_Msg *txMsg, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Tries to send transmit C-Data to peer module via RF link.
Definition: WiMODLR_BASE.cpp:1064
WiMODLRBASE::ExecuteGenericCmd
bool ExecuteGenericCmd(TWiMODLR_Generic_CmdInfo *info, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Generic Execution Function for HCI commands that are currently not implemented.
Definition: WiMODLR_BASE.cpp:1898
TWiMODLRResultCodes
TWiMODLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
WiMODLRBASE::SetOperationMode
bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current operation mode of the WiMOD module.
Definition: WiMODLR_BASE.cpp:666
WiMODLRBASE::ResetRadioConfig
bool ResetRadioConfig(TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Resets the current configuration to defaults.
Definition: WiMODLR_BASE.cpp:556
WiMOD_SAP_Generic.h
TDevMgmtRtcAlarmCallback
void(* TDevMgmtRtcAlarmCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:96
TDevMgmtPowerUpCallback
void(* TDevMgmtPowerUpCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:93
TWiMODLR_DevMgmt_RadioConfig
Structure containing the radio (stack) config parameters of the WiMOD (only for LR-BASE)
Definition: WiMOD_SAP_DEVMGMT_IDs.h:406
WiMODLRBASE::GetRtcAlarm
bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm *rtcAlarm, TWiMODLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets information about the RTC alarm feature of the WiMOD.
Definition: WiMODLR_BASE.cpp:839
TWiMODLR_DevMgmt_SystemStatus
Basic information about system status of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:234
FreqCalc_SX127x.h
WiMODLRBASE::GetLastHciResult
TWiMODLRResultCodes GetLastHciResult(void)
Gets the value of the last local HCI TX status.
Definition: WiMODLR_BASE.cpp:1793
WiMODLRBASE::RegisterAckTxCallback
void RegisterAckTxCallback(TRadioLinkAckTxIndicationCallback cb)
Register a callback function for the TX Ack Indication - optional -.
Definition: WiMODLR_BASE.cpp:1715