Enhance DaliComm: refactor checkGatewayType to use checksum for newProbe and handle legacy tail
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
+9
-5
@@ -169,8 +169,10 @@ int DaliComm::checkGatewayType(int gateway) const {
|
||||
const std::vector<uint8_t> usbProbe{0x01, 0x00, 0x00};
|
||||
const std::vector<uint8_t> legacyProbe{0x28, 0x01, static_cast<uint8_t>(gateway), 0x11, 0x00, 0x00,
|
||||
0xFF};
|
||||
const std::vector<uint8_t> newProbe{0x28, 0x01, static_cast<uint8_t>(gateway), 0x11, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF};
|
||||
const auto newProbe = checksum({0x28, 0x01, static_cast<uint8_t>(gateway), 0x11, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00});
|
||||
const std::vector<uint8_t> newProbeLegacyTail{0x28, 0x01, static_cast<uint8_t>(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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user