Project

General

Profile

Statistics
| Revision:

root / branches / slam / code / projects / colonet / DataRequests / server / test_main.c @ 294

History | View | Annotate | Download (1.92 KB)

1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <unistd.h>
4
#include "data_requests.h"
5
#include "wireless.h"
6
#include "wl_token_ring.h"
7
#include "pthread.h"
8

    
9
void IR_handler(unsigned char* data);
10
void bom_handler(BomNode* head);
11
void encoder_handler(unsigned char* data);
12

    
13
unsigned char bom_responded_flag;
14
unsigned char ir_responded_flag;
15
unsigned char encoder_responded_flag;
16
void* wl_do_routine(void* arg){
17
  while(1){
18
     wl_do();
19
  }
20
}
21

    
22
pthread_t* wl_do_thread;
23

    
24
int main(void){
25
  wl_set_com_port("/dev/cu.usbserial-A1000Qu6");
26
  wl_init();
27
  wl_token_ring_register();
28
  data_requests_init(bom_handler,IR_handler,encoder_handler);
29
  
30
  int robot_id;
31
  bom_responded_flag = 0;
32
  ir_responded_flag = 0;
33
  encoder_responded_flag = 0;
34
  int test_count; 
35

    
36
  wl_do_thread = malloc(sizeof(pthread_t));
37
  pthread_create(wl_do_thread,NULL,wl_do_routine,NULL);
38

    
39
  while(1){
40
      printf(".");
41
      wl_token_iterator_begin();
42
      while(wl_token_iterator_has_next()){
43
        robot_id = wl_token_iterator_next();
44

    
45
        bom_responded_flag = 0;
46
        ir_responded_flag = 0;
47
        encoder_responded_flag = 0;
48
/*
49
        request_bom_data(robot_id);
50
        while(!bom_responded_flag){
51
          delay_ms(50);
52
        }
53
*/       
54
        printf("Sending a request to %i\n",robot_id);
55
        request_IR_data(robot_id);
56
        test_count=0;
57
        while(!(ir_responded_flag)&&(test_count++<20)){
58
          printf("Waiting on %i..\n",robot_id);
59
          usleep(5000000);
60
        }
61
/*       
62
        request_encoder_data(robot_id);
63
        while(!encoder_responded_flag){
64
          delay_ms(50);
65
        }
66
*/
67
      }
68
      usleep(5000000);
69
  }
70
}
71

    
72
void IR_handler(unsigned char* data){
73
  char i = 0;
74
  printf("IR Callback occurred.\n");
75
  for(i=0;i<5;i++){
76
    printf("IR %i is %i\n",i+1,(int)data[i]);
77
  }
78
  ir_responded_flag=1;
79
}
80

    
81
void bom_handler(BomNode* head){
82
  bom_responded_flag=1;
83
}
84

    
85
void encoder_handler(unsigned char* data){
86
  encoder_responded_flag=1;
87
}
88