Project

General

Profile

Revision 904

Compiles now. This code worked a while ago but I haven't touched it since early last semester.
The idea was to do exactly what Abe is doing now... so it might be useful.

View differences:

data_response.c
29 29
}
30 30

  
31 31

  
32
/**
33
* Sorry for the lack of modularity, I didn't want to deal with memory issues for too long, plus it'll be faster!
34
*/
35 32
void handle_receive(char type, int source, unsigned char* packet, int length){
36 33
  
37 34
  char buf[MAX_PACKET_LENGTH]; 
......
57 54
  
58 55
  case IR_TYPE:
59 56

  
60
    //usb_puts("Generating an IR packet.\n");
61 57
    for(i=0;i<5;i++){
62 58
      ir_value = (short)range_read_distance(ranges[i]);
63 59
      buf[2*i] = (char)((ir_value>>8)&255);   
64 60
      buf[2*i+1] = (ir_value&255);   
65
      //usb_puts("Distance :\t");
66
      //usb_puti(ir_value);
67
      //usb_puts("\n");
68 61
    }
69 62
    size = 10;
70 63

  
......
80 73
  case ENCODER_TYPE:
81 74
    break; 
82 75
    //Not yet supported.
83
  }
76
  
84 77
  case ALL_TYPE:
85 78
    for(i=0;i<5;i++){
86 79
      ir_value = (short)range_read_distance(ranges[i]);
87 80
      buf[2*i] = (char)((ir_value>>8)&255);   
88 81
      buf[2*i+1] = (ir_value&255);   
89 82
    } //Buf 0...9 filled.
90
    
83

  
91 84
    //Tack on the Encoder data... 
92 85
    //Then BOM: 
93 86
    wl_token_iterator_begin();
......
99 92
    }
100 93
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,ALL_TYPE,buf,size,source,0);
101 94
    break;
102
}
103

  
104
/** 
105
* @brief  Generates a BOM Data packet. **NO LONGER USED** Delete once this code is used often.
106
*/
107
int generate_bom_packet(char** buf){
108
  short int i=0, robot_id; 
109
  wl_token_iterator_begin();
110
  while(wl_token_iterator_has_next() && i<=96){
111
    robot_id = wl_token_iterator_next();
112
    (*buf)[i++] = (char)((robot_id>>8) & 0xFF);
113
    (*buf)[i++] = (char)(robot_id & 0xFF);
114
    (*buf)[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
115 95
  }
116
  //i is one greater than the index of the last byte... the size.
117
  return i;
118 96
}
119 97

  
120
/** 
121
* @brief Generates an IR Packet **NO LONGER USED** Delete once this code is used often.
122
* 
123
*/
124
int generate_IR_packet(char** buf){
125
  //usb_puts("Generating an IR packet.\n");
126
  char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
127
  int i;
128
  short ir_value; 
129
  for(i=0;i<5;i++){
130
    ir_value = (short)range_read_distance(ranges[i]);
131
    (*buf)[2*i] = (char)((ir_value>>8)&255);   
132
    (*buf)[2*i+1] = (ir_value&255);   
133
    //usb_puts("Distance :\t");
134
    //usb_puti(ir_value);
135
    //usb_puts("\n");
136
  }
137
  return 10;
138
}
98

  

Also available in: Unified diff