feat(gateway): implement GatewayController and enhance GatewayRuntime

- Added GatewayController class to manage gateway operations, including command handling, scene and group management, and BLE state management.
- Introduced methods for scene and group storage, including loading, saving, and deleting scenes/groups.
- Enhanced GatewayRuntime with BLE management capabilities, including methods to check and set BLE state, and to generate BLE gateway names.
- Implemented utility functions for string normalization and CSV parsing.
- Added notification sinks for various events in the GatewayController.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Tony
2026-04-29 23:02:40 +08:00
parent f4756ce816
commit 4433fe97c7
13 changed files with 1967 additions and 12 deletions
@@ -295,6 +295,21 @@ bool DaliDomainService::resetBus(uint8_t gateway_id) const {
return channel != nullptr && channel->comm != nullptr && channel->comm->resetBus();
}
bool DaliDomainService::writeBridgeFrame(uint8_t gateway_id, const uint8_t* data, size_t len) const {
const auto* channel = findChannelByGateway(gateway_id);
return channel != nullptr && channel->hooks.send && channel->hooks.send(data, len);
}
std::vector<uint8_t> DaliDomainService::transactBridgeFrame(uint8_t gateway_id,
const uint8_t* data,
size_t len) const {
const auto* channel = findChannelByGateway(gateway_id);
if (channel == nullptr || !channel->hooks.transact) {
return {};
}
return channel->hooks.transact(data, len);
}
bool DaliDomainService::sendRaw(uint8_t gateway_id, uint8_t raw_addr, uint8_t command) const {
const auto* channel = findChannelByGateway(gateway_id);
return channel != nullptr && channel->comm != nullptr && channel->comm->sendRawNew(raw_addr, command);
@@ -363,6 +378,51 @@ bool DaliDomainService::off(int short_address) const {
return off(channels_.front()->config.gateway_id, short_address);
}
bool DaliDomainService::updateChannelName(uint8_t gateway_id, std::string_view name) {
auto* channel = findChannelByGateway(gateway_id);
if (channel == nullptr) {
return false;
}
channel->config.name = std::string(name);
if (channel->dali != nullptr) {
channel->dali->name = channel->config.name;
}
return true;
}
bool DaliDomainService::allocateAllAddr(uint8_t gateway_id, int start_address) const {
const auto* channel = findChannelByGateway(gateway_id);
return channel != nullptr && channel->dali != nullptr &&
channel->dali->addr.allocateAllAddr(start_address);
}
void DaliDomainService::stopAllocAddr(uint8_t gateway_id) const {
const auto* channel = findChannelByGateway(gateway_id);
if (channel != nullptr && channel->dali != nullptr) {
channel->dali->addr.stopAllocAddr();
}
}
bool DaliDomainService::resetAndAllocAddr(uint8_t gateway_id, int start_address,
bool remove_addr_first, bool close_light) const {
const auto* channel = findChannelByGateway(gateway_id);
return channel != nullptr && channel->dali != nullptr &&
channel->dali->addr.resetAndAllocAddr(start_address, remove_addr_first, close_light);
}
bool DaliDomainService::isAllocAddr(uint8_t gateway_id) const {
const auto* channel = findChannelByGateway(gateway_id);
return channel != nullptr && channel->dali != nullptr && channel->dali->addr.isAllocAddr();
}
int DaliDomainService::lastAllocAddr(uint8_t gateway_id) const {
const auto* channel = findChannelByGateway(gateway_id);
if (channel == nullptr || channel->dali == nullptr) {
return 0;
}
return channel->dali->addr.lastAllocAddr();
}
DaliDomainService::DaliChannel* DaliDomainService::findChannelByGateway(uint8_t gateway_id) {
const auto it = std::find_if(channels_.begin(), channels_.end(), [gateway_id](const auto& channel) {
return channel->config.gateway_id == gateway_id;