summaryrefslogtreecommitdiffstats
path: root/low-can-binding/can
diff options
context:
space:
mode:
Diffstat (limited to 'low-can-binding/can')
-rw-r--r--low-can-binding/can/can-encoder.cpp11
-rw-r--r--low-can-binding/can/can-encoder.hpp2
-rw-r--r--low-can-binding/can/can-message-definition.cpp7
-rw-r--r--low-can-binding/can/can-message-definition.hpp10
-rw-r--r--low-can-binding/can/can-message.cpp121
-rw-r--r--low-can-binding/can/can-message.hpp4
6 files changed, 23 insertions, 132 deletions
diff --git a/low-can-binding/can/can-encoder.cpp b/low-can-binding/can/can-encoder.cpp
index 4f1efa2a..4b8a2963 100644
--- a/low-can-binding/can/can-encoder.cpp
+++ b/low-can-binding/can/can-encoder.cpp
@@ -28,14 +28,15 @@
/// @param[out] data - The destination buffer.
/// @param[in] length - The length of the destination buffer.
///
-/// @return Returns a can_frame struct initialized and ready to be send.
-const can_frame encoder_t::build_frame(const std::shared_ptr<can_signal_t>& signal, uint64_t value)
+/// @return Returns a canfd_frame struct initialized and ready to be send.
+const canfd_frame encoder_t::build_frame(const std::shared_ptr<can_signal_t>& signal, uint64_t value)
{
- struct can_frame cf;
+ struct canfd_frame cf;
::memset(&cf, 0, sizeof(cf));
cf.can_id = signal->get_message()->get_id();
- cf.can_dlc = CAN_MAX_DLEN;
+ cf.len = signal->get_message()->is_fd() ?
+ CANFD_MAX_DLEN : CAN_MAX_DLEN;
signal->set_last_value((float)value);
@@ -48,7 +49,7 @@ const can_frame encoder_t::build_frame(const std::shared_ptr<can_signal_t>& sign
sig->get_factor(),
sig->get_offset(),
cf.data,
- CAN_MAX_DLEN);
+ cf.len);
}
return cf;
diff --git a/low-can-binding/can/can-encoder.hpp b/low-can-binding/can/can-encoder.hpp
index c79e2245..f8398836 100644
--- a/low-can-binding/can/can-encoder.hpp
+++ b/low-can-binding/can/can-encoder.hpp
@@ -24,7 +24,7 @@
class encoder_t
{
public:
- static const can_frame build_frame(const std::shared_ptr<can_signal_t>& signal, uint64_t value);
+ static const canfd_frame build_frame(const std::shared_ptr<can_signal_t>& signal, uint64_t value);
static uint64_t encode_state(const can_signal_t& signal, const std::string& value, bool* send);
static uint64_t encode_boolean(const can_signal_t& signal, bool value, bool* send);
static uint64_t encode_number(const can_signal_t& signal, float value, bool* send);
diff --git a/low-can-binding/can/can-message-definition.cpp b/low-can-binding/can/can-message-definition.cpp
index 28d45fe5..ae957d14 100644
--- a/low-can-binding/can/can-message-definition.cpp
+++ b/low-can-binding/can/can-message-definition.cpp
@@ -54,6 +54,7 @@ can_message_definition_t::can_message_definition_t(
can_message_definition_t::can_message_definition_t(
const std::string bus,
uint32_t id,
+ bool is_fd,
can_message_format_t format,
frequency_clock_t frequency_clock,
bool force_send_changed,
@@ -61,6 +62,7 @@ can_message_definition_t::can_message_definition_t(
: parent_{nullptr},
bus_{bus},
id_{id},
+ is_fd_(is_fd),
format_{format},
frequency_clock_{frequency_clock},
force_send_changed_{force_send_changed},
@@ -84,6 +86,11 @@ uint32_t can_message_definition_t::get_id() const
return id_;
}
+bool can_message_definition_t::is_fd() const
+{
+ return is_fd_;
+}
+
std::vector<std::shared_ptr<can_signal_t> >& can_message_definition_t::get_can_signals()
{
return can_signals_;
diff --git a/low-can-binding/can/can-message-definition.hpp b/low-can-binding/can/can-message-definition.hpp
index 6d0f17d6..b9025cbb 100644
--- a/low-can-binding/can/can-message-definition.hpp
+++ b/low-can-binding/can/can-message-definition.hpp
@@ -43,6 +43,7 @@ private:
can_message_set_t* parent_; ///< parent_ - Pointer to the CAN message set holding this CAN message definition */
std::string bus_; ///< bus_ - Address of CAN bus device. */
uint32_t id_; ///< id_ - The ID of the message.*/
+ bool is_fd_; /*!< uses_fd_ - Flags to enable an FD CAN message communication*/
can_message_format_t format_; ///< format_ - the format of the message's ID.*/
frequency_clock_t frequency_clock_; ///< clock_ - an optional frequency clock to control the output of this
/// message, if sent raw, or simply to mark the max frequency for custom
@@ -59,11 +60,18 @@ public:
can_message_definition_t(const std::string bus);
can_message_definition_t(const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed);
can_message_definition_t(const std::string bus, uint32_t id, can_message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed);
- can_message_definition_t(const std::string bus, uint32_t id, can_message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed, const std::vector<std::shared_ptr<can_signal_t> >& can_signals);
+ can_message_definition_t(const std::string bus,
+ uint32_t id,
+ bool is_fd,
+ can_message_format_t format,
+ frequency_clock_t frequency_clock,
+ bool force_send_changed,
+ const std::vector<std::shared_ptr<can_signal_t> >& can_signals);
const std::string get_bus_name() const;
const std::string get_bus_device_name() const;
uint32_t get_id() const;
+ bool is_fd() const;
std::vector<std::shared_ptr<can_signal_t> >& get_can_signals();
void set_parent(can_message_set_t* parent);
diff --git a/low-can-binding/can/can-message.cpp b/low-can-binding/can/can-message.cpp
index 1b27d0f6..9ec35668 100644
--- a/low-can-binding/can/can-message.cpp
+++ b/low-can-binding/can/can-message.cpp
@@ -266,124 +266,3 @@ can_message_t can_message_t::convert_from_frame(const struct canfd_frame& frame,
return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp);
}
-
-/// @brief Take a can_frame struct to initialize class members
-///
-/// This is the preferred way to initialize class members.
-///
-/// @param[in] frame - can_frame to convert coming from a read of CAN socket
-/// @param[in] nbytes - bytes read from socket read operation.
-///
-/// @return A can_message_t object fully initialized with can_frame values.
-can_message_t can_message_t::convert_from_frame(const struct can_frame& frame, size_t nbytes, uint64_t timestamp)
-{
- uint8_t maxdlen = 0, length = 0, flags = 0;
- uint32_t id;
- can_message_format_t format;
- bool rtr_flag;
- std::vector<uint8_t> data;
-
- if(nbytes <= CAN_MTU)
- {
- AFB_DEBUG("Got a legacy CAN frame");
- maxdlen = CAN_MAX_DLEN;
- }
- else
- {
- AFB_ERROR("unsupported CAN frame");
- }
-
- if (frame.can_id & CAN_ERR_FLAG)
- {
- format = can_message_format_t::INVALID;
- id = frame.can_id & (CAN_ERR_MASK|CAN_ERR_FLAG);
- }
- else if (frame.can_id & CAN_EFF_FLAG)
- {
- format = can_message_format_t::EXTENDED;
- id = frame.can_id & CAN_EFF_MASK;
- }
- else
- {
- format = can_message_format_t::STANDARD;
- id = frame.can_id & CAN_SFF_MASK;
- }
-
- /* Overwrite length_ if RTR flags is detected.
- * standard CAN frames may have RTR enabled. There are no ERR frames with RTR */
- if (frame.can_id & CAN_RTR_FLAG)
- {
- rtr_flag = true;
- if(frame.can_dlc && frame.can_dlc <= CAN_MAX_DLC)
- {
- if(rtr_flag)
- length = frame.can_dlc& 0xF;
- else
- {
- length = (frame.can_dlc > maxdlen) ? maxdlen : frame.can_dlc;
- }
- }
- }
- else
- {
- length = (frame.can_dlc > maxdlen) ? maxdlen : frame.can_dlc;
-
- if (data.capacity() < maxdlen)
- data.reserve(maxdlen);
- int i;
-
- data.clear();
- /* maxdlen_ is now set at CAN_MAX_DLEN or CANFD_MAX_DLEN, respectively 8 and 64 bytes*/
- for(i=0;i<maxdlen;i++)
- {
- data.push_back(frame.data[i]);
- };
-
-// AFB_DEBUG("Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X",
-// id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
- }
-
- return 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 = 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 = get_length();
- ::memcpy(frame.data, get_data(), length_);
- }
- else
- AFB_ERROR("can_message_t not correctly initialized to be sent");
-
- return frame;
-}
diff --git a/low-can-binding/can/can-message.hpp b/low-can-binding/can/can-message.hpp
index b206ebdb..cf960b95 100644
--- a/low-can-binding/can/can-message.hpp
+++ b/low-can-binding/can/can-message.hpp
@@ -73,8 +73,4 @@ public:
bool is_correct_to_send();
static can_message_t convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp);
- static can_message_t convert_from_frame(const can_frame& frame, size_t nbytes, uint64_t timestamp);
-
- struct canfd_frame convert_to_canfd_frame();
- struct can_frame convert_to_can_frame();
};