Project

General

Profile

Revision 444

colonet wireless position reporting

View differences:

trunk/code/projects/colonet/ColonetServer/colonet_wireless.cpp
170 170
}
171 171

  
172 172
static void handle_response(int frame, int received) {
173
  //TODO: remove these assignments.  they are just here to stop getting compile warnings for not being used
174
  frame = frame;
175
  received =received;
176

  
177 173
  //printf("got response.\n");
178 174
}
179 175

  
180 176
static void handle_receive(char type, int source, unsigned char* data, int len) {
181
  //TODO: remove this assignment.  it is just here to stop getting compile warnings for not being used
182
  type=type;
177
  printf("handle receive\n");
183 178

  
184 179
  ColonetRobotServerPacket* pkt = (ColonetRobotServerPacket*)data;
185 180

  
......
187 182
    log_packet(data, len);
188 183
  }
189 184

  
190
  char processed_data[80];
191
  sprintf(processed_data, "%d %d %d %s\n", RESPONSE_TO_CLIENT_REQUEST, pkt->msg_code, source, pkt->data);
185
  if (pkt->msg_code == ROBOT_REQUEST_POSITION_FROM_SERVER) {
186
    /* Robot has requested its position. */
187
    int robot_x, robot_y;
188
    if (colonet_server.getPositionMonitor()->getRobotPosition(source, &robot_x, &robot_y) != 0) {
189
      fprintf(stderr, "Robot %d requested position, but its position is not known.\n", source);
190
    } else {
191
      unsigned char response[80];
192
      response[0] = robot_x & 0xFF;
193
      response[1] = (robot_x >> 8) & 0xFF;
194
      response[2] = robot_y & 0xFF;
195
      response[3] = (robot_y >> 8) & 0xFF;
192 196

  
193
  colonet_server.process_received_wireless_message(pkt->client_id, processed_data, strlen(processed_data));
197
      if (colonet_wl_send(-1, source, COLONET_COMMAND, SERVER_REPORT_POSITION_TO_ROBOT, response) != 0) {
198
        fprintf(stderr, "colonet_wl_send failed!\n");
199
        exit(1);
200
      }
201
    }
202
  } else {
203
    char processed_data[80];
204
    sprintf(processed_data, "%d %d %d %s\n", RESPONSE_TO_CLIENT_REQUEST, pkt->msg_code, source, pkt->data);
194 205

  
195
  printf("handle receive\n");
206
    colonet_server.process_received_wireless_message(pkt->client_id, processed_data, strlen(processed_data));
207
  }
196 208
}
197 209

  
198 210
static void unregister(void) {
......
209 221
 * @return NULL
210 222
 */
211 223
static void* listen(void* args) {
212
  //TODO: remove this assignment.  it is just here to stop getting compile warnings for not being used
213
  args = args;
214

  
215 224
  printf("Called listen.\n");
216 225

  
217 226
  PacketGroupHandler pgh = {COLONET_PACKET_GROUP_ID,
trunk/code/projects/colonet/ColonetServer/includes/ColonetServer.h
19 19
  int start_listening(void);
20 20
  int run_server(void);
21 21
  int process_received_wireless_message(int dest, char* data, int len);
22
  PositionMonitor getPositionMonitor(void);
22
  PositionMonitor* getPositionMonitor(void);
23 23

  
24 24
private:
25 25
  ConnectionPool connection_pool;
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp
246 246
  return 0;
247 247
}
248 248

  
249
PositionMonitor ColonetServer::getPositionMonitor() {
250
  return position_monitor;
249
PositionMonitor* ColonetServer::getPositionMonitor() {
250
  return &position_monitor;
251 251
}

Also available in: Unified diff