Project

General

Profile

Revision 129

Added by Jason knichel almost 13 years ago

moved the send to robot code out into its own function in the Command class

View differences:

Command.cpp
22 22
//TODO: write a function to write data into the write buffers (jason: what was this referring to?)
23 23
int Command::parse_command(char* command, int pool_index, ConnectionPool * connection_pool) {
24 24
  char tokens[MAX_TOKENS][MAX_TOKEN_SIZE];
25
  unsigned char int_tokens[MAX_TOKENS];
26 25
  int number_tokens = 0;
27 26
  char* end_pointer = NULL;
28 27
  int command_id;
29
  int i;
30
  unsigned char arguments[PACKET_DATA_LEN];
31 28

  
32
  memset(arguments, 1, PACKET_DATA_LEN);
33

  
34 29
  if (!command) {
35 30
    return -1;
36 31
  }
......
52 47
  }
53 48

  
54 49
  if (command_id == SEND_TO_ROBOT) {
55
    int number_int_tokens = number_tokens;
56

  
57
    // Convert tokens to ints 
58
    for (i = ROBOT_COMMAND_OFFSET; i < number_int_tokens; i++) {
59
      int_tokens[i-ROBOT_COMMAND_OFFSET] = atoi(tokens[i]);
50
    if (parse_send_to_robot(number_tokens, tokens)) {
51
      return -1;
60 52
    }
61

  
62
    // Fill arguments buffer with arguments 
63
    for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET;
64
         i++) {
65
      arguments[i-ROBOT_COMMAND_LEN] = int_tokens[i];
66
    }
67

  
68
    // Check the tokens 
69
    if (check_tokens(int_tokens, number_int_tokens) < 0) {
70
      fprintf(stderr, "%s: Error - Invalid command/request.\n", __FUNCTION__);
71
      return 0;
72
    }
73

  
74
    /*  
75
    // Send packet to robot 
76
    fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n", 
77
            int_tokens[0], int_tokens[1], int_tokens[2]);
78
    colonet_wl_send(pool_index, int_tokens[0],
79
                    (ColonetMessageType)int_tokens[1], int_tokens[2],
80
                    arguments);
81
    */
82 53
  } else if (command_id == REQUEST_FROM_SERVER) {
83 54
    if (number_tokens < 2)
84 55
      return -1;
......
233 204

  
234 205
  return 0;
235 206
}
207

  
208

  
209

  
210

  
211

  
212

  
213
int Command::parse_send_to_robot(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]) {
214
  int i;
215
  unsigned char int_tokens[MAX_TOKENS];
216
  int number_int_tokens = number_tokens;
217
  unsigned char arguments[PACKET_DATA_LEN];
218

  
219
  memset(arguments, 1, PACKET_DATA_LEN);
220

  
221
  // Convert tokens to ints 
222
  for (i = ROBOT_COMMAND_OFFSET; i < number_int_tokens; i++) {
223
    int_tokens[i-ROBOT_COMMAND_OFFSET] = atoi(tokens[i]);
224
  }
225

  
226
  // Fill arguments buffer with arguments 
227
  for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET;
228
       i++) {
229
    arguments[i-ROBOT_COMMAND_LEN] = int_tokens[i];
230
  }
231

  
232
  // Check the tokens 
233
  if (check_tokens(int_tokens, number_int_tokens) < 0) {
234
    fprintf(stderr, "%s: Error - Invalid command/request.\n", __FUNCTION__);
235
    return -1;
236
  }
237

  
238
  /*  
239
  // Send packet to robot 
240
  fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n", 
241
  int_tokens[0], int_tokens[1], int_tokens[2]);
242
  colonet_wl_send(pool_index, int_tokens[0],
243
  (ColonetMessageType)int_tokens[1], int_tokens[2],
244
  arguments);
245
  */
246
  return 0;
247
}

Also available in: Unified diff