mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
Fix RIP bugs, add in UART
This commit is contained in:
@@ -10,12 +10,20 @@
|
||||
#include "freertos/semphr.h"
|
||||
#include "Frames.h"
|
||||
#include "Tables.h"
|
||||
#include "RMTManager.h"
|
||||
#include "IPhysicalLayer.h"
|
||||
#include "BlockingQueue.h"
|
||||
#include "BlockingPriorityQueue.h"
|
||||
#include <unordered_map>
|
||||
#include "Scheduler.h"
|
||||
|
||||
/**
|
||||
* @brief Selects which physical layer implementation to instantiate.
|
||||
*/
|
||||
enum class PhysicalLayerType : uint8_t {
|
||||
RMT = 0, ///< Use the RMT-based Manchester-encoded physical layer (default)
|
||||
SOFT_UART = 1, ///< Use the software-UART physical layer
|
||||
};
|
||||
|
||||
#define DEBUG_LINK_TAG "LinkLayer"
|
||||
|
||||
#define CRC_POLYNOMIAL 0x1021
|
||||
@@ -56,7 +64,7 @@ static const uint16_t crc16_table[256] = {
|
||||
*/
|
||||
class DataLinkManager{
|
||||
public:
|
||||
DataLinkManager(uint8_t board_id, uint8_t num_channels);
|
||||
DataLinkManager(uint8_t board_id, uint8_t num_channels, PhysicalLayerType phy_type = PhysicalLayerType::SOFT_UART);
|
||||
~DataLinkManager();
|
||||
esp_err_t send(uint8_t dest_board, std::unique_ptr<std::vector<uint8_t>>&& buffer, FrameType type, uint8_t flag);
|
||||
esp_err_t start_receive_frames(uint8_t curr_channel);
|
||||
@@ -69,7 +77,7 @@ class DataLinkManager{
|
||||
private:
|
||||
uint8_t this_board_id = 0;
|
||||
uint8_t num_channels = MAX_CHANNELS;
|
||||
std::unique_ptr<RMTManager> phys_comms;
|
||||
std::unique_ptr<IPhysicalLayer> phys_comms;
|
||||
|
||||
std::unordered_map<uint8_t, uint16_t> sequence_num_map;
|
||||
SemaphoreHandle_t sequence_num_map_mutex;
|
||||
@@ -93,10 +101,11 @@ class DataLinkManager{
|
||||
|
||||
void init_rip();
|
||||
esp_err_t rip_find_entry(uint8_t board_id, RIPRow** entry, bool reserve_row);
|
||||
esp_err_t rip_update_entry(uint8_t new_hop, uint8_t channel, RIPRow** entry);
|
||||
esp_err_t rip_add_entry(uint8_t board_id, uint8_t hops, uint8_t channel, RIPRow** entry);
|
||||
esp_err_t rip_update_entry(uint8_t new_hop, uint8_t new_sum_of_hops, uint8_t channel, RIPRow** entry);
|
||||
esp_err_t rip_add_entry(uint8_t board_id, uint8_t hops, uint8_t sum_of_hops, uint8_t channel, RIPRow** entry);
|
||||
esp_err_t rip_reset_entry_ttl(uint8_t board_id);
|
||||
esp_err_t rip_get_row(RIPRow** entry, uint8_t row_num);
|
||||
void rip_update_self_sum_of_hops();
|
||||
|
||||
//this is stored locally with metadata `ttl`
|
||||
// std::unordered_map<uint8_t, RIPRow> rip_table; //using a hash map to store the routes to other boards - will be used as we scale up
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define RIP_INVALID_ROW 0
|
||||
#define RIP_VALID_ROW 1
|
||||
#define RIP_NEW_ROW 2
|
||||
#define RIP_BROADCAST_INTERVAL 30000 //broadcast every 30 seconds (30000ms)
|
||||
#define RIP_BROADCAST_INTERVAL 15000 //broadcast every 30 seconds (15000ms)
|
||||
// #define RIP_BROADCAST_INTERVAL 3000 //temp broadcast every 3 seconds (3000ms)
|
||||
#define RIP_TTL_START 180 //seconds
|
||||
#define RIP_MS_TO_SEC 1000 //1000 ms to 1 sec
|
||||
@@ -15,13 +15,15 @@
|
||||
#define RIP_FLUSH_COUNT 8 //flush after 8*30 seconds = 240 seconds
|
||||
|
||||
#define RIP_DISCOVERY_MESSAGE_SIZE 1
|
||||
#define RIP_WIRE_STRIDE 3 // bytes per entry on the wire: board_id, hops, sum_of_hops
|
||||
/**
|
||||
* @brief Routing data to a board
|
||||
* This struct will be sent to other boards
|
||||
*/
|
||||
typedef struct _rip_hops{
|
||||
uint8_t board_id; //ID of the destination
|
||||
uint8_t hops; //hop count to `board_id`
|
||||
uint8_t board_id; //ID of the destination
|
||||
uint8_t hops; //hop count to `board_id`
|
||||
uint8_t sum_of_hops; //sum of hops from `board_id` to all other known boards (centrality score)
|
||||
} RIPHop;
|
||||
|
||||
typedef struct _rip_row{
|
||||
@@ -36,7 +38,7 @@ typedef struct _rip_row{
|
||||
|
||||
/**
|
||||
* @brief Public facing RIP table row
|
||||
*
|
||||
*
|
||||
*/
|
||||
typedef struct _rip_public_row{
|
||||
RIPHop info;
|
||||
|
||||
Reference in New Issue
Block a user