Revision 75
made it send a random sensor matrix when client requests bom matrix
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