Added icsneo_can_messages_create, untested.
parent
2a63bbf13f
commit
b0575fe658
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace icsneo;
|
||||
|
|
@ -18,7 +19,8 @@ typedef struct icsneo_device_t {
|
|||
// Received messages from the device, we can automatically free them without the user.
|
||||
std::vector<std::shared_ptr<icsneo_message_t>> messages;
|
||||
// Seperate buffer for transmit messages for simplicity. User is responsible for freeing.
|
||||
std::vector<std::shared_ptr<icsneo_message_t>> tx_messages;
|
||||
// This needs to be a deque so that pointers aren't invalidated on push_back.
|
||||
std::deque<std::shared_ptr<icsneo_message_t>> tx_messages;
|
||||
std::vector<icsneo_event_t> events;
|
||||
|
||||
icsneo_open_options_t options;
|
||||
|
|
@ -604,6 +606,23 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_error_state_indicator(icsneo_de
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_messages_create(icsneo_device_t* device, icsneo_message_t** messages, uint32_t messages_count) {
|
||||
if (!device || !messages) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
auto dev = device->device;
|
||||
// Get the device messages
|
||||
for (uint32_t i = 0; i < messages_count; i++) {
|
||||
auto can_message = std::static_pointer_cast<Message>(std::make_shared<CANMessage>());
|
||||
auto message = std::make_shared<icsneo_message_t>(can_message, true);
|
||||
device->tx_messages.push_back(message);
|
||||
messages[i] = message.get();
|
||||
}
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_get_events(icsneo_event_t** events, uint32_t* events_count) {
|
||||
if (!events || !events_count) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
|
|||
|
|
@ -434,6 +434,17 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_baudrate_switch(icsneo_device_t
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_error_state_indicator(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
/** @brief Create CAN messages for 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] uint32_t* messages_count Size of the messages array.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_messages_create(icsneo_device_t* device, icsneo_message_t** messages, uint32_t messages_count);
|
||||
|
||||
/** @brief Get the global events not specifically related to a device.
|
||||
*
|
||||
* @param[out] icsneo_event_t** events Pointer to an array of icsneo_event_t to copy the events into.
|
||||
|
|
|
|||
Loading…
Reference in New Issue