Project

General

Profile

Revision 738

Updated wireless library binaries and headers.

View differences:

wireless.c
51 51

  
52 52
/*Function Prototypes*/
53 53

  
54
void wl_do_timeout(void);
54
static void wl_do_timeout(void);
55 55

  
56 56
//Note: the actual frame sent has group as the first four bits and
57 57
//frame as the last four.
58
void wl_send_packet(char group, char type, char* data, int len,
59
					int dest, char options, char frame);
58
static int wl_send_packet(char group, char type, char* data, int len, int dest, char options, char frame);
60 59

  
61 60
/*Data Members*/
62 61

  
63 62
//used to store incoming and outgoing packets
64
unsigned char wl_buf[128];
63
//TODO: does this need to be 128?  can it be smaller to save memory?
64
//TODO: this shouldn't be hardcoded as 128.  it should be a define.
65
static unsigned char wl_buf[128];
65 66
//1 if we have timed out since we last checked, 0 otherwise.
66
int wl_timeout = 0;
67
static int wl_timeout = 0;
67 68

  
68
PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS];
69
static PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS];
69 70

  
70 71
#ifndef ROBOT
71 72

  
72 73
//called when we time out, or receive interrupt
73
void sig_handler(int signo)
74
static void sig_handler(int signo)
74 75
{
75 76
	switch (signo)
76 77
	{
......
87 88
#else
88 89

  
89 90
//called when the timer ticks
90
void timer_handler(void)
91
static void timer_handler(void)
91 92
{
92 93
	wl_timeout = 1;
93 94
}
......
97 98
/**
98 99
 * Initializes the wireless library. Must be called before any
99 100
 * other function.
101
 *
102
 * @param wl_port File descriptor for wireless port, or NULL for default.
100 103
 **/
101 104
int wl_init()
102 105
{
103 106
	int i;
107
  //TODO: using memset here instead of this loop, *might* be less instructions and *might* reduce code size but not sure
104 108
	for (i = 0; i < WL_MAX_PACKET_GROUPS; i++)
105 109
		wl_packet_groups[i] = NULL;
106 110

  
107 111
	if (xbee_lib_init() == -1) {
108
	  return -1;
112
		return -1;
109 113
	}
110 114

  
111 115
	//begin timeout timer
112
	#ifdef ROBOT
113
	#ifdef FIREFLY
116
#ifdef ROBOT
117
#ifdef FIREFLY
114 118
	rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
115
	#else
119
#else
116 120
	rtc_init(HALF_SECOND, &timer_handler);
117
	#endif
118
	#else
121
#endif
122
#else
119 123

  
120 124
	//create our timer
121 125
	struct itimerval timer_val;
......
141 145
	sigemptyset(&wl_sig_act.sa_mask);
142 146
	sigaction(SIGALRM, &wl_sig_act, 0);
143 147
	sigaction(SIGINT, &wl_sig_act, 0);
144
	#endif
148
#endif
145 149

  
146 150
	return 0;
147 151
}
......
152 156
void wl_terminate()
153 157
{
154 158
	int i;
155
	for (i = 0; i < WL_MAX_PACKET_GROUPS; i++)
159
	for (i = 0; i < WL_MAX_PACKET_GROUPS; i++) {
156 160
		if (wl_packet_groups[i] != NULL &&
157
			wl_packet_groups[i]->unregister != NULL)
161
			wl_packet_groups[i]->unregister != NULL) {
158 162
			wl_packet_groups[i]->unregister();
163
		}
164
	}
159 165

  
160 166
	xbee_terminate();
161 167
}
......
167 173
 *
168 174
 * @see wl_get_pan
169 175
 **/
170
void wl_set_pan(int pan)
176
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
177
// it reduces code size or not should be done to be sure.
178
int wl_set_pan(int pan)
171 179
{
172
	xbee_set_pan_id(pan);
180
	return xbee_set_pan_id(pan);
173 181
}
174 182

  
175 183
/**
......
179 187
 *
180 188
 * @see wl_set_pan
181 189
 **/
190
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
191
// it reduces code size or not should be done to be sure.
182 192
int wl_get_pan(void)
183 193
{
184 194
	return xbee_get_pan_id();
......
191 201
 *
192 202
 * @see wl_get_channel
193 203
 **/
194
void wl_set_channel(int channel)
204
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
205
// it reduces code size or not should be done to be sure.
206
int wl_set_channel(int channel)
195 207
{
196
	xbee_set_channel(channel);
208
	return xbee_set_channel(channel);
197 209
}
198 210

  
199 211
/**
......
203 215
 *
204 216
 * @see wl_set_channel
205 217
 **/
218
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
219
// it reduces code size or not should be done to be sure.
206 220
int wl_get_channel(void)
207 221
{
208 222
	return xbee_get_channel();
......
213 227
 *
214 228
 * @return the 16-bit address of the XBee module.
215 229
 **/
230
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
231
// it reduces code size or not should be done to be sure.
216 232
int wl_get_xbee_id()
217 233
{
218 234
	return xbee_get_address();
......
228 244
 * @param dest the 16-bit address of the XBee to send the packet to
229 245
 * @param frame the frame number to see with a TX_STATUS response
230 246
 **/
231
void wl_send_robot_to_robot_global_packet(char group, char type,
232
		char* data, int len, int dest, char frame)
247
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
248
// it reduces code size or not should be done to be sure.
249
int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame)
233 250
{
234
	wl_send_packet(group, type, data, len, dest,
235
			XBEE_OPTIONS_BROADCAST_ALL_PANS, frame);
251
	return wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_BROADCAST_ALL_PANS, frame);
236 252
}
237 253

  
238 254
/**
......
245 261
 * @param dest the 16-bit address of the XBee to send the packet to
246 262
 * @param frame the frame number to see with a TX_STATUS response
247 263
 **/
248
void wl_send_robot_to_robot_packet(char group, char type,
249
		char* data, int len, int dest, char frame)
264
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
265
// it reduces code size or not should be done to be sure.
266
int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame)
250 267
{
251
	wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_NONE,
252
			frame);
268
	return wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_NONE, frame);
