Revision 75
made it send a random sensor matrix when client requests bom matrix
trunk/code/projects/colonet/lib/colonet_defs.h | ||
---|---|---|
150 | 150 |
#define KILL_ROBOT 0x52 |
151 | 151 |
|
152 | 152 |
//Colonet specific commands |
153 |
#define REQUEST_BOM_MATRIX 0x90 |
|
154 |
//request: REQUEST_FROM_SERVER REQUEST_BOM_MATRIX |
|
155 |
//response: RESPONSE_TO_CLIENT_REQUEST REQUEST_BOM_MATRIX <numRobots> <row by row, values separated by spaces> |
|
156 |
// if you don't know a value in the matrix, put -1 in there |
|
153 | 157 |
|
154 | 158 |
|
155 |
|
|
156 | 159 |
/* End low-level robot commands */ |
157 | 160 |
|
158 | 161 |
|
159 | 162 |
//Colonet Client commands |
163 |
//TODO: renamed these to end in LENGTH |
|
160 | 164 |
#define MAX_COMMAND_LEN 128 |
161 |
#define MAX_RESPONSE_LEN 512
|
|
165 |
#define MAX_RESPONSE_LEN 1024
|
|
162 | 166 |
|
163 | 167 |
#define SEND_TO_ROBOT 0x00 |
164 | 168 |
#define REQUEST_FROM_SERVER 0x01 |
trunk/code/projects/colonet/ColonetServer/includes/ConnectionPool.h | ||
---|---|---|
27 | 27 |
|
28 | 28 |
#define MAX_CONNECTIONS 250 |
29 | 29 |
#define READ_BUFFER_SIZE 1024 |
30 |
#define WRITE_BUFFER_SIZE 1024
|
|
30 |
#define WRITE_BUFFER_SIZE 4096
|
|
31 | 31 |
|
32 | 32 |
class ConnectionPool { |
33 | 33 |
|
trunk/code/projects/colonet/ColonetServer/ConnectionPool.cpp | ||
---|---|---|
450 | 450 |
int_tokens[0], int_tokens[1], int_tokens[2]); |
451 | 451 |
wireless->send(int_tokens[0], int_tokens[1], int_tokens[2], arguments); |
452 | 452 |
} else if (command_id == REQUEST_FROM_SERVER) { |
453 |
char * my_current_message = "Hi, how are you?"; |
|
454 |
printf("Sending %s\n", my_current_message); |
|
455 |
write_to_client(pool_index, my_current_message, strlen(my_current_message)); |
|
453 |
if (number_tokens < 2) |
|
454 |
return -1; |
|
455 |
|
|
456 |
end_pointer=NULL; |
|
457 |
int second_token = strtol(tokens[1], &end_pointer, 10); |
|
458 |
|
|
459 |
if (!end_pointer || *end_pointer != '\0') { |
|
460 |
printf("There was an error converting second token into a number.\n"); |
|
461 |
return -1; |
|
462 |
} |
|
463 |
|
|
464 |
if (second_token == REQUEST_BOM_MATRIX) { |
|
465 |
//TODO: rename to indicate its actually the response message |
|
466 |
char bom_matrix_buffer[MAX_RESPONSE_LEN]; |
|
467 |
char temp_bom_matrix_buffer[MAX_RESPONSE_LEN]; |
|
468 |
|
|
469 |
//TODO: change after we start keeping track of bom matrix |
|
470 |
int number_robots = rand()%10; |
|
471 |
int bom_matrix[number_robots][number_robots]; |
|
472 |
for (int ii = 0; ii < number_robots; ii++) { |
|
473 |
for (int j = 0; j < number_robots; j++) { |
|
474 |
//do this to generate some -1 values which mean they can't see each other |
|
475 |
int matrix_value = rand()%(number_robots+1)-1; |
|
476 |
bom_matrix[ii][j] = matrix_value; |
|
477 |
} |
|
478 |
} |
|
479 |
|
|
480 |
printf("number of robots is %d\n", number_robots); |
|
481 |
|
|
482 |
//TODO: separate parameters with spaces |
|
483 |
//TODO: make this better |
|
484 |
//TODO: make sure I don't need to do MAX_RESPONSE_LENGTH-1 |
|
485 |
snprintf(bom_matrix_buffer,MAX_RESPONSE_LEN, "%d %d %d", RESPONSE_TO_CLIENT_REQUEST, REQUEST_BOM_MATRIX, number_robots); |
|
486 |
for (int ii = 0; ii < number_robots; ii++) { |
|
487 |
for (int j = 0; j < number_robots; j++) { |
|
488 |
//TODO: don't use strcpy |
|
489 |
strcpy(temp_bom_matrix_buffer, bom_matrix_buffer); |
|
490 |
//TODO: put length checking in here so array doesn't go out of bounds |
|
491 |
//TODO: maybe use strncat? |
|
492 |
printf("Buffer is %s\n", bom_matrix_buffer); |
|
493 |
strcat(temp_bom_matrix_buffer," %d"); |
|
494 |
snprintf(bom_matrix_buffer, MAX_RESPONSE_LEN, temp_bom_matrix_buffer, bom_matrix[ii][j]); |
|
495 |
} |
|
496 |
} |
|
497 |
strcat(bom_matrix_buffer,"\n"); |
|
498 |
write_to_client(pool_index, bom_matrix_buffer, strlen(bom_matrix_buffer)); |
|
499 |
printf("Sending %s", bom_matrix_buffer); |
|
500 |
} else { |
|
501 |
char * my_current_message = "Hi, how are you?\n"; |
|
502 |
printf("Sending %s\n", my_current_message); |
|
503 |
write_to_client(pool_index, my_current_message, strlen(my_current_message)); |
|
504 |
} |
|
456 | 505 |
} |
457 | 506 |
|
458 | 507 |
return 0; |
Also available in: Unified diff