summaryrefslogtreecommitdiffstats
path: root/src/can-decoder.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-27 20:25:52 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-27 20:25:52 +0100
commit06acf7a42da0ab605d9dac3c4c0c66f426a06d17 (patch)
treebf31e8870354bc88b1c217e29cfd69205e837dce /src/can-decoder.cpp
parentf06cda1411cc087ca551e6e9bffa9cb2dc79b4ca (diff)
Changed the decoding function
Change-Id: Ib27fb13d4fb7959509400a3c2eff2859d1ce9c2b Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can-decoder.cpp')
-rw-r--r--src/can-decoder.cpp83
1 files changed, 52 insertions, 31 deletions
diff --git a/src/can-decoder.cpp b/src/can-decoder.cpp
index b163011f..b222bc62 100644
--- a/src/can-decoder.cpp
+++ b/src/can-decoder.cpp
@@ -27,17 +27,17 @@ float decoder_t::parseSignalBitfield(const CanSignal& signal, const CanMessage&
}
openxc_DynamicField decoder_t::noopDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+ const CanSignal& signals, float value, bool* send)
{
decoded_value = { .has_type = true,
.type = openxc_DynamicField_Type_NUM,
.has_numeric_value = true,
.numeric_value = value };
- return decoded_value;
+ return decoded_value;
}
openxc_DynamicField decoder_t::booleanDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+ const CanSignal& signals, float value, bool* send)
{
decoded_value = { .has_type = true,
.type = openxc_DynamicField_Type_BOOL,
@@ -47,45 +47,66 @@ openxc_DynamicField decoder_t::booleanDecoder(const CanSignal& signal,
}
openxc_DynamicField decoder_t::ignoreDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+ const CanSignal& signals, float value, bool* send)
{
- if(send)
- *send = false;
-
- openxc_DynamicField decoded_value = {0};
- return decoded_value;
+ if(send)
+ *send = false;
+
+ openxc_DynamicField decoded_value = {0};
+ return decoded_value;
}
openxc_DynamicField decoder_t::stateDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+ const CanSignal& signals, float value, bool* send)
+{
+ openxc_DynamicField decoded_value = {0};
+ decoded_value.has_type = true;
+ decoded_value.type = openxc_DynamicField_Type_STRING;
+ decoded_value.has_string_value = true;
+
+ const CanSignalState* signalState = lookupSignalState(value, signal);
+ if(signalState != NULL) {
+ ::strcpy(decoded_value.string_value, signalState->name);
+ } else {
+ *send = false;
+ }
+ return decoded_value;
+}
+
+openxc_DynamicField decoder_t::translateSignal(CanSignal& signal, can_message_t& message,
+ const std::vector<CanSignal>& signals)
{
- openxc_DynamicField decoded_value = {0};
- decoded_value.has_type = true;
- decoded_value.type = openxc_DynamicField_Type_STRING;
- decoded_value.has_string_value = true;
+ if(signal == nullptr || message == nullptr)
+ {
+ return {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+ }
+
+ float value = parseSignalBitfield(signal, message);
+
+ 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 = decodeSignal(signal,
+ value, signals, &send);
- const CanSignalState* signalState = lookupSignalState(value, signal);
- if(signalState != NULL) {
- ::strcpy(decoded_value.string_value, signalState->name);
- } else {
- *send = false;
- }
- return decoded_value;
+ signal.received = true;
+ signal.lastValue = value;
+ return decoded_value;
}
openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
- float value, const std::vector<CanSignal>& signals, bool* send)
+ float value, const std::vector<CanSignal>& signals, bool* send)
{
- SignalDecoder decoder = signal->decoder == NULL ?
- noopDecoder : signal->decoder;
- openxc_DynamicField decoded_value = decoder(signal, signals,
- value, send);
- return decoded_value;
+ SignalDecoder decoder = signal->decoder == NULL ?
+ noopDecoder : signal->decoder;
+ openxc_DynamicField decoded_value = decoder(signal, signals,
+ value, send);
+ return decoded_value;
}
openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
- const can_message_t& message, const std::vector<CanSignal>& signals, bool* send)
+ const can_message_t& message, const std::vector<CanSignal>& signals, bool* send)
{
- float value = parseSignalBitfield(signal, message);
- return decodeSignal(signal, value, signals, send);
-} \ No newline at end of file
+ float value = parseSignalBitfield(signal, message);
+ return decodeSignal(signal, value, signals, send);
+}