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

- Main Page
- Classes
- Files

- File List
- File Members

WiMODLRHCI.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32
33
34 #ifndef ARDUINO_WIMODLRHCI_H_
35 #define ARDUINO_WIMODLRHCI_H_
36
37 //------------------------------------------------------------------------------
38 //
39 // Section Includes Files
40 //
41 //------------------------------------------------------------------------------
42
43
44 #include "utils/WMDefs.h"
45
46 #include <string.h>
47
48 #include "utils/ComSLIP.h"
49
50 #include "Arduino.h"
51
52 /*
53 * C++11 supports a better way for function pointers / function objects
54 * But C++11 mode is not supported by all platforms.
55 */
56 #ifdef WIMOD_USE_CPP11
57 #include <functional>
58 #endif
59
60 //------------------------------------------------------------------------------
61 //
62 // Serial Baudrate
63 //
64 //------------------------------------------------------------------------------
66 #define WIMODLR_SERIAL_BAUDRATE 115200
67
69 #define WIMODLR_RESPOMSE_TIMEOUT_MS 1000;
70
71 //------------------------------------------------------------------------------
72 //
73 // HCI Message Declaration
74 //
75 //------------------------------------------------------------------------------
77
78 // message header size: 2 bytes for SapID + MsgID
79 #define WIMODLR_HCI_MSG_HEADER_SIZE 2
80
81 // message payload size
82 #define WIMODLR_HCI_MSG_PAYLOAD_SIZE 280
83
84 // frame check sequence field size: 2 bytes for CRC16
85 #define WIMODLR_HCI_MSG_FCS_SIZE 2
86
87 // visible max. buffer size for lower SLIP layer
88 #define WIMODLR_HCI_RX_MESSAGE_SIZE (WIMODLR_HCI_MSG_HEADER_SIZE\
89 + WIMODLR_HCI_MSG_PAYLOAD_SIZE\
90 + WIMODLR_HCI_MSG_FCS_SIZE)
91
92
93 #define WiMODLR_HCI_RSP_STATUS_POS 0x00
94
95 #define WiMODLR_HCI_RSP_CMD_PAYLOAD_POS 0x01
96
98
99
100 //------------------------------------------------------------------------------
101 //
102 // Wake up sequence
103 //
104 //------------------------------------------------------------------------------
106
107 #define WIMODLR_NUMBER_OF_WAKEUP_CHARS 40
108
110
111 //------------------------------------------------------------------------------
112 //
113 // HCI Message
114 //
115 //------------------------------------------------------------------------------
116
120 typedef struct TWiMODLR_HCIMessage
121 {
122 // Payload Length Information, not transmitted over UART interface !
123 UINT16 Length;
125 // Service Access Point Identifier
126 UINT8 SapID;
128 // Message Identifier
129 UINT8 MsgID;
131 // Payload Field
132 UINT8 Payload[WIMODLR_HCI_MSG_PAYLOAD_SIZE];
134 // Frame Check Sequence Field
135 UINT8 CRC16[WIMODLR_HCI_MSG_FCS_SIZE];
137 } TWiMODLR_HCIMessage;
138
139
140 //------------------------------------------------------------------------------
141 //
142 // Definition of Result/Error Codes
143 //
144 //------------------------------------------------------------------------------
145
149 typedef enum TWiMDLRResultCodes
150 {
151 WiMODLR_RESULT_OK = 0,
152 WiMODLR_RESULT_PAYLOAD_LENGTH_ERROR,
153 WiMODLR_RESULT_PAYLOAD_PTR_ERROR,
154 WiMODLR_RESULT_TRANMIT_ERROR,
155 WiMODLR_RESULT_SLIP_ENCODER_ERROR,
156 WiMODLR_RESULT_NO_RESPONSE
157 }TWiMDLRResultCodes;
158
159
160
161 //------------------------------------------------------------------------------
162 //
163 // Error indicator callback
164 //
165 //------------------------------------------------------------------------------
166
170 typedef enum TWiMODStackError
171 {
172 WIMOD_STACK_ERR_UNKNOWN_RX_MESSAGE,
173 WIMOD_STACK_ERR_UNKNOWN_RX_SAP_ID,
174 WIMOD_STACK_ERR_UNKNOWN_RX_CMD_ID,
176 } TWiMODStackError;
177
178
179 // C++11 check
180 #ifdef WIMOD_USE_CPP11
181 /* C++11 function callback definitions */
182
183
187 typedef std::function<void (TWiMODStackError)> TWiMODStackErrorClient;
188
189 #else
190 /* pre C++11 function callback definitions */
191
195 typedef void (*TWiMODStackErrorClient)(TWiMODStackError);
196
197 #endif
198
199 //------------------------------------------------------------------------------
200 //
201 // TWiMODLRHCIClient Class Declaration
202 //
203 //------------------------------------------------------------------------------
204
208 class TWiMODLRHCIClient
209 {
210 public:
211 TWiMODLRHCIClient() {}
212 virtual ~TWiMODLRHCIClient() {}
213
214
215 // define handler for received indication messasges
216 virtual void ProcessRxMessage(const TWiMODLR_HCIMessage& /* rxMsg */) = 0;
217 };
218
219
220 //------------------------------------------------------------------------------
221 //
222 // TWiMODLRHCI Class Declaration
223 //
224 //------------------------------------------------------------------------------
225
229 class TWiMODLRHCI : public TComSlipClient
230 {
231 public:
232 TWiMODLRHCI(Stream& s);
233 ~TWiMODLRHCI(void);
234
235 virtual void begin(void);
236 virtual void end(void);
237
238
239 TWiMDLRResultCodes SendHCIMessage(UINT8 dstSapID, UINT8 msgID, UINT8 rxMsgID, UINT8* payload, UINT16 length);
240 void Process(void);
241 void SendWakeUpSequence(void);
242
243 void RegisterStackErrorClient(TWiMODStackErrorClient cb);
244 // void RegisterRxMessageClient(TWiMODLRHCIClient* cb);
245
246 const TWiMODLR_HCIMessage& GetRxMessage(void);
247
249 // enable / disable wakeup sequence
250 void EnableWakeupSequence(bool flag);
251 // @end_cond
252
253
254 protected:
255 TWiMDLRResultCodes PostMessage(UINT8 sapID, UINT8 msgID, UINT8* payload, UINT16 length);
256 TWiMDLRResultCodes SendPacket(UINT8* txData, UINT16 length);
257
258 bool WaitForResponse(UINT8 rxSapID, UINT8 rxMsgID);
259 UINT8* ProcessRxMessage(UINT8* rxBuffer, UINT16 length);
260
261 virtual void ProcessUnexpectedRxMessage(TWiMODLR_HCIMessage& rxMsg) = 0;
262
263 // receiver struct
267 typedef struct TReceiver
268 {
269
270 bool Active;
271 bool Done;
272 UINT8 SapID;
273 UINT8 MsgID;
274 TWiMODLR_HCIMessage Message;
275 // Timeout (~1000ms)
276 int Timeout;
277 }TReceiver;
278
280
281 // receiver instance
282 TReceiver Rx;
283
284
285 // Stack error indicator callback
286 TWiMODStackErrorClient StackErrorClientCB;
287
288
290
291 private:
293 virtual void DispatchRxMessage(TWiMODLR_HCIMessage& rxMsg);
294
295 TWiMODLRHCIClient* RxMessageClient;
296
297 Stream& serial;
298 TComSlip comSlip;
299
300 TWiMODLR_HCIMessage TxMessage;
301
302 bool wakeUp;
303
305 };
306
307 #endif /* ARDUINO_WIMODLRHCI_H_ */
308
309 //------------------------------------------------------------------------------
310 // EOF
311 //------------------------------------------------------------------------------
TWiMODLR_HCIMessage
struct TWiMODLR_HCIMessage TWiMODLR_HCIMessage
basic low level HCI message structure used for all serial messages to/from WiMOD
WiMODLR_RESULT_PAYLOAD_LENGTH_ERROR
Definition: WiMODLRHCI.h:152
TWiMODStackErrorClient
void(* TWiMODStackErrorClient)(TWiMODStackError)
Type definition for indicator callback for stack (internal) error.
Definition: WiMODLRHCI.h:195
TComSlip
Class for handling SLIP encoding and decoding of HCI messages.
Definition: ComSLIP.h:58
TWiMODLR_HCIMessage::Payload
UINT8 Payload[WIMODLR_HCI_MSG_PAYLOAD_SIZE]
Definition: WiMODLRHCI.h:132
TWiMDLRResultCodes
TWiMDLRResultCodes
Result codes for the local serial communication itself.
Definition: WiMODLRHCI.h:149
WIMOD_STACK_ERR_UNKNOWN_RX_MESSAGE
Definition: WiMODLRHCI.h:172
TWiMODStackError
TWiMODStackError
Internal error reasons; not to be used in user code.
Definition: WiMODLRHCI.h:170
WIMOD_STACK_ERR_UNKNOWN_RX_CMD_ID
Definition: WiMODLRHCI.h:174
TWiMODLR_HCIMessage
basic low level HCI message structure used for all serial messages to/from WiMOD
Definition: WiMODLRHCI.h:120
WiMODLR_RESULT_TRANMIT_ERROR
Definition: WiMODLRHCI.h:154
WiMODLR_RESULT_OK
Definition: WiMODLRHCI.h:151
TWiMODLRHCI
Internal helper class for processing SLIP frames.
Definition: WiMODLRHCI.h:229
TWiMODLRHCIClient
Internal helper class for processing HCI frames.
Definition: WiMODLRHCI.h:208
TWiMODLR_HCIMessage::MsgID
UINT8 MsgID
Definition: WiMODLRHCI.h:129
TWiMODLR_HCIMessage::Length
UINT16 Length
Definition: WiMODLRHCI.h:123
WIMOD_STACK_ERR_UNKNOWN_RX_SAP_ID
Definition: WiMODLRHCI.h:173
WiMODLR_RESULT_NO_RESPONSE
Definition: WiMODLRHCI.h:156
TWiMODLR_HCIMessage::SapID
UINT8 SapID
Definition: WiMODLRHCI.h:126
TComSlipClient
Class definition for enabling OO inheritance.
Definition: ComSLIP.h:44
TWiMODLR_HCIMessage::CRC16
UINT8 CRC16[WIMODLR_HCI_MSG_FCS_SIZE]
Definition: WiMODLRHCI.h:135
WiMODLR_RESULT_PAYLOAD_PTR_ERROR
Definition: WiMODLRHCI.h:153
WiMODLR_RESULT_SLIP_ENCODER_ERROR
Definition: WiMODLRHCI.h:155