X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=low-can-binding%2Fcan%2Fcan-encoder.cpp;h=4b8a2963b616384fc87aec98453f122cb6a53583;hb=7cf3679da71727f59c56b446ebf17ad2ce7bfddf;hp=b87407f147688d2cde860ad70acd7b18862a9cb2;hpb=2408a177e8260dcda266df9993e6acd528bebbbc;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/can/can-encoder.cpp b/low-can-binding/can/can-encoder.cpp index b87407f1..4b8a2963 100644 --- a/low-can-binding/can/can-encoder.cpp +++ b/low-can-binding/can/can-encoder.cpp @@ -20,30 +20,37 @@ #include "canutil/write.h" #include "../utils/openxc-utils.hpp" #include "can-message-definition.hpp" -#include "../binding/low-can-hat.hpp" -/// @brief Write a value into a CAN signal in the destination buffer. +/// @brief Write a value in a CAN signal in the destination buffer. /// /// @param[in] signal - The CAN signal to write, including the bit position and bit size. -/// @param[in] value - The encoded integer value to write into the CAN signal. +/// @param[in] value - The encoded integer value to write in the CAN signal. /// @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 build_frame(const 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& 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; - bitfield_encode_float((float)value, - signal.get_bit_position(), - signal.get_bit_size(), - signal.get_factor(), - signal.get_offset(), - cf.data, - CAN_MAX_DLEN); + cf.can_id = signal->get_message()->get_id(); + cf.len = signal->get_message()->is_fd() ? + CANFD_MAX_DLEN : CAN_MAX_DLEN; + + signal->set_last_value((float)value); + + for(const auto& sig: signal->get_message()->get_can_signals()) + { + float last_value = sig->get_last_value(); + bitfield_encode_float(last_value, + sig->get_bit_position(), + sig->get_bit_size(), + sig->get_factor(), + sig->get_offset(), + cf.data, + cf.len); + } return cf; }