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:
Tony
2026-06-11 21:04:20 +08:00
parent 6ffca719d9
commit dceede8602
8 changed files with 298 additions and 14 deletions
@@ -192,6 +192,8 @@ class DaliDomainService {
std::optional<uint8_t> level) const;
bool applyAddressSettings(uint8_t gateway_id, int short_address,
const DaliAddressSettingsSnapshot& settings) const;
std::optional<uint8_t> gatewayIdForChannelIndex(uint8_t channel_index) const;
bool updateChannelGatewayId(uint8_t channel_index, uint8_t gateway_id);
bool updateChannelName(uint8_t gateway_id, std::string_view name);
bool allocateAllAddr(uint8_t gateway_id, int start_address = 0) const;
void stopAllocAddr(uint8_t gateway_id) const;
@@ -212,6 +214,7 @@ class DaliDomainService {
DaliChannel* findChannelByGateway(uint8_t gateway_id);
const DaliChannel* findChannelByGateway(uint8_t gateway_id) const;
DaliChannel* findChannelByIndex(uint8_t channel_index);
const DaliChannel* findChannelByIndex(uint8_t channel_index) const;
const DaliChannel* findChannelByHardwareBus(uint8_t bus_id) const;
bool hasSerialPort(int uart_port) const;
esp_err_t startSerialRxTask(DaliChannel& channel);
@@ -635,6 +635,31 @@ std::vector<DaliChannelInfo> DaliDomainService::channelInfo() const {
return info;
}
std::optional<uint8_t> DaliDomainService::gatewayIdForChannelIndex(uint8_t channel_index) const {
const auto* channel = findChannelByIndex(channel_index);
if (channel == nullptr) {
return std::nullopt;
}
return channel->config.gateway_id;
}
bool DaliDomainService::updateChannelGatewayId(uint8_t channel_index, uint8_t gateway_id) {
auto* channel = findChannelByIndex(channel_index);
if (channel == nullptr) {
return false;
}
for (const auto& other : channels_) {
if (other.get() != channel && other->config.gateway_id == gateway_id) {
return false;
}
}
channel->config.gateway_id = gateway_id;
if (channel->dali != nullptr) {
channel->dali = std::make_unique<Dali>(*channel->comm, gateway_id, channel->config.name);
}
return true;
}
void DaliDomainService::addRawFrameSink(std::function<void(const DaliRawFrame& frame)> sink) {
if (!sink) {
return;
@@ -1674,6 +1699,15 @@ DaliDomainService::DaliChannel* DaliDomainService::findChannelByIndex(uint8_t ch
return it == channels_.end() ? nullptr : it->get();
}
const DaliDomainService::DaliChannel* DaliDomainService::findChannelByIndex(
uint8_t channel_index) const {
const auto it = std::find_if(channels_.begin(), channels_.end(),
[channel_index](const auto& channel) {
return channel->config.channel_index == channel_index;
});
return it == channels_.end() ? nullptr : it->get();
}
const DaliDomainService::DaliChannel* DaliDomainService::findChannelByHardwareBus(
uint8_t bus_id) const {
const auto it = std::find_if(channels_.begin(), channels_.end(), [bus_id](const auto& channel) {