-/// @brief Write a value into 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[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)
+/**
+ * @brief Allows to encode data for a signal
+ *
+ * @param sig The signal to know its location
+ * @param data The data to encode
+ * @param filter If true that will generate the filter BCM for the signal
+ * @param factor If true that will use the factor of the signal else 1
+ * @param offset If true that will use the offset of the signal else 0
+ */
+void encoder_t::encode_data(std::shared_ptr<signal_t> sig, std::vector<uint8_t> &data, bool filter, bool factor, bool offset)
+{
+ uint32_t bit_size = sig->get_bit_size();
+ uint32_t bit_position = sig->get_bit_position();
+ float factor_v = factor ? sig->get_factor() : 1;
+ float offset_v = offset ? sig->get_offset() : 0;
+
+ int new_start_byte = 0;
+ int new_end_byte = 0;
+ uint8_t new_start_bit = 0;
+ uint8_t new_end_bit = 0;
+
+ converter_t::signal_to_bits_bytes(bit_position, bit_size, new_start_byte, new_end_byte, new_start_bit, new_end_bit);
+ std::vector<uint8_t> data_signal(new_end_byte - new_start_byte + 1, 0xFF);
+
+ if(filter)
+ {
+ uint8_t mask_first_v = static_cast<uint8_t>(0xFF >> new_start_bit);
+ uint8_t mask_last_v = static_cast<uint8_t>(0xFF << (7 - new_end_bit));
+
+ if(new_start_byte == new_end_byte)
+ {
+ data_signal[0] = mask_first_v & mask_last_v;
+ }
+ else
+ {
+ data_signal[0] = mask_first_v;
+ data_signal[new_end_byte - new_start_byte] = mask_last_v;
+ }
+ }
+ else
+ {
+ bitfield_encode_float(sig->get_last_value(),
+ new_start_bit,
+ bit_size,
+ factor_v,
+ offset_v,
+ data_signal.data(),
+ bit_size);
+ }
+
+ for(size_t i = new_start_byte; i <= new_end_byte ; i++)
+ data[i] = data[i] | data_signal[i-new_start_byte];
+}
+
+/**
+ * @brief Allows to build a multi frame message with correct data to be send
+ *
+ * @param signal The CAN signal to write, including the bit position and bit size.
+ * @param value The encoded integer value to write in the CAN signal.
+ * @param message A multi frame message to complete
+ * @param factor If true that will use the factor of the signal else 1
+ * @param offset If true that will use the offset of the signal else 0
+ * @return message_t* The message that is generated
+ */
+message_t* encoder_t::build_frame(const std::shared_ptr<signal_t>& signal, uint64_t value, message_t *message, bool factor, bool offset)