fix(gateway): enhance DALI logging and error handling in gateway_knx
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -679,11 +679,27 @@ std::optional<int> ExecuteRawQuery(DaliBridgeEngine& engine, uint8_t addr, uint8
|
||||
const char* sequence) {
|
||||
const auto result = ExecuteRaw(engine, BridgeOperation::query, addr, cmd, sequence);
|
||||
if (!result.ok || !result.data.has_value()) {
|
||||
ESP_LOGD(kTag, "DALI query failed seq=%s addr=0x%02x cmd=0x%02x error=%s",
|
||||
sequence == nullptr ? "" : sequence, static_cast<unsigned>(addr),
|
||||
static_cast<unsigned>(cmd),
|
||||
result.error.empty() ? "no response" : result.error.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
ESP_LOGD(kTag, "DALI query result seq=%s addr=0x%02x cmd=0x%02x data=0x%02x",
|
||||
sequence == nullptr ? "" : sequence, static_cast<unsigned>(addr),
|
||||
static_cast<unsigned>(cmd),
|
||||
static_cast<unsigned>(result.data.value() & 0xff));
|
||||
return result.data.value();
|
||||
}
|
||||
|
||||
bool DaliQueryResultHasStatus(const DaliBridgeResult& result, const char* status) {
|
||||
if (status == nullptr) return false;
|
||||
const auto it = result.metadata.find("queryStatus");
|
||||
if (it == result.metadata.end()) return false;
|
||||
const auto value = it->second.asString();
|
||||
return value.has_value() && value.value() == status;
|
||||
}
|
||||
|
||||
std::optional<uint8_t> RawCommandAddressForTarget(const GatewayKnxDaliTarget& target) {
|
||||
switch (target.kind) {
|
||||
case GatewayKnxDaliTargetKind::kBroadcast:
|
||||
@@ -954,11 +970,27 @@ std::optional<bool> CompareSelectedSearchAddress(DaliBridgeEngine& engine, uint3
|
||||
if (!SetSearchAddress(engine, search_address, sequence)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto raw = ExecuteRawQuery(engine, DALI_CMD_SPECIAL_COMPARE, DALI_CMD_OFF, sequence);
|
||||
if (!raw.has_value()) {
|
||||
const auto result = ExecuteRaw(engine, BridgeOperation::query, DALI_CMD_SPECIAL_COMPARE,
|
||||
DALI_CMD_OFF, sequence);
|
||||
if (result.ok && result.data.has_value()) {
|
||||
return true;
|
||||
}
|
||||
if (DaliQueryResultHasStatus(result, "noResponse") ||
|
||||
DaliQueryResultHasStatus(result, "timeout")) {
|
||||
ESP_LOGD(kTag, "DALI compare no match seq=%s search=0x%06x status=%s",
|
||||
sequence == nullptr ? "" : sequence, static_cast<unsigned>(search_address),
|
||||
DaliQueryResultHasStatus(result, "timeout") ? "timeout" : "noResponse");
|
||||
return false;
|
||||
}
|
||||
if (!result.error.empty()) {
|
||||
ESP_LOGW(kTag, "DALI compare failed seq=%s search=0x%06x error=%s",
|
||||
sequence == nullptr ? "" : sequence, static_cast<unsigned>(search_address),
|
||||
result.error.c_str());
|
||||
}
|
||||
if (!result.ok || !result.data.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return raw.value() == 0xff;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<uint32_t> FindLowestSelectedRandomAddress(DaliBridgeEngine& engine) {
|
||||
|
||||
Reference in New Issue
Block a user