added icsneo_device_transmit_messages, not tested yet.
parent
21964fafe4
commit
b514a55749
|
|
@ -38,7 +38,7 @@ ICSNEO_API icsneo_error_t icsneo_get_error_code(icsneo_error_t error_code, const
|
|||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
|
||||
std::string error;
|
||||
std::string error("Unknown");
|
||||
switch (error_code) {
|
||||
case icsneo_error_success:
|
||||
error = "Success";
|
||||
|
|
@ -64,6 +64,9 @@ ICSNEO_API icsneo_error_t icsneo_get_error_code(icsneo_error_t error_code, const
|
|||
case icsneo_error_set_settings_failure:
|
||||
error = "Setting settings failed";
|
||||
break;
|
||||
case icsneo_error_transmit_messages_failed:
|
||||
error = "Transmitting messages failed";
|
||||
break;
|
||||
// Don't default, let the compiler warn us if we forget to handle an error code
|
||||
}
|
||||
// Find the minimum length of the error string and set value_length
|
||||
|
|
@ -391,6 +394,26 @@ ICSNEO_API icsneo_error_t icsneo_device_get_messages(icsneo_device_t* device, ic
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_device_transmit_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t* messages_count) {
|
||||
if (!device || !messages || !messages_count) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
auto dev = device->device;
|
||||
uint32_t i = 0;
|
||||
bool success = false;
|
||||
for (;i < *messages_count; i++) {
|
||||
// TODO: Check if message is valid
|
||||
success = dev->transmit(std::static_pointer_cast<icsneo::BusMessage>(messages[i]->message));
|
||||
if (!success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*messages_count = i;
|
||||
|
||||
return success ? icsneo_error_success : icsneo_error_transmit_messages_failed;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_message_is_valid(icsneo_device_t* device, icsneo_message_t* message, bool* is_valid) {
|
||||
if (!device || !message || !is_valid) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,9 @@ typedef enum _icsneo_error_t {
|
|||
// Generic RTC error code
|
||||
icsneo_error_rtc_failure,
|
||||
// Error setting settings
|
||||
icsneo_error_set_settings_failure
|
||||
icsneo_error_set_settings_failure,
|
||||
// Failed to transmit messages
|
||||
icsneo_error_transmit_messages_failed,
|
||||
} _icsneo_error_t;
|
||||
|
||||
/** @brief Integer representation of _icsneo_error_t enum.
|
||||
|
|
@ -306,6 +308,17 @@ ICSNEO_API icsneo_error_t icsneo_device_get_timestamp_resolution(icsneo_device_t
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_device_get_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t* messages_count, uint32_t timeout_ms);
|
||||
|
||||
/** @brief Transmit messages from a device
|
||||
*
|
||||
* @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 actually transmitted.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters or icsneo_error_transmission_failed otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_device_transmit_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t* messages_count);
|
||||
|
||||
/** @brief Check if a message is valid
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
|
|
|
|||
Loading…
Reference in New Issue