From 640e78f688a5e31da0c8d9ed6cf78f225f0ac937 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 4 May 2026 09:46:24 +0800 Subject: [PATCH] feat(gateway_bridge): enhance DaliBridgeRequest parsing with support for unknown keys Signed-off-by: Tony --- .../gateway_bridge/src/gateway_bridge.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/components/gateway_bridge/src/gateway_bridge.cpp b/components/gateway_bridge/src/gateway_bridge.cpp index e18323c..b7986fa 100644 --- a/components/gateway_bridge/src/gateway_bridge.cpp +++ b/components/gateway_bridge/src/gateway_bridge.cpp @@ -889,26 +889,68 @@ cJSON* GatewayCloudConfigToCjson(const GatewayCloudConfig& config) { return root; } +bool IsKnownBridgeRequestKey(const char* key) { + if (key == nullptr) return true; + static const char* known[] = {"type", "seq", "sequence", "model", + "modelID", "modelId", "op", "operation", + "addr", "rawAddress", "cmd", "rawCommand", + "shortAddress", "short_address", "value", "meta"}; + for (const char* item : known) { + if (std::strcmp(key, item) == 0) return true; + } + return false; +} + DaliBridgeRequest BridgeRequestFromJson(cJSON* root) { DaliBridgeRequest request; if (const char* seq = JsonString(root, "seq")) { request.sequence = seq; } + if (request.sequence.empty()) { + if (const char* seq = JsonString(root, "sequence")) { + request.sequence = seq; + } + } if (const char* model = JsonString(root, "model")) { request.modelID = model; } + if (request.modelID.empty()) { + if (const char* model = JsonString(root, "modelID")) { + request.modelID = model; + } + } if (const char* op = JsonString(root, "op")) { request.operation = bridgeOperationFromString(op); } + if (!request.operation.has_value()) { + if (const char* op = JsonString(root, "operation")) { + request.operation = bridgeOperationFromString(op); + } + } if (const auto addr = JsonInt(root, "addr")) { request.rawAddress = addr.value(); } + if (!request.rawAddress.has_value()) { + if (const auto addr = JsonInt(root, "rawAddress")) { + request.rawAddress = addr.value(); + } + } if (const auto cmd = JsonInt(root, "cmd")) { request.rawCommand = cmd.value(); } + if (!request.rawCommand.has_value()) { + if (const auto cmd = JsonInt(root, "rawCommand")) { + request.rawCommand = cmd.value(); + } + } if (const auto short_address = JsonInt(root, "shortAddress")) { request.shortAddress = short_address.value(); } + if (!request.shortAddress.has_value()) { + if (const auto short_address = JsonInt(root, "short_address")) { + request.shortAddress = short_address.value(); + } + } if (const cJSON* value = cJSON_GetObjectItemCaseSensitive(root, "value")) { request.value = FromCjson(value); } @@ -918,6 +960,12 @@ DaliBridgeRequest BridgeRequestFromJson(cJSON* root) { request.metadata = *object; } } + for (const cJSON* child = root != nullptr ? root->child : nullptr; child != nullptr; + child = child->next) { + if (!IsKnownBridgeRequestKey(child->string)) { + request.metadata[child->string] = FromCjson(child); + } + } return request; }