summaryrefslogtreecommitdiffstats
path: root/src/can-message.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-01 15:58:42 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-01 15:58:42 +0100
commit834d1a950d38a821284955f2732cdbb5b05ebd2a (patch)
tree8ec03f8510c004e6bcc34a83f9f7bfaba96d5054 /src/can-message.cpp
parent9aa1904f4b0cac0f3cb6ade68cd76954607aa5fe (diff)
Change data_ member of can_message_t object
to a vector of uint8_t instead of an array This is more flexible to allocate dynamically the vector depending if we process classic CAN frame or CAN FD frame which are 64bytes long. Change-Id: I698002139d612e3aaaa33f0f5a895e16ff655f5d Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can-message.cpp')
-rw-r--r--src/can-message.cpp13
1 files changed, 7 insertions, 6 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_,