From e8c14d2baa8841f13beefaa1fb662a280ea8eb96 Mon Sep 17 00:00:00 2001 From: Arthur Guyader Date: Fri, 13 Dec 2019 15:23:27 +0100 Subject: decoder: Add new decoders: ascii, date, time Change-Id: I392bff2c1f4062aee186875335786fcda9cc0649 Signed-off-by: Arthur Guyader Signed-off-by: Romain Forlot --- low-can-binding/can/can-decoder.cpp | 61 +++++++++++++++++++++++++++++++++++++ low-can-binding/can/can-decoder.hpp | 3 ++ 2 files changed, 64 insertions(+) (limited to 'low-can-binding/can') diff --git a/low-can-binding/can/can-decoder.cpp b/low-can-binding/can/can-decoder.cpp index 488fdfb8..15341b1c 100644 --- a/low-can-binding/can/can-decoder.cpp +++ b/low-can-binding/can/can-decoder.cpp @@ -195,6 +195,67 @@ openxc_DynamicField decoder_t::decode_bytes(signal_t& signal, std::shared_ptr message, bool* send) +{ + std::string ret_s = ""; + openxc_DynamicField openxc_bytes = decode_bytes(signal,message,send); + if(!openxc_bytes.has_bytes_value) + { + AFB_ERROR("Error no bytes value to translate to ascii"); + } + ret_s = converter_t::to_ascii(openxc_bytes.bytes_value,openxc_bytes.length_array); + openxc_DynamicField ret = build_DynamicField(ret_s); + return ret; +} + +//edit +openxc_DynamicField decoder_t::decode_date(signal_t& signal, std::shared_ptr message, bool* send) +{ + float value = decoder_t::parse_signal_bitfield(signal, message); + AFB_DEBUG("Decoded message from parse_signal_bitfield: %f", value); + openxc_DynamicField decoded_value = build_DynamicField(value); + + // Don't send if they is no changes + if ((signal.get_last_value() == value && !signal.get_send_same()) || !*send ) + { + *send = false; + } + signal.set_last_value(value); + + return decoded_value; +} + +//edit +openxc_DynamicField decoder_t::decode_time(signal_t& signal, std::shared_ptr message, bool* send) +{ + float value = decoder_t::parse_signal_bitfield(signal, message); + AFB_DEBUG("Decoded message from parse_signal_bitfield: %f", value); + openxc_DynamicField decoded_value = build_DynamicField(value); + + // Don't send if they is no changes + if ((signal.get_last_value() == value && !signal.get_send_same()) || !*send ) + { + *send = false; + } + signal.set_last_value(value); + + return decoded_value; +} + + /// @brief Wraps a raw CAN signal value in a DynamicField without modification. /// /// This is an implementation of the Signal type signature, and can be diff --git a/low-can-binding/can/can-decoder.hpp b/low-can-binding/can/can-decoder.hpp index 2f7823ad..fd246f3c 100644 --- a/low-can-binding/can/can-decoder.hpp +++ b/low-can-binding/can/can-decoder.hpp @@ -32,6 +32,9 @@ public: static openxc_DynamicField decode_ignore(signal_t& signal, std::shared_ptr message, bool* send); static openxc_DynamicField decode_noop(signal_t& signal, std::shared_ptr message, bool* send); static openxc_DynamicField decode_bytes(signal_t& signal, std::shared_ptr message, bool* send); + static openxc_DynamicField decode_ascii(signal_t& signal, std::shared_ptr message, bool* send); + static openxc_DynamicField decode_date(signal_t& signal, std::shared_ptr message, bool* send); + static openxc_DynamicField decode_time(signal_t& signal, std::shared_ptr message, bool* send); static openxc_DynamicField translate_signal(signal_t& signal, std::shared_ptr message, bool* send); -- cgit 1.2.3-korg