Project

General

Profile

Revision 424

changed various things in colonet dragonfly and server to make stuff work

View differences:

Command.cpp
24 24
  connection_pool = connection_pool_temp;
25 25
}
26 26

  
27
Command::~Command() {
28
}
27
Command::~Command() {}
29 28

  
29
/**
30
* Called by connection pool to parse command from client.
31
*/
30 32
int Command::parse_command(char* command, int pool_index) {
31 33
  char tokens[MAX_TOKENS][MAX_TOKEN_SIZE];
32 34
  int number_tokens = 0;
33 35
  char* end_pointer = NULL;
34 36
  int command_id;
35 37

  
36
  if (!connection_pool) {
38
  if (!connection_pool || !command || pool_index < 0) {
37 39
    return -1;
38 40
  }
39 41

  
40
  if (!command) {
41
    return -1;
42
  }
43

  
44
  if (pool_index < 0) {
45
    return -1;
46
  }
47

  
48 42
  if ((number_tokens = tokenize_command(command, tokens)) < 0) {
49 43
    return -1;
50 44
  }
......
59 53

  
60 54
  if (command_id == SEND_TO_ROBOT) {
61 55
    if (parse_send_to_robot(number_tokens, tokens, pool_index)) {
56
      fprintf(stderr, "parse_send_to_robot failed.\n");
62 57
      return -1;
63 58
    }
64 59
  } else if (command_id == REQUEST_FROM_SERVER) {
......
145 140
  return 0;
146 141
}
147 142

  
148
int Command::parse_send_to_robot(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) {
149
  int i;
150
  unsigned char int_tokens[MAX_TOKENS];
151
  int number_int_tokens = number_tokens;
152
  unsigned char arguments[PACKET_DATA_LEN];
143
/**
144
* @brief Sends parsed command from server to robot(s).
145
*/
146
int Command::parse_send_to_robot(int number_int_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) {
147
  unsigned char int_tokens[MAX_TOKENS], arguments[PACKET_DATA_LEN];
153 148

  
154 149
  memset(arguments, 1, PACKET_DATA_LEN);
155 150

  
156 151
  // Convert tokens to ints
157
  for (i = ROBOT_COMMAND_OFFSET; i < number_int_tokens; i++) {
152
  for (int i = ROBOT_COMMAND_OFFSET; i < number_int_tokens; i++) {
158 153
    int_tokens[i-ROBOT_COMMAND_OFFSET] = atoi(tokens[i]);
159 154
  }
160 155

  
161 156
  // Fill arguments buffer with arguments
162
  for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; i++) {
157
  for (int i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; i++) {
163 158
    arguments[i-ROBOT_COMMAND_LEN] = int_tokens[i];
164 159
  }
165 160

  
......
169 164
    return -1;
170 165
  }
171 166

  
167
  printf("parsed command from internet client: ");
168
  for (int i = 0; i < number_int_tokens - ROBOT_COMMAND_OFFSET; i++) {
169
    printf("%d ", int_tokens[i]);
170
  }
171
  printf("\n");
172

  
172 173
  // Send packet to robot
173
  fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n",
174
          int_tokens[0], int_tokens[1], int_tokens[2]);
175
  if (colonet_wl_send((short)pool_index, int_tokens[0], (ColonetMessageType)int_tokens[1], int_tokens[2], arguments)
176
      != 0) {
174
  if (colonet_wl_send((short)pool_index, int_tokens[0], (ColonetRobotMessageType)int_tokens[1], int_tokens[2],
175
    arguments) != 0) {
177 176
    fprintf(stderr, "Error - Colonet_wl_send failed.\n");
178 177
    exit(1);
179 178
  }
......
181 180
  return 0;
182 181
}
183 182

  
183
/**
184
* 
185
*/
184 186
int Command::parse_request_from_server(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) {
185 187
  char* end_pointer = NULL;
186 188

  

Also available in: Unified diff