diff options
Diffstat (limited to 'low-can-binding/can')
19 files changed, 267 insertions, 172 deletions
diff --git a/low-can-binding/can/can-bus.cpp b/low-can-binding/can/can-bus.cpp index 739e865c..48ac697a 100644 --- a/low-can-binding/can/can-bus.cpp +++ b/low-can-binding/can/can-bus.cpp @@ -27,7 +27,7 @@ #include "can-bus.hpp" -#include "can-signals.hpp" +#include "signals.hpp" #include "can-decoder.hpp" #include "../binding/application.hpp" #include "../utils/signals.hpp" @@ -81,21 +81,21 @@ bool can_bus_t::apply_filter(const openxc_VehicleMessage& vehicle_message, std:: /// @param[in] can_message - a single CAN message from the CAN socket read, to be decode. /// /// @return How many signals has been decoded. -void can_bus_t::process_signals(const message_t& message, std::map<int, std::shared_ptr<low_can_subscription_t> >& s) +void can_bus_t::process_signals(std::shared_ptr<message_t> message, std::map<int, std::shared_ptr<low_can_subscription_t> >& s) { - int subscription_id = message.get_sub_id(); + int subscription_id = message->get_sub_id(); openxc_DynamicField decoded_message; openxc_VehicleMessage vehicle_message; if( s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id]->get_event())) { bool send = true; - // First we have to found which can_signal_t it is + // First we have to found which signal_t it is std::shared_ptr<low_can_subscription_t> sig = s[subscription_id]; - decoded_message = decoder_t::translate_signal(*sig->get_can_signal(), message, &send); + decoded_message = decoder_t::translate_signal(*sig->get_signal(), message, &send); openxc_SimpleMessage s_message = build_SimpleMessage(sig->get_name(), decoded_message); - vehicle_message = build_VehicleMessage(s_message, message.get_timestamp()); + vehicle_message = build_VehicleMessage(s_message, message->get_timestamp()); if(send && apply_filter(vehicle_message, sig)) { @@ -166,7 +166,7 @@ void can_bus_t::can_decode_message() process_diagnostic_signals(application_t::instance().get_diagnostic_manager(), message, s); } else - {process_signals(*message, s);} + {process_signals(message, s);} } can_message_lock.lock(); } diff --git a/low-can-binding/can/can-bus.hpp b/low-can-binding/can/can-bus.hpp index 2a798ca6..53e6b9ae 100644 --- a/low-can-binding/can/can-bus.hpp +++ b/low-can-binding/can/can-bus.hpp @@ -46,8 +46,8 @@ private: utils::config_parser_t conf_file_; ///< configuration file handle used to initialize can_bus_dev_t objects. bool apply_filter(const openxc_VehicleMessage& vehicle_message, std::shared_ptr<low_can_subscription_t> can_subscription); - void process_signals(const message_t& message, std::map<int, std::shared_ptr<low_can_subscription_t> >& s); - void process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr<message_t> message, std::map<int, std::shared_ptr<low_can_subscription_t> >& s); + void process_signals(std::shared_ptr<message_t> message, std::map<int, std::shared_ptr<low_can_subscription_t> >& s); + void process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr<message_t> can_message, std::map<int, std::shared_ptr<low_can_subscription_t> >& s); void can_decode_message(); std::thread th_decoding_; ///< thread that will handle decoding a can frame diff --git a/low-can-binding/can/can-command.hpp b/low-can-binding/can/can-command.hpp index c64ad740..c6045dfa 100644 --- a/low-can-binding/can/can-command.hpp +++ b/low-can-binding/can/can-command.hpp @@ -18,7 +18,7 @@ #pragma once #include "openxc.pb.h" -#include "can-signals.hpp" +#include "signals.hpp" /// /// @brief The type signature for a function to handle a custom OpenXC command. @@ -32,7 +32,7 @@ /// @param[in] signalCount - The length of the signals array. /// typedef void (*CommandHandler)(const char* name, openxc_DynamicField* value, - openxc_DynamicField* event, can_signal_t* signals, int signalCount); + openxc_DynamicField* event, signal_t* signals, int signalCount); /// @struct CanCommand /// @brief The structure to represent a supported custom OpenXC command. diff --git a/low-can-binding/can/can-decoder.cpp b/low-can-binding/can/can-decoder.cpp index a2bf411b..46976b5c 100644 --- a/low-can-binding/can/can-decoder.cpp +++ b/low-can-binding/can/can-decoder.cpp @@ -19,7 +19,7 @@ #include "canutil/read.h" #include "../utils/openxc-utils.hpp" -#include "can-message-definition.hpp" +#include "message-definition.hpp" #include "../binding/low-can-hat.hpp" /// @brief Parses the signal's bitfield from the given data and returns the raw @@ -31,9 +31,9 @@ /// @return Returns the raw value of the signal parsed as a bitfield from the given byte /// array. /// -float decoder_t::parse_signal_bitfield(can_signal_t& signal, const message_t& message) +float decoder_t::parse_signal_bitfield(signal_t& signal, std::shared_ptr<message_t> message) { - return bitfield_parse_float(message.get_data(), CAN_MESSAGE_SIZE, + return bitfield_parse_float(message->get_data(), CAN_MESSAGE_SIZE, signal.get_bit_position(), signal.get_bit_size(), signal.get_factor(), signal.get_offset()); } @@ -41,7 +41,7 @@ float decoder_t::parse_signal_bitfield(can_signal_t& signal, const message_t& me /// @brief Wraps a raw CAN signal value in a DynamicField without modification. /// /// This is an implementation of the Signal type signature, and can be -/// used directly in the can_signal_t.decoder field. +/// used directly in the signal_t.decoder field. /// /// @param[in] signal - The details of the signal that contains the state mapping. /// @param[in] value - The numerical value that will be wrapped in a DynamicField. @@ -52,7 +52,7 @@ float decoder_t::parse_signal_bitfield(can_signal_t& signal, const message_t& me /// its numeric value. The 'send' argument will not be modified as this decoder /// always succeeds. /// -openxc_DynamicField decoder_t::decode_noop(can_signal_t& signal, float value, bool* send) +openxc_DynamicField decoder_t::decode_noop(signal_t& signal, float value, bool* send) { openxc_DynamicField decoded_value = build_DynamicField(value); @@ -61,7 +61,7 @@ openxc_DynamicField decoder_t::decode_noop(can_signal_t& signal, float value, bo /// @brief Coerces a numerical value to a boolean. /// /// This is an implementation of the Signal type signature, and can be -/// used directly in the can_signal_t.decoder field. +/// used directly in the signal_t.decoder field. /// /// @param[in] signal - The details of the signal that contains the state mapping. /// @param[in] value - The numerical value that will be converted to a boolean. @@ -72,7 +72,7 @@ openxc_DynamicField decoder_t::decode_noop(can_signal_t& signal, float value, bo /// is 0.0, otherwise true. The 'send' argument will not be modified as this /// decoder always succeeds. /// -openxc_DynamicField decoder_t::decode_boolean(can_signal_t& signal, float value, bool* send) +openxc_DynamicField decoder_t::decode_boolean(signal_t& signal, float value, bool* send) { openxc_DynamicField decoded_value = build_DynamicField(value == 0.0 ? false : true); @@ -81,7 +81,7 @@ openxc_DynamicField decoder_t::decode_boolean(can_signal_t& signal, float value, /// @brief Update the metadata for a signal and the newly received value. /// /// This is an implementation of the Signal type signature, and can be -/// used directly in the can_signal_t.decoder field. +/// used directly in the signal_t.decoder field. /// /// This function always flips 'send' to false. /// @@ -92,7 +92,7 @@ openxc_DynamicField decoder_t::decode_boolean(can_signal_t& signal, float value, /// /// @return Return value is undefined. /// -openxc_DynamicField decoder_t::decode_ignore(can_signal_t& signal, float value, bool* send) +openxc_DynamicField decoder_t::decode_ignore(signal_t& signal, float value, bool* send) { if(send) *send = false; @@ -106,7 +106,7 @@ openxc_DynamicField decoder_t::decode_ignore(can_signal_t& signal, float value, /// raw integer value. /// /// This is an implementation of the Signal type signature, and can be -/// used directly in the can_signal_t.decoder field. +/// used directly in the signal_t.decoder field. /// /// @param[in] signal - The details of the signal that contains the state mapping. /// @param[in] value - The numerical value that should map to a state. @@ -117,7 +117,7 @@ openxc_DynamicField decoder_t::decode_ignore(can_signal_t& signal, float value, /// the signal. If an equivalent isn't found, send is sent to false and the /// return value is undefined. /// -openxc_DynamicField decoder_t::decode_state(can_signal_t& signal, float value, bool* send) +openxc_DynamicField decoder_t::decode_state(signal_t& signal, float value, bool* send) { const std::string signal_state = signal.get_states((uint8_t)value); openxc_DynamicField decoded_value = build_DynamicField(signal_state); @@ -133,7 +133,7 @@ openxc_DynamicField decoder_t::decode_state(can_signal_t& signal, float value, b /// @brief 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 can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value +/// If the signal_t has a non-NULL 'decoder' field, the raw CAN signal value /// will be passed to the decoder before publishing. /// /// @param[in] signal - The details of the signal to decode and forward. @@ -144,7 +144,7 @@ openxc_DynamicField decoder_t::decode_state(can_signal_t& signal, float value, b /// The decoder returns an openxc_DynamicField, which may contain a number, /// string or boolean. /// -openxc_DynamicField decoder_t::translate_signal(can_signal_t& signal, const message_t& message, bool* send) +openxc_DynamicField decoder_t::translate_signal(signal_t& signal, std::shared_ptr<message_t> message, bool* send) { float value = decoder_t::parse_signal_bitfield(signal, message); AFB_DEBUG("Decoded message from parse_signal_bitfield: %f", value); @@ -162,7 +162,7 @@ openxc_DynamicField decoder_t::translate_signal(can_signal_t& signal, const mess *send = false; } signal.set_last_value(value); - signal.set_timestamp(message.get_timestamp()); + signal.set_timestamp(message->get_timestamp()); signal.get_message()->set_last_value(message); return decoded_value; } @@ -170,7 +170,7 @@ openxc_DynamicField decoder_t::translate_signal(can_signal_t& signal, const mess /// @brief Parse a signal from a CAN message and apply any required /// transforations to get a human readable value. /// -/// If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value +/// If the signal_t has a non-NULL 'decoder' field, the raw CAN signal value /// will be passed to the decoder before returning. /// /// @param[in] signal - The details of the signal to decode and forward. @@ -181,7 +181,7 @@ openxc_DynamicField decoder_t::translate_signal(can_signal_t& signal, const mess /// @return 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 decoder_t::decode_signal( can_signal_t& signal, float value, bool* send) +openxc_DynamicField decoder_t::decode_signal( signal_t& signal, float value, bool* send) { signal_decoder decoder = signal.get_decoder() == nullptr ? decode_noop : signal.get_decoder(); @@ -202,7 +202,7 @@ openxc_DynamicField decoder_t::decode_signal( can_signal_t& signal, float value, /// @param[out] send - An output parameter that will be flipped to false if the value could /// not be decoded. /// -openxc_DynamicField decoder_t::decode_signal( can_signal_t& signal, const can_message_t& message, bool* send) +openxc_DynamicField decoder_t::decode_signal( signal_t& signal, std::shared_ptr<message_t> message, bool* send) { float value = parse_signal_bitfield(signal, message); return decode_signal(signal, value, send); diff --git a/low-can-binding/can/can-decoder.hpp b/low-can-binding/can/can-decoder.hpp index ffc881f9..ac9eb5d9 100644 --- a/low-can-binding/can/can-decoder.hpp +++ b/low-can-binding/can/can-decoder.hpp @@ -17,25 +17,25 @@ #pragma once -#include "can-signals.hpp" +#include "signals.hpp" #include "message/can-message.hpp" #include "openxc.pb.h" class decoder_t { public: - static float parse_signal_bitfield(can_signal_t& signal, const message_t& message); + static float parse_signal_bitfield(signal_t& signal, std::shared_ptr<message_t> message); - static openxc_DynamicField decode_state(can_signal_t& signal, float value, bool* send); - static openxc_DynamicField decode_boolean(can_signal_t& signal, float value, bool* send); - static openxc_DynamicField decode_ignore(can_signal_t& signal, float value, bool* send); - static openxc_DynamicField decode_noop(can_signal_t& signal, float value, bool* send); + static openxc_DynamicField decode_state(signal_t& signal, float value, bool* send); + static openxc_DynamicField decode_boolean(signal_t& signal, float value, bool* send); + static openxc_DynamicField decode_ignore(signal_t& signal, float value, bool* send); + static openxc_DynamicField decode_noop(signal_t& signal, float value, bool* send); - static openxc_DynamicField translate_signal(can_signal_t& signal, const message_t& messag, bool* send); + static openxc_DynamicField translate_signal(signal_t& signal, std::shared_ptr<message_t> message, bool* send); - static openxc_DynamicField decode_signal(can_signal_t& signal, const can_message_t& message, bool* send); + static openxc_DynamicField decode_signal(signal_t& signal, std::shared_ptr<message_t> message, bool* send); - static openxc_DynamicField decode_signal(can_signal_t& signal, float value, bool* send); + static openxc_DynamicField decode_signal(signal_t& signal, float value, bool* send); static float decode_obd2_response(const DiagnosticResponse* response, float parsed_payload); }; diff --git a/low-can-binding/can/can-encoder.cpp b/low-can-binding/can/can-encoder.cpp index 4b8a2963..a11dedfc 100644 --- a/low-can-binding/can/can-encoder.cpp +++ b/low-can-binding/can/can-encoder.cpp @@ -19,7 +19,7 @@ #include "canutil/write.h" #include "../utils/openxc-utils.hpp" -#include "can-message-definition.hpp" +#include "message-definition.hpp" /// @brief Write a value in a CAN signal in the destination buffer. /// @@ -29,7 +29,7 @@ /// @param[in] length - The length of the destination buffer. /// /// @return Returns a canfd_frame struct initialized and ready to be send. -const canfd_frame encoder_t::build_frame(const std::shared_ptr<can_signal_t>& signal, uint64_t value) +const canfd_frame encoder_t::build_frame(const std::shared_ptr<signal_t>& signal, uint64_t value) { struct canfd_frame cf; ::memset(&cf, 0, sizeof(cf)); @@ -40,7 +40,7 @@ const canfd_frame encoder_t::build_frame(const std::shared_ptr<can_signal_t>& si signal->set_last_value((float)value); - for(const auto& sig: signal->get_message()->get_can_signals()) + for(const auto& sig: signal->get_message()->get_signals()) { float last_value = sig->get_last_value(); bitfield_encode_float(last_value, @@ -69,7 +69,7 @@ const canfd_frame encoder_t::build_frame(const std::shared_ptr<can_signal_t>& si /// @return Returns the encoded integer. If 'send' is changed to false, the field could /// not be encoded and the return value is undefined. /// -uint64_t encoder_t::encode_boolean(const can_signal_t& signal, bool value, bool* send) +uint64_t encoder_t::encode_boolean(const signal_t& signal, bool value, bool* send) { return encode_number(signal, float(value), send); } @@ -87,7 +87,7 @@ uint64_t encoder_t::encode_boolean(const can_signal_t& signal, bool value, bool* /// @return Returns the encoded integer. If 'send' is changed to false, the field could /// not be encoded and the return value is undefined. /// -uint64_t encoder_t::encode_number(const can_signal_t& signal, float value, bool* send) +uint64_t encoder_t::encode_number(const signal_t& signal, float value, bool* send) { return float_to_fixed_point(value, signal.get_factor(), signal.get_offset()); } @@ -109,7 +109,7 @@ uint64_t encoder_t::encode_number(const can_signal_t& signal, float value, bool* /// @return Returns the encoded integer. If 'send' is changed to false, the field could /// not be encoded and the return value is undefined. /// -uint64_t encoder_t::encode_state(const can_signal_t& signal, const std::string& state, bool* send) +uint64_t encoder_t::encode_state(const signal_t& signal, const std::string& state, bool* send) { uint64_t value = 0; if(state == "") @@ -133,7 +133,7 @@ uint64_t encoder_t::encode_state(const can_signal_t& signal, const std::string& /// @brief Parse a signal from a CAN message and apply any required /// transforations to get a human readable value. /// -/// If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value +/// If the signal_t has a non-NULL 'decoder' field, the raw CAN signal value /// will be passed to the decoder before returning. /// /// @param[in] signal - The details of the signal to decode and forward. @@ -144,7 +144,7 @@ uint64_t encoder_t::encode_state(const can_signal_t& signal, const std::string& /// @return The decoder returns an openxc_DynamicField, which may contain a number, /// string or boolean. If 'send' is false, the return value is undefined. /// -uint64_t encoder_t::encode_DynamicField( can_signal_t& signal, const openxc_DynamicField& field, bool* send) +uint64_t encoder_t::encode_DynamicField( signal_t& signal, const openxc_DynamicField& field, bool* send) { uint64_t value = 0; switch(field.type) { diff --git a/low-can-binding/can/can-encoder.hpp b/low-can-binding/can/can-encoder.hpp index 294b1674..6ae786a1 100644 --- a/low-can-binding/can/can-encoder.hpp +++ b/low-can-binding/can/can-encoder.hpp @@ -17,17 +17,17 @@ #pragma once -#include "can-signals.hpp" +#include "signals.hpp" #include "message/can-message.hpp" #include "openxc.pb.h" class encoder_t { public: - static const canfd_frame build_frame(const std::shared_ptr<can_signal_t>& signal, uint64_t value); - static uint64_t encode_state(const can_signal_t& signal, const std::string& value, bool* send); - static uint64_t encode_boolean(const can_signal_t& signal, bool value, bool* send); - static uint64_t encode_number(const can_signal_t& signal, float value, bool* send); + static const canfd_frame build_frame(const std::shared_ptr<signal_t>& signal, uint64_t value); + static uint64_t encode_state(const signal_t& signal, const std::string& value, bool* send); + static uint64_t encode_boolean(const signal_t& signal, bool value, bool* send); + static uint64_t encode_number(const signal_t& signal, float value, bool* send); - static uint64_t encode_DynamicField(can_signal_t& signal, const openxc_DynamicField& field, bool* send); + static uint64_t encode_DynamicField(signal_t& signal, const openxc_DynamicField& field, bool* send); }; diff --git a/low-can-binding/can/can-message-definition.cpp b/low-can-binding/can/message-definition.cpp index 8f2930f6..efc72f07 100644 --- a/low-can-binding/can/can-message-definition.cpp +++ b/low-can-binding/can/message-definition.cpp @@ -15,18 +15,18 @@ * limitations under the License. */ -#include "can-message-definition.hpp" +#include "message-definition.hpp" #include "../binding/application.hpp" -can_message_definition_t::can_message_definition_t( +message_definition_t::message_definition_t( const std::string bus, uint32_t id, bool is_fd, - can_message_format_t format, + message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector<std::shared_ptr<can_signal_t> >& can_signals) + const std::vector<std::shared_ptr<signal_t> >& signals) : parent_{nullptr}, bus_{bus}, id_{id}, @@ -35,18 +35,18 @@ can_message_definition_t::can_message_definition_t( frequency_clock_{frequency_clock}, force_send_changed_{force_send_changed}, last_value_{CAN_MESSAGE_SIZE}, - can_signals_{can_signals} + signals_{signals} {} -can_message_definition_t::can_message_definition_t(const std::string bus, +message_definition_t::message_definition_t(const std::string bus, uint32_t id, const std::string name, uint32_t length, bool is_fd, - can_message_format_t format, + message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector<std::shared_ptr<can_signal_t> >& can_signals) + const std::vector<std::shared_ptr<signal_t> >& signals) : parent_{nullptr}, bus_{bus}, id_{id}, @@ -57,28 +57,28 @@ can_message_definition_t::can_message_definition_t(const std::string bus, frequency_clock_{frequency_clock}, force_send_changed_{force_send_changed}, last_value_{CAN_MESSAGE_SIZE}, - can_signals_{can_signals} + signals_{signals} {} -const std::string can_message_definition_t::get_bus_device_name() const +const std::string message_definition_t::get_bus_device_name() const { return application_t::instance().get_can_bus_manager() .get_can_device_name(bus_); } -uint32_t can_message_definition_t::get_id() const +uint32_t message_definition_t::get_id() const { return id_; } -bool can_message_definition_t::is_fd() const +bool message_definition_t::is_fd() const { return is_fd_; } -bool can_message_definition_t::is_j1939() const +bool message_definition_t::is_j1939() const { - if(format_ == can_message_format_t::J1939) + if(format_ == message_format_t::J1939) { return true; } @@ -88,17 +88,17 @@ bool can_message_definition_t::is_j1939() const } } -std::vector<std::shared_ptr<can_signal_t> >& can_message_definition_t::get_can_signals() +std::vector<std::shared_ptr<signal_t>>& message_definition_t::get_signals() { - return can_signals_; + return signals_; } -void can_message_definition_t::set_parent(can_message_set_t* parent) +void message_definition_t::set_parent(std::shared_ptr<message_set_t> parent) { parent_= parent; } -void can_message_definition_t::set_last_value(const message_t& cm) +void message_definition_t::set_last_value(std::shared_ptr<message_t> m) { - last_value_= cm.get_data_vector(); + last_value_= m->get_data_vector(); } diff --git a/low-can-binding/can/can-message-definition.hpp b/low-can-binding/can/message-definition.hpp index 03c2fbed..1773e6b8 100644 --- a/low-can-binding/can/can-message-definition.hpp +++ b/low-can-binding/can/message-definition.hpp @@ -16,7 +16,7 @@ */ /** - * @class can_message_definition_t + * @class message_definition_t * * @brief The definition of a CAN message. This includes a lot of metadata, so * to save memory this struct should not be used for storing incoming and @@ -28,25 +28,25 @@ #include <vector> #include <memory> -#include "can-signals.hpp" -#include "message/can-message.hpp" -#include "can-message-set.hpp" +#include "signals.hpp" +#include "message-set.hpp" #include "../utils/timer.hpp" +#include "message/message.hpp" -class can_message_set_t; +class message_set_t; /// @brief The definition of a CAN message. This includes a lot of metadata, so -/// to save memory this class gets the can_signal_t object related to a CAN message. -class can_message_definition_t +/// to save memory this class gets the signal_t object related to a CAN message. +class message_definition_t { private: - can_message_set_t* parent_; ///< parent_ - Pointer to the CAN message set holding this CAN message definition */ + std::shared_ptr<message_set_t> parent_; ///< parent_ - Pointer to the CAN message set holding this CAN message definition */ std::string bus_; ///< bus_ - Address of CAN bus device. */ - uint32_t id_; ///< id_ - The ID of the message.*/ + uint32_t id_; ///< id_ - The ID or the PGN (if j1939) of the message.*/ std::string name_; ///< name_ - J1939 PGN name uint32_t length_; ///< length_ - Message data length in bytes. For J1939 message, this is the expected data size bool is_fd_; /*!< uses_fd_ - Flags to enable an FD CAN message communication*/ - can_message_format_t format_; ///< format_ - the format of the message's ID.*/ + message_format_t format_; ///< format_ - the format of the message's ID.*/ frequency_clock_t frequency_clock_; ///< clock_ - an optional frequency clock to control the output of this /// message, if sent raw, or simply to mark the max frequency for custom /// handlers to retrieve.*/ @@ -55,37 +55,38 @@ private: std::vector<uint8_t> last_value_; ///< last_value_ - The last received value of the message. Defaults to undefined. /// This is required for the forceSendChanged functionality, as the stack /// needs to compare an incoming CAN message with the previous frame.*/ - std::vector<std::shared_ptr<can_signal_t> > can_signals_; ///< can_signals_ - Vector holding can_signal_t object which share the same arbitration ID */ + std::vector<std::shared_ptr<signal_t> > signals_; ///< signals_ - Vector holding signal_t object which share the same arbitration ID */ public: - //can_message_definition_t(const can_message_definition_t& b); - can_message_definition_t(const std::string bus); - can_message_definition_t(const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed); - can_message_definition_t(const std::string bus, uint32_t id, can_message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed); - can_message_definition_t(const std::string bus, + //message_definition_t(const message_definition_t& b); + message_definition_t(const std::string bus); + message_definition_t(const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed); + message_definition_t(const std::string bus, uint32_t id, message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed); + message_definition_t(const std::string bus, uint32_t id, bool is_fd, - can_message_format_t format, + message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector<std::shared_ptr<can_signal_t> >& can_signals); - can_message_definition_t(const std::string bus, + const std::vector<std::shared_ptr<signal_t> >& signals); + message_definition_t(const std::string bus, uint32_t id, std::string name, uint32_t length, bool is_fd, - can_message_format_t format, + message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector<std::shared_ptr<can_signal_t> >& can_signals); + const std::vector<std::shared_ptr<signal_t> >& signals); + const std::string get_bus_name() const; const std::string get_bus_device_name() const; uint32_t get_id() const; bool is_fd() const; bool is_j1939() const; - std::vector<std::shared_ptr<can_signal_t> >& get_can_signals(); + std::vector<std::shared_ptr<signal_t>>& get_signals(); - void set_parent(can_message_set_t* parent); - void set_last_value(const message_t& cm); + void set_parent(std::shared_ptr<message_set_t> parent); + void set_last_value(std::shared_ptr<message_t> m); }; diff --git a/low-can-binding/can/can-message-set.cpp b/low-can-binding/can/message-set.cpp index a5cf8819..69682e1a 100644 --- a/low-can-binding/can/can-message-set.cpp +++ b/low-can-binding/can/message-set.cpp @@ -16,44 +16,44 @@ * limitations under the License. */ -#include "can-message-set.hpp" +#include "message-set.hpp" -#include "../can/can-message-definition.hpp" +#include "../can/message-definition.hpp" -can_message_set_t::can_message_set_t( +message_set_t::message_set_t( uint8_t index, const std::string& name, - const std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition, + const std::vector<std::shared_ptr<message_definition_t> >& messages_definition, const std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages) : index_{index} , name_{name} - , can_messages_definition_{can_messages_definition} + , messages_definition_{messages_definition} , diagnostic_messages_{diagnostic_messages} {} /// @brief Returns a vector holding all message definitions which are handled by this message set. -std::vector<std::shared_ptr<can_message_definition_t> >& can_message_set_t::get_can_message_definition() +std::vector<std::shared_ptr<message_definition_t>>& message_set_t::get_messages_definition() { - return can_messages_definition_; + return messages_definition_; } -std::vector<std::shared_ptr<can_signal_t> > can_message_set_t::get_all_can_signals() const +std::vector<std::shared_ptr<signal_t>> message_set_t::get_all_signals() const { - std::vector<std::shared_ptr<can_signal_t> > can_signals; - for(const auto& cmd: can_messages_definition_) + std::vector<std::shared_ptr<signal_t> > signals; + for(const auto& cmd: messages_definition_) { - std::vector<std::shared_ptr<can_signal_t> >& cmd_signals = cmd->get_can_signals(); - can_signals.insert( can_signals.end(), + std::vector<std::shared_ptr<signal_t>> cmd_signals = cmd->get_signals(); + signals.insert( signals.end(), cmd_signals.begin(), cmd_signals.end() ); } - return can_signals; + return signals; } /// @brief Returns a vector holding all diagnostic message definitions which are handled by this message set. -std::vector<std::shared_ptr<diagnostic_message_t> >& can_message_set_t::get_diagnostic_messages() +std::vector<std::shared_ptr<diagnostic_message_t>>& message_set_t::get_diagnostic_messages() { return diagnostic_messages_; -}
\ No newline at end of file +} diff --git a/low-can-binding/can/can-message-set.hpp b/low-can-binding/can/message-set.hpp index 59c27b1a..4af97fa6 100644 --- a/low-can-binding/can/can-message-set.hpp +++ b/low-can-binding/can/message-set.hpp @@ -23,28 +23,28 @@ #include <vector> #include <memory> -class can_signal_t; -class can_message_definition_t; +class signal_t; +class message_definition_t; class diagnostic_message_t; /// @brief A parent wrapper for a particular set of CAN messages and diagnostic messages /// (e.g. a vehicle or program). -class can_message_set_t +class message_set_t { private: uint8_t index_; /// < A numerical ID for the message set, ideally the index is in an array for fast lookup const std::string name_; /// < The name of the message set. - std::vector<std::shared_ptr<can_message_definition_t> > can_messages_definition_; ///< Vector holding all message definitions handled by the message set. + std::vector<std::shared_ptr<message_definition_t> > messages_definition_; ///< Vector holding all message definitions handled by the message set. std::vector<std::shared_ptr<diagnostic_message_t> > diagnostic_messages_; ///< Vector holding all diagnostics messages from JSON signals description file. First vector map to message set public: - can_message_set_t( + message_set_t( uint8_t index, const std::string& name, - const std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition, + const std::vector<std::shared_ptr<message_definition_t> >& messages_definition, const std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages); - std::vector<std::shared_ptr<can_message_definition_t> >& get_can_message_definition(); - std::vector<std::shared_ptr<can_signal_t> > get_all_can_signals() const; - std::vector<std::shared_ptr<diagnostic_message_t> >& get_diagnostic_messages(); + std::vector<std::shared_ptr<message_definition_t>>& get_messages_definition(); + std::vector<std::shared_ptr<signal_t>> get_all_signals() const; + std::vector<std::shared_ptr<diagnostic_message_t>>& get_diagnostic_messages(); }; diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp index 91f66252..b012bbe5 100644 --- a/low-can-binding/can/message/can-message.cpp +++ b/low-can-binding/can/message/can-message.cpp @@ -37,7 +37,7 @@ can_message_t::can_message_t() can_message_t::can_message_t(uint8_t maxdlen, uint32_t id, uint8_t length, - can_message_format_t format, + message_format_t format, bool rtr_flag, uint8_t flags, std::vector<uint8_t>& data, @@ -66,7 +66,7 @@ uint32_t can_message_t::get_id() const /// @return True if object correctly initialized and false if not. bool can_message_t::is_correct_to_send() { - if (id_ != 0 && length_ != 0 && format_ != can_message_format_t::INVALID) + if (id_ != 0 && length_ != 0 && format_ != message_format_t::INVALID) { int i; for(i=0;i<CAN_MESSAGE_SIZE;i++) @@ -88,7 +88,7 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca { uint8_t maxdlen = 0, length = 0, flags = 0; uint32_t id; - can_message_format_t format; + message_format_t format; bool rtr_flag; std::vector<uint8_t> data; @@ -109,17 +109,17 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca if (frame.can_id & CAN_ERR_FLAG) { - format = can_message_format_t::INVALID; + format = message_format_t::INVALID; id = frame.can_id & (CAN_ERR_MASK|CAN_ERR_FLAG); } else if (frame.can_id & CAN_EFF_FLAG) { - format = can_message_format_t::EXTENDED; + format = message_format_t::EXTENDED; id = frame.can_id & CAN_EFF_MASK; } else { - format = can_message_format_t::STANDARD; + format = message_format_t::STANDARD; id = frame.can_id & CAN_SFF_MASK; } diff --git a/low-can-binding/can/message/can-message.hpp b/low-can-binding/can/message/can-message.hpp index 5aa302cc..df0d2a19 100644 --- a/low-can-binding/can/message/can-message.hpp +++ b/low-can-binding/can/message/can-message.hpp @@ -34,7 +34,7 @@ class can_message_t : public message_t { public: can_message_t(); - can_message_t(uint8_t maxdlen, uint32_t id, uint8_t length, can_message_format_t format, bool rtr_flag_, uint8_t flags, std::vector<uint8_t>& data, uint64_t timestamp); + can_message_t(uint8_t maxdlen, uint32_t id, uint8_t length, message_format_t format, bool rtr_flag_, uint8_t flags, std::vector<uint8_t>& data, uint64_t timestamp); uint32_t get_id() const; diff --git a/low-can-binding/can/message/j1939-message.cpp b/low-can-binding/can/message/j1939-message.cpp index 8269cbfa..147ab735 100644 --- a/low-can-binding/can/message/j1939-message.cpp +++ b/low-can-binding/can/message/j1939-message.cpp @@ -33,7 +33,7 @@ j1939_message_t::j1939_message_t(): {} j1939_message_t::j1939_message_t(uint8_t length, - can_message_format_t format, + message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, @@ -86,18 +86,18 @@ uint8_t j1939_message_t::get_addr() const{ std::shared_ptr<j1939_message_t> j1939_message_t::convert_from_addr(struct sockaddr_can& addr, uint8_t (&data)[128],size_t nbytes, uint64_t timestamp) { uint8_t length = 0; - can_message_format_t format; + message_format_t format; std::vector<uint8_t> dataVector; if(nbytes > J1939_MAX_DLEN) { AFB_DEBUG("Unsupported j1939 frame"); - format = can_message_format_t::INVALID; + format = message_format_t::INVALID; } else { AFB_DEBUG("Got a j1939 frame"); - format = can_message_format_t::J1939; + format = message_format_t::J1939; } length = (uint8_t) nbytes; diff --git a/low-can-binding/can/message/j1939-message.hpp b/low-can-binding/can/message/j1939-message.hpp index 74b625e0..b0f0b090 100644 --- a/low-can-binding/can/message/j1939-message.hpp +++ b/low-can-binding/can/message/j1939-message.hpp @@ -58,7 +58,7 @@ class j1939_message_t : public message_t public: j1939_message_t(); - j1939_message_t(uint8_t length, can_message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr); + j1939_message_t(uint8_t length, message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr); uint64_t get_name() const; uint32_t get_pgn() const; uint8_t get_addr() const; diff --git a/low-can-binding/can/message/message.cpp b/low-can-binding/can/message/message.cpp index fe37e7ad..2ae095cb 100644 --- a/low-can-binding/can/message/message.cpp +++ b/low-can-binding/can/message/message.cpp @@ -28,13 +28,13 @@ /// message_t::message_t() : length_{0}, - format_{can_message_format_t::INVALID}, + format_{message_format_t::INVALID}, timestamp_{0}, sub_id_{-1} {} message_t::message_t(uint8_t length, - can_message_format_t format, + message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp) : length_{length}, @@ -90,7 +90,7 @@ uint64_t message_t::get_timestamp() const return timestamp_; } -can_message_format_t message_t::get_msg_format() +message_format_t message_t::get_msg_format() { return format_; } diff --git a/low-can-binding/can/message/message.hpp b/low-can-binding/can/message/message.hpp index 6e0daada..e62b6c6b 100644 --- a/low-can-binding/can/message/message.hpp +++ b/low-can-binding/can/message/message.hpp @@ -40,10 +40,10 @@ struct bcm_msg }; /** - * @enum can_message_format_t + * @enum message_format_t * @brief The ID format for a CAN message. */ -enum class can_message_format_t { +enum class message_format_t { STANDARD, ///< STANDARD - standard 11-bit CAN arbitration ID. */ EXTENDED, ///< EXTENDED - an extended frame, with a 29-bit arbitration ID. */ J1939, ///< J1939 - Format for j1939 messages @@ -58,7 +58,7 @@ enum class can_message_format_t { class message_t { protected: uint8_t length_; ///< length_ - the length of the data array (max 8). */ - can_message_format_t format_; ///< format_ - the format of the message's ID.*/ + message_format_t format_; ///< format_ - the format of the message's ID.*/ std::vector<uint8_t> data_; ///< data_ - The message's data field with a size of 8 which is the standard about CAN bus messages.*/ uint64_t timestamp_; ///< timestamp_ - timestamp of the received message*/ int sub_id_; ///< sub_id_ - Subscription index. */ @@ -66,7 +66,7 @@ protected: public: message_t(); - message_t(uint8_t length, can_message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp); + message_t(uint8_t length, message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp); int get_sub_id() const; const uint8_t* get_data() const; @@ -76,7 +76,7 @@ public: void set_sub_id(int sub_id); void set_timestamp(uint64_t timestamp); - can_message_format_t get_msg_format(); + message_format_t get_msg_format(); virtual bool is_set() = 0; virtual std::string get_debug_message() = 0; virtual uint32_t get_id() const = 0; diff --git a/low-can-binding/can/can-signals.cpp b/low-can-binding/can/signals.cpp index 76a9665f..e843bedb 100644 --- a/low-can-binding/can/can-signals.cpp +++ b/low-can-binding/can/signals.cpp @@ -17,7 +17,7 @@ #include <fnmatch.h> -#include "can-signals.hpp" +#include "signals.hpp" #include "../binding/application.hpp" #include "../utils/signals.hpp" @@ -27,9 +27,9 @@ #include "../diagnostic/diagnostic-message.hpp" #include "canutil/write.h" -std::string can_signal_t::prefix_ = "messages"; +std::string signal_t::prefix_ = "messages"; -can_signal_t::can_signal_t( +signal_t::signal_t( std::string generic_name, uint8_t bit_position, uint8_t bit_size, @@ -44,7 +44,11 @@ can_signal_t::can_signal_t( bool writable, signal_decoder decoder, signal_encoder encoder, - bool received) + bool received, + std::pair<bool,int> multiplex, + bool is_big_endian, + bool is_signed, + std::string unit) : parent_{nullptr}, generic_name_{ generic_name } , bit_position_{ bit_position } @@ -62,61 +66,98 @@ can_signal_t::can_signal_t( , encoder_{encoder} , received_{received} , last_value_{.0f} + , multiplex_{multiplex} + , is_big_endian_{is_big_endian} + , is_signed_{is_signed} + , unit_{unit} {} -can_message_definition_t* can_signal_t::get_message() const +signal_t::signal_t( + std::string generic_name, + uint8_t bit_position, + uint8_t bit_size, + float factor, + float offset, + float min_value, + float max_value, + frequency_clock_t frequency, + bool send_same, + bool force_send_changed, + std::map<uint8_t, std::string> states, + bool writable, + signal_decoder decoder, + signal_encoder encoder, + bool received) + : generic_name_{ generic_name } + , bit_position_{ bit_position } + , bit_size_{ bit_size } + , factor_{ factor } + , offset_{ offset } + , min_value_{min_value} + , max_value_{max_value} + , frequency_{frequency} + , send_same_{send_same} + , force_send_changed_{force_send_changed} + , states_{states} + , writable_{writable} + , decoder_{decoder} + , encoder_{encoder} + , received_{received} +{} + +std::shared_ptr<message_definition_t> signal_t::get_message() const { return parent_; } -const std::string can_signal_t::get_generic_name() const +const std::string signal_t::get_generic_name() const { return generic_name_; } -const std::string can_signal_t::get_name() const +const std::string signal_t::get_name() const { return prefix_ + "." + generic_name_; } -uint8_t can_signal_t::get_bit_position() const +uint8_t signal_t::get_bit_position() const { return bit_position_; } -uint8_t can_signal_t::get_bit_size() const +uint8_t signal_t::get_bit_size() const { return bit_size_; } -float can_signal_t::get_factor() const +float signal_t::get_factor() const { return factor_; } -float can_signal_t::get_offset() const +float signal_t::get_offset() const { return offset_; } -frequency_clock_t& can_signal_t::get_frequency() +frequency_clock_t& signal_t::get_frequency() { return frequency_; } -bool can_signal_t::get_send_same() const +bool signal_t::get_send_same() const { return send_same_; } -const std::string can_signal_t::get_states(uint8_t value) +const std::string signal_t::get_states(uint8_t value) { if ( states_.count(value) > 0 ) return states_[value]; return std::string(); } -uint64_t can_signal_t::get_states(const std::string& value) const +uint64_t signal_t::get_states(const std::string& value) const { uint64_t ret = -1; for( const auto& state: states_) @@ -130,53 +171,72 @@ uint64_t can_signal_t::get_states(const std::string& value) const return ret; } -bool can_signal_t::get_writable() const +bool signal_t::get_writable() const { return writable_; } -signal_decoder& can_signal_t::get_decoder() +signal_decoder& signal_t::get_decoder() { return decoder_; } -signal_encoder& can_signal_t::get_encoder() +signal_encoder& signal_t::get_encoder() { return encoder_; } -bool can_signal_t::get_received() const +bool signal_t::get_received() const { return received_; } -float can_signal_t::get_last_value() const +float signal_t::get_last_value() const { return last_value_; } -std::pair<float, uint64_t> can_signal_t::get_last_value_with_timestamp() const +std::pair<float, uint64_t> signal_t::get_last_value_with_timestamp() const { return std::make_pair(last_value_, frequency_.get_last_tick()); } -void can_signal_t::set_parent(can_message_definition_t* parent) +void signal_t::set_parent(std::shared_ptr<message_definition_t> parent) { parent_ = parent; } -void can_signal_t::set_received(bool r) +void signal_t::set_received(bool r) { received_ = r; } -void can_signal_t::set_last_value(float val) +void signal_t::set_last_value(float val) { last_value_ = val; } -void can_signal_t::set_timestamp(uint64_t timestamp) +void signal_t::set_timestamp(uint64_t timestamp) { frequency_.tick(timestamp); } +std::pair<bool,int> signal_t::get_multiplex() const +{ + return multiplex_; +} + +bool signal_t::get_is_big_endian() const +{ + return is_big_endian_; +} + +bool signal_t::get_is_signed() const +{ + return is_signed_; +} + +const std::string signal_t::get_unit() const +{ + return unit_; +} diff --git a/low-can-binding/can/can-signals.hpp b/low-can-binding/can/signals.hpp index 9ac55081..2507fd2a 100644 --- a/low-can-binding/can/can-signals.hpp +++ b/low-can-binding/can/signals.hpp @@ -24,7 +24,7 @@ #include <memory> #include "openxc.pb.h" -#include "can-message-definition.hpp" +#include "message-definition.hpp" #include "../utils/timer.hpp" #include "../utils/socketcan-bcm.hpp" #include "message/can-message.hpp" @@ -32,7 +32,7 @@ #define MESSAGE_SET_ID 0 -class can_signal_t; +class signal_t; /// /// @brief The type signature for a CAN signal decoder. /// @@ -48,7 +48,7 @@ class can_signal_t; /// /// @return a decoded value in an openxc_DynamicField struct. /// -typedef openxc_DynamicField (*signal_decoder)(can_signal_t& signal, float value, bool* send); +typedef openxc_DynamicField (*signal_decoder)(signal_t& signal, float value, bool* send); /// /// @brief: The type signature for a CAN signal encoder. @@ -61,13 +61,13 @@ typedef openxc_DynamicField (*signal_decoder)(can_signal_t& signal, float value, /// @param[out] send - An output parameter. If the encoding failed or the CAN signal should /// not be encoded for some other reason, this will be flipped to false. /// -typedef uint64_t (*signal_encoder)(can_signal_t& signal, +typedef uint64_t (*signal_encoder)(signal_t& signal, const openxc_DynamicField& field, bool* send); -class can_signal_t +class signal_t { private: - can_message_definition_t* parent_; /*!< parent_ - pointer to the parent message definition holding this signal*/ + std::shared_ptr<message_definition_t> parent_; /*!< parent_ - pointer to the parent message definition holding this signal*/ std::string generic_name_; /*!< generic_name_ - The name of the signal to be output.*/ static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol. * which make easier to sort message when the come in.*/ @@ -99,9 +99,38 @@ private: bool received_; /*!< received_ - True if this signal has ever been received.*/ float last_value_; /*!< lastValue_ - The last received value of the signal. If 'received' is false, * this value is undefined. */ + std::pair<bool,int> multiplex_; /*!< multiplex_ - If bool is false and int is 0 is not a multiplex signal + If bool is true, that indicate that is a multiplexor + If int is different of 0, that indicate the link with a multiplexor */ + bool is_big_endian_; /*!< is_big_endian - True if the signal's data are meant to be read as a big_endian */ + bool is_signed_; /* !< is_signed_ - True if the data is signed */ + std::string unit_; /* !< unit_ - The unit of the data */ public: - can_signal_t( + + signal_t( + std::string generic_name, + uint8_t bit_position, + uint8_t bit_size, + float factor, + float offset, + float min_value, + float max_value, + frequency_clock_t frequency, + bool send_same, + bool force_send_changed, + std::map<uint8_t, std::string> states, + bool writable, + signal_decoder decoder, + signal_encoder encoder, + bool received, + std::pair<bool,int> multiplex, + bool is_big_endian, + bool is_signed, + std::string unit); + + + signal_t( std::string generic_name, uint8_t bit_position, uint8_t bit_size, @@ -118,7 +147,8 @@ public: signal_encoder encoder, bool received); - can_message_definition_t* get_message() const; + + std::shared_ptr<message_definition_t> get_message() const; const std::string get_generic_name() const; const std::string get_name() const; uint8_t get_bit_position() const; @@ -135,8 +165,12 @@ public: bool get_received() const; float get_last_value() const; std::pair<float, uint64_t> get_last_value_with_timestamp() const; + std::pair<bool,int> get_multiplex() const; + bool get_is_big_endian() const; + bool get_is_signed() const; + const std::string get_unit() const; - void set_parent(can_message_definition_t* parent); + void set_parent(std::shared_ptr<message_definition_t> parent); void set_received(bool r); void set_last_value(float val); void set_timestamp(uint64_t timestamp); |