-
Notifications
You must be signed in to change notification settings - Fork 1
/
collector.h
324 lines (277 loc) · 10.2 KB
/
collector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/******************************************************************************
@file collector.h
@brief TIMAC 2.0 Collector Example Application Header
Group: WCS LPC
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2016 $
******************************************************************************
$Release Name: PACKAGE NAME $
$Release Date: PACKAGE RELEASE DATE $
*****************************************************************************/
#ifndef COLLECTOR_H
#define COLLECTOR_H
/******************************************************************************
Includes
*****************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "api_mac.h"
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************
Constants and definitions
*****************************************************************************/
#ifndef MAX
#define MAX(n,m) (((n) < (m)) ? (m) : (n))
#endif
/*! Event ID - Start the device in the network */
#define COLLECTOR_START_EVT 0x0001
/*! Event ID - Tracking Timeout Event */
#define COLLECTOR_TRACKING_TIMEOUT_EVT 0x0002
/*! Event ID - Generate Configs Event */
#define COLLECTOR_CONFIG_EVT 0x0004
/*! Event ID - Broadcast Timeout Event */
#define COLLECTOR_BROADCAST_TIMEOUT_EVT 0x0008
/*! Collector Status Values */
typedef enum
{
/*! Success */
Collector_status_success = 0,
/*! Device Not Found */
Collector_status_deviceNotFound = 1,
/*! Collector isn't in the correct state to send a message */
Collector_status_invalid_state = 2,
/*! Collector isn't in the correct state to send a message */
Collector_status_invalid_file = 3,
/*! Collector cannot locate the file_id provided */
Collector_status_invalid_file_id = 4,
} Collector_status_t;
/* Beacon order for non beacon network */
#define NON_BEACON_ORDER 15
/* Number of superframe periods to hold a indirect packet at collector for
Sensor to poll and get the frame*/
#define BCN_MODE_INDIRECT_PERSISTENT_TIME 3
#define MIN_PERSISTENCE_TIME_USEC 2000000
#if ((CONFIG_PHY_ID >= APIMAC_MRFSK_STD_PHY_ID_BEGIN) && (CONFIG_PHY_ID <= APIMAC_MRFSK_GENERIC_PHY_ID_BEGIN))
/* MAC Indirect Persistent Timeout */
#define INDIRECT_PERSISTENT_TIME (MAX((5 * 1000 * CONFIG_POLLING_INTERVAL / 2), MIN_PERSISTENCE_TIME_USEC)/ \
(BASE_SUPER_FRAME_DURATION * \
SYMBOL_DURATION_50_kbps))
#elif ((CONFIG_PHY_ID >= APIMAC_200KBPS_915MHZ_PHY_132) && (CONFIG_PHY_ID <= APIMAC_200KBPS_868MHZ_PHY_133))
/* MAC Indirect Persistent Timeout */
#define INDIRECT_PERSISTENT_TIME (MAX((5 * 1000 * CONFIG_POLLING_INTERVAL / 2),MIN_PERSISTENCE_TIME_USEC) / \
(BASE_SUPER_FRAME_DURATION * \
SYMBOL_DURATION_200_kbps))
#elif (CONFIG_PHY_ID == APIMAC_250KBPS_IEEE_PHY_0)
/* MAC Indirect Persistent Timeout */
#define INDIRECT_PERSISTENT_TIME (MAX((5* 10 * 1000 * CONFIG_POLLING_INTERVAL / 2), MIN_PERSISTENCE_TIME_USEC)/ \
(BASE_SUPER_FRAME_DURATION * \
SYMBOL_DURATION_250_kbps))
#else
/* MAC Indirect Persistent Timeout */
#define INDIRECT_PERSISTENT_TIME (MAX((5 * 1000 * CONFIG_POLLING_INTERVAL / 2), MIN_PERSISTENCE_TIME_USEC)/ \
(BASE_SUPER_FRAME_DURATION * \
SYMBOL_DURATION_LRM))
#endif
/******************************************************************************
Structures
*****************************************************************************/
/*! Collector Statistics */
typedef struct
{
/*!
Total number of tracking request messages attempted
*/
uint32_t trackingRequestAttempts;
/*!
Total number of tracking request messages sent
*/
uint32_t trackingReqRequestSent;
/*!
Total number of tracking response messages received
*/
uint32_t trackingResponseReceived;
/*!
Total number of config request messages attempted
*/
uint32_t configRequestAttempts;
/*!
Total number of config request messages sent
*/
uint32_t configReqRequestSent;
/*!
Total number of config response messages received
*/
uint32_t configResponseReceived;
/*!
Total number of sensor messages received
*/
uint32_t sensorMessagesReceived;
/*!
Total number of failed messages because of channel access failure
*/
uint32_t channelAccessFailures;
/*!
Total number of failed messages because of ACKs not received
*/
uint32_t ackFailures;
/*!
Total number of failed transmit messages that are not channel access
failure and not ACK failures
*/
uint32_t otherTxFailures;
/*! Total number of RX Decrypt failures. */
uint32_t rxDecryptFailures;
/*! Total number of TX Encrypt failures. */
uint32_t txEncryptFailures;
/* Total Transaction Expired Count */
uint32_t txTransactionExpired;
/* Total transaction Overflow error */
uint32_t txTransactionOverflow;
/* Total broadcast messages sent */
uint16_t broadcastMsgSentCnt;
} Collector_statistics_t;
/******************************************************************************
Global Variables
*****************************************************************************/
/*! Collector events flags */
extern uint16_t Collector_events;
/*! Collector statistics */
extern Collector_statistics_t Collector_statistics;
extern ApiMac_callbacks_t Collector_macCallbacks;
/******************************************************************************
Function Prototypes
*****************************************************************************/
/*!
* @brief Initialize this application.
*/
extern void Collector_init(void);
/*!
* @brief Application task processing.
*/
extern void Collector_process(void);
/*!
* @brief Build and send the configuration message to a device.
*
* @param pDstAddr - destination address of the device to send the message
* @param frameControl - configure what to the device is to report back.
* Ref. Smsgs_dataFields_t.
* @param reportingInterval - in milliseconds- how often to report, 0
* means to turn off automated reporting, but will
* force the sensor device to send the Sensor Data
* message once.
* @param pollingInterval - in milliseconds- how often to the device is to
* poll its parent for data (for sleeping devices
* only.
*
* @return Collector_status_success, Collector_status_invalid_state
* or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_sendConfigRequest(ApiMac_sAddr_t *pDstAddr,
uint16_t frameControl,
uint32_t reportingInterval,
uint32_t pollingInterval);
/*!
* @brief Update the collector statistics
*/
extern void Collector_updateStats( void );
/*!
* @brief Build and send the toggle led message to a device.
*
* @param pDstAddr - destination address of the device to send the message
*
* @return Collector_status_success, Collector_status_invalid_state
* or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_sendToggleLedRequest(
ApiMac_sAddr_t *pDstAddr);
extern Collector_status_t Collector_sendCustomCommand(
ApiMac_sAddr_t *pDstAddr,
uint8_t *payload,
uint16_t length);
/*!
* @brief Build and send the device type request message to a device.
*
* @param pDstAddr - destination address of the device to send the message
*
* @return Collector_status_success, Collector_status_invalid_state
* or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_sendDeviceTypeRequest(
ApiMac_sAddr_t *pDstAddr);
/*!
* @brief Get the file name associated with file_id
*
* @param file_id - id of file who's name you wish to get
*
* @param file_name - buffer to store null terminating file_name into.
*
* @return Collector_status_success or Collector_status_invalid_file_id
*/
extern Collector_status_t Collector_getFileName(uint32_t file_id, char* file_name, size_t max_len);
/*!
* @brief Adds a new file to the OAd file list.
*
* @param new_oad_file - path to OAD file
*
* @return OAD file ID
*/
extern uint32_t Collector_updateFwList(char *new_oad_file);
/*!
* @brief Send OAD version request message.
*
* @param pDstAddr - destination address of the device to send the message
*
* @return Collector_status_success, Collector_status_invalid_state
* or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_sendFwVersionRequest(
ApiMac_sAddr_t *pDstAddr);
/*!
* @brief Check if a device exists
*
* @param pAddr - destination address of the device
*
* @return Collector_status_success or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_findDevice(
ApiMac_sAddr_t *pAddr);
/*!
* @brief Send OAD update request message.
*
* @param pDstAddr - destination address of the device to send the message
* @param oad_file_id - OAD file ID
*
* @return Collector_status_success, Collector_status_invalid_state
* or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_startFwUpdate(ApiMac_sAddr_t *pDstAddr, uint32_t oad_file_id);
/*!
* @brief Send OAD target reset request message.
*
* @param pDstAddr - destination address of the device to send the message
*
* @return Collector_status_success, Collector_status_invalid_state
* or Collector_status_deviceNotFound
*/
extern Collector_status_t Collector_sendResetReq(ApiMac_sAddr_t *pDstAddr);
#ifdef __cplusplus
}
#endif
#endif /* COLLECTOR_H */
/*
* ========================================
* Texas Instruments Micro Controller Style
* ========================================
* Local Variables:
* mode: c
* c-file-style: "bsd"
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
* vim:set filetype=c tabstop=4 shiftwidth=4 expandtab=true
*/