Demo HCI Implementation for WiMOD-LR Devices  V1.3.1
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 #include <string.h>
52 
53 #include "utils/WMDefs.h"
54 #include "utils/ComSLIP.h"
55 #include "HCI/WiMODLRHCI.h"
56 
57 #include "SAP/WiMOD_SAP_DEVMGMT.h"
59 
60 #include "SAP/WiMOD_SAP_HWTest.h"
61 
62 #include "utils/FreqCalc.h"
63 
64 /*
65  * C++11 supports a better way for function pointers / function objects
66  * But C++11 mode is not supported by all platforms.
67  */
68 #ifdef WIMOD_USE_CPP11
69 #include <functional>
70 #endif
71 //-----------------------------------------------------------------------------
72 // common defines
73 //-----------------------------------------------------------------------------
75 #define WIMOD_LR_BASE_SERIAL_BAUDRATE 115200
76 
77 #define WiMOD_LR_BASE_TX_BUFFER_SIZE 100
78 //-----------------------------------------------------------------------------
80 // types for callback functions
81 //-----------------------------------------------------------------------------
82 
83 // C++11 check
84 #ifdef WIMOD_USE_CPP11
85  /* C++11 function callback definitions */
86 
88  typedef std::function<void (UINT8* data, UINT16 length)> TDataLinkRxUDataIndClient;
89 
91  typedef std::function<void (UINT8 status)> TDataLinkSendUdataIndClient;
92 
93 #else
94  /* pre C++11 function callback definitions */
95 
97  typedef void (*TDataLinkRxUDataIndClient)(UINT8* data, UINT16 length);
98 
100  typedef void (*TDataLinkSendUdataIndClient)(UINT8 status);
101 
102 #endif
103 
104 //-----------------------------------------------------------------------------
105 // API class declaration for the WiMOD LR BASE Stack
106 //
107 // note: this is NOT compliant with the WiMOD LoRaWAN Stack
108 //-----------------------------------------------------------------------------
109 
117 class WiMODLRBASE : public TWiMODLRHCI {
118 public:
119  WiMODLRBASE(Stream& s);
120  ~WiMODLRBASE(void);
121 
122  void begin(void);
123  void end(void);
124 
125  /*
126  * DevMgmt SAP
127  */
128  bool Ping(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
129  bool Reset(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
130  bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfo* info, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
131  bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo* info, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
132  bool GetSystemStatus(TWiMODLR_DevMgmt_SystemStatus* info, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
133  bool GetRtc(UINT32* rtcTime,TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
134  bool SetRtc(const UINT32 rtcTime, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
135 
136  bool GetRadioConfig(TWiMODLR_DevMgmt_RadioConfig* radioCfg, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
137  bool SetRadioConfig(const TWiMODLR_DevMgmt_RadioConfig* radioCfg, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
138  bool ResetRadioConfig(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
139 
140  bool GetOperationMode(TWiMOD_OperationMode* opMode, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
141  bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
142 
143  bool SetAesKey(const UINT8* key, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
144  bool GetAesKey(UINT8* key, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
145 
146  bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
147  bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm* rtcAlarm, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
148  bool ClearRtcAlarm(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
149 
152 
153  /*
154  * Radio Link SAP
155  */
156  bool SendUData(const TWiMODLR_RadioLink_Msg* txMsg, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
157  bool SendCData(const TWiMODLR_RadioLink_Msg* txMsg, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
158 
159  bool SetAckData(const TWiMODLR_RadioLink_Msg* txMsg, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
160 
161  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_Msg* radioLinkMsg);
162  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_RadioLink_CdataInd* cDataTxInfo);
163  bool convert(TWiMODLR_HCIMessage& RxMsg, TWiMODLR_AckTxInd_Msg* txAckIndInfo);
164 
167  void RegisterRawDataRxClient(TRadioLinkRawDataRxIndicationCallback cb);
173 
174  /*
175  * Hardware Test SAP
176  */
177 // bool StartRadioTest(const TWiMODLR_HWTestParameter* testParams, TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
178 // bool StopRadioTest(TWiMDLRResultCodes* hciResult = NULL, UINT8* rspStatus = NULL);
179 
180 
181  void calcFreqToRegister(uint32_t freq, uint8_t* msb, uint8_t* mid, uint8_t* lsb);
182  uint32_t calcRegisterToFreq(uint8_t msb, uint8_t mid, uint8_t lsb);
183 
184 
186  UINT8 GetLastResponseStatus(void);
187 
188 protected:
189 
190  bool copyResultInfos(TWiMDLRResultCodes* hciResult, UINT8* rspStatus, UINT8 successValue);
191 
192 
193  virtual void ProcessUnexpectedRxMessage(TWiMODLR_HCIMessage& rxMsg);
194 
197 // WiMOD_SAP_HWTest SapHwTest; /*!< Service Access Point for 'HW Test' */
198 private:
200  UINT8 txBuffer[WiMOD_LR_BASE_TX_BUFFER_SIZE];
201 
202  UINT8 localStatusRsp;
203  bool cmdResult;
204 
205  TWiMDLRResultCodes localHciRes;
206 
207  TWiMDLRResultCodes lastHciRes;
208  UINT8 lastStatusRsp;
210 };
211 
212 
213 
214 #endif /* WIMODLR_BASE_H_ */
bool GetDeviceInfo(TWiMODLR_DevMgmt_DevInfo *info, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the basic DeviceInfo from WiMOD module.
Definition: WiMODLR_BASE.cpp:259
Basic information about system status of the WiMOD.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:208
bool GetSystemStatus(TWiMODLR_DevMgmt_SystemStatus *info, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the bas SystemStatus info from WiMOD module.
Definition: WiMODLR_BASE.cpp:339
bool GetFirmwareInfo(TWiMODLR_DevMgmt_FwInfo *info, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the basic FirmwareInfo from WiMOD module.
Definition: WiMODLR_BASE.cpp:298
void RegisterAckTxCallback(TRadioLinkAckTxIndicationCallback cb)
Register a callback function for the TX Ack Indication - optional -.
Definition: WiMODLR_BASE.cpp:1610
TWiMDLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
void(* TDevMgmtRtcAlarmCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:96
bool Reset(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Reset Cmd - Do a local reboot of the WiMOD module.
Definition: WiMODLR_BASE.cpp:220
void RegisterRtcAlarmIndicationClient(TDevMgmtRtcAlarmCallback cb)
Register a callback function for the RTC Alarm Indication - optional -.
Definition: WiMODLR_BASE.cpp:918
void end(void)
De-Setup internal things.
Definition: WiMODLR_BASE.cpp:122
bool SetRtc(const UINT32 rtcTime, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current RTC values to WiMOD module.
Definition: WiMODLR_BASE.cpp:425
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
void RegisterCDataTxClient(TRadioLinkCDataTxIndicationCallback cb)
Register a callback function for the TX C-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1470
Declarations for the DeviceManagement SericeAccessPoint.
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:229
void RegisterAckRxClient(TRadioLinkAckRxIndicationCallback cb)
Register a callback function for the RX Ack (+data) Indication - optional -.
Definition: WiMODLR_BASE.cpp:1518
Common low level HCI message processing base.
WiMOD_SAP_RadioLink SapRadioLink
Definition: WiMODLR_BASE.h:196
TWiMOD_OperationMode
This enum describes the possible operation modes of the WiMOD (only for LR-BASE). ...
Definition: WiMOD_SAP_DEVMGMT_IDs.h:410
void begin(void)
Setup internal things.
Definition: WiMODLR_BASE.cpp:111
Implementation for the ServiceAccessPoint DeviceManagement.
Definition: WiMOD_SAP_DEVMGMT.h:109
bool GetRtcAlarm(TWiMODLR_DevMgmt_RtcAlarm *rtcAlarm, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets information about the RTC alarm feature of the WiMOD.
Definition: WiMODLR_BASE.cpp:810
bool SetAesKey(const UINT8 *key, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the security 128bit AES key to use for RF communication.
Definition: WiMODLR_BASE.cpp:674
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:1100
Structure containing information about an acknowledgment transmission.
Definition: WiMOD_SAP_RadioLink_IDs.h:189
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:1626
Structure containing the radio (stack) config parameters of the WiMOD (only for LR-BASE) ...
Definition: WiMOD_SAP_DEVMGMT_IDs.h:376
WiMOD_SAP_DevMgmt SapDevMgmt
Definition: WiMODLR_BASE.h:195
bool GetAesKey(UINT8 *key, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the used security 128bit AES key.
Definition: WiMODLR_BASE.cpp:713
Main class representing the interface to the WiMOD running the firmware WiMODLR-BASE.
Definition: WiMODLR_BASE.h:117
bool SendCData(const TWiMODLR_RadioLink_Msg *txMsg, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Tries to send transmit C-Data to peer module via RF link.
Definition: WiMODLR_BASE.cpp:1035
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
~WiMODLRBASE(void)
Destructor.
Definition: WiMODLR_BASE.cpp:88
bool SetOperationMode(const TWiMOD_OperationMode opMode, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current operation mode of the WiMOD module.
Definition: WiMODLR_BASE.cpp:637
void RegisterPowerUpIndicationClient(TDevMgmtPowerUpCallback cb)
Register a callback function for the PowerUp Indication - optional -.
Definition: WiMODLR_BASE.cpp:881
uint32_t calcRegisterToFreq(uint8_t msb, uint8_t mid, uint8_t lsb)
Convert a frequency registers to frequency in Hz.
Definition: WiMODLR_BASE.cpp:1642
void(* TDataLinkSendUdataIndClient)(UINT8 status)
Definition: WiMODLR_BASE.h:100
bool ResetRadioConfig(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Resets the current configuration to defaults.
Definition: WiMODLR_BASE.cpp:556
bool copyResultInfos(TWiMDLRResultCodes *hciResult, UINT8 *rspStatus, UINT8 successValue)
Definition: WiMODLR_BASE.cpp:1816
bool GetRtc(UINT32 *rtcTime, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current RTC data info from WiMOD module.
Definition: WiMODLR_BASE.cpp:386
bool SendUData(const TWiMODLR_RadioLink_Msg *txMsg, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Tries to send transmit U-Data to peer module via RF link.
Definition: WiMODLR_BASE.cpp:973
bool SetRtcAlarm(const TWiMODLR_DevMgmt_RtcAlarm *rtcAlarm, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets and enables the RTC alarm feature of the WiMOD.
Definition: WiMODLR_BASE.cpp:767
void RegisterCDataRxClient(TRadioLinkCDataRxIndicationCallback cb)
Register a callback function for the RX C-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1423
bool ClearRtcAlarm(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Clears pending RTC Alarms of the WiMOD.
Definition: WiMODLR_BASE.cpp:839
WiMODLRBASE(Stream &s)
Constructor.
Definition: WiMODLR_BASE.cpp:70
bool GetRadioConfig(TWiMODLR_DevMgmt_RadioConfig *radioCfg, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current configuration of the radio of the WiMOD module.
Definition: WiMODLR_BASE.cpp:471
TWiMDLRResultCodes GetLastHciResult(void)
Gets the value of the last local HCI TX status.
Definition: WiMODLR_BASE.cpp:1688
UINT8 GetLastResponseStatus(void)
Gets the value of the last status response value of the WiMOD.
Definition: WiMODLR_BASE.cpp:1733
void RegisterUDataRxClient(TRadioLinkUDataRxIndicationCallback cb)
Register a callback function for the RX U-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1317
bool SetAckData(const TWiMODLR_RadioLink_Msg *txMsg, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets additional user payload for the next ack frame to send.
Definition: WiMODLR_BASE.cpp:1267
void(* TDataLinkRxUDataIndClient)(UINT8 *data, UINT16 length)
Definition: WiMODLR_BASE.h:97
void RegisterAckRxTimeoutClient(TRadioLinkAckRxTimeoutIndicationCallback cb)
Register a callback function for the Ack Timeout Indication - optional -.
Definition: WiMODLR_BASE.cpp:1566
Structure containing basic information about the WiMOD device.
Definition: WiMOD_SAP_DEVMGMT_IDs.h:156
bool GetOperationMode(TWiMOD_OperationMode *opMode, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Gets the current operation mode of the WiMOD module.
Definition: WiMODLR_BASE.cpp:596
void(* TDevMgmtPowerUpCallback)(void)
Definition: WiMOD_SAP_DEVMGMT.h:93
virtual void ProcessUnexpectedRxMessage(TWiMODLR_HCIMessage &rxMsg)
Definition: WiMODLR_BASE.cpp:1773
void RegisterUDataTxClient(TRadioLinkUDataTxIndicationCallback cb)
Register a callback function for the TX U-Data Indication - optional -.
Definition: WiMODLR_BASE.cpp:1359
bool SetRadioConfig(const TWiMODLR_DevMgmt_RadioConfig *radioCfg, TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Sets the current configuration for the radio of the WiMOD module.
Definition: WiMODLR_BASE.cpp:521
bool Ping(TWiMDLRResultCodes *hciResult=NULL, UINT8 *rspStatus=NULL)
Ping Cmd - Checks serial connetion to WiMOD module.
Definition: WiMODLR_BASE.cpp:187