summaryrefslogtreecommitdiffstats
path: root/low-can-binding/can/message/can-message.cpp
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-07-29 12:19:13 +0200
committerArthur Guyader <arthur.guyader@iot.bzh>2019-08-12 15:06:45 +0200
commit88077fb4b383cf7f35093b6cc0d2d9d86c6f1bf3 (patch)
treeae7df9ff1f6981c629bb4456ae8d17fc383e71ef /low-can-binding/can/message/can-message.cpp
parent8c0a3d45ca37f710100afab065b07e82682dc1ef (diff)
Add feature to build messages and fix some functions
Allows to build a message (J1939,BCM) with a signal and a value. Bug-AGL: SPEC-2386 Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh> Change-Id: Iadca13a927ff83f713f39da441c88356695a1285
Diffstat (limited to 'low-can-binding/can/message/can-message.cpp')
-rw-r--r--low-can-binding/can/message/can-message.cpp58
1 files changed, 51 insertions, 7 deletions
diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp
index b012bbe5..945c0ba7 100644
--- a/low-can-binding/can/message/can-message.cpp
+++ b/low-can-binding/can/message/can-message.cpp
@@ -28,22 +28,20 @@
///
can_message_t::can_message_t()
: message_t(),
- maxdlen_{0},
id_{0},
rtr_flag_{false},
flags_{0}
{}
-can_message_t::can_message_t(uint8_t maxdlen,
+can_message_t::can_message_t(uint32_t maxdlen,
uint32_t id,
- uint8_t length,
+ uint32_t length,
message_format_t format,
bool rtr_flag,
- uint8_t flags,
+ uint32_t flags,
std::vector<uint8_t>& data,
uint64_t timestamp)
- : message_t(length, format, data, timestamp),
- maxdlen_{maxdlen},
+ : message_t(maxdlen, length, format, data, timestamp),
id_{id},
rtr_flag_{rtr_flag},
flags_{flags}
@@ -86,7 +84,8 @@ bool can_message_t::is_correct_to_send()
/// @return A can_message_t object fully initialized with canfd_frame values.
std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct canfd_frame& frame, size_t nbytes, uint64_t timestamp)
{
- uint8_t maxdlen = 0, length = 0, flags = 0;
+ uint32_t maxdlen = 0, length = 0;
+ uint8_t flags = 0;
uint32_t id;
message_format_t format;
bool rtr_flag;
@@ -164,6 +163,47 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca
return std::make_shared<can_message_t>(can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp));
}
+/// @brief Take all initialized class members and build a
+/// canfd_frame struct that can be use to send a CAN message over
+/// the bus.
+///
+/// @return canfd_frame struct built from class members.
+struct canfd_frame can_message_t::convert_to_canfd_frame()
+{
+ canfd_frame frame;
+
+ if(is_correct_to_send())
+ {
+ frame.can_id = get_id();
+ frame.len = (uint8_t) get_length();
+ ::memcpy(frame.data, get_data(), length_);
+ }
+ else
+ AFB_ERROR("can_message_t not correctly initialized to be sent");
+
+ return frame;
+}
+
+/// @brief Take all initialized class members and build a
+/// can_frame struct that can be use to send a CAN message over
+/// the bus.
+///
+/// @return can_frame struct built from class members.
+struct can_frame can_message_t::convert_to_can_frame()
+{
+ can_frame frame;
+
+ if(is_correct_to_send())
+ {
+ frame.can_id = get_id();
+ frame.can_dlc = (uint8_t) get_length();
+ ::memcpy(frame.data, get_data(), length_);
+ }
+ else
+ AFB_ERROR("can_message_t not correctly initialized to be sent");
+
+ return frame;
+}
bool can_message_t::is_set()
{
@@ -192,3 +232,7 @@ void can_message_t::set_bcm_msg(struct bcm_msg bcm_msg)
bcm_msg_ = bcm_msg;
}
+uint32_t can_message_t::get_flags()
+{
+ return flags_;
+} \ No newline at end of file