From 3e624c015e7e90ecedb597c71d9b77d185d318a7 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Mon, 13 Mar 2017 23:11:18 +0100 Subject: Make decoder systematic use of openxc-utils to build its objects. We don't want random initialization on boolean value of openxc_DynamicField (has_string, has_numeric...) else we have a risk that the final decoded and convert into json object will not be the good one. Change-Id: If4d69e6ace615fd8e097ba9a04e5482c82b9a7db Signed-off-by: Romain Forlot --- src/can/can-decoder.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/can/can-decoder.cpp') diff --git a/src/can/can-decoder.cpp b/src/can/can-decoder.cpp index 5f5bce8c..a5e4d8ee 100644 --- a/src/can/can-decoder.cpp +++ b/src/can/can-decoder.cpp @@ -17,6 +17,7 @@ #include "can-decoder.hpp" #include "canutil/read.h" +#include "../utils/openxc-utils.hpp" float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& message) { @@ -28,11 +29,7 @@ float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, const std::vector& signals, float value, bool* send) { - openxc_DynamicField decoded_value; - decoded_value.has_type = true; - decoded_value.type = openxc_DynamicField_Type_NUM; - decoded_value.has_numeric_value = true; - decoded_value.numeric_value = value; + openxc_DynamicField decoded_value = build_DynamicField(value); return decoded_value; } @@ -40,11 +37,7 @@ openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, openxc_DynamicField decoder_t::booleanDecoder(can_signal_t& signal, const std::vector& signals, float value, bool* send) { - openxc_DynamicField decoded_value; - decoded_value.has_type = true; - decoded_value.type = openxc_DynamicField_Type_BOOL; - decoded_value.has_boolean_value = true; - decoded_value.boolean_value = value == 0.0 ? false : true; + openxc_DynamicField decoded_value = build_DynamicField(value == 0.0 ? false : true); return decoded_value; } @@ -83,7 +76,7 @@ openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, can_message } float value = decoder_t::parseSignalBitfield(signal, message); - DEBUG(binder_interface, "translateSignal: Decoded message: %f", value); + DEBUG(binder_interface, "translateSignal: Decoded message from parseSignalBitfield: %f", value); bool send = true; // Must call the decoders every time, regardless of if we are going to @@ -99,7 +92,7 @@ openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, can_message openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, float value, const std::vector& signals, bool* send) { - SignalDecoder decoder = signal.get_decoder() == NULL ? + SignalDecoder decoder = signal.get_decoder() == nullptr ? noopDecoder : signal.get_decoder(); openxc_DynamicField decoded_value = decoder(signal, signals, value, send); -- cgit 1.2.3-korg