253 269
}
254 270

  
255 271
/**
......
261 277
 * @param len the packet length in bytes
262 278
 * @param frame the frame number to see with a TX_STATUS response
263 279
 **/
264
void wl_send_global_packet(char group, char type,
265
		char* data, int len, char frame)
280
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
281
// it reduces code size or not should be done to be sure.
282
int wl_send_global_packet(char group, char type, char* data, int len, char frame)
266 283
{
267
	wl_send_packet(group, type, data, len, XBEE_BROADCAST,
268
			XBEE_OPTIONS_BROADCAST_ALL_PANS, frame);
284
	return wl_send_packet(group, type, data, len, XBEE_BROADCAST, XBEE_OPTIONS_BROADCAST_ALL_PANS, frame);
269 285
}
270 286

  
271 287
/**
......
277 293
 * @param len the packet length in bytes
278 294
 * @param frame the frame number to see with a TX_STATUS response
279 295
 **/
280
void wl_send_pan_packet(char group, char type,
281
		char* data, int len, char frame)
296
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
297
// it reduces code size or not should be done to be sure.
298
void wl_send_pan_packet(char group, char type, char* data, int len, char frame)
282 299
{
283 300
	wl_send_packet(group, type, data, len, XBEE_BROADCAST,
284 301
			XBEE_OPTIONS_NONE, frame);
......
295 312
 * @param options the options for sending the packet
296 313
 * @param frame the frame number to see with a TX_STATUS response
297 314
 **/
298
void wl_send_packet(char group, char type, char* data, int len,
299
					int dest, char options, char frame)
315
int wl_send_packet(char group, char type, char* data, int len, int dest, char options, char frame)
300 316
{
317
  //TODO: does this need to be 128?  can it be smaller to save memory?
318
  //TODO: this shouldn't be hardcoded as 128.  it should be a define.
301 319
	char buf[128];
302 320
	int i;
303 321
	if (frame != 0)
304 322
		frame = (frame & 0x0F) | ((group & 0x0F) << 4);
323

  
305 324
	buf[0] = group;
306 325
	buf[1] = type;
307 326
	for (i = 0; i < len; i++)
308 327
		buf[2 + i] = data[i];
309
	xbee_send_packet(buf, len + 2, dest, options, frame);
328

  
329
	return xbee_send_packet(buf, len + 2, dest, options, frame);
310 330
}
311 331

  
312 332
/**
......
389 409
		int group = (int)(wl_buf[1] >> 4);
390 410
		int success = 0;
391 411
		if (wl_buf[2] == 0)
412
		{
392 413
			success = 1;
414
		}
393 415
		else
394 416
		{
395 417
			WL_DEBUG_PRINT("No response received.\r\n");
......
403 425
			}
404 426
		}
405 427

  
406
		if (wl_packet_groups[group] != NULL &&
407
					wl_packet_groups[group]->handle_response != NULL)
408
			wl_packet_groups[group]->handle_response(
409
					(int)wl_buf[1] & 0x0F, success);
410
		return;
428
		if (wl_packet_groups[group] != NULL && wl_packet_groups[group]->handle_response != NULL)
429
			wl_packet_groups[group]->handle_response((int)wl_buf[1] & 0x0F, success);
411 430
	}
412

  
413
	if (wl_buf[0] == XBEE_RX)
431
	else if (wl_buf[0] == XBEE_RX)
414 432
	{
433
    //TODO: what does this 7 represent?  It shouldn't be hardcoded.  It should be set as a define
415 434
		if (len < 7)
416 435
		{
417 436
			WL_DEBUG_PRINT("Packet is too small.\r\n");
......
427 446
		int options = wl_buf[4];
428 447
		*/
429 448

  
449
    //TODO: these indices, etc should be defined, not hardcoded
430 450
		int group = wl_buf[5];
431 451
		int type = wl_buf[6];
432 452
		int packetLen = len - 7;
433 453

  
434
		if (wl_packet_groups[group] != NULL
435
				&& wl_packet_groups[group]->handle_receive != NULL)
436
			wl_packet_groups[group]->handle_receive(type, source,
437
				wl_buf + 7, packetLen);
438
		return;
454
		if (wl_packet_groups[group] != NULL && wl_packet_groups[group]->handle_receive != NULL) {
455
			wl_packet_groups[group]->handle_receive(type, source, wl_buf + 7, packetLen);
456
		}
439 457
	}
440

  
441
	WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n");
442
	return;
458
	else
459
	{
460
		WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n");
461
	}
443 462
}
444 463

  
445 464

  
446 465
#ifndef ROBOT
466
//TODO: this function is so simple, it *may* be beneficial to inline this function.  testing of if
467
// it reduces code size or not should be done to be sure.
447 468
void wl_set_com_port(char* port)
448 469
{
449 470
	xbee_set_com_port(port);

Also available in: Unified diff