UDP implementation

This commit is contained in:
Johnathon Slightham
2026-01-06 14:02:56 -05:00
committed by Johnathon Slightham
parent 92ddc3faf9
commit 53d3c775ba
12 changed files with 388 additions and 86 deletions

View File

@@ -4,7 +4,7 @@
/**
* @brief Initializes the RIP table
*
*
*/
void DataLinkManager::init_rip(){
for (size_t i = 0; i < RIP_MAX_ROUTES; i++){
@@ -54,11 +54,11 @@ esp_err_t DataLinkManager::rip_add_entry(uint8_t board_id, uint8_t hops, uint8_t
(*entry)->ttl = RIP_TTL_START;
(*entry)->valid = 1;
// ESP_LOGI(DEBUG_LINK_TAG, "board_id %d now has hops %d from channel %d", (*entry)->info.board_id, (*entry)->info.hops, channel);
xSemaphoreGive((*entry)->row_sem);
if (uxQueueMessagesWaiting(manual_broadcasts) == 0){
bool dummy = true;
xQueueSend(manual_broadcasts, &dummy, 0); //new row - send broadcast
@@ -108,9 +108,9 @@ esp_err_t DataLinkManager::rip_update_entry(uint8_t new_hop, uint8_t channel, RI
(*entry)->channel = channel;
// ESP_LOGI(DEBUG_LINK_TAG, "updated board_id %d now has hops %d from channel %d", (*entry)->info.board_id, (*entry)->info.hops, channel);
}
(*entry)->ttl = RIP_TTL_START;
(*entry)->valid = 1;
(*entry)->valid = 1;
// ESP_LOGI(DEBUG_LINK_TAG, "refreshed board_id %d ttl", (*entry)->info.board_id);
@@ -128,10 +128,10 @@ esp_err_t DataLinkManager::rip_update_entry(uint8_t new_hop, uint8_t channel, RI
/**
* @brief Finds the board_id in the table if it exists and stores that row in `entry`
* TODO: use an unordered map instead of an array?
*
* @param board_id
* @param entry
* @return esp_err_t
*
* @param board_id
* @param entry
* @return esp_err_t
*/
esp_err_t DataLinkManager::rip_find_entry(uint8_t board_id, RIPRow** entry, bool reserve_row = false){
RIPRow* free_slot = nullptr;
@@ -144,7 +144,7 @@ esp_err_t DataLinkManager::rip_find_entry(uint8_t board_id, RIPRow** entry, bool
xSemaphoreGive(rip_table[i].row_sem);
// ESP_LOGI(DEBUG_LINK_TAG, "Found %d in table at row %d", board_id, i);
return ESP_OK;
}
}
if (rip_table[i].valid == RIP_INVALID_ROW && free_slot == nullptr){
free_slot = &rip_table[i];
}
@@ -176,10 +176,10 @@ esp_err_t DataLinkManager::rip_find_entry(uint8_t board_id, RIPRow** entry, bool
/**
* @brief Returns the associated RIP Table row by row number. Information returned is read only.
*
* @param entry
* @param row_num
* @return esp_err_t
*
* @param entry
* @param row_num
* @return esp_err_t
*/
esp_err_t DataLinkManager::rip_get_row(RIPRow** entry, uint8_t row_num){
if (entry == nullptr){
@@ -216,10 +216,10 @@ esp_err_t DataLinkManager::rip_get_row(RIPRow** entry, uint8_t row_num){
/**
* @brief Sends RIP frame
*
*
* @param broadcast True - broadcasts (sends rip table to all available channels); False - sends rip table via routing based on `dest_id`
* @param dest_id Destination board (requesting board) to send the rip table to (ignored if `broadcast is true`)
* @return esp_err_t
* @return esp_err_t
*/
esp_err_t DataLinkManager::send_rip_frame(bool broadcast, uint8_t dest_id){
//use the control frame for the demo (as the number of rows increase, we will need to use the generic frame)
@@ -236,17 +236,17 @@ esp_err_t DataLinkManager::send_rip_frame(bool broadcast, uint8_t dest_id){
for (size_t channel = 0; channel < num_channels; channel++){
for (size_t i = 0; i < RIP_MAX_ROUTES; i++){
res = rip_get_row(&entry, i);
if (res != ESP_OK){
continue;
}
if (entry == nullptr){
continue;
}
// ESP_LOGI(DEBUG_LINK_TAG, "Found entry for board %d with hops %d", entry->info.board_id, entry->info.hops);
if (entry->channel == channel){
//poisoned reverse
rip_message[message_idx++] = entry->info.board_id;
@@ -264,7 +264,7 @@ esp_err_t DataLinkManager::send_rip_frame(bool broadcast, uint8_t dest_id){
}
memset(send_data, 0, message_idx);
memcpy(send_data, rip_message, message_idx);
SchedulerMetadata metadata = {
.header = {
.preamble = START_OF_FRAME,
@@ -314,10 +314,10 @@ esp_err_t DataLinkManager::send_rip_frame(bool broadcast, uint8_t dest_id){
/**
* @brief Determines which channel to route the frame to, depending on the dest (board) id
*
* @param dest_id
* @param channel_to_send
* @return esp_err_t
*
* @param dest_id
* @param channel_to_send
* @return esp_err_t
*/
esp_err_t DataLinkManager::route_frame(uint8_t dest_id, uint8_t* channel_to_send){
RIPRow* entry = nullptr;
@@ -364,7 +364,7 @@ esp_err_t DataLinkManager::get_routing_table(RIPRow_public* table, size_t* table
table[i].info = rip_table[i].info;
table[i].channel = rip_table[i].channel;
curr_size++;
}
}
xSemaphoreGive(rip_table[i].row_sem);
}
@@ -427,7 +427,7 @@ esp_err_t DataLinkManager::get_routing_table(RIPRow_public* table, size_t* table
link_layer_obj->rip_table[i].ttl_flush = RIP_FLUSH_COUNT;
broadcast = true;
}
}
}
xSemaphoreGive(link_layer_obj->rip_table[i].row_sem);
}
@@ -452,5 +452,5 @@ void DataLinkManager::start_rip_tasks(){
ESP_LOGI(DEBUG_LINK_TAG, "Starting RIP Broadcast task");
xTaskCreate(DataLinkManager::rip_broadcast_timer_function, "RIPBroadcast", 4096, static_cast<void*>(this), 5, &rip_broadcast_task);
ESP_LOGI(DEBUG_LINK_TAG, "Starting RIP TTL task");
xTaskCreate(DataLinkManager::rip_ttl_decrement_task, "RIPTTL", 2048, static_cast<void*>(this), 5, &rip_ttl_task);
}
xTaskCreate(DataLinkManager::rip_ttl_decrement_task, "RIPTTL", 4096, static_cast<void*>(this), 5, &rip_ttl_task);
}