From 530f0ecf120f77c30b94ae8484d099b31a5711a2 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 13 Jun 2026 14:43:47 +0800 Subject: [PATCH] feat: add chip level command handling in GatewayController Signed-off-by: Tony --- components/gateway_ble/src/gateway_ble.cpp | 5 ++- .../src/gateway_controller.cpp | 39 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/components/gateway_ble/src/gateway_ble.cpp b/components/gateway_ble/src/gateway_ble.cpp index 7021461..9957539 100644 --- a/components/gateway_ble/src/gateway_ble.cpp +++ b/components/gateway_ble/src/gateway_ble.cpp @@ -552,7 +552,8 @@ int GatewayBleBridge::handleAccess(uint16_t, uint16_t attr_handle, return 0; } - if (index == static_cast(kGatewayCharacteristicIndex)) { + if (GatewayRuntime::isGatewayCommandFrame(payload) || + index == static_cast(kGatewayCharacteristicIndex)) { handleGatewayWrite(payload); } else { handleRawWrite(static_cast(index), payload); @@ -565,4 +566,4 @@ int GatewayBleBridge::handleAccess(uint16_t, uint16_t attr_handle, } } -} // namespace gateway \ No newline at end of file +} // namespace gateway diff --git a/components/gateway_controller/src/gateway_controller.cpp b/components/gateway_controller/src/gateway_controller.cpp index a54e2d7..406a802 100644 --- a/components/gateway_controller/src/gateway_controller.cpp +++ b/components/gateway_controller/src/gateway_controller.cpp @@ -135,6 +135,25 @@ bool IsDaliHostCommandOpcode(uint8_t opcode) { } } +bool IsChipLevelCommand(uint8_t opcode, uint8_t op) { + switch (opcode) { + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + return true; + case 0x05: + return op == 0x02 || op == 0x03; + case 0x09: + return op == 0x00; + case 0x0A: + return op == 0x02; + default: + return false; + } +} + std::string NormalizeName(std::string_view name) { std::string normalized(name); if (normalized.size() > kMaxNameBytes) { @@ -851,23 +870,16 @@ void GatewayController::dispatchCommand(const std::vector& command) { const uint8_t opcode = command[3]; const uint8_t addr = command[4]; const uint8_t data = command[5]; - if (opcode == 0x09 && addr == 0x00) { - const auto ids = gatewayIds(); - const auto count = std::min(ids.size(), 16); - std::vector payload{0x09, static_cast(count)}; - payload.insert(payload.end(), ids.begin(), ids.begin() + count); - publishPayload(gateway_id, payload); - return; - } if (opcode == kGatewaySerialOpcode) { handleGatewaySerialCommand(gateway_id, command); return; } - if (!hasGateway(gateway_id)) { + const bool chip_level_command = IsChipLevelCommand(opcode, addr); + if (!chip_level_command && !hasGateway(gateway_id)) { ESP_LOGW(kTag, "command for unknown gateway=%u opcode=0x%02x", gateway_id, opcode); return; } - if (IsDaliHostCommandOpcode(opcode)) { + if (!chip_level_command && IsDaliHostCommandOpcode(opcode)) { dali_domain_.markHostActivity(gateway_id); } @@ -960,7 +972,12 @@ void GatewayController::dispatchCommand(const std::vector& command) { break; case 0x09: { const auto ids = gatewayIds(); - if (addr >= 1 && addr <= ids.size()) { + if (addr == 0) { + const auto count = std::min(ids.size(), 16); + std::vector payload{0x09, static_cast(count)}; + payload.insert(payload.end(), ids.begin(), ids.begin() + count); + publishPayload(gateway_id, payload); + } else if (addr >= 1 && addr <= ids.size()) { const auto selected_gateway = ids[addr - 1]; publishPayload(gateway_id, {0x03, selected_gateway, selected_gateway}); } else {