Skip to content

Commit

Permalink
Client: implement RSSI reporting after time sync
Browse files Browse the repository at this point in the history
Handy for network monitoring.
  • Loading branch information
DavidB137 committed Sep 24, 2024
1 parent c98729c commit 16c1ab9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/kvik/client_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions src/common/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
63 changes: 63 additions & 0 deletions test/tests/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const ClientConfig CONF = {
.trigTimeSyncNoRespCnt = 2,
},
.reporting = {
.rssiOnTimeSync = false,
.rssiOnGwDscv = false,
},
.subDB = {
Expand Down Expand Up @@ -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<PubData> 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});
}
}

0 comments on commit 16c1ab9

Please sign in to comment.