Revision 629
added some more documentation
trunk/code/projects/colonet/server/Command.cpp | ||
---|---|---|
24 | 24 |
|
25 | 25 |
using namespace std; |
26 | 26 |
|
27 |
/** |
|
28 |
* @brief Constructor for the Command class |
|
29 |
* |
|
30 |
* @param connection_pool_temp The connection pool this instance of the Command class is supposed to use |
|
31 |
* @param cs The ColonetServer this instance of the Command class is supposed to use |
|
32 |
*/ |
|
27 | 33 |
Command::Command(ConnectionPool * connection_pool_temp, ColonetServer* cs) { |
28 | 34 |
connection_pool = connection_pool_temp; |
29 | 35 |
colonet_server = cs; |
30 | 36 |
} |
31 | 37 |
|
38 |
/** |
|
39 |
* @brief Destructor for the Command class |
|
40 |
*/ |
|
32 | 41 |
Command::~Command() {} |
33 | 42 |
|
34 | 43 |
/** |
35 |
* Called by connection pool to parse command from client. |
|
36 |
*/ |
|
44 |
* @brief Called by connection pool to parse command from client. |
|
45 |
* |
|
46 |
* @param command The command to parse |
|
47 |
* @param pool_index The index in the connection pool of the client who generated this command |
|
48 |
* |
|
49 |
* @return 0 on success, negative error code on failure |
|
50 |
*/ |
|
37 | 51 |
int Command::parse_command(char* command, int pool_index) { |
38 | 52 |
char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]; |
39 | 53 |
int number_tokens = 0; |
... | ... | |
87 | 101 |
return -1; |
88 | 102 |
} |
89 | 103 |
|
104 |
//look for the end of the next token (tokens are separated by spaces) |
|
90 | 105 |
while ((end_token = strstr(next_token, " "))) { |
106 |
//set the location of the space to a null terminator |
|
91 | 107 |
*end_token = '\0'; |
92 | 108 |
|
109 |
//make sure the token isn't too long |
|
93 | 110 |
if (strlen(next_token) > MAX_TOKEN_SIZE-1) { |
94 | 111 |
return -1; |
95 | 112 |
} |
96 | 113 |
|
114 |
//copy the next token into the token array |
|
97 | 115 |
strcpy(tokens[number_tokens], next_token); |
98 | 116 |
|
99 | 117 |
number_tokens++; |
118 |
|
|
100 | 119 |
next_token = end_token + 1; |
101 | 120 |
|
121 |
//skip over extra whitespace if there is any between tokens |
|
102 | 122 |
while (isspace(*next_token) && *next_token != '\0') { |
103 | 123 |
next_token++; |
104 | 124 |
} |
105 | 125 |
} |
106 | 126 |
|
127 |
//get the last token if there were no spaces at the end of the string to indicate an end of token |
|
107 | 128 |
if (end_token == NULL && *next_token != '\0') { |
108 | 129 |
if (strlen(next_token) > MAX_TOKEN_SIZE-1) { |
109 | 130 |
return -1; |
... | ... | |
144 | 165 |
return 0; |
145 | 166 |
} |
146 | 167 |
|
168 |
//TODO: fill in the doxygen comments for this |
|
147 | 169 |
/** |
148 | 170 |
* @brief Sends parsed command from server to robot(s). |
171 |
* |
|
172 |
* @param number_int_tokens |
|
173 |
* @param tokens |
|
174 |
* @param pool_index |
|
175 |
* |
|
176 |
* @return 0 on success, negative error code on failure |
|
149 | 177 |
*/ |
150 | 178 |
int Command::parse_send_to_robot(int number_int_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) { |
151 | 179 |
unsigned char int_tokens[MAX_TOKENS], arguments[PACKET_DATA_LEN]; |
... | ... | |
185 | 213 |
} |
186 | 214 |
|
187 | 215 |
/** |
188 |
* |
|
189 |
*/ |
|
216 |
*
|
|
217 |
*/
|
|
190 | 218 |
int Command::parse_request_from_server(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) { |
191 | 219 |
char* end_pointer = NULL; |
192 | 220 |
|
trunk/code/projects/colonet/server/colonet_wireless.cpp | ||
---|---|---|
222 | 222 |
|
223 | 223 |
/**************************** Private functions ******************************/ |
224 | 224 |
|
225 |
//TODO: fill in the doxygen comments |
|
226 |
/** |
|
227 |
* @brief |
|
228 |
* |
|
229 |
* @return Void |
|
230 |
*/ |
|
225 | 231 |
static void timeout_handler() { |
226 | 232 |
// printf("colonet wireless - timeout!\n"); |
227 | 233 |
} |
228 | 234 |
|
235 |
//TODO: fill in the doxygen comments |
|
236 |
/** |
|
237 |
* @brief |
|
238 |
* |
|
239 |
* @param frame |
|
240 |
* @param received |
|
241 |
* |
|
242 |
* @return Void |
|
243 |
*/ |
|
229 | 244 |
static void handle_response(int frame, int received) { |
230 | 245 |
//TODO: These are just here to get rid of compiler warnings |
231 | 246 |
frame = frame; |
... | ... | |
233 | 248 |
printf("handle_response\n"); |
234 | 249 |
} |
235 | 250 |
|
251 |
/** |
|
252 |
* @brief When a packet is received via wireless, the data is passed to this function |
|
253 |
* |
|
254 |
* @param type |
|
255 |
* @param source The robot the packet came from |
|
256 |
* @param data The data the robot sent |
|
257 |
* @param len The length of the data |
|
258 |
* |
|
259 |
* @return Void |
|
260 |
*/ |
|
236 | 261 |
static void handle_receive(char type, int source, unsigned char* data, int len) { |
237 | 262 |
type = type; //TODO: This is just here to get rid of compiler warnings. |
238 | 263 |
|
... | ... | |
250 | 275 |
int robot_x, robot_y; |
251 | 276 |
PositionMonitor* pm = colonet_server.getPositionMonitor(); |
252 | 277 |
int num_robots = pm->getNumVisibleRobots(); |
278 |
|
|
253 | 279 |
//ask the position monitor for where that robot is. |
254 | 280 |
int ret = pm->getRobotPosition(source, &robot_x, &robot_y); |
255 | 281 |
if (ret != 0 && num_robots != 1) { |
... | ... | |
285 | 311 |
} |
286 | 312 |
} |
287 | 313 |
|
314 |
//TODO: fill in the doxygen comments |
|
315 |
/** |
|
316 |
* @brief |
|
317 |
* |
|
318 |
* @return Void |
|
319 |
*/ |
|
288 | 320 |
static void unregister(void) { |
289 | 321 |
printf("unregister\n"); |
290 | 322 |
} |
... | ... | |
308 | 340 |
|
309 | 341 |
while (1) { |
310 | 342 |
wl_do(); |
343 |
|
|
344 |
//this sleep is here so the thread this runs in doesn't hog the cpu |
|
311 | 345 |
usleep(1000); |
312 | 346 |
} |
313 | 347 |
|
... | ... | |
317 | 351 |
return NULL; |
318 | 352 |
} |
319 | 353 |
|
320 |
/** @brief |
|
354 |
/** |
|
355 |
* @brief |
|
321 | 356 |
* |
322 | 357 |
* @param pkt Packet to be logged |
323 | 358 |
* |
Also available in: Unified diff