Revision 294
Got the data response to work, however analog8 reads are failing to get good data.
test_main.c | ||
---|---|---|
2 | 2 |
#include <stdio.h> |
3 | 3 |
#include <unistd.h> |
4 | 4 |
#include "wireless.h" |
5 |
#include "wl_token_ring.h" |
|
5 | 6 |
|
7 |
#define TEST_CODE 12 |
|
8 |
|
|
6 | 9 |
void handle_receive(char type, int source, unsigned char* packet, int length); |
7 | 10 |
|
8 |
unsigned char bom_responded_flag;
|
|
11 |
unsigned char response_flag;
|
|
9 | 12 |
|
10 | 13 |
int main(void){ |
11 | 14 |
wl_set_com_port("/dev/cu.usbserial-A1000Qu6"); |
12 | 15 |
wl_init(); |
16 |
|
|
13 | 17 |
PacketGroupHandler* pgh = malloc(sizeof(PacketGroupHandler)); |
14 | 18 |
pgh->groupCode=12; |
15 | 19 |
pgh->timeout_handler=NULL; |
16 | 20 |
pgh->handle_response=NULL; |
17 | 21 |
pgh->handle_receive=handle_receive; |
18 | 22 |
pgh->unregister=NULL; |
23 |
|
|
19 | 24 |
wl_register_packet_group(pgh); |
20 |
int i; |
|
25 |
wl_token_ring_register(); |
|
26 |
int i,robot_id; |
|
27 |
response_flag=0; |
|
28 |
wl_token_iterator_begin(); |
|
21 | 29 |
while(1){ |
22 |
wl_send_robot_to_robot_global_packet (12, 0, NULL, 0, 9, 0); |
|
23 |
printf("Sending robot to robot global packet.\n"); |
|
24 |
for(i=0;i<1000;i++){ |
|
30 |
while(wl_token_iterator_has_next()){ |
|
31 |
wl_do(); |
|
32 |
|
|
33 |
robot_id = wl_token_iterator_next(); |
|
34 |
|
|
35 |
wl_send_robot_to_robot_global_packet (12, 0, NULL, 0, robot_id, 0); |
|
36 |
printf("Sent robot to robot global packet.\n"); |
|
37 |
while(response_flag==0){ |
|
25 | 38 |
wl_do(); |
26 |
usleep(100); |
|
39 |
if(i>5000){ |
|
40 |
printf("Response timed out\n"); |
|
41 |
break; |
|
42 |
} |
|
43 |
} |
|
44 |
response_flag =0; |
|
27 | 45 |
} |
28 | 46 |
} |
29 | 47 |
return -1; |
30 | 48 |
} |
31 | 49 |
|
32 | 50 |
void handle_receive(char type, int source, unsigned char* packet, int length){ |
33 |
printf("Received the callback!\n"); |
|
51 |
printf("Received a callback from %i!\n",source); |
|
52 |
response_flag=1; |
|
34 | 53 |
} |
Also available in: Unified diff