Skip to content

Commit

Permalink
dataman: Add client sync perf counter and increase default timeout to 5s
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaut authored and Peize-Liu committed Mar 24, 2024
1 parent 1d5f527 commit 3ead63a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/lib/dataman_client/DatamanClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

DatamanClient::DatamanClient()
{
_sync_perf = perf_alloc(PC_ELAPSED, "DatamanClient: sync");

_dataman_request_pub.advertise();
_dataman_response_sub = orb_subscribe(ORB_ID(dataman_response));

Expand Down Expand Up @@ -74,6 +76,8 @@ DatamanClient::DatamanClient()

DatamanClient::~DatamanClient()
{
perf_free(_sync_perf);

if (_dataman_response_sub >= 0) {
orb_unsubscribe(_dataman_response_sub);
}
Expand All @@ -85,6 +89,7 @@ bool DatamanClient::syncHandler(const dataman_request_s &request, dataman_respon
bool response_received = false;
int32_t ret = 0;
hrt_abstime time_elapsed = hrt_elapsed_time(&start_time);
perf_begin(_sync_perf);
_dataman_request_pub.publish(request);

while (!response_received && (time_elapsed < timeout)) {
Expand Down Expand Up @@ -132,6 +137,8 @@ bool DatamanClient::syncHandler(const dataman_request_s &request, dataman_respon
time_elapsed = hrt_elapsed_time(&start_time);
}

perf_end(_sync_perf);

if (!response_received && ret >= 0) {
PX4_ERR("timeout after %" PRIu32 " ms!", static_cast<uint32_t>(timeout / 1000));
}
Expand Down
10 changes: 6 additions & 4 deletions src/lib/dataman_client/DatamanClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DatamanClient
*
* @return true if data was read successfully within the timeout, false otherwise.
*/
bool readSync(dm_item_t item, uint32_t index, uint8_t *buffer, uint32_t length, hrt_abstime timeout = 1000_ms);
bool readSync(dm_item_t item, uint32_t index, uint8_t *buffer, uint32_t length, hrt_abstime timeout = 5000_ms);

/**
* @brief Write data to the dataman synchronously.
Expand All @@ -75,7 +75,7 @@ class DatamanClient
*
* @return True if the write operation succeeded, false otherwise.
*/
bool writeSync(dm_item_t item, uint32_t index, uint8_t *buffer, uint32_t length, hrt_abstime timeout = 1000_ms);
bool writeSync(dm_item_t item, uint32_t index, uint8_t *buffer, uint32_t length, hrt_abstime timeout = 5000_ms);

/**
* @brief Clears the data in the specified dataman item.
Expand All @@ -85,7 +85,7 @@ class DatamanClient
*
* @return True if the operation was successful, false otherwise.
*/
bool clearSync(dm_item_t item, hrt_abstime timeout = 1000_ms);
bool clearSync(dm_item_t item, hrt_abstime timeout = 5000_ms);

/**
* @brief Initiates an asynchronous request to read the data from dataman for a specific item and index.
Expand Down Expand Up @@ -185,6 +185,8 @@ class DatamanClient

uint8_t _client_id{0};

perf_counter_t _sync_perf{nullptr};

static constexpr uint8_t CLIENT_ID_NOT_SET{0};
};

Expand Down Expand Up @@ -246,7 +248,7 @@ class DatamanCache
*
* @return True if the write operation succeeded, false otherwise.
*/
bool writeWait(dm_item_t item, uint32_t index, uint8_t *buffer, uint32_t length, hrt_abstime timeout = 1000_ms);
bool writeWait(dm_item_t item, uint32_t index, uint8_t *buffer, uint32_t length, hrt_abstime timeout = 5000_ms);

/**
* @brief Updates the dataman cache by checking for responses from the DatamanClient and processing them.
Expand Down

0 comments on commit 3ead63a

Please sign in to comment.