Revision 157
Sweet stuff. Eugene use this. It's good.
(But not tested yet, should work, modular, works for all server side applications,
even those that aren't explicitly colonet related.)
data_response.c | ||
---|---|---|
1 | 1 |
#include "data_response.h" |
2 |
#include <dragonfly_lib.h>
|
|
2 |
#include "dragonfly_lib.h"
|
|
3 | 3 |
#include "wl_token_ring.h" |
4 | 4 |
#include "wireless.h" |
5 | 5 |
|
6 | 6 |
|
7 | 7 |
PacketGroupHandler pgh; |
8 | 8 |
|
9 |
void handle_receive(char type, int source, unsigned char * packet, int length);
|
|
9 |
void handle_receive(char type, int source, unsigned char* packet, int length); |
|
10 | 10 |
|
11 | 11 |
int generate_bom_packet(char** buf); |
12 | 12 |
int generate_IR_packet(char** buf); |
... | ... | |
15 | 15 |
range_init(); |
16 | 16 |
pgh.timeout_handler = NULL; |
17 | 17 |
pgh.handle_response = NULL; |
18 |
pgh.handle_response = handle_receive;
|
|
18 |
pgh.handle_receive = handle_receive;
|
|
19 | 19 |
pgh.unregister = NULL; |
20 |
wl_register_packet_group(&pgh); |
|
20 | 21 |
} |
21 | 22 |
|
22 | 23 |
void handle_receive(char type, int source, unsigned char* packet, int length){ |
... | ... | |
25 | 26 |
switch(type){ |
26 | 27 |
case BOM_TYPE: |
27 | 28 |
size = generate_bom_packet(&buf); |
28 |
wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,BOM_TYPE,data,size,source,0);
|
|
29 |
wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,BOM_TYPE,buf,size,source,0);
|
|
29 | 30 |
case IR_TYPE: |
30 | 31 |
size = generate_IR_packet(&buf); |
31 |
wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,IR_TYPE,data,size,source,0);
|
|
32 |
wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,IR_TYPE,buf,size,source,0);
|
|
32 | 33 |
case ENCODER_TYPE: |
34 |
break; |
|
33 | 35 |
//Not yet supported. |
34 |
|
|
35 | 36 |
} |
36 | 37 |
} |
37 | 38 |
|
... | ... | |
41 | 42 |
wl_token_iterator_begin(); |
42 | 43 |
while(wl_token_iterator_has_next() && i<=99){ |
43 | 44 |
robot_id = wl_token_iterator_next(); |
44 |
*buf[i++] = (char)((robot_id>>8) & 255);
|
|
45 |
*buf[i++] = (char)(robot_id & 255);
|
|
46 |
*buf[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
|
|
45 |
(*buf)[i++] = (char)((robot_id>>8) & 0xFF);
|
|
46 |
(*buf)[i++] = (char)(robot_id & 0xFF);
|
|
47 |
(*buf)[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
|
|
47 | 48 |
} |
48 | 49 |
//i is one greater than the index of the last byte... the size. |
49 | 50 |
return i; |
Also available in: Unified diff