Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataman: Add client sync perf counter and increase default timeout to 5s #22845

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
niklaut marked this conversation as resolved.
Show resolved Hide resolved

_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
Loading