feat(gateway): implement GatewayController and enhance GatewayRuntime
- Added GatewayController class to manage gateway operations, including command handling, scene and group management, and BLE state management. - Introduced methods for scene and group storage, including loading, saving, and deleting scenes/groups. - Enhanced GatewayRuntime with BLE management capabilities, including methods to check and set BLE state, and to generate BLE gateway names. - Implemented utility functions for string normalization and CSV parsing. - Added notification sinks for various events in the GatewayController. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
idf_component_register(
|
||||
SRCS "app_main.cpp"
|
||||
REQUIRES gateway_core dali_domain gateway_runtime log
|
||||
REQUIRES gateway_core gateway_controller dali_domain gateway_runtime gateway_ble log
|
||||
)
|
||||
|
||||
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
|
||||
@@ -1,10 +1,13 @@
|
||||
#include "dali_domain.hpp"
|
||||
#include "gateway_ble.hpp"
|
||||
#include "gateway_controller.hpp"
|
||||
#include "gateway_core.hpp"
|
||||
#include "gateway_runtime.hpp"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#ifndef CONFIG_GATEWAY_CHANNEL_COUNT
|
||||
#define CONFIG_GATEWAY_CHANNEL_COUNT 2
|
||||
@@ -14,6 +17,11 @@ namespace {
|
||||
constexpr const char* kProjectName = "DALI_485_Gateway";
|
||||
constexpr const char* kProjectVersion = "0.1.0";
|
||||
|
||||
std::unique_ptr<gateway::DaliDomainService> s_dali_domain;
|
||||
std::unique_ptr<gateway::GatewayRuntime> s_runtime;
|
||||
std::unique_ptr<gateway::GatewayController> s_controller;
|
||||
std::unique_ptr<gateway::GatewayBleBridge> s_ble_bridge;
|
||||
|
||||
[[maybe_unused]] void LogBindError(const char* channel_name, esp_err_t err) {
|
||||
if (err != ESP_OK) {
|
||||
std::printf("gateway_main: failed to bind %s err=%d\n", channel_name, err);
|
||||
@@ -99,24 +107,42 @@ extern "C" void app_main(void) {
|
||||
gateway::GatewayCore core(profile);
|
||||
core.start();
|
||||
|
||||
gateway::DaliDomainService dali_domain;
|
||||
gateway::GatewayRuntime runtime(
|
||||
s_dali_domain = std::make_unique<gateway::DaliDomainService>();
|
||||
s_runtime = std::make_unique<gateway::GatewayRuntime>(
|
||||
profile,
|
||||
gateway::GatewayRuntimeConfig{
|
||||
kProjectName,
|
||||
kProjectVersion,
|
||||
gateway::ReadRuntimeSerialId(),
|
||||
},
|
||||
&dali_domain);
|
||||
ESP_ERROR_CHECK(runtime.start());
|
||||
runtime.setGatewayCount(CONFIG_GATEWAY_CHANNEL_COUNT);
|
||||
BindConfiguredChannels(dali_domain, runtime);
|
||||
s_dali_domain.get());
|
||||
ESP_ERROR_CHECK(s_runtime->start());
|
||||
s_runtime->setGatewayCount(CONFIG_GATEWAY_CHANNEL_COUNT);
|
||||
BindConfiguredChannels(*s_dali_domain, *s_runtime);
|
||||
|
||||
const auto device_info = runtime.deviceInfo();
|
||||
gateway::GatewayControllerConfig controller_config;
|
||||
controller_config.setup_supported = true;
|
||||
controller_config.ble_supported = profile.enable_ble;
|
||||
controller_config.wifi_supported = profile.enable_wifi;
|
||||
controller_config.ip_router_supported = profile.enable_wifi || profile.enable_eth;
|
||||
controller_config.internal_scene_supported = true;
|
||||
controller_config.internal_group_supported = true;
|
||||
|
||||
s_controller = std::make_unique<gateway::GatewayController>(*s_runtime, *s_dali_domain,
|
||||
controller_config);
|
||||
ESP_ERROR_CHECK(s_controller->start());
|
||||
|
||||
if (profile.enable_ble) {
|
||||
s_ble_bridge = std::make_unique<gateway::GatewayBleBridge>(*s_controller, *s_runtime,
|
||||
*s_dali_domain);
|
||||
ESP_ERROR_CHECK(s_ble_bridge->start());
|
||||
}
|
||||
|
||||
const auto device_info = s_runtime->deviceInfo();
|
||||
std::printf("gateway_main: dali domain implementation=%s bound=%d channels=%u\n",
|
||||
dali_domain.implementationName(), dali_domain.isBound(),
|
||||
static_cast<unsigned>(dali_domain.channelCount()));
|
||||
for (const auto& channel : dali_domain.channelInfo()) {
|
||||
s_dali_domain->implementationName(), s_dali_domain->isBound(),
|
||||
static_cast<unsigned>(s_dali_domain->channelCount()));
|
||||
for (const auto& channel : s_dali_domain->channelInfo()) {
|
||||
std::printf("gateway_main: channel=%u gateway=%u name=%s\n", channel.channel_index,
|
||||
channel.gateway_id, channel.name.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user