Skip to content

Commit

Permalink
Refine based on feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Zhou committed Oct 27, 2023
1 parent f85ca49 commit 29f545d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
25 changes: 12 additions & 13 deletions src/utils/thread_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,6 @@ void ThreadHelper::DetachGracefullyCallback(void)
otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadnetwork::TelemetryData &telemetryData)
{
otError error = OT_ERROR_NONE;
otError latestError = OT_ERROR_NONE;

// Begin of WpanStats section.
auto wpanStats = telemetryData.mutable_wpan_stats();
Expand All @@ -914,13 +913,13 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
{
int8_t radioTxPower;

if ((latestError = otPlatRadioGetTransmitPower(mInstance, &radioTxPower)) == OT_ERROR_NONE)
if (otPlatRadioGetTransmitPower(mInstance, &radioTxPower) == OT_ERROR_NONE)
{
wpanStats->set_radio_tx_power(radioTxPower);
}
else
{
error = latestError;
error = OT_ERROR_FAILED;
}
}

Expand Down Expand Up @@ -978,13 +977,13 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
{
otRouterInfo info;

if ((latestError = otThreadGetRouterInfo(mInstance, rloc16, &info)) == OT_ERROR_NONE)
if (otThreadGetRouterInfo(mInstance, rloc16, &info) == OT_ERROR_NONE)
{
wpanTopoFull->set_router_id(info.mRouterId);
}
else
{
error = latestError;
error = OT_ERROR_FAILED;
}
}

Expand Down Expand Up @@ -1012,7 +1011,7 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
{
struct otLeaderData leaderData;

if ((latestError = otThreadGetLeaderData(mInstance, &leaderData)) == OT_ERROR_NONE)
if (otThreadGetLeaderData(mInstance, &leaderData) == OT_ERROR_NONE)
{
wpanTopoFull->set_leader_router_id(leaderData.mLeaderRouterId);
wpanTopoFull->set_leader_weight(leaderData.mWeighting);
Expand All @@ -1021,7 +1020,7 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
}
else
{
error = latestError;
error = OT_ERROR_FAILED;
}
}

Expand All @@ -1039,14 +1038,14 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
uint8_t len = sizeof(data);
std::vector<uint8_t> networkData;

if ((latestError = otNetDataGet(mInstance, /*stable=*/false, data, &len)) == OT_ERROR_NONE)
if (otNetDataGet(mInstance, /*stable=*/false, data, &len) == OT_ERROR_NONE)
{
networkData = std::vector<uint8_t>(&data[0], &data[len]);
wpanTopoFull->set_network_data(std::string(networkData.begin(), networkData.end()));
}
else
{
error = latestError;
error = OT_ERROR_FAILED;
}
}

Expand All @@ -1055,14 +1054,14 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
uint8_t len = sizeof(data);
std::vector<uint8_t> networkData;

if ((latestError = otNetDataGet(mInstance, /*stable=*/true, data, &len)) == OT_ERROR_NONE)
if (otNetDataGet(mInstance, /*stable=*/true, data, &len) == OT_ERROR_NONE)
{
networkData = std::vector<uint8_t>(&data[0], &data[len]);
wpanTopoFull->set_stable_network_data(std::string(networkData.begin(), networkData.end()));
}
else
{
error = latestError;
error = OT_ERROR_FAILED;
}
}

Expand Down Expand Up @@ -1403,7 +1402,7 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
auto coexMetrics = telemetryData.mutable_coex_metrics();
otRadioCoexMetrics otRadioCoexMetrics;

if ((latestError = otPlatRadioGetCoexMetrics(mInstance, &otRadioCoexMetrics)) == OT_ERROR_NONE)
if (otPlatRadioGetCoexMetrics(mInstance, &otRadioCoexMetrics) == OT_ERROR_NONE)
{
coexMetrics->set_count_tx_request(otRadioCoexMetrics.mNumTxRequest);
coexMetrics->set_count_tx_grant_immediate(otRadioCoexMetrics.mNumTxGrantImmediate);
Expand All @@ -1425,7 +1424,7 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
}
else
{
error = latestError;
error = OT_ERROR_FAILED;
}
}
// End of CoexMetrics section.
Expand Down
10 changes: 5 additions & 5 deletions src/utils/thread_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ class ThreadHelper

#if OTBR_ENABLE_TELEMETRY_DATA_API
/**
* This method populates the telemetry data with best effort. The best effort means, if some error happens
* on a telemetry retrieval, it is left unpopulated and the remaining telemetries in telemetryData proto
* will still be retrieved with best effort. The last error code will be returned if any error happens
* during the whole process, together with the populated telemetryData.
* This method populates the telemetry data with best effort. The best effort means, for a given
* telemetry, if its retrieval has error, it is left unpopulated and the process continues to
* retrieve the remaining telemetries instead of the immediately return. The error code
* OT_ERRROR_FAILED will be returned if there is one or more error(s) happened in the process.
*
* @param[in] aPublisher The Mdns::Publisher to provide MDNS telemetry if it is not `nullptr`.
* @param[in] telemetryData The telemetry data to be populated.
*
* @returns The last error code if any error happens during the population of the telemetry data.
* @returns The error code OT_ERRROR_FAILED if there is one or more error(s) happened in the process
*/
otError RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadnetwork::TelemetryData &telemetryData);
#endif // OTBR_ENABLE_TELEMETRY_DATA_API
Expand Down

0 comments on commit 29f545d

Please sign in to comment.