#include "canutil/read.h"
#include "../utils/openxc-utils.hpp"
+#include "can-message-definition.hpp"
+#include "../binding/low-can-hat.hpp"
/// @brief Parse the signal's bitfield from the given data and return the raw
/// value.
/// always succeeds.
///
openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal,
- const std::vector<can_signal_t>& signals, float value, bool* send)
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send)
{
openxc_DynamicField decoded_value = build_DynamicField(value);
/// decoder always succeeds.
///
openxc_DynamicField decoder_t::booleanDecoder(can_signal_t& signal,
- const std::vector<can_signal_t>& signals, float value, bool* send)
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send)
{
openxc_DynamicField decoded_value = build_DynamicField(value == 0.0 ? false : true);
/// @return Return value is undefined.
///
openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal,
- const std::vector<can_signal_t>& signals, float value, bool* send)
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send)
{
if(send)
*send = false;
/// return value is undefined.
///
openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal,
- const std::vector<can_signal_t>& signals, float value, bool* send)
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send)
{
const std::string signal_state = signal.get_states((uint8_t)value);
openxc_DynamicField decoded_value = build_DynamicField(signal_state);
if(signal_state.size() <= 0)
{
*send = false;
- ERROR(binder_interface, "stateDecoder: No state found with index: %d", (int)value);
+ AFB_ERROR("No state found with index: %d", (int)value);
}
return decoded_value;
}
/// @param[in] signal - The details of the signal to decode and forward.
/// @param[in] message - The received CAN message that should contain this signal.
/// @param[in] signals - an array of all active signals.
+/// @param[out] send - An output parameter that will be flipped to false if the value could
+/// not be decoded.
///
/// The decoder returns an openxc_DynamicField, which may contain a number,
/// string or boolean.
///
-openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, can_message_t& message,
- const std::vector<can_signal_t>& signals)
+openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, const can_message_t& message,
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send)
{
float value = decoder_t::parseSignalBitfield(signal, message);
- DEBUG(binder_interface, "translateSignal: Decoded message from parseSignalBitfield: %f", value);
+ AFB_DEBUG("Decoded message from parseSignalBitfield: %f", value);
- bool send = true;
// Must call the decoders every time, regardless of if we are going to
// decide to send the signal or not.
openxc_DynamicField decoded_value = decoder_t::decodeSignal(signal,
- value, signals, &send);
+ value, signals, send);
signal.set_received(true);
+
+ // Don't send if they is no changes
+ if ((signal.get_last_value() == value && !signal.get_send_same()) || !*send )
+ {
+ *send = false;
+ }
signal.set_last_value(value);
+ signal.set_timestamp(message.get_timestamp());
+ signal.get_message()->set_last_value(message);
return decoded_value;
}
/// string or boolean. If 'send' is false, the return value is undefined.
///
openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal,
- float value, const std::vector<can_signal_t>& signals, bool* send)
+ float value, const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send)
{
SignalDecoder decoder = signal.get_decoder() == nullptr ?
noopDecoder : signal.get_decoder();
/// not be decoded.
///
openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal,
- const can_message_t& message, const std::vector<can_signal_t>& signals, bool* send)
+ const can_message_t& message, const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send)
{
float value = parseSignalBitfield(signal, message);
return decodeSignal(signal, value, signals, send);
float decoder_t::decode_obd2_response(const DiagnosticResponse* response, float parsed_payload)
{
return diagnostic_decode_obd2_pid(response);
-}
\ No newline at end of file
+}