Change way to find signals to make it a little bit more generic.
[apps/agl-service-can-low-level.git] / src / can-decoder.hpp
index eda7727..e7dfff8 100644 (file)
 
 #pragma once
 
-#include "can-utils.hpp"
+#include "can-bus.hpp"
 
 class decoder_t
 {
        private:
-               openxc_DynamicField decoded_value;
 
        public:
                /* Public: Parse the signal's bitfield from the given data and return the raw
@@ -35,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.
@@ -54,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.
                */
-               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.
@@ -73,7 +72,7 @@ class decoder_t
                * is 0.0, otherwise true. The 'send' argument will not be modified as this
                * decoder always succeeds.
                */
-               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.
@@ -92,7 +91,7 @@ class decoder_t
                *
                * The return value is undefined.
                */
-               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.
@@ -111,9 +110,26 @@ class decoder_t
                * its numeric value. The 'send' argument will not be modified as this decoder
                * always succeeds.
                */
-               openxc_DynamicField noopDecoder(const CanSignal& signal, const CanSignal& signals,
+               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
+                *      to get a human readable value and public the result to the pipeline.
+                *
+               * If the CanSignal has a non-NULL 'decoder' field, the raw CAN signal value
+               * will be passed to the decoder before publishing.
+               *
+               * signal - The details of the signal to decode and forward.
+               * message   - The received CAN message that should contain this signal.
+               * signals - an array of all active signals.
+               *
+               * The decoder returns an openxc_DynamicField, which may contain a number,
+               * string or boolean.
+               */
+               openxc_DynamicField translateSignal(CanSignal& signal, can_message_t& message,
+                       const std::vector<CanSignal>& signals);
+               
                /* Public: Parse a signal from a CAN message and apply any required
                * transforations to get a human readable value.
                *
@@ -123,16 +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 CanSignal& signals,
-                               bool* send);
+               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.
@@ -142,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,
-               const CanSignal& signals, bool* send);
-}
\ No newline at end of file
+               openxc_DynamicField decodeSignal(CanSignal& signal, float value,
+                       const std::vector<CanSignal>& signals, bool* send);
+};
\ No newline at end of file