#include "canutil/write.h"
#include "../utils/openxc-utils.hpp"
-#include "can-message-definition.hpp"
-#include "../binding/low-can-hat.hpp"
+#include "message-definition.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 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<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);
- for(const auto& sig: signal->get_message()->get_can_signals())
+ for(const auto& sig: signal->get_message()->get_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,
- CAN_MAX_DLEN);
+ sig->get_bit_position(),
+ sig->get_bit_size(),
+ sig->get_factor(),
+ sig->get_offset(),
+ cf.data,
+ cf.len);
}
return cf;
/// @return Returns the encoded integer. If 'send' is changed to false, the field could
/// not be encoded and the return value is undefined.
///
-uint64_t encoder_t::encode_boolean(const can_signal_t& signal, bool value, bool* send)
+uint64_t encoder_t::encode_boolean(const signal_t& signal, bool value, bool* send)
{
return encode_number(signal, float(value), send);
}
/// @return Returns the encoded integer. If 'send' is changed to false, the field could
/// not be encoded and the return value is undefined.
///
-uint64_t encoder_t::encode_number(const can_signal_t& signal, float value, bool* send)
+uint64_t encoder_t::encode_number(const signal_t& signal, float value, bool* send)
{
return float_to_fixed_point(value, signal.get_factor(), signal.get_offset());
}
/// @return Returns the encoded integer. If 'send' is changed to false, the field could
/// not be encoded and the return value is undefined.
///
-uint64_t encoder_t::encode_state(const can_signal_t& signal, const std::string& state, bool* send)
+uint64_t encoder_t::encode_state(const signal_t& signal, const std::string& state, bool* send)
{
uint64_t value = 0;
if(state == "")
/// @brief Parse a signal from a CAN message and apply any required
/// transforations to get a human readable value.
///
-/// If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value
+/// If the signal_t has a non-NULL 'decoder' field, the raw CAN signal value
/// will be passed to the decoder before returning.
///
/// @param[in] signal - The details of the signal to decode and forward.
/// @return The decoder returns an openxc_DynamicField, which may contain a number,
/// string or boolean. If 'send' is false, the return value is undefined.
///
-uint64_t encoder_t::encode_DynamicField( can_signal_t& signal, const openxc_DynamicField& field, bool* send)
+uint64_t encoder_t::encode_DynamicField( signal_t& signal, const openxc_DynamicField& field, bool* send)
{
uint64_t value = 0;
switch(field.type) {