Project

General

Profile

Revision 366

The lib things were just because of a few recompilations.
Data requests project works for IR, the problems with IR were almost definitely the problems with the others (encoder / BOM data).
I'll fix the code for those next time, and then begin work on encoders.
Hopefully I'll be able to abstract the robots out completely and just work with raw data in a month or two.

View differences:

test_main.c
5 5
#include "wireless.h"
6 6
#include "wl_token_ring.h"
7 7
#include "pthread.h"
8
#include "string.h"
8 9

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

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

  
22 23
pthread_t* wl_do_thread;
23 24

  
24 25
int main(void){
25
  wl_set_com_port("/dev/cu.usbserial-A1000Qu6");
26
  char* com_port = malloc(strlen("/dev/cu.usbserial-A4001hAN"));
27
  strcpy(com_port,"/dev/cu.usbserial-A4001hAN");
28
  wl_set_com_port(com_port);
26 29
  wl_init();
30
  wl_set_channel(0xD); 
27 31
  wl_token_ring_register();
28 32
  data_requests_init(bom_handler,IR_handler,encoder_handler);
29
  
30 33
  int robot_id;
31 34
  bom_responded_flag = 0;
32 35
  ir_responded_flag = 0;
33 36
  encoder_responded_flag = 0;
34
  int test_count; 
37
  int test_count,test_count2; 
35 38

  
36
  wl_do_thread = malloc(sizeof(pthread_t));
37
  pthread_create(wl_do_thread,NULL,wl_do_routine,NULL);
39
  //wl_do_thread = malloc(sizeof(pthread_t));
40
  //pthread_create(wl_do_thread,NULL,wl_do_routine,NULL);
38 41

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

  
45 49
        bom_responded_flag = 0;
......
56 60
        test_count=0;
57 61
        while(!(ir_responded_flag)&&(test_count++<20)){
58 62
          printf("Waiting on %i..\n",robot_id);
59
          usleep(5000000);
60
        }
63
          for(test_count2=0;test_count2<1000;test_count2++){
64
            wl_do();
65
            usleep(500);
66
          } //100 ms Total.
67
        } //Waits for 2 seconds total.
68

  
69

  
61 70
/*       
62 71
        request_encoder_data(robot_id);
63 72
        while(!encoder_responded_flag){
......
65 74
        }
66 75
*/
67 76
      }
68
      usleep(5000000);
77
      for(test_count=0;test_count<1000;test_count++){
78
        wl_do();
79
        usleep(5000); //1 Second total.
80
      }
81

  
69 82
  }
70 83
}
71 84

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

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

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

  

Also available in: Unified diff