mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Remove NVS from data link layer
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
#include "DataLinkManager.h"
|
#include "DataLinkManager.h"
|
||||||
#include "RMTManager.h"
|
#include "RMTManager.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "nvs_flash.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Data Link Manager:: Data Link Manager object
|
* @brief Construct a new Data Link Manager:: Data Link Manager object
|
||||||
*
|
*
|
||||||
* @param board_id Board ID of the current board. Will be written to the NVM under key "board" if not already written.
|
* @param board_id Board ID of the current board.
|
||||||
*/
|
*/
|
||||||
DataLinkManager::DataLinkManager(uint8_t board_id, uint8_t num_channels = MAX_CHANNELS){
|
DataLinkManager::DataLinkManager(uint8_t board_id, uint8_t num_channels = MAX_CHANNELS){
|
||||||
//init table for this board and set up link layer priority queue
|
//init table for this board and set up link layer priority queue
|
||||||
@@ -16,18 +15,7 @@ DataLinkManager::DataLinkManager(uint8_t board_id, uint8_t num_channels = MAX_CH
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (get_board_id(this_board_id) != ESP_OK){
|
this->this_board_id = board_id;
|
||||||
//failed to read from NVM for board id under key "board". Will write a new entry
|
|
||||||
this_board_id = board_id;
|
|
||||||
set_board_id(this_board_id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (this_board_id != board_id){
|
|
||||||
// //NVM board id is different from `board_id` -> update entry to the new board id
|
|
||||||
// this_board_id = board_id;
|
|
||||||
// set_board_id(this_board_id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
this->num_channels = num_channels;
|
this->num_channels = num_channels;
|
||||||
|
|
||||||
init_rip();
|
init_rip();
|
||||||
@@ -37,63 +25,6 @@ DataLinkManager::~DataLinkManager(){
|
|||||||
phys_comms.reset(); //not strictly necessary to do this explicitly
|
phys_comms.reset(); //not strictly necessary to do this explicitly
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t DataLinkManager::set_board_id(uint8_t board_id){
|
|
||||||
if (board_id == BROADCAST_ADDR || board_id == PC_ADDR){
|
|
||||||
ESP_LOGE(DEBUG_LINK_TAG, "Invalid board id");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
nvs_handle_t handle;
|
|
||||||
esp_err_t res = nvs_open("board", NVS_READWRITE, &handle);
|
|
||||||
if (res != ESP_OK){
|
|
||||||
ESP_LOGE(DEBUG_LINK_TAG, "Failed to open NVS Handle");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = nvs_set_u8(handle, "id", board_id);
|
|
||||||
if (res != ESP_OK){
|
|
||||||
ESP_LOGE(DEBUG_LINK_TAG, "Failed to write ID %d to NVM", board_id);
|
|
||||||
nvs_close(handle);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = nvs_commit(handle);
|
|
||||||
if (res != ESP_OK){
|
|
||||||
ESP_LOGE(DEBUG_LINK_TAG, "Failed to commit write");
|
|
||||||
nvs_close(handle);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
this_board_id = board_id;
|
|
||||||
printf("Successfully wrote %d to NVM\n", board_id);
|
|
||||||
|
|
||||||
nvs_close(handle);
|
|
||||||
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t DataLinkManager::get_board_id(uint8_t& board_id){
|
|
||||||
nvs_handle_t handle;
|
|
||||||
esp_err_t res = nvs_open("board", NVS_READWRITE, &handle);
|
|
||||||
if (res != ESP_OK){
|
|
||||||
ESP_LOGE(DEBUG_LINK_TAG, "Failed to open NVS Handle");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = nvs_get_u8(handle, "id", &board_id);
|
|
||||||
if (res != ESP_OK){
|
|
||||||
ESP_LOGE(DEBUG_LINK_TAG, "Failed to get ID from NVM. Please make sure NVM is already assigned a board id!");
|
|
||||||
nvs_close(handle);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Successfully got board id %d from NVM\n", board_id);
|
|
||||||
|
|
||||||
nvs_close(handle);
|
|
||||||
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends a frame to another board (node to node communication) via RMT (physical layer)
|
* @brief Sends a frame to another board (node to node communication) via RMT (physical layer)
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user