link layer routing works

This commit is contained in:
superkor
2025-07-11 12:39:35 -04:00
parent 32254d6645
commit bf1c72215f
6 changed files with 279 additions and 73 deletions

View File

@@ -41,11 +41,12 @@ class DataLinkManager{
public:
DataLinkManager(uint8_t board_id, uint8_t num_channels);
~DataLinkManager();
esp_err_t send(uint8_t dest_board, uint8_t* data, uint16_t data_len, FrameType type, uint8_t curr_channel);
esp_err_t send(uint8_t dest_board, uint8_t* data, uint16_t data_len, FrameType type, uint8_t flag);
esp_err_t start_receive_frames(uint8_t curr_channel);
esp_err_t receive(uint8_t* data, size_t data_len, size_t* recv_len, uint8_t curr_channel);
esp_err_t print_frame_info(uint8_t* data, size_t data_len, uint8_t* message);
esp_err_t send_discover_frame();
esp_err_t get_network_toplogy(RIPRow_public_matrix* matrix, size_t* matrix_size);
esp_err_t get_routing_table(RIPRow_public* table, size_t* table_size);
private:
uint8_t this_board_id = 0;
uint8_t num_channels = MAX_CHANNELS;
@@ -80,10 +81,12 @@ class DataLinkManager{
RIPRow rip_table[RIP_MAX_ROUTES]; //temp using a static array
void start_rip_tasks();
esp_err_t broadcast_rip_frame(bool manual_broadcast);
esp_err_t send_rip_frame(bool broadcast, uint8_t dest_id);
[[noreturn]] static void rip_broadcast_timer_function(void* args);
[[noreturn]] static void rip_ttl_decrement_task(void* args);
QueueHandle_t manual_broadcasts;
QueueHandle_t discovery_tables;
esp_err_t route_frame(uint8_t dest_id, uint8_t* channel_to_send);
};

View File

@@ -20,7 +20,7 @@
#define GET_TYPE(x) ((x) & 0xF0)
#define GET_FLAG(x) ((x) & 0x0F)
#define MAKE_TYPE_FLAG(type, flag) ((type) | (flag))
#define MAKE_TYPE_FLAG(type, flag) ((uint8_t)((type & 0xF0) | (flag & 0xF)))
#define IS_CONTROL_FRAME(x) (((x) & 0x80) != 0)
#define CONTROL_FRAME_OVERHEAD 9

View File

@@ -14,6 +14,7 @@
#define RIP_MAX_SEM_WAIT 30
#define RIP_FLUSH_COUNT 8 //flush after 8*30 seconds = 240 seconds
#define RIP_DISCOVERY_MESSAGE_SIZE 1
/**
* @brief Routing data to a board
* This struct will be sent to other boards
@@ -28,9 +29,24 @@ typedef struct _rip_row{
uint8_t channel; //rmt channel
uint8_t ttl; //how long this entry is valid for. starting value is 180 seconds
uint8_t valid; //is this a valid entry?
uint8_t ttl_flush; //if hops is invalid, this would count the amount of time until this entry would be invalid (in multiples of 30 seconds)
uint8_t ttl_flush; //if hops is invalid, this would count the amount of time until this entry would be invalid (max is in multiples of 30 seconds) but can vary
StaticSemaphore_t mutex_buf; //where mutex state is stored
SemaphoreHandle_t row_sem; //mutex sem handle of mutex_buf
} RIPRow;
/**
* @brief Public facing RIP table row
*
*/
typedef struct _rip_public_row{
RIPHop info;
uint8_t channel; //rmt channel
} RIPRow_public;
typedef struct _rip_public_matrix{
RIPRow_public* table;
size_t size;
uint8_t board_id; //Board ID's routing table
} RIPRow_public_matrix;
#endif //DATA_LINK