add timestamp and get_messages, untested.
parent
32815943d5
commit
983552657b
|
|
@ -14,8 +14,13 @@ typedef struct icsneo_device_t {
|
||||||
icsneo_open_options_t options;
|
icsneo_open_options_t options;
|
||||||
} icsneo_device_t;
|
} icsneo_device_t;
|
||||||
|
|
||||||
|
typedef struct icsneo_message_t {
|
||||||
|
std::shared_ptr<Message> message;
|
||||||
|
} icsneo_message_t;
|
||||||
|
|
||||||
|
|
||||||
static std::deque<std::shared_ptr<icsneo_device_t>> g_devices;
|
static std::deque<std::shared_ptr<icsneo_device_t>> g_devices;
|
||||||
|
static std::deque<std::shared_ptr<icsneo_message_t>> g_messages;
|
||||||
|
|
||||||
ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const char* value, uint32_t* value_length) {
|
ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const char* value, uint32_t* value_length) {
|
||||||
if (!value || !value_length) {
|
if (!value || !value_length) {
|
||||||
|
|
@ -298,5 +303,53 @@ ICSNEO_API icsneo_error_t icsneo_get_message_count(icsneo_device_t* device, uint
|
||||||
auto dev = device->device;
|
auto dev = device->device;
|
||||||
*count = static_cast<uint32_t>(dev->getCurrentMessageCount());
|
*count = static_cast<uint32_t>(dev->getCurrentMessageCount());
|
||||||
|
|
||||||
|
return icsneo_error_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_get_timestamp_resolution(icsneo_device_t* device, uint32_t* resolution) {
|
||||||
|
if (!device || !resolution) {
|
||||||
|
return icsneo_error_invalid_parameters;
|
||||||
|
}
|
||||||
|
auto dev = device->device;
|
||||||
|
*resolution = static_cast<uint32_t>(dev->getTimestampResolution());
|
||||||
|
|
||||||
|
return icsneo_error_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_get_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t* messages_count) {
|
||||||
|
if (!device || !messages || !messages_count) {
|
||||||
|
return icsneo_error_invalid_parameters;
|
||||||
|
}
|
||||||
|
auto dev = device->device;
|
||||||
|
// Get the messages
|
||||||
|
auto results = dev->getMessages();
|
||||||
|
auto& queried_messages = results.first;
|
||||||
|
auto& success = results.second;
|
||||||
|
if (!success) {
|
||||||
|
return icsneo_error_get_messages_failed;
|
||||||
|
}
|
||||||
|
// Find the minimum number of messages
|
||||||
|
uint32_t message_size = std::minmax(static_cast<uint32_t>(queried_messages.size()), *messages_count).first;
|
||||||
|
*messages_count = message_size;
|
||||||
|
|
||||||
|
// Copy the messages into our global message container
|
||||||
|
g_messages.clear();
|
||||||
|
for (auto& message : queried_messages) {
|
||||||
|
auto message_t = std::make_shared<icsneo_message_t>();
|
||||||
|
message_t->message = message;
|
||||||
|
g_messages.push_back(message_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return icsneo_error_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_is_message_valid(icsneo_message_t* message, bool* is_valid) {
|
||||||
|
if (!message || !is_valid) {
|
||||||
|
return icsneo_error_invalid_parameters;
|
||||||
|
}
|
||||||
|
*is_valid = std::find_if(g_messages.begin(), g_messages.end(), [&](const auto& msg) {
|
||||||
|
return msg->message == message->message;
|
||||||
|
}) == g_messages.end();
|
||||||
|
|
||||||
return icsneo_error_success;
|
return icsneo_error_success;
|
||||||
}
|
}
|
||||||
|
|
@ -39,6 +39,9 @@ extern "C" {
|
||||||
typedef struct icsneo_device_t icsneo_device_t;
|
typedef struct icsneo_device_t icsneo_device_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct icsneo_message_t icsneo_message_t;
|
||||||
|
|
||||||
|
|
||||||
/** @brief Error codes for icsneo functions.
|
/** @brief Error codes for icsneo functions.
|
||||||
*
|
*
|
||||||
* This enum is guaranteed to be ABI stable, any new values will be appended to the end.
|
* This enum is guaranteed to be ABI stable, any new values will be appended to the end.
|
||||||
|
|
@ -56,6 +59,8 @@ typedef enum _icsneo_error_t {
|
||||||
icsneo_error_enable_message_polling_failed,
|
icsneo_error_enable_message_polling_failed,
|
||||||
// Error syncing RTC.
|
// Error syncing RTC.
|
||||||
icsneo_error_sync_rtc_failed,
|
icsneo_error_sync_rtc_failed,
|
||||||
|
// Error getting messages.
|
||||||
|
icsneo_error_get_messages_failed,
|
||||||
} _icsneo_error_t;
|
} _icsneo_error_t;
|
||||||
|
|
||||||
/** @brief Integer representation of _icsneo_error_t enum.
|
/** @brief Integer representation of _icsneo_error_t enum.
|
||||||
|
|
@ -244,6 +249,37 @@ ICSNEO_API icsneo_error_t icsneo_get_message_polling_limit(icsneo_device_t* devi
|
||||||
ICSNEO_API icsneo_error_t icsneo_get_message_count(icsneo_device_t* device, uint32_t* count);
|
ICSNEO_API icsneo_error_t icsneo_get_message_count(icsneo_device_t* device, uint32_t* count);
|
||||||
|
|
||||||
|
|
||||||
|
/** @brief Get the timestamp resolution (nanoseconds) of a device
|
||||||
|
*
|
||||||
|
* @param[in] icsneo_device_t device The device to get the timestamp resolution of.
|
||||||
|
* @param[out] uint32_t* resolution Pointer to a uint32_t to copy the timestamp resolution in nanoseconds into.
|
||||||
|
*
|
||||||
|
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||||
|
*/
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_get_timestamp_resolution(icsneo_device_t* device, uint32_t* resolution);
|
||||||
|
|
||||||
|
/** @brief Get the messages of a device
|
||||||
|
*
|
||||||
|
* When calling this function, the previous messages retrieved by this function will be invalid.
|
||||||
|
*
|
||||||
|
* @param[in] icsneo_device_t device The device to get the messages of.
|
||||||
|
* @param[out] icsneo_message_t** messages Pointer to an array of icsneo_message_t to copy the messages into.
|
||||||
|
* Undefined behaviour if index is out of range of messages_count.
|
||||||
|
* @param[in,out] uint32_t* messages_count Size of the messages array. Modified with the number of messages found.
|
||||||
|
*
|
||||||
|
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||||
|
*/
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_get_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t* messages_count);
|
||||||
|
|
||||||
|
/** @brief Check if a message is valid
|
||||||
|
*
|
||||||
|
* @param[in] icsneo_message_t* message The message to check.
|
||||||
|
* @param[out] bool* is_valid Pointer to a bool to copy the validity of the message into.
|
||||||
|
*
|
||||||
|
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||||
|
*/
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_is_message_valid(icsneo_message_t* message, bool* is_valid);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue