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:

data_response.c
26 26

  
27 27
void handle_receive(char type, int source, unsigned char* packet, int length){
28 28
  char buf[MAX_PACKET_LENGTH]; 
29
  int size;
29
  int size, i;
30 30
  usb_puts("Got a packet!\n\r");
31 31
  switch(type){
32 32
  case BOM_TYPE:
33 33
    size = generate_bom_packet(&buf); 
34 34
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,BOM_TYPE,buf,size,source,0);
35
  
36
  
35 37
  case IR_TYPE:
36
    size = generate_IR_packet(&buf); 
38

  
39
    usb_puts("Generating an IR packet.\n");
40
    char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
41
    int i;
42
    short ir_value; 
43
    for(i=0;i<5;i++){
44
      ir_value = (short)range_read_distance(ranges[i]);
45
      buf[2*i] = (char)((ir_value>>8)&255);   
46
      buf[2*i+1] = (ir_value&255);   
47
      usb_puts("Distance :\t");
48
      usb_puti(ir_value);
49
      usb_puts("\n");
50
    }
51
    size = 10;
52

  
53
    usb_puts("Packet Contents: ");
54
    for(i = 0; i<size;i++){
55
        usb_puti(buf[i]);
56
        usb_putc(' ');
57
    }
37 58
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,IR_TYPE,buf,size,source,0);
59
  
60
  
61
  
38 62
  case ENCODER_TYPE:
39 63
    break; 
40 64
    //Not yet supported.
......
43 67

  
44 68
int generate_bom_packet(char** buf){
45 69
  short int i=0, robot_id; 
46
  char bom_data;
47 70
  wl_token_iterator_begin();
48 71
  while(wl_token_iterator_has_next() && i<=96){
49 72
    robot_id = wl_token_iterator_next();
......
56 79
}
57 80

  
58 81
int generate_IR_packet(char** buf){
59
  *buf[0] = range_read_distance(IR1);   
60
  delay_ms(20);
61
  *buf[1] = range_read_distance(IR2);   
62
  delay_ms(20);
63
  *buf[2] = range_read_distance(IR3);   
64
  delay_ms(20);
65
  *buf[3] = range_read_distance(IR4);   
66
  delay_ms(20);
67
  *buf[4] = range_read_distance(IR5); 
68
  char i;
69
  return 5;
82
  usb_puts("Generating an IR packet.\n");
83
  char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
84
  int i;
85
  short ir_value; 
86
  for(i=0;i<5;i++){
87
    ir_value = (short)range_read_distance(ranges[i]);
88
    (*buf)[2*i] = (char)((ir_value>>8)&255);   
89
    (*buf)[2*i+1] = (ir_value&255);   
90
    usb_puts("Distance :\t");
91
    usb_puti(ir_value);
92
    usb_puts("\n");
93
  }
94
  return 10;
70 95
}

Also available in: Unified diff