mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Cleanup RPC component
This commit is contained in:
2
.idea/firmware.iml
generated
Normal file
2
.idea/firmware.iml
generated
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/firmware.iml" filepath="$PROJECT_DIR$/.idea/firmware.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
idf_component_register(SRCS "rpc.cpp" "TCPServer.cpp" "WifiManager.cpp"
|
idf_component_register(SRCS "rpc.cpp" "WifiManager.cpp"
|
||||||
PRIV_REQUIRES driver esp_event nvs_flash esp_netif esp_wifi
|
PRIV_REQUIRES driver esp_event nvs_flash esp_netif esp_wifi
|
||||||
INCLUDE_DIRS "include")
|
INCLUDE_DIRS "include")
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Johnathon Slightham on 2025-05-25.
|
|
||||||
//
|
|
||||||
@@ -8,26 +8,17 @@
|
|||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
|
|
||||||
int WifiManager::init() {
|
WifiManager::WifiManager() {
|
||||||
esp_netif_init();
|
esp_netif_init();
|
||||||
esp_event_loop_create_default();
|
esp_event_loop_create_default();
|
||||||
esp_netif_create_default_wifi_sta();
|
esp_netif_create_default_wifi_sta();
|
||||||
|
|
||||||
printf("finished esp init");
|
|
||||||
|
|
||||||
this->m_mutex = xSemaphoreCreateMutex();
|
this->m_mutex = xSemaphoreCreateMutex();
|
||||||
this->m_state = wifi_state::connect;
|
this->m_state = wifi_state::disconnected;
|
||||||
this->m_attempts = 0;
|
this->m_attempts = 0;
|
||||||
|
this->m_task = nullptr; // suppress warning
|
||||||
printf("finished variable init");
|
|
||||||
|
|
||||||
printf("lambda");
|
|
||||||
|
|
||||||
xTaskCreate(reinterpret_cast<TaskFunction_t>(s_manage), "wifi_task", 4096, this, 5, &m_task);
|
xTaskCreate(reinterpret_cast<TaskFunction_t>(s_manage), "wifi_task", 4096, this, 5, &m_task);
|
||||||
|
|
||||||
printf("task create");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int WifiManager::connect() {
|
int WifiManager::connect() {
|
||||||
@@ -51,25 +42,20 @@ int WifiManager::disconnect() {
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case wifi_state::connect:
|
case wifi_state::connect:
|
||||||
printf("connect state\n");
|
|
||||||
init_connection();
|
init_connection();
|
||||||
update_state(wifi_state::connecting);
|
update_state(wifi_state::connecting);
|
||||||
break;
|
break;
|
||||||
case wifi_state::connecting:
|
case wifi_state::connecting:
|
||||||
printf("connecting state\n");
|
|
||||||
handle_connecting();
|
handle_connecting();
|
||||||
break;
|
break;
|
||||||
case wifi_state::searching:
|
case wifi_state::searching:
|
||||||
printf("searching state\n");
|
|
||||||
handle_search();
|
handle_search();
|
||||||
break;
|
break;
|
||||||
case wifi_state::disconnect:
|
case wifi_state::disconnect:
|
||||||
printf("disconnect state\n");
|
|
||||||
handle_disconnect();
|
handle_disconnect();
|
||||||
update_state(wifi_state::disconnected);
|
update_state(wifi_state::disconnected);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("sleep state\n");
|
|
||||||
vTaskSuspend(nullptr);
|
vTaskSuspend(nullptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -128,6 +114,8 @@ int WifiManager::handle_disconnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int WifiManager::handle_search() {
|
int WifiManager::handle_search() {
|
||||||
|
// todo: softap
|
||||||
|
|
||||||
printf("Waiting for configuration");
|
printf("Waiting for configuration");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CommunicationRouter {
|
class CommunicationRouter : ICommunicationRouter {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,4 +5,8 @@
|
|||||||
#ifndef ICOMMUNICATIONROUTER_H
|
#ifndef ICOMMUNICATIONROUTER_H
|
||||||
#define ICOMMUNICATIONROUTER_H
|
#define ICOMMUNICATIONROUTER_H
|
||||||
|
|
||||||
|
class ICommunicationRouter {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif //ICOMMUNICATIONROUTER_H
|
#endif //ICOMMUNICATIONROUTER_H
|
||||||
|
|||||||
12
components/rpc/include/IDiscoveryService.h
Normal file
12
components/rpc/include/IDiscoveryService.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// Created by Johnathon Slightham on 2025-05-26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef IDISCOVERYSERVICE_H
|
||||||
|
#define IDISCOVERYSERVICE_H
|
||||||
|
|
||||||
|
class IDiscoveryService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //IDISCOVERYSERVICE_H
|
||||||
@@ -5,4 +5,8 @@
|
|||||||
#ifndef IRPCSERVER_H
|
#ifndef IRPCSERVER_H
|
||||||
#define IRPCSERVER_H
|
#define IRPCSERVER_H
|
||||||
|
|
||||||
|
class IRPCServer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif //IRPCSERVER_H
|
#endif //IRPCSERVER_H
|
||||||
|
|||||||
15
components/rpc/include/IWifiManager.h
Normal file
15
components/rpc/include/IWifiManager.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// Created by Johnathon Slightham on 2025-05-26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef IWIFIMANAGER_H
|
||||||
|
#define IWIFIMANAGER_H
|
||||||
|
|
||||||
|
class IWifiManager {
|
||||||
|
public:
|
||||||
|
virtual ~IWifiManager() {};
|
||||||
|
virtual int connect() = 0;
|
||||||
|
virtual int disconnect() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //IWIFIMANAGER_H
|
||||||
@@ -5,4 +5,10 @@
|
|||||||
#ifndef RPCFACTORY_H
|
#ifndef RPCFACTORY_H
|
||||||
#define RPCFACTORY_H
|
#define RPCFACTORY_H
|
||||||
|
|
||||||
|
class RPCFactory {
|
||||||
|
public:
|
||||||
|
static std::shared_ptr<IRPCServer> createRPCServer() {
|
||||||
|
return std::make_shared<TCPServer>();
|
||||||
|
}
|
||||||
|
|
||||||
#endif //RPCFACTORY_H
|
#endif //RPCFACTORY_H
|
||||||
|
|||||||
@@ -5,4 +5,15 @@
|
|||||||
#ifndef TCPSERVER_H
|
#ifndef TCPSERVER_H
|
||||||
#define TCPSERVER_H
|
#define TCPSERVER_H
|
||||||
|
|
||||||
|
#include "IRPCServer.h"
|
||||||
|
|
||||||
|
class TCPServer : IRPCServer {
|
||||||
|
public:
|
||||||
|
TCPServer();
|
||||||
|
~TCPServer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif //TCPSERVER_H
|
#endif //TCPSERVER_H
|
||||||
|
|||||||
@@ -6,13 +6,14 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
|
|
||||||
class WifiManager {
|
#include "IWifiManager.h"
|
||||||
|
|
||||||
|
class WifiManager final : IWifiManager {
|
||||||
public:
|
public:
|
||||||
WifiManager() = default;
|
WifiManager();
|
||||||
~WifiManager() = default;
|
~WifiManager() override = default;
|
||||||
int init();
|
int connect() override;
|
||||||
int connect();
|
int disconnect() override;
|
||||||
int disconnect();
|
|
||||||
|
|
||||||
[[noreturn]] void manage();
|
[[noreturn]] void manage();
|
||||||
|
|
||||||
@@ -28,7 +29,6 @@ private:
|
|||||||
|
|
||||||
static void wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
static void wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||||
|
|
||||||
|
|
||||||
SemaphoreHandle_t m_mutex;
|
SemaphoreHandle_t m_mutex;
|
||||||
wifi_state m_state;
|
wifi_state m_state;
|
||||||
TaskHandle_t m_task;
|
TaskHandle_t m_task;
|
||||||
|
|||||||
@@ -5,4 +5,8 @@
|
|||||||
#ifndef DISCOVERYSERVICE_H
|
#ifndef DISCOVERYSERVICE_H
|
||||||
#define DISCOVERYSERVICE_H
|
#define DISCOVERYSERVICE_H
|
||||||
|
|
||||||
|
class mDNSDiscoveryService : IDiscoveryService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif //DISCOVERYSERVICE_H
|
#endif //DISCOVERYSERVICE_H
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cinttypes>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_chip_info.h"
|
|
||||||
#include "esp_flash.h"
|
#include "esp_flash.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
@@ -15,7 +13,7 @@ extern "C" [[noreturn]] void app_main(void) {
|
|||||||
nvs_flash_init();
|
nvs_flash_init();
|
||||||
|
|
||||||
const auto manager = std::make_unique<WifiManager>();
|
const auto manager = std::make_unique<WifiManager>();
|
||||||
manager->init();
|
manager->connect();
|
||||||
|
|
||||||
printf("Hello world!\n");
|
printf("Hello world!\n");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user