root / trunk / code / projects / test / testtokenring.c @ 858
History | View | Annotate | Download (2.61 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <wireless.h> |
3 |
#include <wl_token_ring.h> |
4 |
|
5 |
|
6 |
/**
|
7 |
* Tests the token ring and BOM
|
8 |
* - prints table of bom values for every robot in token ring
|
9 |
* - takes several seconds to initialize token ring
|
10 |
*/
|
11 |
|
12 |
#define MAX_ROBOTS 16 |
13 |
|
14 |
// set a list of integers to 0
|
15 |
void clearRobots(int* list) { |
16 |
for(int i=0;i<MAX_ROBOTS;i++) |
17 |
list[i] = 0;
|
18 |
} |
19 |
|
20 |
int testtokenring(void) { |
21 |
// initialize everything
|
22 |
dragonfly_init(ALL_ON); |
23 |
usb_init(); |
24 |
usb_puts("usb turned on\r\n");
|
25 |
wl_init(); |
26 |
usb_puts("wireless turned on\r\n");
|
27 |
wl_token_ring_register(); |
28 |
wl_token_ring_join(); // join token ring
|
29 |
usb_puts("token ring joined\r\n");
|
30 |
int* robotList = (int*)malloc(sizeof(int)*MAX_ROBOTS); |
31 |
int numRobots = 0; |
32 |
delay_ms(1000);
|
33 |
|
34 |
// start testing wireless/token ring/BOM
|
35 |
int i=0; |
36 |
while(1) { |
37 |
wl_do(); |
38 |
// only print table every 200 loops
|
39 |
if (i%200==0) { |
40 |
// get token ring size values
|
41 |
usb_puts("\r\nnumber of robots in token ring:");
|
42 |
usb_puti(wl_token_get_robots_in_ring()); |
43 |
usb_puts("\r\nnumber of robots in matrix:");
|
44 |
usb_puti(wl_token_get_num_robots()); |
45 |
|
46 |
// get list of robots
|
47 |
numRobots = 0;
|
48 |
clearRobots(robotList); |
49 |
wl_token_iterator_begin(); |
50 |
while(wl_token_iterator_has_next()) {
|
51 |
int tmp = wl_token_iterator_next();
|
52 |
if (tmp < 0) |
53 |
break;
|
54 |
robotList[tmp] = 1;
|
55 |
numRobots++; |
56 |
} |
57 |
if (numRobots < 1) { |
58 |
usb_puts("\r\nNo BOM table available.");
|
59 |
continue; // skip table printing |
60 |
} else {
|
61 |
usb_puts("\r\nBOM table: (* indicates this robot)");
|
62 |
} |
63 |
|
64 |
// print table of bom readings between robots
|
65 |
usb_puts("\r\ns \\ d");
|
66 |
// print header
|
67 |
for(int j=0;j<MAX_ROBOTS;j++) |
68 |
if (robotList[j]) {
|
69 |
usb_puts("\t|");
|
70 |
if (j == wl_get_xbee_id())
|
71 |
usb_puts("*"); // indicate that this is the current bot |
72 |
usb_puti(j); |
73 |
} |
74 |
usb_puts("\r\n");
|
75 |
// print body
|
76 |
for(int l=0;l<MAX_ROBOTS;l++) |
77 |
if (robotList[l]) {
|
78 |
if (l == wl_get_xbee_id())
|
79 |
usb_puts("*"); // indicate that this is the current bot |
80 |
usb_puti(l); // print label col
|
81 |
for(int k=0;k<MAX_ROBOTS;k++) |
82 |
if (robotList[k]) {
|
83 |
usb_puts("\t|");
|
84 |
if (k != l) {
|
85 |
int bom = wl_token_get_sensor_reading(l,k);
|
86 |
if (bom >= 0 && bom <= 15) |
87 |
usb_puti(bom); // print bom value
|
88 |
} |
89 |
} |
90 |
usb_puts("\r\n");
|
91 |
} |
92 |
usb_puts("\r\n");
|
93 |
} |
94 |
} |
95 |
|
96 |
// end testing token ring and bom
|
97 |
return 0; |
98 |
} |
99 |
|
100 |
|