summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-13 23:11:18 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:15:55 +0100
commit3e624c015e7e90ecedb597c71d9b77d185d318a7 (patch)
treecc491e0c0226e91b082d11f5a9125581f56f2f9a
parentac96a95e79d89eb667276f87c389d5ea4ff14efd (diff)
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 <romain.forlot@iot.bzh>
-rw-r--r--src/can/can-decoder.cpp17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/can/can-decoder.cpp b/src/can/can-decoder.cpp
index 5f5bce8..a5e4d8e 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<can_signal_t>& 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<can_signal_t>& 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<can_signal_t>& 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);