feat(gateway): implement reconciliation mechanism and command prioritization
- Introduced a reconciliation job structure to manage the reconciliation process for gateway channels. - Added methods to schedule and run reconciliation steps, including group, scene, and settings reconciliation. - Implemented a locking mechanism to ensure thread safety during reconciliation operations. - Enhanced command handling in GatewayRuntime to classify commands by priority (control, normal, maintenance). - Updated command enqueueing and processing to respect command priorities, ensuring maintenance commands are handled appropriately. - Added configuration options for enabling/disabling cache functionality in GatewayRuntime. - Improved logging to include cache status during runtime initialization. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -221,8 +221,39 @@ endmenu
|
||||
|
||||
menu "Gateway Cache"
|
||||
|
||||
config GATEWAY_CACHE_SUPPORTED
|
||||
bool "Gateway cache support"
|
||||
default y
|
||||
help
|
||||
Enables the gateway cache facade. When disabled, internal scene and group
|
||||
commands still persist through direct NVS writes.
|
||||
|
||||
config GATEWAY_CACHE_START_ENABLED
|
||||
bool "Start gateway cache in deferred mode"
|
||||
depends on GATEWAY_CACHE_SUPPORTED
|
||||
default y
|
||||
help
|
||||
Starts the deferred RAM cache and background flush task at boot. Disable
|
||||
this to keep scene and group persistence in direct-NVS mode.
|
||||
|
||||
config GATEWAY_CACHE_RECONCILIATION_ENABLED
|
||||
bool "Enable cache reconciliation tracking"
|
||||
depends on GATEWAY_CACHE_SUPPORTED && GATEWAY_CACHE_START_ENABLED
|
||||
default y
|
||||
help
|
||||
Tracks outside DALI bus mutations as update-needed flags for resumable
|
||||
reconciliation work.
|
||||
|
||||
config GATEWAY_CACHE_FULL_STATE_MIRROR
|
||||
bool "Enable full DALI state mirror"
|
||||
depends on GATEWAY_CACHE_RECONCILIATION_ENABLED
|
||||
default n
|
||||
help
|
||||
Enables the heavier full bus-state mirror path for future reconciliation.
|
||||
|
||||
config GATEWAY_CACHE_FLUSH_INTERVAL_MS
|
||||
int "Cache flush interval ms"
|
||||
depends on GATEWAY_CACHE_SUPPORTED && GATEWAY_CACHE_START_ENABLED
|
||||
range 100 600000
|
||||
default 5000
|
||||
help
|
||||
@@ -230,6 +261,7 @@ config GATEWAY_CACHE_FLUSH_INTERVAL_MS
|
||||
|
||||
choice GATEWAY_CACHE_CONFLICT_PRIORITY
|
||||
prompt "Cache conflict priority default"
|
||||
depends on GATEWAY_CACHE_RECONCILIATION_ENABLED
|
||||
default GATEWAY_CACHE_OUTSIDE_BUS_FIRST
|
||||
help
|
||||
Default source of truth to use when future cache reconciliation detects
|
||||
|
||||
@@ -180,6 +180,30 @@ constexpr bool kCloudBridgeStartupEnabled = true;
|
||||
constexpr bool kCloudBridgeStartupEnabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_CACHE_SUPPORTED
|
||||
constexpr bool kCacheSupported = true;
|
||||
#else
|
||||
constexpr bool kCacheSupported = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_CACHE_START_ENABLED
|
||||
constexpr bool kCacheStartupEnabled = true;
|
||||
#else
|
||||
constexpr bool kCacheStartupEnabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_CACHE_RECONCILIATION_ENABLED
|
||||
constexpr bool kCacheReconciliationEnabled = true;
|
||||
#else
|
||||
constexpr bool kCacheReconciliationEnabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_CACHE_FULL_STATE_MIRROR
|
||||
constexpr bool kCacheFullStateMirrorEnabled = true;
|
||||
#else
|
||||
constexpr bool kCacheFullStateMirrorEnabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GATEWAY_CACHE_LOCAL_GATEWAY_FIRST
|
||||
constexpr gateway::GatewayCachePriorityMode kCachePriorityMode =
|
||||
gateway::GatewayCachePriorityMode::kLocalGatewayFirst;
|
||||
@@ -417,6 +441,7 @@ extern "C" void app_main(void) {
|
||||
kProjectVersion,
|
||||
gateway::ReadRuntimeSerialId(),
|
||||
kBleStartupEnabled,
|
||||
kCacheSupported && kCacheStartupEnabled,
|
||||
},
|
||||
s_dali_domain.get());
|
||||
ESP_ERROR_CHECK(s_runtime->start());
|
||||
@@ -424,6 +449,10 @@ extern "C" void app_main(void) {
|
||||
ESP_ERROR_CHECK(BindConfiguredChannels(*s_dali_domain, *s_runtime));
|
||||
|
||||
gateway::GatewayCacheConfig cache_config;
|
||||
cache_config.cache_enabled = kCacheSupported && kCacheStartupEnabled && s_runtime->cacheEnabled();
|
||||
cache_config.reconciliation_enabled = cache_config.cache_enabled && kCacheReconciliationEnabled;
|
||||
cache_config.full_state_mirror_enabled = cache_config.reconciliation_enabled &&
|
||||
kCacheFullStateMirrorEnabled;
|
||||
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);
|
||||
|
||||
@@ -621,6 +621,10 @@ CONFIG_GATEWAY_CHANNEL2_PHY_DISABLED=y
|
||||
#
|
||||
# Gateway Cache
|
||||
#
|
||||
CONFIG_GATEWAY_CACHE_SUPPORTED=y
|
||||
CONFIG_GATEWAY_CACHE_START_ENABLED=y
|
||||
CONFIG_GATEWAY_CACHE_RECONCILIATION_ENABLED=y
|
||||
# CONFIG_GATEWAY_CACHE_FULL_STATE_MIRROR is not set
|
||||
CONFIG_GATEWAY_CACHE_FLUSH_INTERVAL_MS=5000
|
||||
CONFIG_GATEWAY_CACHE_OUTSIDE_BUS_FIRST=y
|
||||
# CONFIG_GATEWAY_CACHE_LOCAL_GATEWAY_FIRST is not set
|
||||
|
||||
Reference in New Issue
Block a user