aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/can-decoder.cpp68
-rw-r--r--src/can-decoder.hpp19
-rw-r--r--src/can-signals.cpp9
-rw-r--r--src/can-utils.hpp4
4 files changed, 55 insertions, 45 deletions
diff --git a/src/can-decoder.cpp b/src/can-decoder.cpp
index b222bc62..bc4d0be7 100644
--- a/src/can-decoder.cpp
+++ b/src/can-decoder.cpp
@@ -15,70 +15,76 @@
* limitations under the License.
*/
-#pragma once
-
#include "can-decoder.hpp"
+#include "canutil/read.h"
-float decoder_t::parseSignalBitfield(const CanSignal& signal, const CanMessage& message)
+float decoder_t::parseSignalBitfield(CanSignal& signal, const can_message_t& message)
{
- return bitfield_parse_float(message->data, CAN_MESSAGE_SIZE,
- signal->bitPosition, signal->bitSize, signal->factor,
- signal->offset);
+ return bitfield_parse_float(message.get_data(), CAN_MESSAGE_SIZE,
+ signal.bitPosition, signal.bitSize, signal.factor,
+ signal.offset);
}
-openxc_DynamicField decoder_t::noopDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+openxc_DynamicField decoder_t::noopDecoder(CanSignal& signal,
+ const std::vector<CanSignal>& signals, float value, bool* send)
{
- decoded_value = { .has_type = true,
- .type = openxc_DynamicField_Type_NUM,
- .has_numeric_value = true,
- .numeric_value = value };
+ 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;
+
return decoded_value;
}
-openxc_DynamicField decoder_t::booleanDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+openxc_DynamicField decoder_t::booleanDecoder(CanSignal& signal,
+ const std::vector<CanSignal>& signals, float value, bool* send)
{
- decoded_value = { .has_type = true,
- .type = openxc_DynamicField_Type_BOOL,
- .has_boolean_value = true,
- .numeric_value = value == 0.0 ? false : true };
+ 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;
+
return decoded_value;
}
-openxc_DynamicField decoder_t::ignoreDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+openxc_DynamicField decoder_t::ignoreDecoder(CanSignal& signal,
+ const std::vector<CanSignal>& signals, float value, bool* send)
{
if(send)
*send = false;
- openxc_DynamicField decoded_value = {0};
+ openxc_DynamicField decoded_value = {0, openxc_DynamicField_Type_BOOL, 0, "", 0, 0, 0, 0};
+
return decoded_value;
}
-openxc_DynamicField decoder_t::stateDecoder(const CanSignal& signal,
- const CanSignal& signals, float value, bool* send)
+openxc_DynamicField decoder_t::stateDecoder(CanSignal& signal,
+ const std::vector<CanSignal>& signals, float value, bool* send)
{
- openxc_DynamicField decoded_value = {0};
+ openxc_DynamicField decoded_value = {0, openxc_DynamicField_Type_BOOL, 0, "", 0, 0, 0, 0};
decoded_value.has_type = true;
decoded_value.type = openxc_DynamicField_Type_STRING;
decoded_value.has_string_value = true;
+ /* TODO: Handle SignalState
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)
{
- if(signal == nullptr || message == nullptr)
+ if(&signal == nullptr || &message == nullptr)
{
- return {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+ openxc_DynamicField ret = {0, openxc_DynamicField_Type_BOOL, 0, "", 0, 0, 0, 0};
+ return ret;
}
float value = parseSignalBitfield(signal, message);
@@ -94,17 +100,17 @@ openxc_DynamicField decoder_t::translateSignal(CanSignal& signal, can_message_t&
return decoded_value;
}
-openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
+openxc_DynamicField decoder_t::decodeSignal( CanSignal& signal,
float value, const std::vector<CanSignal>& signals, bool* send)
{
- SignalDecoder decoder = signal->decoder == NULL ?
- noopDecoder : signal->decoder;
+ 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,
+openxc_DynamicField decoder_t::decodeSignal( CanSignal& signal,
const can_message_t& message, const std::vector<CanSignal>& signals, bool* send)
{
float value = parseSignalBitfield(signal, message);
diff --git a/src/can-decoder.hpp b/src/can-decoder.hpp
index ac967300..200035d3 100644
--- a/src/can-decoder.hpp
+++ b/src/can-decoder.hpp
@@ -34,7 +34,7 @@ class decoder_t
* Returns the raw value of the signal parsed as a bitfield from the given byte
* array.
*/
- float parseSignalBitfield(const CanSignal& signal, const can_message_t& message);
+ float parseSignalBitfield(CanSignal& signal, const can_message_t& message);
/* Public: Find and return the corresponding string state for a CAN signal's
* raw integer value.
@@ -53,7 +53,7 @@ class decoder_t
* the signal. If an equivalent isn't found, send is sent to false and the
* return value is undefined.
*/
- static openxc_DynamicField stateDecoder(const CanSignal& signal, const CanSignal& signals,
+ static openxc_DynamicField stateDecoder(CanSignal& signal, const std::vector<CanSignal>& signals,
float value, bool* send);
/* Public: Coerces a numerical value to a boolean.
@@ -72,7 +72,7 @@ class decoder_t
* is 0.0, otherwise true. The 'send' argument will not be modified as this
* decoder always succeeds.
*/
- static openxc_DynamicField booleanDecoder(const CanSignal& signal, const CanSignal& signals,
+ static openxc_DynamicField booleanDecoder(CanSignal& signal, const std::vector<CanSignal>& signals,
float value, bool* send);
/* Public: Update the metadata for a signal and the newly received value.
@@ -91,7 +91,7 @@ class decoder_t
*
* The return value is undefined.
*/
- static openxc_DynamicField ignoreDecoder(const CanSignal& signal, const CanSignal& signals,
+ openxc_DynamicField ignoreDecoder(CanSignal& signal, const std::vector<CanSignal>& signals,
float value, bool* send);
/* Public: Wrap a raw CAN signal value in a DynamicField without modification.
@@ -110,8 +110,8 @@ class decoder_t
* its numeric value. The 'send' argument will not be modified as this decoder
* always succeeds.
*/
- static openxc_DynamicField noopDecoder(const CanSignal& signal, const CanSignal& signals,
- float value);
+ static openxc_DynamicField noopDecoder(CanSignal& signal, const std::vector<CanSignal>& signals,
+ float value, bool* send);
/* Public: Parse a signal from a CAN message, apply any required transforations
@@ -139,15 +139,14 @@ class decoder_t
* signal - The details of the signal to decode and forward.
* message - The CAN message that contains the signal.
* signals - an array of all active signals.
- * signalCount - The length of the signals array.
* 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. If 'send' is false, the return value is undefined.
*/
- openxc_DynamicField decodeSignal(const CanSignal& signal, const can_message_t& message,
- const std::vector<CanSignal>& signals);
+ openxc_DynamicField decodeSignal(CanSignal& signal, const can_message_t& message,
+ const std::vector<CanSignal>& signals, bool* send);
/* Public: Decode a transformed, human readable value from an raw CAN signal
* already parsed from a CAN message.
@@ -157,6 +156,6 @@ class decoder_t
* message yourself. This is useful if you need that raw value for something
* else.
*/
- openxc_DynamicField decodeSignal(const CanSignal& signal, float value,
+ openxc_DynamicField decodeSignal(CanSignal& signal, float value,
const std::vector<CanSignal>& signals, bool* send);
}; \ No newline at end of file
diff --git a/src/can-signals.cpp b/src/can-signals.cpp
index 54c03425..add6654d 100644
--- a/src/can-signals.cpp
+++ b/src/can-signals.cpp
@@ -19,14 +19,19 @@
#include <fnmatch.h>
+#include "can-decoder.hpp"
#include "low-can-binding.hpp"
+std::vector<std::vector<CanMessageDefinition>> CAN_MESSAGES = {
+ {{620, CanMessageFormat::STANDARD, {10, 0, nullptr}, false, (uint8_t)NULL}},
+};
+
/**
* @brief Dumb SIGNALS array. It is composed by CanMessageSet
* SIGNALS[MESSAGE_SET_ID][CanSignal]
*/
-std::vector<std::vector<CanSignal>> SIGNALS {
- {}// message set: example
+std::vector<std::vector<CanSignal>> SIGNALS = {
+ {{&(CAN_MESSAGES[0][0]), "can.driver_door.open", 2, 4, 1.000000, 0.000000, 0.000000, 0.000000, {10, 0, nullptr}, false, true, nullptr, 0, false, decoder_t::booleanDecoder, nullptr, false, (float)NULL}},
};
/**
diff --git a/src/can-utils.hpp b/src/can-utils.hpp
index 50d5eb99..29a41f26 100644
--- a/src/can-utils.hpp
+++ b/src/can-utils.hpp
@@ -52,8 +52,8 @@
*
* @return a decoded value in an openxc_DynamicField struct.
*/
-typedef openxc_DynamicField (*SignalDecoder)(const struct CanSignal& signal,
- const CanSignal& signals, float value, bool* send);
+typedef openxc_DynamicField (*SignalDecoder)(struct CanSignal& signal,
+ const std::vector<CanSignal>& signals, float value, bool* send);
/**
* @brief: The type signature for a CAN signal encoder.