link layer routing works

This commit is contained in:
Justin Chow
2025-07-11 12:39:35 -04:00
committed by Johnathon Slightham
parent 732f141e45
commit c57fbd53e7
6 changed files with 279 additions and 73 deletions

View File

@@ -97,12 +97,11 @@ void multi_transceiver(void* arg) {
uint8_t dest_board_id = args->receiver_id; //using a dummy number for now - there is no board with id 2 right now
const char* message = "THIS IS A TEXT MESSAGE";
const char* message = "FROM BEST BOARD";
uint8_t curr_channel = args->task_id;
QueueHandle_t shared_queue = (QueueHandle_t)args->receive_queue;
uint8_t send_buf[DATA_SIZE_TEST];
uint8_t recv_buf[DATA_SIZE_TEST];
memset(recv_buf, 0, DATA_SIZE_TEST);
@@ -125,55 +124,93 @@ void multi_transceiver(void* arg) {
uint32_t num_incorrect = 0;
uint32_t total_transactions = 0;
RIPRow_public_matrix matrix[RIP_MAX_ROUTES];
size_t matrix_size = RIP_MAX_ROUTES;
for (int i = 0; i < RIP_MAX_ROUTES; i++){
RIPRow_public* table = (RIPRow_public*)pvPortMalloc(sizeof(RIPRow_public)*RIP_MAX_ROUTES);
matrix[i] = {
.table = table,
.size = RIP_MAX_ROUTES
};
}
ReceviedFrame recv_frame = {};
printf("task %d starting...\n", curr_channel);
vTaskDelay(3000 / portTICK_PERIOD_MS);
bool receive_only = false;
while(1){
// vTaskDelay(1000 / portTICK_PERIOD_MS); // wait 1 second before trying to send again
// snprintf(reinterpret_cast<char*>(send_buf), sizeof(send_buf), "%s %d CH. %d", message, iteration, curr_channel);
// ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer, &start_count));
// res = obj->send(dest_board_id, send_buf, strlen(reinterpret_cast<char*>(send_buf)), FrameType::DEBUG_CONTROL_TYPE, curr_channel);
// ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer, &end_count));
// snprintf(reinterpret_cast<char*>(send_buf), sizeof(send_buf), "%s RANDOM", message); //modifying the data while it transmits shouldn't affect the actual transmission here
// if (res != ESP_OK){
// ESP_LOGE("thread", "Failed to send message on thread %d", curr_channel);
// } else {
// printf("Successfully sent message\n");
// // printf("Sent %zu B sized in %" PRIu64 " us\n", strlen(reinterpret_cast<char*>(send_buf)) + CONTROL_FRAME_OVERHEAD, end_count-start_count);
// }
//wait on a queue for a few ms (if there's nothing, just send another frame. otherwise pop from queue and read it)
if (xQueueReceive(shared_queue, (void*)&recv_frame, (TickType_t) 50) != pdPASS){
memset(send_buf, 0, 256);
continue; //nothing or failed to pop from queue
if(!receive_only){
vTaskDelay(1000 / portTICK_PERIOD_MS); // wait 1 second before trying to send again
snprintf(reinterpret_cast<char*>(send_buf), sizeof(send_buf), "%s %d CH. %d", message, 4, curr_channel);
// ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer, &start_count));
res = obj->send(dest_board_id, send_buf, strlen(reinterpret_cast<char*>(send_buf)), FrameType::DEBUG_CONTROL_TYPE, 0x0);
// ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer, &end_count));
snprintf(reinterpret_cast<char*>(send_buf), sizeof(send_buf), "%s RANDOM", message); //modifying the data while it transmits shouldn't affect the actual transmission here
if (res != ESP_OK){
ESP_LOGE("thread", "Failed to send message on thread %d", curr_channel);
continue;
} else {
printf("Successfully sent message\n");
// printf("Sent %zu B sized in %" PRIu64 " us\n", strlen(reinterpret_cast<char*>(send_buf)) + CONTROL_FRAME_OVERHEAD, end_count-start_count);
}
}
res = obj->print_frame_info(recv_frame.buf, recv_frame.len, recv_buf);
if (res != ESP_OK){
num_incorrect++;
printf("Received %ld bad frames on tx/rx round %ld for thread %d\n", num_incorrect, total_transactions, curr_channel);
} else {
printf("Received message %s on channel %d on round %ld. Total bad frames %ld\n", recv_buf, curr_channel, total_transactions, num_incorrect);
if (receive_only){
//wait on a queue for a few ms (if there's nothing, just send another frame. otherwise pop from queue and read it)
if (xQueueReceive(shared_queue, (void*)&recv_frame, (TickType_t) 50) != pdPASS){
memset(send_buf, 0, 256);
continue; //nothing or failed to pop from queue
}
res = obj->print_frame_info(recv_frame.buf, recv_frame.len, recv_buf);
if (res != ESP_OK){
num_incorrect++;
printf("Received %ld bad frames on tx/rx round %ld for thread %d\n", num_incorrect, total_transactions, curr_channel);
} else {
printf("Received message %s on channel %d on round %ld. Total bad frames %ld\n", recv_buf, curr_channel, total_transactions, num_incorrect);
}
}
total_transactions++;
iteration++;
if (iteration == 100){
if (iteration == 10){
iteration = 0;
// if (!receive_only){
// matrix_size = RIP_MAX_ROUTES;
// res = obj->get_network_toplogy(matrix, &matrix_size);
// if (res != ESP_OK){
// ESP_LOGE("multi", "Failed to get topology");
// } else {
// for (int i = 0; i < matrix_size; i++){
// printf("Table for board %d:\n", matrix[i].board_id);
// printf("board_id\t\tHops\t\tChannel\n");
// for (int j = 0; j < matrix[i].size; j++){
// printf("%d\t\t%d\t\t%d\n", matrix[i].table[j].info.board_id, matrix[i].table[j].info.hops, matrix[i].table[j].channel);
// }
// printf("=====\n");
// //reset matrix
// matrix[i].size = RIP_MAX_ROUTES;
// }
// }
// }
}
// vTaskDelay(1000 / portTICK_PERIOD_MS); // wait 1 second before trying to send again
//reset temp buffers
memset(recv_buf, 0, DATA_SIZE_TEST);
memset(send_buf, 0, DATA_SIZE_TEST);
}
while(true){
@@ -215,7 +252,7 @@ extern "C" [[noreturn]] void app_main(void) {
// uint8_t iteration = 0;
// const char* message = "THIS IS A TEXT MESSAGE";
uint8_t num_channels = 1;
uint8_t board_id = 69;
uint8_t board_id = 4;
std::unique_ptr<DataLinkManager> obj = std::make_unique<DataLinkManager>(board_id, num_channels);
// uint8_t dest_board_id = 2; //using a dummy number for now - there is no board with id 2 right now
@@ -235,7 +272,7 @@ extern "C" [[noreturn]] void app_main(void) {
for (uint8_t i = 0; i < num_channels; i++){
args[i].link_layer_obj = obj_to_send;
args[i].task_id = i;
args[i].receiver_id = 1;
args[i].receiver_id = 69;
args[i].receive_queue = xQueueCreate(10, sizeof(ReceviedFrame)); //queue storing up to 10 control frames
xTaskCreate(multi_transceiver, "multi_transceiver", 4096, static_cast<void*>(&args[i]), 5, NULL);
vTaskDelay(500 / portTICK_PERIOD_MS);