fix(gateway): update DALI configuration parameters for improved performance and reliability
This commit add comat parameter for some old DALI-1 control gear. Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -247,6 +247,121 @@ void GatewayKnxBridge::runCommissioningScanTask() {
|
||||
}
|
||||
|
||||
while (!is_cancelled()) {
|
||||
auto log_and_record_ballast = [&](const GatewayKnxCommissioningBallast& ballast) {
|
||||
record_ballast(ballast);
|
||||
ESP_LOGI(kTag, "REG1-Dali scan found random=0x%02X%02X%02X short=%u",
|
||||
ballast.high, ballast.middle, ballast.low,
|
||||
static_cast<unsigned>(ballast.short_address));
|
||||
};
|
||||
auto withdraw_selected = [&]() {
|
||||
return SendRaw(engine_, DALI_CMD_SPECIAL_WITHDRAW, DALI_CMD_OFF,
|
||||
"knx-function-scan-withdraw");
|
||||
};
|
||||
auto program_selected_ballast =
|
||||
[&](uint8_t short_address,
|
||||
uint32_t fallback_random_address) -> std::optional<GatewayKnxCommissioningBallast> {
|
||||
if (!ProgramShortAddressAndConfirm(engine_, short_address)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto random_address =
|
||||
QueryRandomAddressForShortAddress(engine_, short_address).value_or(fallback_random_address);
|
||||
GatewayKnxCommissioningBallast ballast;
|
||||
ballast.high = static_cast<uint8_t>((random_address >> 16) & 0xff);
|
||||
ballast.middle = static_cast<uint8_t>((random_address >> 8) & 0xff);
|
||||
ballast.low = static_cast<uint8_t>(random_address & 0xff);
|
||||
ballast.short_address = short_address;
|
||||
return ballast;
|
||||
};
|
||||
|
||||
if (options.assign) {
|
||||
const auto next_address = NextFreeShortAddress(used_addresses);
|
||||
if (!next_address.has_value()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan has no free short address left");
|
||||
break;
|
||||
}
|
||||
|
||||
const auto compare_base = FindSelectedCommissioningCompareBase(engine_);
|
||||
if (!compare_base.has_value()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const auto first_ballast =
|
||||
program_selected_ballast(next_address.value(), compare_base.value());
|
||||
if (!first_ballast.has_value()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan failed to program short address %u",
|
||||
static_cast<unsigned>(next_address.value()));
|
||||
break;
|
||||
}
|
||||
used_addresses[next_address.value()] = true;
|
||||
log_and_record_ballast(first_ballast.value());
|
||||
|
||||
if (is_cancelled()) {
|
||||
clear_results = true;
|
||||
break;
|
||||
}
|
||||
if (!withdraw_selected()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan failed while withdrawing matched device");
|
||||
break;
|
||||
}
|
||||
|
||||
auto compare_cursor = IncrementRandomAddress(compare_base.value());
|
||||
bool compare_multi_failed = false;
|
||||
while (!is_cancelled() && compare_cursor.has_value()) {
|
||||
const auto contiguous_short = NextFreeShortAddress(used_addresses);
|
||||
if (!contiguous_short.has_value()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const auto next_search = IncrementRandomAddress(compare_cursor.value());
|
||||
if (!next_search.has_value()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const auto matched = CompareSelectedSearchAddress(
|
||||
engine_, next_search.value(), "knx-function-scan-compare-multi");
|
||||
if (!matched.has_value()) {
|
||||
compare_multi_failed = true;
|
||||
break;
|
||||
}
|
||||
if (!matched.value()) {
|
||||
break;
|
||||
}
|
||||
|
||||
compare_cursor = next_search.value();
|
||||
const auto ballast =
|
||||
program_selected_ballast(contiguous_short.value(), compare_cursor.value());
|
||||
if (!ballast.has_value()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan failed to program short address %u",
|
||||
static_cast<unsigned>(contiguous_short.value()));
|
||||
compare_multi_failed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
used_addresses[contiguous_short.value()] = true;
|
||||
log_and_record_ballast(ballast.value());
|
||||
|
||||
if (is_cancelled()) {
|
||||
clear_results = true;
|
||||
break;
|
||||
}
|
||||
if (!withdraw_selected()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan failed while withdrawing matched device");
|
||||
compare_multi_failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (compare_multi_failed) {
|
||||
break;
|
||||
}
|
||||
if (is_cancelled()) {
|
||||
clear_results = true;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto random_address = FindLowestSelectedRandomAddress(engine_);
|
||||
if (!random_address.has_value()) {
|
||||
break;
|
||||
@@ -258,38 +373,15 @@ void GatewayKnxBridge::runCommissioningScanTask() {
|
||||
ballast.low = static_cast<uint8_t>(random_address.value() & 0xff);
|
||||
ballast.short_address = 0xff;
|
||||
|
||||
if (options.assign) {
|
||||
const auto next_address = NextFreeShortAddress(used_addresses);
|
||||
if (!next_address.has_value()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan has no free short address left for 0x%06x",
|
||||
static_cast<unsigned>(random_address.value()));
|
||||
break;
|
||||
}
|
||||
if (!SendRaw(engine_, DALI_CMD_SPECIAL_PROGRAM_SHORT_ADDRESS,
|
||||
DaliComm::toCmdAddr(next_address.value()),
|
||||
"knx-function-scan-program-short") ||
|
||||
!VerifyShortAddress(engine_, next_address.value())) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan failed to program short address %u",
|
||||
static_cast<unsigned>(next_address.value()));
|
||||
break;
|
||||
}
|
||||
used_addresses[next_address.value()] = true;
|
||||
ballast.short_address = next_address.value();
|
||||
} else {
|
||||
ballast.short_address = QuerySelectedShortAddress(engine_).value_or(0xff);
|
||||
}
|
||||
ballast.short_address = QuerySelectedShortAddress(engine_).value_or(0xff);
|
||||
|
||||
record_ballast(ballast);
|
||||
ESP_LOGI(kTag, "REG1-Dali scan found random=0x%02X%02X%02X short=%u",
|
||||
ballast.high, ballast.middle, ballast.low,
|
||||
static_cast<unsigned>(ballast.short_address));
|
||||
log_and_record_ballast(ballast);
|
||||
|
||||
if (is_cancelled()) {
|
||||
clear_results = true;
|
||||
break;
|
||||
}
|
||||
if (!SendRaw(engine_, DALI_CMD_SPECIAL_WITHDRAW, DALI_CMD_OFF,
|
||||
"knx-function-scan-withdraw")) {
|
||||
if (!withdraw_selected()) {
|
||||
ESP_LOGW(kTag, "REG1-Dali scan failed while withdrawing matched device");
|
||||
break;
|
||||
}
|
||||
@@ -662,12 +754,12 @@ bool GatewayKnxBridge::handleReg1AssignCommand(const uint8_t* data, size_t len,
|
||||
const uint8_t short_address = data[1] == 99 ? 0xff : data[1];
|
||||
const bool ok = SendRawExt(engine_, DALI_CMD_SPECIAL_INITIALIZE, 0x00,
|
||||
"knx-function-assign-init") &&
|
||||
SendRaw(engine_, DALI_CMD_SPECIAL_SEARCHADDRH, data[2],
|
||||
"knx-function-assign-search-h") &&
|
||||
SendRaw(engine_, DALI_CMD_SPECIAL_SEARCHADDRM, data[3],
|
||||
"knx-function-assign-search-m") &&
|
||||
SendRaw(engine_, DALI_CMD_SPECIAL_SEARCHADDRL, data[4],
|
||||
"knx-function-assign-search-l") &&
|
||||
"knx-function-assign-search-l") &&
|
||||
SendRaw(engine_, DALI_CMD_SPECIAL_SEARCHADDRM, data[3],
|
||||
"knx-function-assign-search-m") &&
|
||||
SendRaw(engine_, DALI_CMD_SPECIAL_SEARCHADDRH, data[2],
|
||||
"knx-function-assign-search-h") &&
|
||||
SendRaw(engine_, DALI_CMD_SPECIAL_PROGRAM_SHORT_ADDRESS,
|
||||
short_address == 0xff ? 0xff : DaliComm::toCmdAddr(short_address),
|
||||
"knx-function-assign-program") &&
|
||||
|
||||
Reference in New Issue
Block a user