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:
@@ -35,6 +35,7 @@ struct GatewayRuntimeConfig {
|
||||
std::string_view version;
|
||||
std::string serial_id;
|
||||
bool default_ble_enabled{true};
|
||||
bool default_cache_enabled{true};
|
||||
size_t command_queue_capacity{16};
|
||||
};
|
||||
|
||||
@@ -59,6 +60,9 @@ class GatewaySettingsStore {
|
||||
bool getBleEnabled(bool default_value = false) const;
|
||||
bool setBleEnabled(bool enabled);
|
||||
|
||||
bool getCacheEnabled(bool default_value = true) const;
|
||||
bool setCacheEnabled(bool enabled);
|
||||
|
||||
std::optional<std::string> getWifiSsid() const;
|
||||
std::optional<std::string> getWifiPassword() const;
|
||||
bool setWifiCredentials(std::string_view ssid, std::string_view password);
|
||||
@@ -83,6 +87,12 @@ class GatewayRuntime {
|
||||
kQueueFull,
|
||||
};
|
||||
|
||||
enum class CommandPriority : uint8_t {
|
||||
kControl = 0,
|
||||
kNormal = 1,
|
||||
kMaintenance = 2,
|
||||
};
|
||||
|
||||
GatewayRuntime(BootProfile profile, GatewayRuntimeConfig config,
|
||||
DaliDomainService* dali_domain);
|
||||
~GatewayRuntime();
|
||||
@@ -93,11 +103,16 @@ class GatewayRuntime {
|
||||
static bool hasValidChecksum(const std::vector<uint8_t>& frame);
|
||||
static bool isGatewayCommandFrame(const std::vector<uint8_t>& frame);
|
||||
static std::vector<uint8_t> buildNotificationFrame(const std::vector<uint8_t>& payload);
|
||||
static CommandPriority classifyCommandPriority(const std::vector<uint8_t>& command);
|
||||
|
||||
bool enqueueCommand(std::vector<uint8_t> command);
|
||||
bool enqueueCommand(std::vector<uint8_t> command,
|
||||
CommandPriority priority = CommandPriority::kNormal);
|
||||
std::optional<std::vector<uint8_t>> popNextCommand();
|
||||
void completeCurrentCommand();
|
||||
bool hasPendingQueryCommand(const std::vector<uint8_t>& command) const;
|
||||
bool hasPendingControlCommand(uint8_t gateway_id) const;
|
||||
bool shouldYieldMaintenance(uint8_t gateway_id) const;
|
||||
bool hasActiveCommand(uint8_t gateway_id) const;
|
||||
bool hasActiveQueryCommand(uint8_t gateway_id) const;
|
||||
CommandDropReason lastEnqueueDropReason() const;
|
||||
|
||||
@@ -109,6 +124,8 @@ class GatewayRuntime {
|
||||
GatewayDeviceInfo deviceInfo() const;
|
||||
bool bleEnabled() const;
|
||||
bool setBleEnabled(bool enabled);
|
||||
bool cacheEnabled() const;
|
||||
bool setCacheEnabled(bool enabled);
|
||||
std::string gatewayName(uint8_t gateway_id) const;
|
||||
bool setGatewayName(uint8_t gateway_id, std::string_view name);
|
||||
std::string gatewaySerialHex(uint8_t gateway_id) const;
|
||||
@@ -118,6 +135,9 @@ class GatewayRuntime {
|
||||
|
||||
private:
|
||||
bool isQueryCommand(const std::vector<uint8_t>& command) const;
|
||||
size_t pendingCommandCountLocked() const;
|
||||
std::deque<std::vector<uint8_t>>& queueForPriorityLocked(CommandPriority priority);
|
||||
const std::deque<std::vector<uint8_t>>& queueForPriorityLocked(CommandPriority priority) const;
|
||||
std::optional<std::string> queryCommandKey(const std::vector<uint8_t>& command) const;
|
||||
std::string defaultGatewayName(uint8_t gateway_id) const;
|
||||
std::vector<uint8_t> serialBytes() const;
|
||||
@@ -128,10 +148,14 @@ class GatewayRuntime {
|
||||
DaliDomainService* dali_domain_;
|
||||
GatewaySettingsStore settings_;
|
||||
std::optional<std::vector<uint8_t>> current_command_;
|
||||
std::deque<std::vector<uint8_t>> pending_commands_;
|
||||
CommandPriority current_command_priority_{CommandPriority::kNormal};
|
||||
std::deque<std::vector<uint8_t>> control_commands_;
|
||||
std::deque<std::vector<uint8_t>> normal_commands_;
|
||||
std::deque<std::vector<uint8_t>> maintenance_commands_;
|
||||
mutable std::map<uint8_t, std::string> gateway_names_;
|
||||
size_t gateway_count_{0};
|
||||
bool ble_enabled_{false};
|
||||
bool cache_enabled_{true};
|
||||
CommandDropReason last_enqueue_drop_reason_{CommandDropReason::kNone};
|
||||
std::function<uint8_t(uint8_t gw, uint8_t raw_addr)> command_address_resolver_;
|
||||
std::optional<WirelessInfo> wireless_info_;
|
||||
|
||||
Reference in New Issue
Block a user