-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkt_Queue.h
306 lines (186 loc) · 5.88 KB
/
pkt_Queue.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
/*
2020 © Copyright (c) BiDaE Technology Inc.
Provided under BiDaE SHAREWARE LICENSE-1.0 in the LICENSE.
Project Name:
BeDIS
File Name:
pkt_Queue.h
File Description:
This file contains the header of function declarations used in pkt_Queue.c
Version:
2.0, 20190608
Abstract:
BeDIS uses LBeacons to deliver 3D coordinates and textual descriptions of
their locations to users' devices. Basically, a LBeacon is an inexpensive,
Bluetooth Smart Ready device. The 3D coordinates and location description
of every LBeacon are retrieved from BeDIS (Building/environment Data and
Information System) and stored locally during deployment and maintenance
times. Once initialized, each LBeacon broadcasts its coordinates and
location description to Bluetooth enabled user devices within its coverage
area.
Authors:
Gary Xiao , [email protected]
*/
#ifndef pkt_Queue_H
#define pkt_Queue_H
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdbool.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#endif
/* When debugging is needed */
//#define debugging
/* The size of the IP address in char */
#define NETWORK_ADDR_LENGTH 16
/* Maximum length of message to be sent over Wi-Fi in bytes
(The maximum UDP pkt size is 65535 bytes - 8 bytes UDP header -
20 bytes IP header = 65507 bytes)
*/
#define MESSAGE_LENGTH (8192 + 512)
/* The maximum length of the pkt Queue. */
#define MAX_QUEUE_LENGTH 512
enum{
pkt_Queue_SUCCESS = 0,
pkt_Queue_FULL = -1,
queue_len_error = -2,
pkt_Queue_is_free = -3,
pkt_Queue_is_NULL = -4,
pkt_Queue_display_over_range = -5,
MESSAGE_OVERSIZE = -6
};
/* packet format */
typedef struct pkt {
/* If the pkt is not in use, the flag set to true */
bool is_null;
/* The IP adddress of the current pkt */
unsigned char address[NETWORK_ADDR_LENGTH];
/* The port number of the current pkt */
unsigned int port;
/* The content of the current pkt */
char content[MESSAGE_LENGTH];
/* The size of the current pkt */
int content_size;
} sPkt;
typedef sPkt *pPkt;
typedef struct pkt_header {
/* front store the location of the first of thr Pkt Queue */
int front;
/* rear store the location of the end of the Pkt Queue */
int rear;
/* The array is used to store pkts. */
sPkt Queue[MAX_QUEUE_LENGTH];
/* If the pkt queue is initialized, the flag will set to false */
bool is_free;
/* The mutex is used to read/write lock before processing the pkt queue */
pthread_mutex_t mutex;
} spkt_ptr;
typedef spkt_ptr *pkt_ptr;
/* init_Packet_Queue
Initialize the queue for storing pkts.
Parameter:
pkt_queue : The pointer points to the pkt queue.
Return Value:
int: If return 0, everything work successful.
If not 0, Something wrong during init mutex.
*/
int init_Packet_Queue(pkt_ptr pkt_queue);
/*
Free_Packet_Queue
Release all the packets in the packet queue, the header and the tail of
the packet queue and release the struct stores the pointer of the packet
queue.
Parameter:
pkt_queue : The pointer points to the struct stores the first and the
last of the packet queue.
Return Value:
int: If return 0, everything work successful.
If not 0, Something wrong during delpkt or destroy mutex.
*/
int Free_Packet_Queue(pkt_ptr pkt_queue);
/*
addpkt
Add new packet into the packet queue. This function is only allow for the
data length shorter than the MESSAGE_LENGTH.
Parameter:
pkt_queue : The pointer points to the pkt queue we prepare to store the
pkt.
address : The IP address of the packet.
port : The port number of the packet.
content : The content of the packet.
content_size : The size of the content.
Return Value:
int: If return 0, everything work successfully.
If return pkt_Queue_FULL, the pkt is FULL.
If not 0, Somthing Wrong.
*/
int addpkt(pkt_ptr pkt_queue, char *address, unsigned int port,
char *content, int content_size);
/* get_pkt
Get the first pkt of the pkt queue.
Parameter:
pkt_queue : The pointer points to the pkt queue we going to get
a pkt from.
Return Value:
sPkt : return the content of the first pkt.
*/
sPkt get_pkt(pkt_ptr pkt_queue);
/*
delpkt
Delete the first of the packet queue.
Parameter:
pkt_queue: The pointer points to the pkt queue.
Return Value:
int: If return 0, work successfully.
*/
int delpkt(pkt_ptr pkt_queue);
/* display_pkt
Display the packet we decide to see.
Parameter:
display_title : The title we want to show in front of the packet content.
pkt : The packet we want to see it's content.
pkt_num : Choose whitch pkts we want to display.
Return Value:
int
*/
int display_pkt(char *display_title, pkt_ptr pkt_queue, int pkt_num);
/*
is_null
check if pkt_Queue is null.
Parameter:
pkt_queue : The pointer points to the pkt queue.
Return Value:
bool : true if null.
*/
bool is_null(pkt_ptr pkt_queue);
/*
is_null
check if pkt_Queue is full.
Parameter:
pkt_queue : The pointer points to the pkt queue.
Return Value:
bool : true if full.
*/
bool is_full(pkt_ptr pkt_queue);
/*
queue-len
Count the length of the queue.
Parameter:
pkt_queue : The queue we want to count.
Return Value:
int : The length of the Queue.
*/
int queue_len(pkt_ptr pkt_queue);
/*
print_content
print the content.
Parameter:
content : The pointer of content we desire to read.
size : The size of the content.
Return Value:
NONE
*/
void print_content(char *content, int size);
#endif