summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-26 18:27:35 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-27 01:03:34 +0200
commiteb5fc27fce3d832f1f969ebb01056a69c5f4c120 (patch)
tree5c07e6f015fdfa3baa0648828def26248795703b
parentabd0190c2ba3a624272ed1f6a3a9c8fe8c4dd140 (diff)
Check last value before send the event, if no change no event.
Adding a boolean parameter similarly of existing function to know if we would send the event. Change-Id: I03ee17f656065e556fd2b72b160b140852b68dcc Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--CAN-binder/low-can-binding/can/can-bus.cpp14
-rw-r--r--CAN-binder/low-can-binding/can/can-decoder.cpp13
-rw-r--r--CAN-binder/low-can-binding/can/can-decoder.hpp2
3 files changed, 20 insertions, 9 deletions
diff --git a/CAN-binder/low-can-binding/can/can-bus.cpp b/CAN-binder/low-can-binding/can/can-bus.cpp
index 6f9e78d9..0de8aeb6 100644
--- a/CAN-binder/low-can-binding/can/can-bus.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus.cpp
@@ -126,13 +126,17 @@ int can_bus_t::process_can_signals(can_message_t& can_message)
//DEBUG(binder_interface, "Nb elt matched string: %d", (int)s.count(std::string(sig.generic_name));
if( s.find(sig->get_name()) != s.end() && afb_event_is_valid(s[sig->get_name()]))
{
- decoded_message = decoder_t::translateSignal(*sig, can_message, conf.get_can_signals());
+ bool send = true;
+ decoded_message = decoder_t::translateSignal(*sig, can_message, conf.get_can_signals(), &send);
- openxc_SimpleMessage s_message = build_SimpleMessage(sig->get_name(), decoded_message);
- vehicle_message = build_VehicleMessage(s_message);
+ if(send)
+ {
+ openxc_SimpleMessage s_message = build_SimpleMessage(sig->get_name(), decoded_message);
+ vehicle_message = build_VehicleMessage(s_message);
- std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex_);
- push_new_vehicle_message(vehicle_message);
+ std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex_);
+ push_new_vehicle_message(vehicle_message);
+ }
processed_signals++;
}
}
diff --git a/CAN-binder/low-can-binding/can/can-decoder.cpp b/CAN-binder/low-can-binding/can/can-decoder.cpp
index 902484e5..e01e43bb 100644
--- a/CAN-binder/low-can-binding/can/can-decoder.cpp
+++ b/CAN-binder/low-can-binding/can/can-decoder.cpp
@@ -147,23 +147,30 @@ openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal,
/// @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)
+ const std::vector<can_signal_t>& signals, bool* send)
{
float value = decoder_t::parseSignalBitfield(signal, message);
DEBUG(binder_interface, "%s: Decoded message from parseSignalBitfield: %f", __FUNCTION__, 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);
return decoded_value;
}
diff --git a/CAN-binder/low-can-binding/can/can-decoder.hpp b/CAN-binder/low-can-binding/can/can-decoder.hpp
index ebe1de20..15e02294 100644
--- a/CAN-binder/low-can-binding/can/can-decoder.hpp
+++ b/CAN-binder/low-can-binding/can/can-decoder.hpp
@@ -36,7 +36,7 @@ public:
float value, bool* send);
static openxc_DynamicField translateSignal(can_signal_t& signal, can_message_t& message,
- const std::vector<can_signal_t>& signals);
+ const std::vector<can_signal_t>& signals, bool* send);
static openxc_DynamicField decodeSignal(can_signal_t& signal, const can_message_t& message,
const std::vector<can_signal_t>& signals, bool* send);