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
+3 -2
View File
@@ -552,7 +552,8 @@ int GatewayBleBridge::handleAccess(uint16_t, uint16_t attr_handle,
return 0;
}
if (index == static_cast<int>(kGatewayCharacteristicIndex)) {
if (GatewayRuntime::isGatewayCommandFrame(payload) ||
index == static_cast<int>(kGatewayCharacteristicIndex)) {
handleGatewayWrite(payload);
} else {
handleRawWrite(static_cast<size_t>(index), payload);
@@ -565,4 +566,4 @@ int GatewayBleBridge::handleAccess(uint16_t, uint16_t attr_handle,
}
}
} // namespace gateway
} // namespace gateway
@@ -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<uint8_t>& 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<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) {
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<uint8_t>& command) {
break;
case 0x09: {
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];
publishPayload(gateway_id, {0x03, selected_gateway, selected_gateway});
} else {