mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Cleanup rpc interfaces
This commit is contained in:
41
components/rpc/include/wireless/TCPServer.h
Normal file
41
components/rpc/include/wireless/TCPServer.h
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-05-25.
|
||||
//
|
||||
|
||||
#ifndef TCPSERVER_H
|
||||
#define TCPSERVER_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "IRPCServer.h"
|
||||
#include "PtrQueue.h"
|
||||
|
||||
class TCPServer final : public IRPCServer {
|
||||
public:
|
||||
TCPServer(int port, const std::shared_ptr<PtrQueue<std::vector<uint8_t>>>& rx_queue);
|
||||
~TCPServer() override;
|
||||
int send_msg(char* buffer, uint32_t length) const override;
|
||||
|
||||
private:
|
||||
bool authenticate_client(int client_sock);
|
||||
|
||||
static bool is_network_connected();
|
||||
[[noreturn]] static void tcp_server_task(void *args);
|
||||
[[noreturn]] static void socket_monitor_thread(void *args);
|
||||
|
||||
int m_port;
|
||||
int m_server_sock;
|
||||
|
||||
TaskHandle_t m_task;
|
||||
TaskHandle_t m_rx_task;
|
||||
|
||||
std::shared_ptr<PtrQueue<std::vector<uint8_t>>> m_rx_queue;
|
||||
|
||||
SemaphoreHandle_t m_mutex;
|
||||
std::unordered_set<int> m_clients;
|
||||
};
|
||||
|
||||
#endif //TCPSERVER_H
|
||||
53
components/rpc/include/wireless/WifiManager.h
Normal file
53
components/rpc/include/wireless/WifiManager.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef NETWORKMANAGER_H
|
||||
#define NETWORKMANAGER_H
|
||||
|
||||
#include "esp_netif_types.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "IConnectionManager.h"
|
||||
|
||||
class WifiManager final : public IConnectionManager {
|
||||
public:
|
||||
WifiManager() : m_config_manager(ConfigManager::get_instance()),
|
||||
m_mutex(xSemaphoreCreateMutex()),
|
||||
m_state(wifi_state::disconnected) {
|
||||
esp_netif_init();
|
||||
esp_wifi_set_storage(WIFI_STORAGE_RAM);
|
||||
esp_event_loop_create_default();
|
||||
// todo: move all task metadata to a constants/config file
|
||||
xTaskCreate(reinterpret_cast<TaskFunction_t>(s_manage), "wifi_task", 3096, this, 5, &m_task);
|
||||
}
|
||||
|
||||
~WifiManager() override;
|
||||
int connect() override;
|
||||
int disconnect() override;
|
||||
|
||||
[[noreturn]] void manage();
|
||||
|
||||
enum class wifi_state { connect, connecting, connected, disconnect, disconnected, broadcast, broadcasting };
|
||||
|
||||
private:
|
||||
void update_state(wifi_state state);
|
||||
[[noreturn]] static void s_manage(WifiManager *that);
|
||||
int init_connection();
|
||||
int handle_connecting();
|
||||
int handle_disconnect();
|
||||
int handle_broadcasting();
|
||||
int init_softap();
|
||||
|
||||
static void wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
|
||||
ConfigManager& m_config_manager;
|
||||
SemaphoreHandle_t m_mutex;
|
||||
wifi_state m_state;
|
||||
TaskHandle_t m_task = nullptr;
|
||||
unsigned int m_attempts = 0;
|
||||
esp_netif_t *m_netif = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif //NETWORKMANAGER_H
|
||||
20
components/rpc/include/wireless/mDNSDiscoveryService.h
Normal file
20
components/rpc/include/wireless/mDNSDiscoveryService.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-05-25.
|
||||
//
|
||||
|
||||
#ifndef DISCOVERYSERVICE_H
|
||||
#define DISCOVERYSERVICE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "IDiscoveryService.h"
|
||||
|
||||
class mDNSDiscoveryService final : public IDiscoveryService {
|
||||
public:
|
||||
mDNSDiscoveryService();
|
||||
~mDNSDiscoveryService() override;
|
||||
|
||||
void set_connected_boards(const std::vector<int>& boards) override;
|
||||
};
|
||||
|
||||
#endif //DISCOVERYSERVICE_H
|
||||
Reference in New Issue
Block a user