From e11a0f646c1eecca9719ad8292fb7fb7105649dd Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 8 Jun 2026 19:23:52 +0800 Subject: [PATCH] Enhance DaliComm: refactor checkGatewayType to use checksum for newProbe and handle legacy tail Signed-off-by: Tony --- src/dali_comm.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dali_comm.cpp b/src/dali_comm.cpp index f2f5b30..09c5d27 100644 --- a/src/dali_comm.cpp +++ b/src/dali_comm.cpp @@ -169,8 +169,10 @@ int DaliComm::checkGatewayType(int gateway) const { const std::vector usbProbe{0x01, 0x00, 0x00}; const std::vector legacyProbe{0x28, 0x01, static_cast(gateway), 0x11, 0x00, 0x00, 0xFF}; - const std::vector newProbe{0x28, 0x01, static_cast(gateway), 0x11, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xFF}; + const auto newProbe = checksum({0x28, 0x01, static_cast(gateway), 0x11, 0x00, + 0x00, 0x00, 0x00, 0x00}); + const std::vector newProbeLegacyTail{0x28, 0x01, static_cast(gateway), 0x11, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF}; prepareForQuery(); const auto usbResp = transact_(usbProbe.data(), usbProbe.size()); @@ -180,9 +182,11 @@ int DaliComm::checkGatewayType(int gateway) const { const auto legacyResp = transact_(legacyProbe.data(), legacyProbe.size()); if (legacyResp.size() >= 2 && legacyResp[0] == gateway) return 2; - prepareForQuery(); - const auto newResp = transact_(newProbe.data(), newProbe.size()); - if (newResp.size() >= 2 && newResp[0] == gateway) return 3; + for (const auto& probe : {newProbe, newProbeLegacyTail}) { + prepareForQuery(); + const auto newResp = transact_(probe.data(), probe.size()); + if (newResp.size() >= 2 && newResp[0] == gateway) return 3; + } return 0; }