Compare commits
5 Commits
1ca9f0fdb4
...
14cf054635
| Author | SHA1 | Date |
|---|---|---|
|
|
14cf054635 | |
|
|
b75305d1d3 | |
|
|
d8ee35c36d | |
|
|
c8de60f40d | |
|
|
528ffedeb7 |
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace icsneo;
|
||||
|
|
@ -19,8 +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.
|
||||
// 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;
|
||||
// This needs to be a list so that pointers aren't invalidated on push_back or erase.
|
||||
std::list<std::shared_ptr<icsneo_message_t>> tx_messages;
|
||||
std::vector<icsneo_event_t> events;
|
||||
|
||||
icsneo_open_options_t options;
|
||||
|
|
@ -34,7 +34,6 @@ typedef struct icsneo_device_t {
|
|||
events.clear();
|
||||
events.shrink_to_fit();
|
||||
tx_messages.clear();
|
||||
tx_messages.shrink_to_fit();
|
||||
}
|
||||
} icsneo_device_t;
|
||||
|
||||
|
|
@ -438,7 +437,7 @@ ICSNEO_API icsneo_error_t icsneo_device_transmit_messages(icsneo_device_t* devic
|
|||
auto dev = device->device;
|
||||
uint32_t i = 0;
|
||||
bool success = false;
|
||||
for (;i < *messages_count; i++) {
|
||||
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) {
|
||||
|
|
@ -525,6 +524,47 @@ ICSNEO_API icsneo_error_t icsneo_get_netid_name(icsneo_netid_t netid, const char
|
|||
return safe_str_copy(value, value_length, netid_str) ? icsneo_error_success : icsneo_error_string_copy_failed;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_message_set_netid(icsneo_device_t* device, icsneo_message_t* message, icsneo_netid_t netid) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
// Make sure the message has the data field, internal and bus currently have this.
|
||||
if (message->message->getMsgType() != icsneo_msg_type_internal && message->message->getMsgType() != icsneo_msg_type_bus) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
auto* internal_message = dynamic_cast<InternalMessage*>(message->message.get());
|
||||
if (!internal_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
internal_message->network = Network(static_cast<_icsneo_netid_t>(netid), true);
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_message_set_data(icsneo_device_t* device, icsneo_message_t* message, uint8_t* data, uint32_t data_length) {
|
||||
if (!device || !message | !data) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
// Make sure the message has the data field, internal and bus currently have this.
|
||||
if (message->message->getMsgType() != icsneo_msg_type_internal && message->message->getMsgType() != icsneo_msg_type_bus) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
auto* internal_message = dynamic_cast<InternalMessage*>(message->message.get());
|
||||
if (!internal_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
internal_message->data.clear();
|
||||
internal_message->data.resize(data_length);
|
||||
internal_message->data.shrink_to_fit();
|
||||
std::copy(data, data + data_length, internal_message->data.begin());
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_message_get_data(icsneo_device_t* device, icsneo_message_t* message, uint8_t* data, uint32_t* data_length) {
|
||||
if (!device || !message || !data || !data_length) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -563,6 +603,22 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_arbid(icsneo_device_t* device,
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_arbid(icsneo_device_t* device, icsneo_message_t* message, uint32_t value) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
auto* const can_message = dynamic_cast<CANMessage*>(message->message.get());
|
||||
if (!can_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
|
||||
can_message->arbid = value;
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_dlc_on_wire(icsneo_device_t* device, icsneo_message_t* message, uint32_t* value) {
|
||||
if (!device || !message || !value) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -579,6 +635,22 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_dlc_on_wire(icsneo_device_t* de
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_dlc_on_wire(icsneo_device_t* device, icsneo_message_t* message, uint32_t value) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
auto* const can_message = dynamic_cast<CANMessage*>(message->message.get());
|
||||
if (!can_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
|
||||
can_message->dlcOnWire = static_cast<uint8_t>(value);
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_is_remote(icsneo_device_t* device, icsneo_message_t* message, bool* value) {
|
||||
if (!device || !message || !value) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -595,6 +667,22 @@ ICSNEO_API icsneo_error_t icsneo_can_message_is_remote(icsneo_device_t* device,
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_remote(icsneo_device_t* device, icsneo_message_t* message, bool value) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
auto* const can_message = dynamic_cast<CANMessage*>(message->message.get());
|
||||
if (!can_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
|
||||
can_message->isRemote = value;
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_is_extended(icsneo_device_t* device, icsneo_message_t* message, bool* value) {
|
||||
if (!device || !message || !value) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -611,6 +699,22 @@ ICSNEO_API icsneo_error_t icsneo_can_message_is_extended(icsneo_device_t* device
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_extended(icsneo_device_t* device, icsneo_message_t* message, bool value) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
auto* const can_message = dynamic_cast<CANMessage*>(message->message.get());
|
||||
if (!can_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
|
||||
can_message->isExtended = value;
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_is_canfd(icsneo_device_t* device, icsneo_message_t* message, bool* value) {
|
||||
if (!device || !message || !value) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -627,6 +731,22 @@ ICSNEO_API icsneo_error_t icsneo_can_message_is_canfd(icsneo_device_t* device, i
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_canfd(icsneo_device_t* device, icsneo_message_t* message, bool value) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
auto* const can_message = dynamic_cast<CANMessage*>(message->message.get());
|
||||
if (!can_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
|
||||
can_message->isCANFD = value;
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_baudrate_switch(icsneo_device_t* device, icsneo_message_t* message, bool* value) {
|
||||
if (!device || !message || !value) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -643,6 +763,22 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_baudrate_switch(icsneo_device_t
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_baudrate_switch(icsneo_device_t* device, icsneo_message_t* message, bool value) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
// TODO: Check if message is valid
|
||||
auto* const can_message = dynamic_cast<CANMessage*>(message->message.get());
|
||||
if (!can_message) {
|
||||
return icsneo_error_invalid_type;
|
||||
}
|
||||
|
||||
can_message->baudrateSwitch = value;
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_error_state_indicator(icsneo_device_t* device, icsneo_message_t* message, bool* value) {
|
||||
if (!device || !message || !value) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
|
|
@ -676,6 +812,23 @@ ICSNEO_API icsneo_error_t icsneo_can_messages_create(icsneo_device_t* device, ic
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_free(icsneo_device_t* device, icsneo_message_t* message) {
|
||||
if (!device || !message) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
bool removed = false;
|
||||
for (auto it = device->tx_messages.begin(); it != device->tx_messages.end(); it++) {
|
||||
if (it->get() == message) {
|
||||
device->tx_messages.erase(it);
|
||||
removed = true;
|
||||
message = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return removed ? icsneo_error_success : icsneo_error_invalid_parameters;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -387,13 +387,33 @@ ICSNEO_API icsneo_error_t icsneo_message_get_netid(icsneo_device_t* device, icsn
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_get_netid_name(icsneo_netid_t netid, const char* value, uint32_t* value_length);
|
||||
|
||||
/** @brief Set the Network ID (netid) of a bus message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to check.
|
||||
* @param[in] icsneo_netid_t netid The netid to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_message_set_netid(icsneo_device_t* device, icsneo_message_t* message, icsneo_netid_t netid);
|
||||
|
||||
/** @brief Set the data bytes of a message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to copy the data into.
|
||||
* @param[out] uint8_t* data Pointer to a uint8_t array to copy from.
|
||||
* @param[in] uint32_t data_length length of the data.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_message_set_data(icsneo_device_t* device, icsneo_message_t* message, uint8_t* data, uint32_t data_length);
|
||||
|
||||
/** @brief Get the data bytes of a message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to check.
|
||||
* @param[out] uint8_t* data Pointer to a uint8_t to copy the data bytes into.
|
||||
* @param[out] uint32_t* data_length Pointer to a uint32_t to copy the length of the data into.
|
||||
* @param[in,out] uint32_t* data_length Pointer to a uint32_t to copy the length of the data into.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
|
|
@ -409,6 +429,16 @@ ICSNEO_API icsneo_error_t icsneo_message_get_data(icsneo_device_t* device, icsne
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_arbid(icsneo_device_t* device, icsneo_message_t* message, uint32_t* value);
|
||||
|
||||
/** @brief Set the Arbitration ID of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to check.
|
||||
* @param[out] uint32_t value Arbitration ID to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_arbid(icsneo_device_t* device, icsneo_message_t* message, uint32_t value);
|
||||
|
||||
/** @brief Get the DLC on wire of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
|
|
@ -419,7 +449,17 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_arbid(icsneo_device_t* device,
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_dlc_on_wire(icsneo_device_t* device, icsneo_message_t* message, uint32_t* value);
|
||||
|
||||
/** @brief Get the remote status of a CAN message
|
||||
/** @brief Set the DLC on wire of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to check.
|
||||
* @param[out] uint32_t value DLC to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_dlc_on_wire(icsneo_device_t* device, icsneo_message_t* message, uint32_t value);
|
||||
|
||||
/** @brief Get the Remote Transmission Request (RTR) status of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to check.
|
||||
|
|
@ -429,6 +469,16 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_dlc_on_wire(icsneo_device_t* de
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_is_remote(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
/** @brief Set the Remote Transmission Request (RTR) of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to modify.
|
||||
* @param[out] bool value Remote status to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_remote(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
/** @brief Get the extended status of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
|
|
@ -439,6 +489,16 @@ ICSNEO_API icsneo_error_t icsneo_can_message_is_remote(icsneo_device_t* device,
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_is_extended(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
/** @brief Set the extended status of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to modify.
|
||||
* @param[out] bool value Extended status to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_extended(icsneo_device_t* device, icsneo_message_t* message, bool value);
|
||||
|
||||
/** @brief Get the CANFD status of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
|
|
@ -449,16 +509,36 @@ ICSNEO_API icsneo_error_t icsneo_can_message_is_extended(icsneo_device_t* device
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_is_canfd(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
/** @brief Get the baudrate switch status of a CAN message
|
||||
/** @brief Set the CANFD status of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to modify.
|
||||
* @param[out] bool value CANFD status to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_canfd(icsneo_device_t* device, icsneo_message_t* message, bool value);
|
||||
|
||||
/** @brief Get the baudrate switch status (BRS) of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to check.
|
||||
* @param[out] bool* value Pointer to a uint32_t to copy the baudrate switch status into.
|
||||
* @param[out] bool* value Pointer to a uint32_t to copy the baudrate switch (BRS) status into.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_get_baudrate_switch(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
/** @brief Set the baudrate switch status (BRS) of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
* @param[in] icsneo_message_t* message The message to modify.
|
||||
* @param[out] bool value baudrate switch status (BRS) to set.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_set_baudrate_switch(icsneo_device_t* device, icsneo_message_t* message, bool value);
|
||||
|
||||
/** @brief Get the error state indicator status of a CAN message
|
||||
*
|
||||
* @param[in] icsneo_device_t* device The device to check against.
|
||||
|
|
@ -480,6 +560,19 @@ ICSNEO_API icsneo_error_t icsneo_can_message_get_error_state_indicator(icsneo_de
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_messages_create(icsneo_device_t* device, icsneo_message_t** messages, uint32_t messages_count);
|
||||
|
||||
/** @brief Free CAN messages for a device
|
||||
*
|
||||
* @param[in] icsneo_device_t device The device to free the messages of.
|
||||
* @param[in] icsneo_message_t* message The message to free.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*
|
||||
* @warning This function should only be called on messages created by icsneo_can_messages_create.
|
||||
*
|
||||
* @see icsneo_can_messages_create
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_free(icsneo_device_t* device, icsneo_message_t* message);
|
||||
|
||||
/** @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