Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / test / test_tokenring.c @ 1452

History | View | Annotate | Download (2.55 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
  usb_init();
22
        usb_puts("usb turned on\r\n");
23
  wl_init();
24
  usb_puts("wireless turned on\r\n");
25
  wl_token_ring_register();
26
  wl_token_ring_join(); // join token ring
27
  usb_puts("token ring joined\r\n");
28
  int robotList[sizeof(int)*MAX_ROBOTS];
29
  int numRobots = 0;
30
  delay_ms(1000);
31
  
32
  // start testing wireless/token ring/BOM
33
  int i=0;
34
  while(1) {
35
    wl_do();
36
    // only print table every 200 loops
37
    if (i%200==0) {
38
      // get token ring size values
39
      usb_puts("\r\nnumber of robots in token ring:");
40
      usb_puti(wl_token_get_robots_in_ring());
41
      usb_puts("\r\nnumber of robots in matrix:"); 
42
      usb_puti(wl_token_get_num_robots());
43
      
44
      // get list of robots
45
      numRobots = 0;
46
      clearRobots(robotList);
47
      wl_token_iterator_begin();
48
      while(wl_token_iterator_has_next()) {
49
        int tmp = wl_token_iterator_next();
50
        if (tmp < 0)
51
          break;
52
        robotList[tmp] = 1;
53
        numRobots++;
54
      }
55
      if (numRobots < 1) {
56
        usb_puts("\r\nNo BOM table available.");
57
        continue; // skip table printing
58
      } else {
59
        usb_puts("\r\nBOM table: (* indicates this robot)");
60
      }
61
      
62
      // print table of bom readings between robots
63
      usb_puts("\r\ns \\ d");
64
      // print header
65
      for(int j=0;j<MAX_ROBOTS;j++)
66
        if (robotList[j]) {
67
          usb_puts("\t|");
68
          if (j == wl_get_xbee_id())
69
            usb_puts("*"); // indicate that this is the current bot
70
          usb_puti(j);
71
        }
72
      usb_puts("\r\n");
73
      // print body
74
      for(int l=0;l<MAX_ROBOTS;l++) 
75
        if (robotList[l]) {        
76
          if (l == wl_get_xbee_id())
77
            usb_puts("*"); // indicate that this is the current bot
78
          usb_puti(l); // print label col
79
          for(int k=0;k<MAX_ROBOTS;k++) 
80
            if (robotList[k]) {
81
              usb_puts("\t|");
82
              if (k != l) {
83
                int bom = wl_token_get_sensor_reading(l,k);
84
                if (bom >= 0 && bom <= 15)
85
                  usb_puti(bom); // print bom value
86
              }
87
            }
88
          usb_puts("\r\n");
89
        }
90
      usb_puts("\r\n");
91
    }
92
  }
93
  
94
  // end testing token ring and bom
95
        return 0;
96
}
97

    
98