feat: implement device name handling and update gateway name features

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-06-12 01:26:31 +08:00
parent dceede8602
commit 40a0e8e303
11 changed files with 192 additions and 23 deletions
@@ -18,6 +18,7 @@ namespace gateway {
struct GatewayBacnetServerConfig {
uint32_t device_instance{4194303};
std::string device_name{"DALI Gateway"};
std::string channel_name;
std::string local_address;
uint16_t udp_port{47808};
uint32_t task_stack_size{8192};
@@ -91,4 +92,4 @@ class GatewayBacnetServer {
bool started_{false};
};
} // namespace gateway
} // namespace gateway
@@ -48,6 +48,8 @@ bool gateway_bacnet_stack_start(
void gateway_bacnet_stack_cleanup(void);
bool gateway_bacnet_stack_set_device_name(const char* device_name);
bool gateway_bacnet_stack_upsert_object(
gateway_bacnet_object_kind_t object_kind,
uint32_t object_instance,
@@ -74,4 +76,4 @@ void gateway_bacnet_stack_poll(uint16_t elapsed_ms);
#ifdef __cplusplus
}
#endif
#endif
@@ -251,6 +251,11 @@ esp_err_t GatewayBacnetServer::registerChannel(
return ESP_ERR_INVALID_ARG;
}
GatewayBacnetServerConfig effective_config = config;
if (effective_config.device_name.empty()) {
effective_config.device_name = "DALI Gateway";
}
bindings.erase(std::remove_if(bindings.begin(), bindings.end(), [](const auto& binding) {
return !IsSupportedObjectType(binding.object_type) ||
binding.object_instance > kMaxBacnetInstance;
@@ -258,7 +263,7 @@ esp_err_t GatewayBacnetServer::registerChannel(
bindings.end());
LockGuard guard(lock_);
if (started_ && !configCompatible(config)) {
if (started_ && !configCompatible(effective_config)) {
return ESP_ERR_INVALID_STATE;
}
@@ -268,7 +273,15 @@ esp_err_t GatewayBacnetServer::registerChannel(
if (bindings.empty() && !started_ && channel == channels_.end()) {
return ESP_ERR_NOT_FOUND;
}
ChannelRegistration registration{gateway_id, config, std::move(bindings),
if (started_ && active_config_.device_name != effective_config.device_name) {
if (!gateway_bacnet_stack_set_device_name(effective_config.device_name.c_str())) {
return ESP_FAIL;
}
active_config_.device_name = effective_config.device_name;
gateway_bacnet_stack_send_i_am();
}
ChannelRegistration registration{gateway_id, effective_config, std::move(bindings),
std::move(write_callback), std::move(read_callback)};
if (channel == channels_.end()) {
channels_.push_back(std::move(registration));
@@ -276,7 +289,7 @@ esp_err_t GatewayBacnetServer::registerChannel(
*channel = std::move(registration);
}
esp_err_t err = startStackLocked(config);
esp_err_t err = startStackLocked(effective_config);
if (err != ESP_OK) {
return err;
}
@@ -341,9 +354,16 @@ esp_err_t GatewayBacnetServer::rebuildObjectsLocked() {
used_objects.insert(key);
const std::string name = ObjectName(binding);
std::string description = channel.config.channel_name;
if (!binding.model_id.empty()) {
if (!description.empty()) {
description += " / ";
}
description += binding.model_id;
}
if (!gateway_bacnet_stack_upsert_object(ToBacnetKind(binding.object_type),
binding.object_instance, name.c_str(),
binding.model_id.c_str(),
description.c_str(),
binding.out_of_service,
binding.reliability)) {
return ESP_FAIL;
@@ -465,4 +485,4 @@ void GatewayBacnetServer::taskLoop() {
}
}
} // namespace gateway
} // namespace gateway
@@ -410,6 +410,14 @@ void gateway_bacnet_stack_cleanup(void)
Write_Callback_Context = NULL;
}
bool gateway_bacnet_stack_set_device_name(const char* device_name)
{
if (!device_name || device_name[0] == '\0') {
device_name = "DALI Gateway";
}
return Device_Object_Name_ANSI_Init(device_name);
}
bool gateway_bacnet_stack_upsert_object(
gateway_bacnet_object_kind_t object_kind,
uint32_t object_instance,
@@ -636,4 +644,4 @@ void gateway_bacnet_stack_poll(uint16_t elapsed_ms)
tsm_timer_milliseconds(elapsed_ms);
Device_Timer(elapsed_ms);
}
}
}