summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/can-message.cpp13
-rw-r--r--src/can-message.hpp6
2 files changed, 11 insertions, 8 deletions
diff --git a/src/can-message.cpp b/src/can-message.cpp
index 77fce685..a95722e8 100644
--- a/src/can-message.cpp
+++ b/src/can-message.cpp
@@ -55,8 +55,9 @@ uint8_t can_message_t::get_flags() const
const uint8_t* can_message_t::get_data() const
{
- return data_;
+ return data_.data();
}
+
uint8_t can_message_t::get_length() const
{
return length_;
@@ -149,15 +150,15 @@ void can_message_t::set_length(const uint8_t new_length)
void can_message_t::set_data(const __u8 new_data[], size_t dlen)
{
- if (sizeof(dlen)/sizeof(__u8) > maxdlen_)
+ if (dlen > maxdlen_)
ERROR(binder_interface, "Can set data, too big ! It is a CAN frame ?");
else
{
int i;
- /* Limiting to 8 bytes message for now on 64 bytes from fd frames*/
+ /* Limiting to 8 bytes message for now, even on 64 bytes from fd frames*/
for(i=0;i<CAN_MESSAGE_SIZE;i++)
{
- data_[i] = new_data[i];
+ data_.push_back(new_data[i]);
}
}
}
@@ -181,8 +182,8 @@ void can_message_t::convert_from_canfd_frame(const struct canfd_frame& frame)
if(maxdlen_ == CANFD_MAX_DLEN)
set_flags(frame.flags);
- size_t dlen = sizeof(frame.data);
- memset(data_, 0, dlen);
+ size_t dlen = sizeof(frame.data)/sizeof(__u8);
+ data_.reserve(dlen);
set_data(frame.data, dlen);
DEBUG(binder_interface, "convert_from_canfd_frame: Found id: %d, format: %d, length: %d, data %d%d%d%d%d%d%d%d", id_, format_, length_,
diff --git a/src/can-message.hpp b/src/can-message.hpp
index f24c1700..82e2e019 100644
--- a/src/can-message.hpp
+++ b/src/can-message.hpp
@@ -17,6 +17,7 @@
#pragma once
+#include <vector>
#include <string>
#include <cstdint>
#include <linux/can.h>
@@ -61,7 +62,7 @@ class can_message_t {
uint8_t length_; /*!< uint8_t length - the length of the data array (max 8). */
uint8_t flags_; /*!< unint8_t flags of a CAN FD frame. Needed if we catch FD frames.*/
CanMessageFormat format_; /*!< CanMessageFormat format - the format of the message's ID.*/
- uint8_t data_[CAN_MESSAGE_SIZE]; /*!< uint8_t data - The message's data field with a size of 8 which is the standard about CAN bus messages.*/
+ std::vector<uint8_t> data_; /*!< uint8_t data - The message's data field with a size of 8 which is the standard about CAN bus messages.*/
uint8_t maxdlen_;
@@ -104,7 +105,8 @@ class can_message_t {
/**
* @brief Retrieve data_ member value.
*
- * @return uint8_t data_ pointer class member
+ * @return uint8_t data_ pointer to the first element
+ * of class member data_
*/
const uint8_t* get_data() const;