feat: enhance gateway channel management with serial command handling and gateway ID updates
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -893,14 +893,22 @@ bool ValidateChannelBindings() {
|
||||
|
||||
esp_err_t BindConfiguredChannels(gateway::DaliDomainService& dali_domain,
|
||||
const gateway::GatewayRuntime& runtime) {
|
||||
std::array<bool, 256> used_gateway_ids{};
|
||||
for (const auto& channel : BuildChannelBindings()) {
|
||||
if (!channel.enabled) {
|
||||
continue;
|
||||
}
|
||||
const uint8_t gateway_id =
|
||||
runtime.gatewayIdForChannel(channel.channel_index, channel.gateway_id);
|
||||
if (used_gateway_ids[gateway_id]) {
|
||||
ESP_LOGE(kTag, "duplicate runtime gateway id configured: %u", gateway_id);
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
used_gateway_ids[gateway_id] = true;
|
||||
if (channel.native_phy) {
|
||||
gateway::DaliHardwareBusConfig config{};
|
||||
config.channel_index = channel.channel_index;
|
||||
config.gateway_id = channel.gateway_id;
|
||||
config.gateway_id = gateway_id;
|
||||
config.bus_id = channel.native_bus_id;
|
||||
config.tx_pin = static_cast<uint8_t>(channel.native_tx_pin);
|
||||
config.rx_pin = static_cast<uint8_t>(channel.native_rx_pin);
|
||||
@@ -914,7 +922,7 @@ esp_err_t BindConfiguredChannels(gateway::DaliDomainService& dali_domain,
|
||||
} else if (channel.serial_phy) {
|
||||
gateway::DaliSerialBusConfig config{};
|
||||
config.channel_index = channel.channel_index;
|
||||
config.gateway_id = channel.gateway_id;
|
||||
config.gateway_id = gateway_id;
|
||||
config.uart_port = channel.uart_port;
|
||||
config.tx_pin = channel.serial_tx_pin;
|
||||
config.rx_pin = channel.serial_rx_pin;
|
||||
@@ -966,8 +974,8 @@ extern "C" void app_main(void) {
|
||||
},
|
||||
s_dali_domain.get());
|
||||
ESP_ERROR_CHECK(s_runtime->start());
|
||||
s_runtime->setGatewayCount(CONFIG_GATEWAY_CHANNEL_COUNT);
|
||||
ESP_ERROR_CHECK(BindConfiguredChannels(*s_dali_domain, *s_runtime));
|
||||
s_runtime->setGatewayCount(s_dali_domain->channelCount());
|
||||
|
||||
gateway::GatewayCacheConfig cache_config;
|
||||
cache_config.cache_enabled = kCacheSupported && kCacheStartupEnabled && s_runtime->cacheEnabled();
|
||||
@@ -1244,4 +1252,4 @@ extern "C" void app_main(void) {
|
||||
std::printf("gateway_main: runtime device type=%s serial=%s project=%s version=%s\n",
|
||||
device_info.type.c_str(), device_info.serial_id.c_str(),
|
||||
device_info.project.c_str(), device_info.version.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user