feat: implement device name handling and update gateway name features
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -2100,8 +2100,17 @@ struct GatewayBridgeService::ChannelRuntime {
|
||||
#if defined(CONFIG_GATEWAY_BACNET_BRIDGE_SUPPORTED)
|
||||
GatewayBacnetServerConfig bacnetServerConfigLocked() const {
|
||||
GatewayBacnetServerConfig config;
|
||||
config.device_name = channel.name.empty() ? "DALI Gateway " + std::to_string(channel.gateway_id)
|
||||
: channel.name;
|
||||
config.channel_name = channel.name.empty()
|
||||
? "Gateway " + std::to_string(channel.gateway_id)
|
||||
: channel.name;
|
||||
if (service_config.gateway_device_name_provider) {
|
||||
config.device_name = service_config.gateway_device_name_provider();
|
||||
}
|
||||
if (config.device_name.empty()) {
|
||||
config.device_name = channel.name.empty()
|
||||
? "DALI Gateway " + std::to_string(channel.gateway_id)
|
||||
: channel.name;
|
||||
}
|
||||
config.task_stack_size = service_config.bacnet_task_stack_size;
|
||||
config.task_priority = service_config.bacnet_task_priority;
|
||||
if (bacnet_server_config.has_value()) {
|
||||
@@ -2320,6 +2329,21 @@ struct GatewayBridgeService::ChannelRuntime {
|
||||
}
|
||||
#endif
|
||||
|
||||
void updateChannelInfo(DaliChannelInfo next_channel) {
|
||||
LockGuard guard(lock);
|
||||
channel = std::move(next_channel);
|
||||
#if defined(CONFIG_GATEWAY_BACNET_BRIDGE_SUPPORTED)
|
||||
if (bacnet_started) {
|
||||
const esp_err_t err = syncBacnetServerLocked();
|
||||
if (err != ESP_OK && err != ESP_ERR_NOT_FOUND) {
|
||||
ESP_LOGW(kTag, "gateway=%u BACnet name refresh failed: %s", channel.gateway_id,
|
||||
esp_err_to_name(err));
|
||||
}
|
||||
bacnet_started = err == ESP_OK;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t startKnx(std::set<uint16_t>* used_ports = nullptr,
|
||||
std::set<int>* used_uarts = nullptr) {
|
||||
LockGuard guard(lock);
|
||||
@@ -4379,6 +4403,24 @@ const GatewayBridgeService::ChannelRuntime* GatewayBridgeService::findRuntime(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GatewayBridgeService::handleGatewayNameChanged(uint8_t gateway_id) {
|
||||
const auto channels = dali_domain_.channelInfo();
|
||||
for (const auto& runtime : runtimes_) {
|
||||
if (gateway_id != 0xff && runtime->channel.gateway_id != gateway_id) {
|
||||
continue;
|
||||
}
|
||||
const uint8_t runtime_gateway = runtime->channel.gateway_id;
|
||||
const auto channel =
|
||||
std::find_if(channels.begin(), channels.end(), [runtime_gateway](
|
||||
const DaliChannelInfo& item) {
|
||||
return item.gateway_id == runtime_gateway;
|
||||
});
|
||||
if (channel != channels.end()) {
|
||||
runtime->updateChannelInfo(*channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GatewayBridgeService::ChannelRuntime* GatewayBridgeService::selectKnxEndpointRuntime() {
|
||||
auto eligible = [](ChannelRuntime* runtime) {
|
||||
if (runtime == nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user