diff --git a/include/kvik/client_config.hpp b/include/kvik/client_config.hpp index 3c59c08..6b9c638 100644 --- a/include/kvik/client_config.hpp +++ b/include/kvik/client_config.hpp @@ -80,6 +80,14 @@ namespace kvik struct Reporting { + /** + * @brief Report RSSI during time synchronization + * + * Whether to report RSSI value (if used by local layer protocol) + * of PROBE_RES message received during time synchronization. + */ + bool rssiOnTimeSync = true; + /** * @brief Report RSSI during gateway discovery * diff --git a/src/common/client.cpp b/src/common/client.cpp index 8afe6c5..8ef2b4e 100644 --- a/src/common/client.cpp +++ b/src/common/client.cpp @@ -478,6 +478,17 @@ namespace kvik KVIK_LOGD("Successful (tsDiff=%zu ms)", m_gw.tsDiff.count()); } + // Report gateway RSSI + if (m_conf.reporting.rssiOnTimeSync && respMsg.rssi != RSSI_UNKNOWN) { + auto reportErr = this->publish( + this->buildReportRssiTopic(m_gw.addr), + std::to_string(respMsg.rssi)); + + if (reportErr != ErrCode::SUCCESS) { + KVIK_LOGW("Reporting RSSI failed"); + } + } + return ErrCode::SUCCESS; fail: diff --git a/test/tests/client.cpp b/test/tests/client.cpp index c198b92..e8bd205 100644 --- a/test/tests/client.cpp +++ b/test/tests/client.cpp @@ -45,6 +45,7 @@ static const ClientConfig CONF = { .trigTimeSyncNoRespCnt = 2, }, .reporting = { + .rssiOnTimeSync = false, .rssiOnGwDscv = false, }, .subDB = { @@ -1413,3 +1414,65 @@ TEST_CASE("Reporting of RSSI after gateway discovery", "[Client]") CHECK(ll.respSuccLog == RespSuccLog(2, true)); } } + +TEST_CASE("Reporting of RSSI after time sync", "[Client]") +{ + auto modifConf = CONF; + modifConf.reporting.rssiOnTimeSync = true; + + DEFAULT_LL(ll); + ll.responses.push(MSG_PROBE_RES_GW2); + + Client cl(modifConf, &ll); + + std::vector correctReportPub = {PUB_DATA_GW2_RSSI}; + + SECTION("Success without RSSI") + { + ll.responses.push(MSG_PROBE_RES_GW2); + + CHECK(cl.syncTime() == ErrCode::SUCCESS); + + std::this_thread::sleep_for(10ms); + + // No report should be made + REQUIRE(ll.sentLog.size() == 2); + CHECK(ll.respSuccLog == RespSuccLog(2, true)); + } + + SECTION("Success with RSSI, report successful") + { + ll.responses.push(MSG_PROBE_RES_GW2_WITH_RSSI); + ll.responses.push(MSG_OK_GW2); + + CHECK(cl.syncTime() == ErrCode::SUCCESS); + + std::this_thread::sleep_for(10ms); + REQUIRE(ll.sentLog.size() == 3); + CHECK(ll.sentLog.back().pubs == correctReportPub); + CHECK(ll.respSuccLog == RespSuccLog(3, true)); + } + + SECTION("Success with RSSI, report failed") + { + ll.responses.push(MSG_PROBE_RES_GW2_WITH_RSSI); + + CHECK(cl.syncTime() == ErrCode::SUCCESS); + + std::this_thread::sleep_for(10ms); + REQUIRE(ll.sentLog.size() == 3); + CHECK(ll.sentLog.back().pubs == correctReportPub); + CHECK(ll.respSuccLog == RespSuccLog(2, true)); + } + + SECTION("Failure with RSSI") + { + CHECK(cl.syncTime() == ErrCode::TIMEOUT); + + std::this_thread::sleep_for(10ms); + + // No report should be made + REQUIRE(ll.sentLog.size() == 2); + CHECK(ll.respSuccLog == RespSuccLog{true}); + } +}