feat: add chip level command handling in GatewayController

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-06-13 14:43:47 +08:00
parent be9ff9c2c9
commit 530f0ecf12
2 changed files with 31 additions and 13 deletions
+2 -1
View File
@@ -552,7 +552,8 @@ int GatewayBleBridge::handleAccess(uint16_t, uint16_t attr_handle,
return 0; return 0;
} }
if (index == static_cast<int>(kGatewayCharacteristicIndex)) { if (GatewayRuntime::isGatewayCommandFrame(payload) ||
index == static_cast<int>(kGatewayCharacteristicIndex)) {
handleGatewayWrite(payload); handleGatewayWrite(payload);
} else { } else {
handleRawWrite(static_cast<size_t>(index), payload); handleRawWrite(static_cast<size_t>(index), payload);
@@ -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 NormalizeName(std::string_view name) {
std::string normalized(name); std::string normalized(name);
if (normalized.size() > kMaxNameBytes) { if (normalized.size() > kMaxNameBytes) {
@@ -851,23 +870,16 @@ void GatewayController::dispatchCommand(const std::vector<uint8_t>& command) {
const uint8_t opcode = command[3]; const uint8_t opcode = command[3];
const uint8_t addr = command[4]; const uint8_t addr = command[4];
const uint8_t data = command[5]; const uint8_t data = command[5];
if (opcode == 0x09 && addr == 0x00) {
const auto ids = gatewayIds();
const auto count = std::min<size_t>(ids.size(), 16);
std::vector<uint8_t> payload{0x09, static_cast<uint8_t>(count)};
payload.insert(payload.end(), ids.begin(), ids.begin() + count);
publishPayload(gateway_id, payload);
return;
}
if (opcode == kGatewaySerialOpcode) { if (opcode == kGatewaySerialOpcode) {
handleGatewaySerialCommand(gateway_id, command); handleGatewaySerialCommand(gateway_id, command);
return; 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); ESP_LOGW(kTag, "command for unknown gateway=%u opcode=0x%02x", gateway_id, opcode);
return; return;
} }
if (IsDaliHostCommandOpcode(opcode)) { if (!chip_level_command && IsDaliHostCommandOpcode(opcode)) {
dali_domain_.markHostActivity(gateway_id); dali_domain_.markHostActivity(gateway_id);
} }
@@ -960,7 +972,12 @@ void GatewayController::dispatchCommand(const std::vector<uint8_t>& command) {
break; break;
case 0x09: { case 0x09: {
const auto ids = gatewayIds(); const auto ids = gatewayIds();
if (addr >= 1 && addr <= ids.size()) { if (addr == 0) {
const auto count = std::min<size_t>(ids.size(), 16);
std::vector<uint8_t> payload{0x09, static_cast<uint8_t>(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]; const auto selected_gateway = ids[addr - 1];
publishPayload(gateway_id, {0x03, selected_gateway, selected_gateway}); publishPayload(gateway_id, {0x03, selected_gateway, selected_gateway});
} else { } else {