Refactor GatewayController to integrate GatewayCache

- Updated CMakeLists.txt to require gateway_cache component.
- Modified gateway_controller.hpp to include GatewayCache and adjust constructor.
- Removed internal scene and group management logic from GatewayController, delegating to GatewayCache.
- Simplified scene and group operations by utilizing GatewayCache methods for enabling, setting details, and deleting.
- Eliminated NVS storage handling code, as scene and group data is now managed by GatewayCache.
- Updated command handling methods to use cached data instead of internal structures.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Tony
2026-05-01 04:39:58 +08:00
parent d16c289626
commit 70c39ea1e1
10 changed files with 781 additions and 400 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
idf_component_register(
SRCS "app_main.cpp"
REQUIRES gateway_core gateway_controller gateway_network gateway_bridge dali_domain gateway_runtime gateway_ble gateway_usb_setup log
REQUIRES gateway_core gateway_controller gateway_network gateway_bridge gateway_cache dali_domain gateway_runtime gateway_ble gateway_usb_setup log
)
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
+26
View File
@@ -219,6 +219,32 @@ config GATEWAY_CHANNEL2_SERIAL_QUERY_TIMEOUT_MS
endmenu
menu "Gateway Cache"
config GATEWAY_CACHE_FLUSH_INTERVAL_MS
int "Cache flush interval ms"
range 100 600000
default 5000
help
Interval used to batch scene and group cache writes to flash.
choice GATEWAY_CACHE_CONFLICT_PRIORITY
prompt "Cache conflict priority default"
default GATEWAY_CACHE_OUTSIDE_BUS_FIRST
help
Default source of truth to use when future cache reconciliation detects
changes made on the DALI bus outside this gateway.
config GATEWAY_CACHE_OUTSIDE_BUS_FIRST
bool "Outside bus first"
config GATEWAY_CACHE_LOCAL_GATEWAY_FIRST
bool "Local gateway first"
endchoice
endmenu
config GATEWAY_ENABLE_DALI_BUS
bool "Legacy single local DALI bus switch"
default n
+21
View File
@@ -1,6 +1,7 @@
#include "dali_domain.hpp"
#include "gateway_ble.hpp"
#include "gateway_bridge.hpp"
#include "gateway_cache.hpp"
#include "gateway_controller.hpp"
#include "gateway_core.hpp"
#include "gateway_network.hpp"
@@ -74,6 +75,10 @@
#define CONFIG_GATEWAY_BRIDGE_BACNET_TASK_PRIORITY 5
#endif
#ifndef CONFIG_GATEWAY_CACHE_FLUSH_INTERVAL_MS
#define CONFIG_GATEWAY_CACHE_FLUSH_INTERVAL_MS 5000
#endif
namespace {
constexpr const char* kProjectName = "DALI_485_Gateway";
constexpr const char* kProjectVersion = "0.1.0";
@@ -175,8 +180,17 @@ constexpr bool kCloudBridgeStartupEnabled = true;
constexpr bool kCloudBridgeStartupEnabled = false;
#endif
#ifdef CONFIG_GATEWAY_CACHE_LOCAL_GATEWAY_FIRST
constexpr gateway::GatewayCachePriorityMode kCachePriorityMode =
gateway::GatewayCachePriorityMode::kLocalGatewayFirst;
#else
constexpr gateway::GatewayCachePriorityMode kCachePriorityMode =
gateway::GatewayCachePriorityMode::kOutsideBusFirst;
#endif
std::unique_ptr<gateway::DaliDomainService> s_dali_domain;
std::unique_ptr<gateway::GatewayRuntime> s_runtime;
std::unique_ptr<gateway::GatewayCache> s_cache;
std::unique_ptr<gateway::GatewayController> s_controller;
std::unique_ptr<gateway::GatewayBridgeService> s_bridge;
std::unique_ptr<gateway::GatewayNetworkService> s_network;
@@ -409,6 +423,12 @@ extern "C" void app_main(void) {
s_runtime->setGatewayCount(CONFIG_GATEWAY_CHANNEL_COUNT);
ESP_ERROR_CHECK(BindConfiguredChannels(*s_dali_domain, *s_runtime));
gateway::GatewayCacheConfig cache_config;
cache_config.flush_interval_ms = static_cast<uint32_t>(CONFIG_GATEWAY_CACHE_FLUSH_INTERVAL_MS);
cache_config.default_priority_mode = kCachePriorityMode;
s_cache = std::make_unique<gateway::GatewayCache>(cache_config);
ESP_ERROR_CHECK(s_cache->start());
gateway::GatewayControllerConfig controller_config;
controller_config.setup_supported = true;
controller_config.ble_supported = profile.enable_ble;
@@ -418,6 +438,7 @@ extern "C" void app_main(void) {
controller_config.internal_group_supported = true;
s_controller = std::make_unique<gateway::GatewayController>(*s_runtime, *s_dali_domain,
*s_cache,
controller_config);
ESP_ERROR_CHECK(s_controller->start());
+8
View File
@@ -618,6 +618,14 @@ CONFIG_GATEWAY_CHANNEL2_PHY_DISABLED=y
# CONFIG_GATEWAY_CHANNEL2_PHY_UART2 is not set
# end of Gateway Channel 2
#
# Gateway Cache
#
CONFIG_GATEWAY_CACHE_FLUSH_INTERVAL_MS=5000
CONFIG_GATEWAY_CACHE_OUTSIDE_BUS_FIRST=y
# CONFIG_GATEWAY_CACHE_LOCAL_GATEWAY_FIRST is not set
# end of Gateway Cache
# CONFIG_GATEWAY_ENABLE_DALI_BUS is not set
#