Fix wired integration

This commit is contained in:
2025-07-21 20:52:45 -04:00
parent ce61cf64d4
commit 6ff185149d
5 changed files with 28 additions and 28 deletions

View File

@@ -138,7 +138,7 @@ esp_err_t DataLinkManager::send(uint8_t dest_board, uint8_t* data, uint16_t data
.crc_16 = 0, //not made yet .crc_16 = 0, //not made yet
}; };
ESP_LOGI(DEBUG_LINK_TAG, "type flag %X\n", new_frame.type_flag); // ESP_LOGI(DEBUG_LINK_TAG, "type flag %X\n", new_frame.type_flag);
// printf("size of control frame %d\n", sizeof(control_frame)); // printf("size of control frame %d\n", sizeof(control_frame));
// printf("size of message %d\n", new_frame.data_len); // printf("size of message %d\n", new_frame.data_len);
// printf("message %s\n", data); // printf("message %s\n", data);
@@ -176,7 +176,7 @@ esp_err_t DataLinkManager::send(uint8_t dest_board, uint8_t* data, uint16_t data
} }
}; };
// printf("sending message:\n"); // ESP_LOGI(DEBUG_LINK_TAG, "Sending %d bytes", offset);
// print_buffer_binary(send_data, frame_size); // print_buffer_binary(send_data, frame_size);
uint8_t channel_to_route = MAX_CHANNELS; uint8_t channel_to_route = MAX_CHANNELS;
@@ -192,6 +192,7 @@ esp_err_t DataLinkManager::send(uint8_t dest_board, uint8_t* data, uint16_t data
ESP_LOGE(DEBUG_LINK_TAG, "Failed to find entry for %d", new_frame.receiver_id); ESP_LOGE(DEBUG_LINK_TAG, "Failed to find entry for %d", new_frame.receiver_id);
return ESP_FAIL; return ESP_FAIL;
} }
// ESP_LOGI(DEBUG_LINK_TAG, "Sending message to %d", new_frame.receiver_id);
phys_comms->send(send_data, offset, &config, channel_to_route); phys_comms->send(send_data, offset, &config, channel_to_route);
} }
@@ -283,6 +284,8 @@ esp_err_t DataLinkManager::receive(uint8_t* data, size_t data_len, size_t* recv_
vPortFree((void*)message); vPortFree((void*)message);
return ESP_FAIL; return ESP_FAIL;
} }
*recv_len = message_size;
memcpy(data, message, message_size);
// ESP_LOGI(DEBUG_LINK_TAG, "Received frame of type 0x%X destined for board %d", GET_TYPE(header.type_flag), header.receiver_id); // ESP_LOGI(DEBUG_LINK_TAG, "Received frame of type 0x%X destined for board %d", GET_TYPE(header.type_flag), header.receiver_id);
//check for a rip frame //check for a rip frame
@@ -292,7 +295,7 @@ esp_err_t DataLinkManager::receive(uint8_t* data, size_t data_len, size_t* recv_
for (size_t i = 0; i < message_size-1; i+=2){ for (size_t i = 0; i < message_size-1; i+=2){
uint8_t board_id = message[i]; uint8_t board_id = message[i];
uint8_t hops = message[i+1]; uint8_t hops = message[i+1];
ESP_LOGI(DEBUG_LINK_TAG, "Received: board_id %d and number of hops %d on channel %d", board_id, hops, curr_channel); // ESP_LOGI(DEBUG_LINK_TAG, "Received: board_id %d and number of hops %d on channel %d", board_id, hops, curr_channel);
RIPRow* entry = nullptr; RIPRow* entry = nullptr;
@@ -318,7 +321,7 @@ esp_err_t DataLinkManager::receive(uint8_t* data, size_t data_len, size_t* recv_
if (GET_FLAG(header.type_flag) == FLAG_DISCOVERY){ if (GET_FLAG(header.type_flag) == FLAG_DISCOVERY){
//discovery -> send routing table //discovery -> send routing table
ESP_LOGI(DEBUG_LINK_TAG, "got discovery reply"); // ESP_LOGI(DEBUG_LINK_TAG, "got discovery reply");
RIPRow_public row_queue = { RIPRow_public row_queue = {
.info = entry->info, .info = entry->info,
.channel = entry->channel .channel = entry->channel
@@ -340,7 +343,7 @@ esp_err_t DataLinkManager::receive(uint8_t* data, size_t data_len, size_t* recv_
//got frame but not destined for this board //got frame but not destined for this board
if (header.receiver_id != this_board_id && header.receiver_id != BROADCAST_ADDR && header.seq_num > sequence_num_map[header.receiver_id]){ if (header.receiver_id != this_board_id && header.receiver_id != BROADCAST_ADDR && header.seq_num > sequence_num_map[header.receiver_id]){
ESP_LOGI(DEBUG_LINK_TAG, "Sending message to board %d with message %s", header.receiver_id, message); // ESP_LOGI(DEBUG_LINK_TAG, "Sending message to board %d with message %s", header.receiver_id, message);
res = send(header.receiver_id, message, message_size, FrameType::DEBUG_CONTROL_TYPE, 0); res = send(header.receiver_id, message, message_size, FrameType::DEBUG_CONTROL_TYPE, 0);
*recv_len = 0; *recv_len = 0;
vPortFree((void*)message); vPortFree((void*)message);
@@ -399,12 +402,12 @@ esp_err_t DataLinkManager::get_data_from_frame(uint8_t* data, size_t data_len, u
return ESP_FAIL; return ESP_FAIL;
} }
// printf("Frame Information:\n"); printf("Frame Information:\n");
// printf("%-10s %-12s %-13s %-15s %-12s %-10s %-6s\n", printf("%-10s %-12s %-13s %-15s %-12s %-10s %-6s\n",
// "Preamble", "Sender ID", "Receiver ID", "Sequence Num", "Type+Flag", "Data Len", "CRC"); "Preamble", "Sender ID", "Receiver ID", "Sequence Num", "Type+Flag", "Data Len", "CRC");
// printf("0x%02X %-12d %-13d %-15d 0x%02X %-10d 0x%04X\n", printf("0x%02X %-12d %-13d %-15d 0x%02X %-10d 0x%04X\n",
// temp.preamble, temp.sender_id, temp.receiver_id, temp.seq_num, temp.type_flag, temp.data_len, temp.crc_16); header->preamble, header->sender_id, header->receiver_id, header->seq_num, header->type_flag, header->data_len, header->crc_16);
} else { } else {
//not implemented yet //not implemented yet
} }
@@ -521,7 +524,7 @@ esp_err_t DataLinkManager::rip_add_entry(uint8_t board_id, uint8_t hops, uint8_t
(*entry)->valid = 1; (*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); // 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); xSemaphoreGive((*entry)->row_sem);
@@ -572,12 +575,12 @@ esp_err_t DataLinkManager::rip_update_entry(uint8_t new_hop, uint8_t channel, RI
if ((*entry)->info.hops > new_hop && (*entry)->info.hops != RIP_MAX_HOPS + 1){ //no count to infinity if path is invalid if ((*entry)->info.hops > new_hop && (*entry)->info.hops != RIP_MAX_HOPS + 1){ //no count to infinity if path is invalid
(*entry)->info.hops = new_hop; (*entry)->info.hops = new_hop;
(*entry)->channel = channel; (*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); // 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)->ttl = RIP_TTL_START;
(*entry)->valid = 1; (*entry)->valid = 1;
ESP_LOGI(DEBUG_LINK_TAG, "refreshed board_id %d ttl", (*entry)->info.board_id); // ESP_LOGI(DEBUG_LINK_TAG, "refreshed board_id %d ttl", (*entry)->info.board_id);
xSemaphoreGive((*entry)->row_sem); xSemaphoreGive((*entry)->row_sem);
@@ -607,7 +610,7 @@ esp_err_t DataLinkManager::rip_find_entry(uint8_t board_id, RIPRow** entry, bool
if (rip_table[i].valid == RIP_VALID_ROW && rip_table[i].info.board_id == board_id){ if (rip_table[i].valid == RIP_VALID_ROW && rip_table[i].info.board_id == board_id){
*entry = &rip_table[i]; *entry = &rip_table[i];
xSemaphoreGive(rip_table[i].row_sem); xSemaphoreGive(rip_table[i].row_sem);
ESP_LOGI(DEBUG_LINK_TAG, "Found %d in table at row %d", board_id, i); // ESP_LOGI(DEBUG_LINK_TAG, "Found %d in table at row %d", board_id, i);
return ESP_OK; return ESP_OK;
} }
if (rip_table[i].valid == RIP_INVALID_ROW && free_slot == nullptr){ if (rip_table[i].valid == RIP_INVALID_ROW && free_slot == nullptr){
@@ -616,7 +619,7 @@ esp_err_t DataLinkManager::rip_find_entry(uint8_t board_id, RIPRow** entry, bool
xSemaphoreGive(rip_table[i].row_sem); xSemaphoreGive(rip_table[i].row_sem);
} }
ESP_LOGI(DEBUG_LINK_TAG, "Finished looking for %d in table", board_id); // ESP_LOGI(DEBUG_LINK_TAG, "Finished looking for %d in table", board_id);
if (!reserve_row){ if (!reserve_row){
return ESP_OK; return ESP_OK;
@@ -633,7 +636,7 @@ esp_err_t DataLinkManager::rip_find_entry(uint8_t board_id, RIPRow** entry, bool
*entry = free_slot; *entry = free_slot;
xSemaphoreGive(free_slot->row_sem); xSemaphoreGive(free_slot->row_sem);
ESP_LOGI(DEBUG_LINK_TAG, "Reserved new entry for board %d", board_id); // ESP_LOGI(DEBUG_LINK_TAG, "Reserved new entry for board %d", board_id);
} }
return ESP_OK; return ESP_OK;
@@ -686,7 +689,7 @@ esp_err_t DataLinkManager::send_rip_frame(bool broadcast, uint8_t dest_id){
if (broadcast){ if (broadcast){
res = send(BROADCAST_ADDR, rip_message, message_idx, FrameType::RIP_TABLE_CONTROL, 0); res = send(BROADCAST_ADDR, rip_message, message_idx, FrameType::RIP_TABLE_CONTROL, 0);
} else { } else {
ESP_LOGI(DEBUG_LINK_TAG, "replying to discovery request to board %d", dest_id); // ESP_LOGI(DEBUG_LINK_TAG, "replying to discovery request to board %d", dest_id);
res = send(dest_id, rip_message, message_idx, FrameType::RIP_TABLE_CONTROL, FLAG_DISCOVERY); res = send(dest_id, rip_message, message_idx, FrameType::RIP_TABLE_CONTROL, FLAG_DISCOVERY);
} }
if (res != ESP_OK){ if (res != ESP_OK){
@@ -801,12 +804,12 @@ esp_err_t DataLinkManager::get_network_toplogy(RIPRow_public_matrix* matrix, siz
uint8_t message[RIP_DISCOVERY_MESSAGE_SIZE] = {0}; uint8_t message[RIP_DISCOVERY_MESSAGE_SIZE] = {0};
for (size_t i = 1; i < matrix[0].size; i++){ for (size_t i = 1; i < matrix[0].size; i++){
ESP_LOGI(DEBUG_LINK_TAG, "Sending discovery request for board %d", matrix[0].table[i].info.board_id); // ESP_LOGI(DEBUG_LINK_TAG, "Sending discovery request for board %d", matrix[0].table[i].info.board_id);
send(matrix[0].table[i].info.board_id, message, 1, FrameType::RIP_TABLE_CONTROL, FLAG_DISCOVERY); //send a discovery request to a board in this board's table index i send(matrix[0].table[i].info.board_id, message, 1, FrameType::RIP_TABLE_CONTROL, FLAG_DISCOVERY); //send a discovery request to a board in this board's table index i
uint8_t table_idx = 0; uint8_t table_idx = 0;
RIPRow_public temp; RIPRow_public temp;
while (xQueueReceive(discovery_tables, &temp, (TickType_t)1000) == pdTRUE){ //the board should have responded with rows from its routing table to insert into the matrix while (xQueueReceive(discovery_tables, &temp, (TickType_t)1000) == pdTRUE){ //the board should have responded with rows from its routing table to insert into the matrix
ESP_LOGI(DEBUG_LINK_TAG, "putting discovery reply into matrix"); // ESP_LOGI(DEBUG_LINK_TAG, "putting discovery reply into matrix");
matrix[i].table[table_idx].info.board_id = temp.info.board_id; matrix[i].table[table_idx].info.board_id = temp.info.board_id;
matrix[i].table[table_idx].info.hops = temp.info.hops; matrix[i].table[table_idx].info.hops = temp.info.hops;
matrix[i].table[table_idx++].channel = temp.channel; matrix[i].table[table_idx++].channel = temp.channel;
@@ -835,7 +838,7 @@ esp_err_t DataLinkManager::get_network_toplogy(RIPRow_public_matrix* matrix, siz
while(true){ while(true){
bool dummy; bool dummy;
xQueueReceive(link_layer_obj->manual_broadcasts, &dummy, pdMS_TO_TICKS(RIP_BROADCAST_INTERVAL)); //wait up to RIP_BROADCAST_INTERVAL ms xQueueReceive(link_layer_obj->manual_broadcasts, &dummy, pdMS_TO_TICKS(RIP_BROADCAST_INTERVAL)); //wait up to RIP_BROADCAST_INTERVAL ms
ESP_LOGI(DEBUG_LINK_TAG, "Broadcasting table..."); //debug // ESP_LOGI(DEBUG_LINK_TAG, "Broadcasting table..."); //debug
res = link_layer_obj->send_rip_frame(true, 0); res = link_layer_obj->send_rip_frame(true, 0);
if (res != ESP_OK){ if (res != ESP_OK){
ESP_LOGE(DEBUG_LINK_TAG, "Failed to broadcast rip frame"); ESP_LOGE(DEBUG_LINK_TAG, "Failed to broadcast rip frame");

View File

@@ -362,6 +362,7 @@ size_t RMTManager::encoder_callback(const void* data, size_t data_size, size_t s
} }
*done = (ctx->byte_index >= data_size); //if the transmit is done, set the `done` flag to true (all bytes have been encoded) *done = (ctx->byte_index >= data_size); //if the transmit is done, set the `done` flag to true (all bytes have been encoded)
ESP_LOGD(DEBUG_TAG, "RMTManager::encoder_callback returned %d", *done);
return symbols_used; return symbols_used;
} }
@@ -440,6 +441,7 @@ esp_err_t RMTManager::send(uint8_t* data, size_t size, rmt_transmit_config_t* co
ESP_LOGE(DEBUG_TAG, "Failed to send %s", data); ESP_LOGE(DEBUG_TAG, "Failed to send %s", data);
return ESP_FAIL; return ESP_FAIL;
} }
// ESP_LOGI(DEBUG_TAG, "RMTManager started transmit job to channel %d", channel_num);
return ESP_OK; return ESP_OK;
} }

View File

@@ -26,6 +26,7 @@ CommunicationRouter::~CommunicationRouter() {
while (true) { while (true) {
const auto buffer = that->m_tcp_rx_queue->dequeue(); const auto buffer = that->m_tcp_rx_queue->dequeue();
std::cout << "routing from tcp" << std::endl;
that->route(buffer->data(), buffer->size()); that->route(buffer->data(), buffer->size());
} }
} }
@@ -55,6 +56,7 @@ CommunicationRouter::~CommunicationRouter() {
continue; continue;
} }
std::cout << "routing message from rmt" << std::endl;
that->route(reinterpret_cast<uint8_t *>(buffer), bytes_received); that->route(reinterpret_cast<uint8_t *>(buffer), bytes_received);
} }
} }
@@ -103,10 +105,6 @@ void CommunicationRouter::route(uint8_t* buffer, const size_t length) const {
if (mpi_message->destination() == m_module_id) { if (mpi_message->destination() == m_module_id) {
std::cout << "Routing to this module [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl; std::cout << "Routing to this module [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;
const auto temp = Flatbuffers::AngleControlMessageBuilder::parse_angle_control_message(reinterpret_cast<const uint8_t *>(mpi_message->payload()))->angle();
std::cout << "angle from before router" << temp << std::endl;
this->m_rx_callback(reinterpret_cast<char *>(buffer), 512); this->m_rx_callback(reinterpret_cast<char *>(buffer), 512);
} else if (mpi_message->destination() == PC_ADDR && this->m_leader == m_module_id) { } else if (mpi_message->destination() == PC_ADDR && this->m_leader == m_module_id) {
std::cout << "Routing to wifi [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl; std::cout << "Routing to wifi [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;

View File

@@ -54,10 +54,6 @@ void MessagingInterface::handleRecv(const char* recv_buffer, int recv_size) {
checkOrInsertTag(mpi_message->tag()); checkOrInsertTag(mpi_message->tag());
const auto temp = Flatbuffers::AngleControlMessageBuilder::parse_angle_control_message(reinterpret_cast<const uint8_t *>(mpi_message->payload()))->angle();
std::cout << "angle from before queue " << temp << std::endl;
xQueueSendToBack(m_tag_to_queue.at(mpi_message->tag()), mpi_message->payload()->data(), 0); xQueueSendToBack(m_tag_to_queue.at(mpi_message->tag()), mpi_message->payload()->data(), 0);
} }

View File

@@ -16,5 +16,6 @@ extern "C" [[noreturn]] void app_main(void) {
ESP_LOGI("MEM", "Free PSRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); ESP_LOGI("MEM", "Free PSRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
ConfigManager::init_config(); ConfigManager::init_config();
LoopManager::control_loop(); LoopManager::control_loop();
} }