diff options
Diffstat (limited to 'low-can-binding')
-rw-r--r-- | low-can-binding/binding/application-generated.cpp | 22 | ||||
-rw-r--r-- | low-can-binding/can/can-bus.cpp | 14 | ||||
-rw-r--r-- | low-can-binding/can/can-bus.hpp | 2 | ||||
-rw-r--r-- | low-can-binding/can/can-decoder.cpp | 60 | ||||
-rw-r--r-- | low-can-binding/can/can-decoder.hpp | 26 | ||||
-rw-r--r-- | low-can-binding/can/can-signals.cpp | 8 | ||||
-rw-r--r-- | low-can-binding/can/can-signals.hpp | 22 | ||||
-rw-r--r-- | low-can-binding/diagnostic/active-diagnostic-request.hpp | 1 | ||||
-rw-r--r-- | low-can-binding/diagnostic/diagnostic-manager.hpp | 1 | ||||
-rw-r--r-- | low-can-binding/utils/signals.hpp | 2 |
10 files changed, 66 insertions, 92 deletions
diff --git a/low-can-binding/binding/application-generated.cpp b/low-can-binding/binding/application-generated.cpp index 60a21f5..fff40fb 100644 --- a/low-can-binding/binding/application-generated.cpp +++ b/low-can-binding/binding/application-generated.cpp @@ -40,7 +40,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -120,7 +120,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })} @@ -142,7 +142,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -160,7 +160,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -178,7 +178,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -196,7 +196,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -214,7 +214,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })} @@ -236,7 +236,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -254,7 +254,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -272,7 +272,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })}, @@ -290,7 +290,7 @@ application_t::application_t() { }, false, - decoder_t::booleanDecoder, + decoder_t::decode_boolean, nullptr, false })} diff --git a/low-can-binding/can/can-bus.cpp b/low-can-binding/can/can-bus.cpp index 71e7849..e9f9fc7 100644 --- a/low-can-binding/can/can-bus.cpp +++ b/low-can-binding/can/can-bus.cpp @@ -83,7 +83,7 @@ void can_bus_t::process_can_signals(const can_message_t& can_message, std::map<i if( s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id]->get_event())) { bool send = true; - decoded_message = decoder_t::translateSignal(*sig->get_can_signal(), can_message, application_t::instance().get_all_can_signals(), &send); + decoded_message = decoder_t::translate_signal(*sig->get_can_signal(), can_message, &send); openxc_SimpleMessage s_message = build_SimpleMessage(sig->get_name(), decoded_message); vehicle_message = build_VehicleMessage(s_message, can_message.get_timestamp()); @@ -128,7 +128,7 @@ void can_bus_t::process_diagnostic_signals(diagnostic_manager_t& manager, const /// /// It will take from the can_message_q_ queue the next can message to process then it search /// about signal subscribed if there is a valid afb_event for it. We only decode signal for which a -/// subscription has been made. Can message will be decoded using translateSignal that will pass it to the +/// subscription has been made. Can message will be decoded using translate_signal that will pass it to the /// corresponding decoding function if there is one assigned for that signal. If not, it will be the default /// noopDecoder function that will operate on it. /// @@ -297,9 +297,9 @@ void can_bus_t::set_can_devices() { if(conf_file_.check_conf()) { - can_devices_ = conf_file_.get_devices_name(); + can_devices_mapping_ = conf_file_.get_devices_name(); - if(can_devices_.empty()) + if(can_devices_mapping_.empty()) { AFB_ERROR("No mapping found in config file: '%s'. Check it that it have a CANbus-mapping section.", conf_file_.filepath().c_str()); @@ -313,7 +313,7 @@ void can_bus_t::set_can_devices() int can_bus_t::get_can_device_index(const std::string& bus_name) const { int i = 0; - for(const auto& d: can_devices_) + for(const auto& d: can_devices_mapping_) { if(d.first == bus_name) break; @@ -327,8 +327,8 @@ int can_bus_t::get_can_device_index(const std::string& bus_name) const /// general. const std::string can_bus_t::get_can_device_name(const std::string& id_name) const { - std::string ret; - for(const auto& d: can_devices_) + std::string ret = ""; + for(const auto& d: can_devices_mapping_) { if(d.first == id_name) { diff --git a/low-can-binding/can/can-bus.hpp b/low-can-binding/can/can-bus.hpp index a76d3e8..00c740c 100644 --- a/low-can-binding/can/can-bus.hpp +++ b/low-can-binding/can/can-bus.hpp @@ -72,7 +72,7 @@ private: std::mutex decoded_can_message_mutex_; ///< mutex protecting the vehicle_message_q_ queue. std::queue <std::pair<int, openxc_VehicleMessage> > vehicle_message_q_; ///< queue that'll store openxc_VehicleMessage to pushed - std::vector<std::pair<std::string, std::string> > can_devices_; ///< can_devices_ - holds a mapping between logical CAN devices names and linux CAN devices names. + std::vector<std::pair<std::string, std::string> > can_devices_mapping_; ///< can_devices_mapping_ - holds a mapping between logical CAN devices names and linux CAN devices names. public: explicit can_bus_t(utils::config_parser_t conf_file); can_bus_t(can_bus_t&&); diff --git a/low-can-binding/can/can-decoder.cpp b/low-can-binding/can/can-decoder.cpp index b77e13e..0c81d7a 100644 --- a/low-can-binding/can/can-decoder.cpp +++ b/low-can-binding/can/can-decoder.cpp @@ -31,7 +31,7 @@ /// @return Returns the raw value of the signal parsed as a bitfield from the given byte /// array. /// -float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& message) +float decoder_t::parse_signal_bitfield(can_signal_t& signal, const can_message_t& message) { return bitfield_parse_float(message.get_data(), CAN_MESSAGE_SIZE, signal.get_bit_position(), signal.get_bit_size(), signal.get_factor(), @@ -40,11 +40,10 @@ float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& /// @brief Wrap a raw CAN signal value in a DynamicField without modification. /// -/// This is an implementation of the SignalDecoder type signature, and can be +/// This is an implementation of the Signal type signature, and can be /// used directly in the can_signal_t.decoder field. /// /// @param[in] signal - The details of the signal that contains the state mapping. -/// @param[in] signals - The list of all signals /// @param[in] value - The numerical value that will be wrapped in a DynamicField. /// @param[out] send - An output argument that will be set to false if the value should /// not be sent for any reason. @@ -53,8 +52,7 @@ float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& /// its numeric value. The 'send' argument will not be modified as this decoder /// always succeeds. /// -openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, - const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send) +openxc_DynamicField decoder_t::decode_noop(can_signal_t& signal, float value, bool* send) { openxc_DynamicField decoded_value = build_DynamicField(value); @@ -62,11 +60,10 @@ openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, } /// @brief Coerces a numerical value to a boolean. /// -/// This is an implementation of the SignalDecoder type signature, and can be +/// This is an implementation of the Signal type signature, and can be /// used directly in the can_signal_t.decoder field. /// /// @param[in] signal - The details of the signal that contains the state mapping. -/// @param[in] signals - The list of all signals /// @param[in] value - The numerical value that will be converted to a boolean. /// @param[out] send - An output argument that will be set to false if the value should /// not be sent for any reason. @@ -75,8 +72,7 @@ openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, /// is 0.0, otherwise true. The 'send' argument will not be modified as this /// decoder always succeeds. /// -openxc_DynamicField decoder_t::booleanDecoder(can_signal_t& signal, - const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send) +openxc_DynamicField decoder_t::decode_boolean(can_signal_t& signal, float value, bool* send) { openxc_DynamicField decoded_value = build_DynamicField(value == 0.0 ? false : true); @@ -84,21 +80,19 @@ openxc_DynamicField decoder_t::booleanDecoder(can_signal_t& signal, } /// @brief Update the metadata for a signal and the newly received value. /// -/// This is an implementation of the SignalDecoder type signature, and can be +/// This is an implementation of the Signal type signature, and can be /// used directly in the can_signal_t.decoder field. /// /// This function always flips 'send' to false. /// /// @param[in] signal - The details of the signal that contains the state mapping. -/// @param[in] signals - The list of all signals. /// @param[in] value - The numerical value that will be converted to a boolean. /// @param[out] send - This output argument will always be set to false, so the caller will /// know not to publish this value to the pipeline. /// /// @return Return value is undefined. /// -openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal, - const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send) +openxc_DynamicField decoder_t::decode_ignore(can_signal_t& signal, float value, bool* send) { if(send) *send = false; @@ -111,11 +105,10 @@ openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal, /// @brief Find and return the corresponding string state for a CAN signal's /// raw integer value. /// -/// This is an implementation of the SignalDecoder type signature, and can be +/// This is an implementation of the Signal type signature, and can be /// used directly in the can_signal_t.decoder field. /// /// @param[in] signal - The details of the signal that contains the state mapping. -/// @param[in] signals - The list of all signals. /// @param[in] value - The numerical value that should map to a state. /// @param[out] send - An output argument that will be set to false if the value should /// not be sent for any reason. @@ -124,8 +117,7 @@ openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal, /// the signal. If an equivalent isn't found, send is sent to false and the /// return value is undefined. /// -openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal, - const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send) +openxc_DynamicField decoder_t::decode_state(can_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); @@ -146,23 +138,21 @@ openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal, /// /// @param[in] signal - The details of the signal to decode and forward. /// @param[in] message - The received CAN message that should contain this signal. -/// @param[in] signals - an array of all active signals. /// @param[out] 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. /// -openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, const can_message_t& message, - const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send) +openxc_DynamicField decoder_t::translate_signal(can_signal_t& signal, const can_message_t& message, bool* send) { - float value = decoder_t::parseSignalBitfield(signal, message); - AFB_DEBUG("Decoded message from parseSignalBitfield: %f", value); + float value = decoder_t::parse_signal_bitfield(signal, message); + AFB_DEBUG("Decoded message from parse_signal_bitfield: %f", value); // Must call the decoders every time, regardless of if we are going to // decide to send the signal or not. - openxc_DynamicField decoded_value = decoder_t::decodeSignal(signal, - value, signals, send); + openxc_DynamicField decoded_value = decoder_t::decode_signal(signal, + value, send); signal.set_received(true); @@ -185,19 +175,17 @@ openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, const can_m /// /// @param[in] signal - The details of the signal to decode and forward. /// @param[in] value - The numerical value that will be converted to a boolean. -/// @param[in] signals - an array of all active signals. /// @param[out] send - An output parameter that will be flipped to false if the value could /// not be decoded. /// /// @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::decodeSignal( can_signal_t& signal, - float value, const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send) +openxc_DynamicField decoder_t::decode_signal( can_signal_t& signal, float value, bool* send) { - SignalDecoder decoder = signal.get_decoder() == nullptr ? - noopDecoder : signal.get_decoder(); - openxc_DynamicField decoded_value = decoder(signal, signals, + signal_decoder decoder = signal.get_decoder() == nullptr ? + decode_noop : signal.get_decoder(); + openxc_DynamicField decoded_value = decoder(signal, value, send); return decoded_value; } @@ -205,28 +193,26 @@ openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, /// @brief Decode a transformed, human readable value from an raw CAN signal /// already parsed from a CAN message. /// -/// This is the same as decodeSignal but you must parse the bitfield value of the signal from the CAN +/// This is the same as decode_signal but you must parse the bitfield value of the signal from the CAN /// message yourself. This is useful if you need that raw value for something /// else. /// /// @param[in] signal - The details of the signal to decode and forward. /// @param[in] message - Raw CAN message to decode -/// @param[in] signals - an array of all active signals. /// @param[out] send - An output parameter that will be flipped to false if the value could /// not be decoded. /// -openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, - const can_message_t& message, const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send) +openxc_DynamicField decoder_t::decode_signal( can_signal_t& signal, const can_message_t& message, bool* send) { - float value = parseSignalBitfield(signal, message); - return decodeSignal(signal, value, signals, send); + float value = parse_signal_bitfield(signal, message); + return decode_signal(signal, value, send); } /// /// @brief Decode the payload of an OBD-II PID. /// -/// This function matches the type signature for a DiagnosticResponseDecoder, so +/// This function matches the type signature for a DiagnosticResponse, so /// it can be used as the decoder for a DiagnosticRequest. It returns the decoded /// value of the PID, using the standard formulas (see /// http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01). diff --git a/low-can-binding/can/can-decoder.hpp b/low-can-binding/can/can-decoder.hpp index 7eaa4a7..7e7349d 100644 --- a/low-can-binding/can/can-decoder.hpp +++ b/low-can-binding/can/can-decoder.hpp @@ -24,26 +24,18 @@ class decoder_t { public: - static float parseSignalBitfield(can_signal_t& signal, const can_message_t& message); + static float parse_signal_bitfield(can_signal_t& signal, const can_message_t& message); - static openxc_DynamicField stateDecoder(can_signal_t& signal, const std::vector<std::shared_ptr<can_signal_t> >& signals, - float value, bool* send); - static openxc_DynamicField booleanDecoder(can_signal_t& signal, const std::vector<std::shared_ptr<can_signal_t> >& signals, - float value, bool* send); - static openxc_DynamicField ignoreDecoder(can_signal_t& signal, const std::vector<std::shared_ptr<can_signal_t> >& signals, - float value, bool* send); - static openxc_DynamicField noopDecoder(can_signal_t& signal, const std::vector<std::shared_ptr<can_signal_t> >& signals, - float value, bool* send); + 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 translateSignal(can_signal_t& signal, const can_message_t& message, - const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send); + static openxc_DynamicField translate_signal(can_signal_t& signal, const can_message_t& messag, bool* send); - static openxc_DynamicField decodeSignal(can_signal_t& signal, const can_message_t& message, - const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send); + static openxc_DynamicField decode_signal(can_signal_t& signal, const can_message_t& message, bool* send); - static openxc_DynamicField decodeSignal(can_signal_t& signal, float value, - const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send); + static openxc_DynamicField decode_signal(can_signal_t& signal, float value, bool* send); static float decode_obd2_response(const DiagnosticResponse* response, float parsed_payload); - -};
\ No newline at end of file +}; diff --git a/low-can-binding/can/can-signals.cpp b/low-can-binding/can/can-signals.cpp index fe74115..573808a 100644 --- a/low-can-binding/can/can-signals.cpp +++ b/low-can-binding/can/can-signals.cpp @@ -42,8 +42,8 @@ can_signal_t::can_signal_t( bool force_send_changed, std::map<uint8_t, std::string> states, bool writable, - SignalDecoder decoder, - SignalEncoder encoder, + signal_decoder decoder, + signal_encoder encoder, bool received) : parent_{nullptr}, generic_name_{ generic_name } @@ -151,12 +151,12 @@ bool can_signal_t::get_writable() const return writable_; } -SignalDecoder& can_signal_t::get_decoder() +signal_decoder& can_signal_t::get_decoder() { return decoder_; } -SignalEncoder& can_signal_t::get_encoder() +signal_encoder& can_signal_t::get_encoder() { return encoder_; } diff --git a/low-can-binding/can/can-signals.hpp b/low-can-binding/can/can-signals.hpp index a56fc8c..f7ff037 100644 --- a/low-can-binding/can/can-signals.hpp +++ b/low-can-binding/can/can-signals.hpp @@ -36,11 +36,10 @@ class can_signal_t; /// /// @brief The type signature for a CAN signal decoder. /// -/// A SignalDecoder transforms a raw floating point CAN signal into a number, +/// A signal_decoder transforms a raw floating point CAN signal into a number, /// string or boolean. /// /// @param[in] signal - The CAN signal that we are decoding. -/// @param[in] signals - The list of all signals. /// @param[in] signalCount - The length of the signals array. /// @param[in] value - The CAN signal parsed from the message as a raw floating point /// value. @@ -49,13 +48,12 @@ class can_signal_t; /// /// @return a decoded value in an openxc_DynamicField struct. /// -typedef openxc_DynamicField (*SignalDecoder)(can_signal_t& signal, - const std::vector<std::shared_ptr<can_signal_t> >& signals, float value, bool* send); +typedef openxc_DynamicField (*signal_decoder)(can_signal_t& signal, float value, bool* send); /// /// @brief: The type signature for a CAN signal encoder. /// -/// A SignalEncoder transforms a number, string or boolean into a raw floating +/// A signal_encoder transforms a number, string or boolean into a raw floating /// point value that fits in the CAN signal. /// /// @param[in] signal - The CAN signal to encode. @@ -63,7 +61,7 @@ typedef openxc_DynamicField (*SignalDecoder)(can_signal_t& signal, /// @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 (*SignalEncoder)(can_signal_t* signal, +typedef uint64_t (*signal_encoder)(can_signal_t* signal, openxc_DynamicField* value, bool* send); class can_signal_t @@ -93,9 +91,9 @@ private: * between numerical and string values for valid states. */ bool writable_; /*!< writable - True if the signal is allowed to be written from the USB host * back to CAN. Defaults to false.*/ - SignalDecoder decoder_; /*!< decoder_ - An optional function to decode a signal from the bus to a human + signal_decoder decoder_; /*!< decoder_ - An optional function to decode a signal from the bus to a human * readable value. If NULL, the default numerical decoder is used. */ - SignalEncoder encoder_; /*!< encoder_ - An optional function to encode a signal value to be written to + signal_encoder encoder_; /*!< encoder_ - An optional function to encode a signal value to be written to * CAN into a byte array. If NULL, the default numerical encoder * is used. */ bool received_; /*!< received_ - True if this signal has ever been received.*/ @@ -116,8 +114,8 @@ public: bool force_send_changed, std::map<uint8_t, std::string> states, bool writable, - SignalDecoder decoder, - SignalEncoder encoder, + signal_decoder decoder, + signal_encoder encoder, bool received); can_message_definition_t* get_message() const; @@ -137,8 +135,8 @@ public: const std::string get_states(uint8_t value); size_t get_state_count() const; bool get_writable() const; - SignalDecoder& get_decoder(); - SignalEncoder& get_encoder(); + signal_decoder& get_decoder(); + signal_encoder& get_encoder(); bool get_received() const; float get_last_value() const; std::pair<float, uint64_t> get_last_value_with_timestamp() const; diff --git a/low-can-binding/diagnostic/active-diagnostic-request.hpp b/low-can-binding/diagnostic/active-diagnostic-request.hpp index d263a2d..ff503d8 100644 --- a/low-can-binding/diagnostic/active-diagnostic-request.hpp +++ b/low-can-binding/diagnostic/active-diagnostic-request.hpp @@ -67,7 +67,6 @@ private: DiagnosticRequestHandle* handle_; ///< handle_ - A handle for the request to keep track of it between ///< sending the frames of the request and receiving all frames of the response. std::string name_; ///< name_ - Human readable name, to be used when publishing received responses. - ///< TODO: If the name is NULL, the published output will use the raw OBD-II response format. static std::string prefix_; ///< prefix_ - It has to reflect the JSON object which it comes from. It makes easier sorting ///< incoming CAN messages. DiagnosticResponseDecoder decoder_; ///< decoder_ - An optional DiagnosticResponseDecoder to parse the payload of responses diff --git a/low-can-binding/diagnostic/diagnostic-manager.hpp b/low-can-binding/diagnostic/diagnostic-manager.hpp index 05a67c8..b503a06 100644 --- a/low-can-binding/diagnostic/diagnostic-manager.hpp +++ b/low-can-binding/diagnostic/diagnostic-manager.hpp @@ -30,7 +30,6 @@ /// Each CAN bus needs its own set of shim functions, so this should /// match the maximum CAN controller count. /// -#define MAX_SHIM_COUNT can_bus_t.get_can_devices().size() #define DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET 0x8 class active_diagnostic_request_t; diff --git a/low-can-binding/utils/signals.hpp b/low-can-binding/utils/signals.hpp index 555c5dd..c604b87 100644 --- a/low-can-binding/utils/signals.hpp +++ b/low-can-binding/utils/signals.hpp @@ -83,4 +83,4 @@ namespace utils } } }; -}
\ No newline at end of file +} |