From 2f60d294b3fa4e243fa67a738f9b82a0b428a7fc Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 26 Jun 2019 15:51:19 +0200 Subject: Rename some of the classes removing can- prefix This commit renames files and classes : - can_message_definition_t -> message_definition_t - can_message_set_t -> message_set_t - can_signals_t -> signals_t This prepares the implementation of j1939 protocol. Bug-AGL: SPEC-2386 Change-Id: Ie3ee4f25c236c861b92eb12a56fa03a5a9afffbb Signed-off-by: Arthur Guyader Signed-off-by: Stephane Desneux Signed-off-by: Romain Forlot --- low-can-binding/CMakeLists.txt | 6 +- low-can-binding/binding/application-generated.cpp | 102 ++++----- low-can-binding/binding/application.cpp | 24 +-- low-can-binding/binding/application.hpp | 16 +- low-can-binding/binding/low-can-cb.cpp | 28 +-- low-can-binding/binding/low-can-subscription.cpp | 40 ++-- low-can-binding/binding/low-can-subscription.hpp | 14 +- low-can-binding/can/can-bus.cpp | 14 +- low-can-binding/can/can-bus.hpp | 4 +- low-can-binding/can/can-command.hpp | 4 +- low-can-binding/can/can-decoder.cpp | 34 +-- low-can-binding/can/can-decoder.hpp | 18 +- low-can-binding/can/can-encoder.cpp | 16 +- low-can-binding/can/can-encoder.hpp | 12 +- low-can-binding/can/can-message-definition.cpp | 104 ---------- low-can-binding/can/can-message-definition.hpp | 91 -------- low-can-binding/can/can-message-set.cpp | 59 ------ low-can-binding/can/can-message-set.hpp | 50 ----- low-can-binding/can/can-signals.cpp | 182 ---------------- low-can-binding/can/can-signals.hpp | 143 ------------- low-can-binding/can/message-definition.cpp | 104 ++++++++++ low-can-binding/can/message-definition.hpp | 92 ++++++++ low-can-binding/can/message-set.cpp | 59 ++++++ low-can-binding/can/message-set.hpp | 50 +++++ low-can-binding/can/message/can-message.cpp | 12 +- low-can-binding/can/message/can-message.hpp | 2 +- low-can-binding/can/message/j1939-message.cpp | 8 +- low-can-binding/can/message/j1939-message.hpp | 2 +- low-can-binding/can/message/message.cpp | 6 +- low-can-binding/can/message/message.hpp | 10 +- low-can-binding/can/signals.cpp | 242 ++++++++++++++++++++++ low-can-binding/can/signals.hpp | 177 ++++++++++++++++ low-can-binding/diagnostic/diagnostic-manager.cpp | 2 +- low-can-binding/diagnostic/diagnostic-message.cpp | 2 +- low-can-binding/diagnostic/diagnostic-message.hpp | 6 +- low-can-binding/utils/signals.cpp | 8 +- low-can-binding/utils/signals.hpp | 6 +- 37 files changed, 922 insertions(+), 827 deletions(-) delete mode 100644 low-can-binding/can/can-message-definition.cpp delete mode 100644 low-can-binding/can/can-message-definition.hpp delete mode 100644 low-can-binding/can/can-message-set.cpp delete mode 100644 low-can-binding/can/can-message-set.hpp delete mode 100644 low-can-binding/can/can-signals.cpp delete mode 100644 low-can-binding/can/can-signals.hpp create mode 100644 low-can-binding/can/message-definition.cpp create mode 100644 low-can-binding/can/message-definition.hpp create mode 100644 low-can-binding/can/message-set.cpp create mode 100644 low-can-binding/can/message-set.hpp create mode 100644 low-can-binding/can/signals.cpp create mode 100644 low-can-binding/can/signals.hpp diff --git a/low-can-binding/CMakeLists.txt b/low-can-binding/CMakeLists.txt index 5c0ef07e..71e467d1 100644 --- a/low-can-binding/CMakeLists.txt +++ b/low-can-binding/CMakeLists.txt @@ -28,11 +28,11 @@ PROJECT_TARGET_ADD(low-can) binding/${TARGET_NAME}-subscription.cpp binding/application.cpp can/can-bus.cpp - can/can-message-set.cpp - can/can-message-definition.cpp + can/message-set.cpp + can/message-definition.cpp can/message/message.cpp can/message/can-message.cpp - can/can-signals.cpp + can/signals.cpp can/can-decoder.cpp can/can-encoder.cpp diagnostic/diagnostic-message.cpp diff --git a/low-can-binding/binding/application-generated.cpp b/low-can-binding/binding/application-generated.cpp index 45b6a8cc..de7d6a17 100644 --- a/low-can-binding/binding/application-generated.cpp +++ b/low-can-binding/binding/application-generated.cpp @@ -4,18 +4,18 @@ application_t::application_t() : can_bus_manager_{utils::config_parser_t{"/etc/dev-mapping.conf"}} - , can_message_set_{ - {std::make_shared(can_message_set_t{0,"AGL Virtual Car", + , message_set_{ + {std::make_shared(message_set_t{0,"AGL Virtual Car", { // beginning can_message_definition_ vector - {std::make_shared(can_message_definition_t{ + {std::make_shared(message_definition_t{ "ls", 0x30, false, - can_message_format_t::EXTENDED, + message_format_t::EXTENDED, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "hvac.fan.speed", 32, 8, @@ -33,7 +33,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "hvac.temperature.left", 0, 8, @@ -51,7 +51,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "hvac.temperature.right", 8, 8, @@ -69,7 +69,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "hvac.temperature.average", 16, 8, @@ -89,15 +89,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x3D9, true, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "engine.speed", 16, 16, @@ -115,7 +115,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "fuel.level.low", 55, 1, @@ -133,7 +133,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "fuel.level", 8, 8, @@ -153,15 +153,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x3E9, false, - can_message_format_t::EXTENDED, + message_format_t::EXTENDED, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "vehicle.average.speed", 0, 15, @@ -181,15 +181,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x4D1, false, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "engine.oil.temp", 16, 8, @@ -207,7 +207,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "engine.oil.temp.high", 7, 1, @@ -227,15 +227,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x5D1, false, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "accelerator.pedal.position", 16, 8, @@ -253,7 +253,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "steering.wheel.angle", 4, 12, @@ -273,15 +273,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x5D2, false, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "transmission.gearinfo", 20, 4, @@ -299,7 +299,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "transmission.mode", 16, 4, @@ -319,15 +319,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x5D3, false, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "turnsignal.status", 26, 3, @@ -345,7 +345,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "lightstatus.brake", 7, 1, @@ -363,7 +363,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "parking.brake.status", 8, 1, @@ -383,15 +383,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x620, false, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "doors.boot.open", 47, 1, @@ -409,7 +409,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "doors.front_left.open", 43, 1, @@ -427,7 +427,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "doors.front_right.open", 44, 1, @@ -445,7 +445,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "doors.rear_left.open", 46, 1, @@ -463,7 +463,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "doors.rear_right.open", 45, 4, @@ -483,15 +483,15 @@ application_t::application_t() })} } // end can_signals vector })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{ +, {std::make_shared(message_definition_t{ "hs", 0x799, false, - can_message_format_t::STANDARD, + message_format_t::STANDARD, frequency_clock_t(5.00000f), true, { // beginning can_signals vector - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "windows.front_left.open", 43, 1, @@ -509,7 +509,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "windows.front_right.open", 44, 1, @@ -527,7 +527,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "windows.rear_left.open", 46, 1, @@ -545,7 +545,7 @@ application_t::application_t() nullptr, false })}, - {std::make_shared (can_signal_t{ + {std::make_shared (signal_t{ "windows.rear_right.open", 45, 4, @@ -825,16 +825,16 @@ application_t::application_t() })} // end can_message_set entry } // end can_message_set vector { - for(auto& cms: can_message_set_) + for(auto& cms: message_set_) { - std::vector >& can_messages_definition = cms->get_can_message_definition(); + std::vector >& can_messages_definition = cms->get_messages_definition(); for(auto& cmd : can_messages_definition) { - cmd->set_parent(cms.get()); - std::vector >& can_signals = cmd->get_can_signals(); + cmd->set_parent(cms); + std::vector >& can_signals = cmd->get_signals(); for(auto& sig: can_signals) { - sig->set_parent(cmd.get()); + sig->set_parent(cmd); } } diff --git a/low-can-binding/binding/application.cpp b/low-can-binding/binding/application.cpp index a85b5184..5e0a6537 100644 --- a/low-can-binding/binding/application.cpp +++ b/low-can-binding/binding/application.cpp @@ -52,24 +52,24 @@ uint8_t application_t::get_active_message_set() const return active_message_set_; } -std::vector > application_t::get_can_message_set() +std::vector > application_t::get_message_set() { - return can_message_set_; + return message_set_; } -std::vector > application_t::get_all_can_signals() +std::vector > application_t::get_all_signals() { - return can_message_set_[active_message_set_]->get_all_can_signals(); + return message_set_[active_message_set_]->get_all_signals(); } -std::vector >& application_t::get_diagnostic_messages() +std::vector > application_t::get_diagnostic_messages() { - return can_message_set_[active_message_set_]->get_diagnostic_messages(); + return message_set_[active_message_set_]->get_diagnostic_messages(); } -std::vector >& application_t::get_can_message_definition() +std::vector> application_t::get_messages_definition() { - return can_message_set_[active_message_set_]->get_can_message_definition(); + return message_set_[active_message_set_]->get_messages_definition(); } uint32_t application_t::get_signal_id(diagnostic_message_t& sig) const @@ -77,7 +77,7 @@ uint32_t application_t::get_signal_id(diagnostic_message_t& sig) const return sig.get_pid(); } -uint32_t application_t::get_signal_id(can_signal_t& sig) const +uint32_t application_t::get_signal_id(signal_t& sig) const { return sig.get_message()->get_id(); } @@ -95,12 +95,12 @@ bool application_t::isEngineOn() bool engine_on = false; uint64_t last_timestamp_in_s; - if(sf.can_signals.size() == 1) + if(sf.signals.size() == 1) { - last_timestamp_in_s = sf.can_signals.front()->get_last_value_with_timestamp().second + last_timestamp_in_s = sf.signals.front()->get_last_value_with_timestamp().second / MICROSECONDS_IN_SECOND; - if(sf.can_signals.front()->get_last_value_with_timestamp().first > 0 && + if(sf.signals.front()->get_last_value_with_timestamp().first > 0 && std::difftime(std::time(nullptr), last_timestamp_in_s) < ENGINE_VALUE_TIMEOUT) { engine_on = true; diff --git a/low-can-binding/binding/application.hpp b/low-can-binding/binding/application.hpp index e017685b..f56900a7 100644 --- a/low-can-binding/binding/application.hpp +++ b/low-can-binding/binding/application.hpp @@ -23,8 +23,8 @@ #include #include "../can/can-bus.hpp" -#include "../can/can-message-set.hpp" -#include "../can/can-signals.hpp" +#include "../can/message-set.hpp" +#include "../can/signals.hpp" #include "../diagnostic/diagnostic-manager.hpp" /// @@ -45,7 +45,7 @@ class application_t diagnostic_manager_t diagnostic_manager_; ///< Diagnostic manager use to manage diagnostic message communication. uint8_t active_message_set_ = 0; ///< Which is the active message set ? Default to 0. - std::vector > can_message_set_; ///< Vector holding all message set from JSON signals description file + std::vector > message_set_; ///< Vector holding all message set from JSON signals description file std::map > can_devices_; ///< Map containing all independant opened CAN sockets, key is the socket int value. @@ -64,19 +64,19 @@ class application_t uint8_t get_active_message_set() const; - std::vector > get_can_message_set(); + std::vector > get_message_set(); - std::vector > get_all_can_signals(); + std::vector > get_all_signals(); - std::vector >& get_diagnostic_messages(); + std::vector > get_diagnostic_messages(); const std::vector& get_signals_prefix() const; - std::vector >& get_can_message_definition(); + std::vector > get_messages_definition(); uint32_t get_signal_id(diagnostic_message_t& sig) const; - uint32_t get_signal_id(can_signal_t& sig) const; + uint32_t get_signal_id(signal_t& sig) const; bool isEngineOn(); diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index 9515424a..8edd1daa 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -31,7 +31,7 @@ #include "application.hpp" #include "../can/can-encoder.hpp" #include "../can/can-bus.hpp" -#include "../can/can-signals.hpp" +#include "../can/signals.hpp" #include "../can/message/message.hpp" #include "../utils/signals.hpp" #include "../diagnostic/diagnostic-message.hpp" @@ -241,14 +241,14 @@ static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request, return rets; } -static int subscribe_unsubscribe_can_signals(afb_req_t request, +static int subscribe_unsubscribe_signals(afb_req_t request, bool subscribe, - std::vector > can_signals, + std::vector > signals, struct event_filter_t& event_filter, std::map >& s) { int rets = 0; - for(const auto& sig: can_signals) + for(const auto& sig: signals) { auto it = std::find_if(s.begin(), s.end(), [&sig, &event_filter](std::pair > sub){ return sub.second->is_signal_subscription_corresponding(sig, event_filter) ; }); std::shared_ptr can_subscription; @@ -277,7 +277,7 @@ static int subscribe_unsubscribe_can_signals(afb_req_t request, /// /// @param[in] afb_req request : contains original request use to subscribe or unsubscribe /// @param[in] subscribe boolean value, which chooses between a subscription operation or an unsubscription -/// @param[in] signals - struct containing vectors with can_signal_t and diagnostic_messages to subscribe +/// @param[in] signals - struct containing vectors with signal_t and diagnostic_messages to subscribe /// /// @return Number of correctly subscribed signal /// @@ -293,7 +293,7 @@ static int subscribe_unsubscribe_signals(afb_req_t request, std::map >& s = sm.get_subscribed_signals(); rets += subscribe_unsubscribe_diagnostic_messages(request, subscribe, signals.diagnostic_messages, event_filter, s, false); - rets += subscribe_unsubscribe_can_signals(request, subscribe, signals.can_signals, event_filter, s); + rets += subscribe_unsubscribe_signals(request, subscribe, signals.signals, event_filter, s); return rets; } @@ -325,7 +325,7 @@ static int one_subscribe_unsubscribe(afb_req_t request, // subscribe or unsubscribe openxc_DynamicField search_key = build_DynamicField(tag); sf = utils::signals_manager_t::instance().find_signals(search_key); - if (sf.can_signals.empty() && sf.diagnostic_messages.empty()) + if (sf.signals.empty() && sf.diagnostic_messages.empty()) { AFB_NOTICE("No signal(s) found for %s.", tag.c_str()); ret = -1; @@ -466,13 +466,13 @@ static void write_signal(afb_req_t request, const std::string& name, json_object sf = utils::signals_manager_t::instance().find_signals(search_key); openxc_DynamicField dynafield_value = build_DynamicField(json_value); - if (sf.can_signals.empty()) + if (sf.signals.empty()) { afb_req_fail_f(request, "No signal(s) found for %s. Message not sent.", name.c_str()); return; } - std::shared_ptr& sig = sf.can_signals[0]; + std::shared_ptr& sig = sf.signals[0]; if(! sig->get_writable()) { afb_req_fail_f(request, "%s isn't writable. Message not sent.", sig->get_name().c_str()); @@ -521,13 +521,13 @@ static struct json_object *get_signals_value(const std::string& name) openxc_DynamicField search_key = build_DynamicField(name); sf = utils::signals_manager_t::instance().find_signals(search_key); - if (sf.can_signals.empty()) + if (sf.signals.empty()) { AFB_WARNING("No signal(s) found for %s.", name.c_str()); return NULL; } ans = json_object_new_array(); - for(const auto& sig: sf.can_signals) + for(const auto& sig: sf.signals) { struct json_object *jobj = json_object_new_object(); json_object_object_add(jobj, "event", json_object_new_string(sig->get_name().c_str())); @@ -575,13 +575,13 @@ static struct json_object *list_can_message(const std::string& name) openxc_DynamicField search_key = build_DynamicField(name); sf = utils::signals_manager_t::instance().find_signals(search_key); - if (sf.can_signals.empty() && sf.diagnostic_messages.empty()) + if (sf.signals.empty() && sf.diagnostic_messages.empty()) { AFB_WARNING("No signal(s) found for %s.", name.c_str()); return NULL; } ans = json_object_new_array(); - for(const auto& sig: sf.can_signals) + for(const auto& sig: sf.signals) { json_object_array_add(ans, json_object_new_string(sig->get_name().c_str())); @@ -646,7 +646,7 @@ int init_binding(afb_api_t api) openxc_DynamicField search_key = build_DynamicField("diagnostic_messages.engine.speed"); struct utils::signals_found sf = utils::signals_manager_t::instance().find_signals(search_key); - if(sf.can_signals.empty() && sf.diagnostic_messages.size() == 1) + if(sf.signals.empty() && sf.diagnostic_messages.size() == 1) { afb_req_t request = nullptr; diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index 27f4ebba..8e4429f5 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -59,7 +59,7 @@ low_can_subscription_t::~low_can_subscription_t() low_can_subscription_t::operator bool() const { - return ((can_signal_ != nullptr || ! diagnostic_message_.empty()) && ! socket_); + return ((signal_ != nullptr || ! diagnostic_message_.empty()) && ! socket_); } afb_event_t low_can_subscription_t::get_event() { @@ -118,14 +118,14 @@ int low_can_subscription_t::get_index() const return index_; } -const std::shared_ptr low_can_subscription_t::get_can_signal() const +const std::shared_ptr low_can_subscription_t::get_signal() const { - return can_signal_; + return signal_; } -bool low_can_subscription_t::is_signal_subscription_corresponding(const std::shared_ptr can_signal, const struct event_filter_t& event_filter) const +bool low_can_subscription_t::is_signal_subscription_corresponding(const std::shared_ptr signal, const struct event_filter_t& event_filter) const { - return can_signal_ == can_signal && event_filter_ == event_filter; + return signal_ == signal && event_filter_ == event_filter; } const std::vector > low_can_subscription_t::get_diagnostic_message() const @@ -169,8 +169,8 @@ const std::shared_ptr low_can_subscription_t::get_diagnost /// or no CAN signal subscribed const std::string low_can_subscription_t::get_name() const { - if (can_signal_ != nullptr) - return can_signal_->get_name(); + if (signal_ != nullptr) + return signal_->get_name(); else if (!diagnostic_message_.empty()) return "diagnostic_messages"; @@ -233,8 +233,8 @@ int low_can_subscription_t::open_socket(const std::string& bus_name) int ret = 0; if(! socket_) { - if( can_signal_ != nullptr) - {ret = socket_->open(can_signal_->get_message()->get_bus_device_name());} + if( signal_ != nullptr) + {ret = socket_->open(signal_->get_message()->get_bus_device_name());} else if (! diagnostic_message_ .empty()) {ret = socket_->open(application_t::instance().get_diagnostic_manager().get_bus_device_name());} else if ( ! bus_name.empty()) @@ -284,9 +284,9 @@ void low_can_subscription_t::add_one_bcm_frame(struct canfd_frame& cfd, struct b } #ifdef USE_FEATURE_J1939 -int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subscription, std::shared_ptr sig) +int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subscription, std::shared_ptr sig) { - subscription.can_signal_= sig; + subscription.signal_= sig; // Make sure that socket is opened. if(subscription.open_socket() < 0) @@ -301,13 +301,13 @@ int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subsc /// subscription /// /// @return 0 if ok else -1 -int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscription, std::shared_ptr sig) +int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscription, std::shared_ptr sig) { uint32_t flags; float val; struct timeval freq, timeout = {0, 0}; struct canfd_frame cfd; - subscription.can_signal_= sig; + subscription.signal_= sig; if (sig->get_message()->is_fd()) { @@ -319,26 +319,26 @@ int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscri flags = SETTIMER|RX_NO_AUTOTIMER; cfd.len = CAN_MAX_DLEN; } - val = (float)(1 << subscription.can_signal_->get_bit_size()) - 1; + val = (float)(1 << subscription.signal_->get_bit_size()) - 1; if(! bitfield_encode_float(val, - subscription.can_signal_->get_bit_position(), - subscription.can_signal_->get_bit_size(), + subscription.signal_->get_bit_position(), + subscription.signal_->get_bit_size(), 1, - subscription.can_signal_->get_offset(), + subscription.signal_->get_offset(), cfd.data, cfd.len)) return -1; - frequency_clock_t f = subscription.event_filter_.frequency == 0 ? subscription.can_signal_->get_frequency() : frequency_clock_t(subscription.event_filter_.frequency); + frequency_clock_t f = subscription.event_filter_.frequency == 0 ? subscription.signal_->get_frequency() : frequency_clock_t(subscription.event_filter_.frequency); freq = f.get_timeval_from_period(); - struct bcm_msg bcm_msg = subscription.make_bcm_head(RX_SETUP, subscription.can_signal_->get_message()->get_id(), flags, timeout, freq); + struct bcm_msg bcm_msg = subscription.make_bcm_head(RX_SETUP, subscription.signal_->get_message()->get_id(), flags, timeout, freq); subscription.add_one_bcm_frame(cfd, bcm_msg); return create_rx_filter_bcm(subscription, bcm_msg); } -int low_can_subscription_t::create_rx_filter(std::shared_ptr sig) +int low_can_subscription_t::create_rx_filter(std::shared_ptr sig) { #ifdef USE_FEATURE_J1939 if(sig->get_message()->is_j1939()) diff --git a/low-can-binding/binding/low-can-subscription.hpp b/low-can-binding/binding/low-can-subscription.hpp index c9cd2e3f..01264ff4 100644 --- a/low-can-binding/binding/low-can-subscription.hpp +++ b/low-can-binding/binding/low-can-subscription.hpp @@ -21,7 +21,7 @@ #include #include -#include "../can/can-signals.hpp" +#include "../can/signals.hpp" #include "../diagnostic/diagnostic-message.hpp" #include "../utils/socketcan-bcm.hpp" @@ -51,7 +51,7 @@ private: afb_event_t event_; ///< event_ - application framework event used to push on client /// Signal part - std::shared_ptr can_signal_; ///< can_signal_ - the CAN signal subscribed + std::shared_ptr signal_; ///< signal_ - the CAN signal subscribed std::vector > diagnostic_message_; ///< diagnostic_message_ - diagnostic messages meant to receive OBD2 /// responses. Normal diagnostic request and response are not tested for now. std::shared_ptr socket_; ///< socket_ - socket_ that receives CAN messages. @@ -73,8 +73,8 @@ public: int unsubscribe(afb_req_t request); int get_index() const; - const std::shared_ptr get_can_signal() const; - bool is_signal_subscription_corresponding(const std::shared_ptr, const struct event_filter_t& event_filter) const; + const std::shared_ptr get_signal() const; + bool is_signal_subscription_corresponding(const std::shared_ptr, const struct event_filter_t& event_filter) const; const std::shared_ptr get_diagnostic_message(uint32_t pid) const; const std::vector > get_diagnostic_message() const; const std::shared_ptr get_diagnostic_message(const std::string& name) const; @@ -94,10 +94,10 @@ public: int open_socket(const std::string& bus_name = ""); - int create_rx_filter(std::shared_ptr sig); + int create_rx_filter(std::shared_ptr sig); int create_rx_filter(std::shared_ptr sig); - static int create_rx_filter_can(low_can_subscription_t &subscription, std::shared_ptr sig); - static int create_rx_filter_j1939(low_can_subscription_t &subscription, std::shared_ptr sig); + static int create_rx_filter_can(low_can_subscription_t &subscription, std::shared_ptr sig); + static int create_rx_filter_j1939(low_can_subscription_t &subscription, std::shared_ptr sig); static int create_rx_filter_bcm(low_can_subscription_t &subscription, struct bcm_msg& bcm_msg); static int tx_send(low_can_subscription_t &subscription, struct canfd_frame& cfd, const std::string& bus_name); 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 >& s) +void can_bus_t::process_signals(std::shared_ptr message, std::map >& 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 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 can_subscription); - void process_signals(const message_t& message, std::map >& s); - void process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr message, std::map >& s); + void process_signals(std::shared_ptr message, std::map >& s); + void process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr can_message, std::map >& 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) { - 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, 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, 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); - 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, 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, 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& signal, uint64_t value) +const canfd_frame encoder_t::build_frame(const std::shared_ptr& 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& 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& 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& 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, 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/can-message-definition.cpp deleted file mode 100644 index 8f2930f6..00000000 --- a/low-can-binding/can/can-message-definition.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2015, 2016 "IoT.bzh" - * Author "Romain Forlot" - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "can-message-definition.hpp" - -#include "../binding/application.hpp" - -can_message_definition_t::can_message_definition_t( - const std::string bus, - uint32_t id, - bool is_fd, - can_message_format_t format, - frequency_clock_t frequency_clock, - bool force_send_changed, - const std::vector >& can_signals) - : parent_{nullptr}, - bus_{bus}, - id_{id}, - is_fd_(is_fd), - format_{format}, - frequency_clock_{frequency_clock}, - force_send_changed_{force_send_changed}, - last_value_{CAN_MESSAGE_SIZE}, - can_signals_{can_signals} -{} - -can_message_definition_t::can_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, - frequency_clock_t frequency_clock, - bool force_send_changed, - const std::vector >& can_signals) - : parent_{nullptr}, - bus_{bus}, - id_{id}, - name_{name}, - length_{length}, - is_fd_(is_fd), - format_{format}, - frequency_clock_{frequency_clock}, - force_send_changed_{force_send_changed}, - last_value_{CAN_MESSAGE_SIZE}, - can_signals_{can_signals} -{} - -const std::string can_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 -{ - return id_; -} - -bool can_message_definition_t::is_fd() const -{ - return is_fd_; -} - -bool can_message_definition_t::is_j1939() const -{ - if(format_ == can_message_format_t::J1939) - { - return true; - } - else - { - return false; - } -} - -std::vector >& can_message_definition_t::get_can_signals() -{ - return can_signals_; -} - -void can_message_definition_t::set_parent(can_message_set_t* parent) -{ - parent_= parent; -} - -void can_message_definition_t::set_last_value(const message_t& cm) -{ - last_value_= cm.get_data_vector(); -} diff --git a/low-can-binding/can/can-message-definition.hpp b/low-can-binding/can/can-message-definition.hpp deleted file mode 100644 index 03c2fbed..00000000 --- a/low-can-binding/can/can-message-definition.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2015, 2016 "IoT.bzh" - * Author "Romain Forlot" - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @class can_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 - * outgoing CAN messages. - */ - -#pragma once - -#include -#include - -#include "can-signals.hpp" -#include "message/can-message.hpp" -#include "can-message-set.hpp" -#include "../utils/timer.hpp" - -class can_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 -{ -private: - can_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.*/ - 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.*/ - 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.*/ - bool force_send_changed_; ///< force_send_changed_ - If true, regardless of the frequency, it will send CAN - /// message if it has changed when using raw passthrough.*/ - std::vector 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 > can_signals_; ///< can_signals_ - Vector holding can_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, - uint32_t id, - bool is_fd, - can_message_format_t format, - frequency_clock_t frequency_clock, - bool force_send_changed, - const std::vector >& can_signals); - can_message_definition_t(const std::string bus, - uint32_t id, - std::string name, - uint32_t length, - bool is_fd, - can_message_format_t format, - frequency_clock_t frequency_clock, - bool force_send_changed, - const std::vector >& can_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 >& get_can_signals(); - - void set_parent(can_message_set_t* parent); - void set_last_value(const message_t& cm); -}; diff --git a/low-can-binding/can/can-message-set.cpp b/low-can-binding/can/can-message-set.cpp deleted file mode 100644 index a5cf8819..00000000 --- a/low-can-binding/can/can-message-set.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2015, 2016, 2017 "IoT.bzh" - * Author "Romain Forlot" - * Author "Loïc Collignon" - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "can-message-set.hpp" - -#include "../can/can-message-definition.hpp" - -can_message_set_t::can_message_set_t( - uint8_t index, - const std::string& name, - const std::vector >& can_messages_definition, - const std::vector >& diagnostic_messages) - : index_{index} - , name_{name} - , can_messages_definition_{can_messages_definition} - , diagnostic_messages_{diagnostic_messages} -{} - -/// @brief Returns a vector holding all message definitions which are handled by this message set. -std::vector >& can_message_set_t::get_can_message_definition() -{ - return can_messages_definition_; -} - -std::vector > can_message_set_t::get_all_can_signals() const -{ - std::vector > can_signals; - for(const auto& cmd: can_messages_definition_) - { - std::vector >& cmd_signals = cmd->get_can_signals(); - can_signals.insert( can_signals.end(), - cmd_signals.begin(), - cmd_signals.end() - ); - } - - return can_signals; -} - -/// @brief Returns a vector holding all diagnostic message definitions which are handled by this message set. -std::vector >& can_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/can-message-set.hpp deleted file mode 100644 index 59c27b1a..00000000 --- a/low-can-binding/can/can-message-set.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2015, 2016, 2017 "IoT.bzh" - * Author "Romain Forlot" - * Author "Loïc Collignon" - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -class can_signal_t; -class can_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 -{ -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 > can_messages_definition_; ///< Vector holding all message definitions handled by the message set. - std::vector > diagnostic_messages_; ///< Vector holding all diagnostics messages from JSON signals description file. First vector map to message set - -public: - can_message_set_t( - uint8_t index, - const std::string& name, - const std::vector >& can_messages_definition, - const std::vector >& diagnostic_messages); - - std::vector >& get_can_message_definition(); - std::vector > get_all_can_signals() const; - std::vector >& get_diagnostic_messages(); -}; diff --git a/low-can-binding/can/can-signals.cpp b/low-can-binding/can/can-signals.cpp deleted file mode 100644 index 76a9665f..00000000 --- a/low-can-binding/can/can-signals.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2015, 2016 "IoT.bzh" - * Author "Romain Forlot" - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "can-signals.hpp" - -#include "../binding/application.hpp" -#include "../utils/signals.hpp" -#include "can-decoder.hpp" -#include "message/can-message.hpp" -#include "can-bus.hpp" -#include "../diagnostic/diagnostic-message.hpp" -#include "canutil/write.h" - -std::string can_signal_t::prefix_ = "messages"; - -can_signal_t::can_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 states, - bool writable, - signal_decoder decoder, - signal_encoder encoder, - bool received) - : parent_{nullptr}, - 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} - , last_value_{.0f} -{} - -can_message_definition_t* can_signal_t::get_message() const -{ - return parent_; -} - -const std::string can_signal_t::get_generic_name() const -{ - return generic_name_; -} - -const std::string can_signal_t::get_name() const -{ - return prefix_ + "." + generic_name_; -} - -uint8_t can_signal_t::get_bit_position() const -{ - return bit_position_; -} - -uint8_t can_signal_t::get_bit_size() const -{ - return bit_size_; -} - -float can_signal_t::get_factor() const -{ - return factor_; -} - -float can_signal_t::get_offset() const -{ - return offset_; -} - -frequency_clock_t& can_signal_t::get_frequency() -{ - return frequency_; -} - -bool can_signal_t::get_send_same() const -{ - return send_same_; -} - -const std::string can_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 ret = -1; - for( const auto& state: states_) - { - if(state.second == value) - { - ret = (uint64_t)state.first; - break; - } - } - return ret; -} - -bool can_signal_t::get_writable() const -{ - return writable_; -} - -signal_decoder& can_signal_t::get_decoder() -{ - return decoder_; -} - -signal_encoder& can_signal_t::get_encoder() -{ - return encoder_; -} - -bool can_signal_t::get_received() const -{ - return received_; -} - -float can_signal_t::get_last_value() const -{ - return last_value_; -} - -std::pair can_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) -{ - parent_ = parent; -} - -void can_signal_t::set_received(bool r) -{ - received_ = r; -} - -void can_signal_t::set_last_value(float val) -{ - last_value_ = val; -} - -void can_signal_t::set_timestamp(uint64_t timestamp) -{ - frequency_.tick(timestamp); -} - diff --git a/low-can-binding/can/can-signals.hpp b/low-can-binding/can/can-signals.hpp deleted file mode 100644 index 9ac55081..00000000 --- a/low-can-binding/can/can-signals.hpp +++ /dev/null @@ -1,143 +0,0 @@ -/// -/// Copyright (C) 2015, 2016 "IoT.bzh" -/// Author "Romain Forlot" -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// - -#pragma once - -#include -#include -#include -#include -#include - -#include "openxc.pb.h" -#include "can-message-definition.hpp" -#include "../utils/timer.hpp" -#include "../utils/socketcan-bcm.hpp" -#include "message/can-message.hpp" -#include "../diagnostic/diagnostic-message.hpp" - -#define MESSAGE_SET_ID 0 - -class can_signal_t; -/// -/// @brief The type signature for a CAN signal decoder. -/// -/// 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] signalCount - The length of the signals array. -/// @param[in] value - The CAN signal parsed from the message as a raw floating point -/// value. -/// @param[out] send - An output parameter. If decoding fails or CAN signal is -/// not sending, this should be flipped to false. -/// -/// @return a decoded value in an openxc_DynamicField struct. -/// -typedef openxc_DynamicField (*signal_decoder)(can_signal_t& signal, float value, bool* send); - -/// -/// @brief: The type signature for a CAN signal encoder. -/// -/// 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. -/// @param[in] value - The dynamic field to encode. -/// @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, - const openxc_DynamicField& field, bool* send); - -class can_signal_t -{ -private: - can_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.*/ - uint8_t bit_position_; /*!< bitPosition_ - The starting bit of the signal in its CAN message (assuming - * non-inverted bit numbering, i.e. the most significant bit of - * each byte is 0) */ - uint8_t bit_size_; /*!< bit_size_ - The width of the bit field in the CAN message. */ - float factor_; /*!< factor_ - The final value will be multiplied by this factor. Use 1 if you - * don't need a factor. */ - float offset_; /*!< offset_ - The final value will be added to this offset. Use 0 if you - * don't need an offset. */ - float min_value_; /*!< min_value_ - The minimum value for the processed signal.*/ - float max_value_; /*!< max_value_ - The maximum value for the processed signal. */ - frequency_clock_t frequency_; /*!< frequency_ - A frequency_clock_t struct to control the maximum frequency to - * process and send this signal. To process every value, set the - * clock's frequency to 0. */ - bool send_same_; /*!< send_same_ - If true, will re-send even if the value hasn't changed.*/ - bool force_send_changed_; /*!< force_send_changed_ - If true, regardless of the frequency, it will send the - * value if it has changed. */ - std::map states_; /*!< states_ - A map of CAN signal state describing the mapping - * 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.*/ - 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. */ - 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.*/ - float last_value_; /*!< lastValue_ - The last received value of the signal. If 'received' is false, - * this value is undefined. */ - -public: - can_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 states, - bool writable, - signal_decoder decoder, - signal_encoder encoder, - bool received); - - can_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; - uint8_t get_bit_size() const; - float get_factor() const; - float get_offset() const; - frequency_clock_t& get_frequency(); - bool get_send_same() const; - const std::string get_states(uint8_t value); - uint64_t get_states(const std::string& value) const; - bool get_writable() const; - signal_decoder& get_decoder(); - signal_encoder& get_encoder(); - bool get_received() const; - float get_last_value() const; - std::pair get_last_value_with_timestamp() const; - - void set_parent(can_message_definition_t* parent); - void set_received(bool r); - void set_last_value(float val); - void set_timestamp(uint64_t timestamp); -}; diff --git a/low-can-binding/can/message-definition.cpp b/low-can-binding/can/message-definition.cpp new file mode 100644 index 00000000..efc72f07 --- /dev/null +++ b/low-can-binding/can/message-definition.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2015, 2016 "IoT.bzh" + * Author "Romain Forlot" + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "message-definition.hpp" + +#include "../binding/application.hpp" + +message_definition_t::message_definition_t( + const std::string bus, + uint32_t id, + bool is_fd, + message_format_t format, + frequency_clock_t frequency_clock, + bool force_send_changed, + const std::vector >& signals) + : parent_{nullptr}, + bus_{bus}, + id_{id}, + is_fd_(is_fd), + format_{format}, + frequency_clock_{frequency_clock}, + force_send_changed_{force_send_changed}, + last_value_{CAN_MESSAGE_SIZE}, + signals_{signals} +{} + +message_definition_t::message_definition_t(const std::string bus, + uint32_t id, + const std::string name, + uint32_t length, + bool is_fd, + message_format_t format, + frequency_clock_t frequency_clock, + bool force_send_changed, + const std::vector >& signals) + : parent_{nullptr}, + bus_{bus}, + id_{id}, + name_{name}, + length_{length}, + is_fd_(is_fd), + format_{format}, + frequency_clock_{frequency_clock}, + force_send_changed_{force_send_changed}, + last_value_{CAN_MESSAGE_SIZE}, + signals_{signals} +{} + +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 message_definition_t::get_id() const +{ + return id_; +} + +bool message_definition_t::is_fd() const +{ + return is_fd_; +} + +bool message_definition_t::is_j1939() const +{ + if(format_ == message_format_t::J1939) + { + return true; + } + else + { + return false; + } +} + +std::vector>& message_definition_t::get_signals() +{ + return signals_; +} + +void message_definition_t::set_parent(std::shared_ptr parent) +{ + parent_= parent; +} + +void message_definition_t::set_last_value(std::shared_ptr m) +{ + last_value_= m->get_data_vector(); +} diff --git a/low-can-binding/can/message-definition.hpp b/low-can-binding/can/message-definition.hpp new file mode 100644 index 00000000..1773e6b8 --- /dev/null +++ b/low-can-binding/can/message-definition.hpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2015, 2016 "IoT.bzh" + * Author "Romain Forlot" + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @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 + * outgoing CAN messages. + */ + +#pragma once + +#include +#include + +#include "signals.hpp" +#include "message-set.hpp" +#include "../utils/timer.hpp" +#include "message/message.hpp" + +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 signal_t object related to a CAN message. +class message_definition_t +{ +private: + std::shared_ptr 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 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*/ + 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.*/ + bool force_send_changed_; ///< force_send_changed_ - If true, regardless of the frequency, it will send CAN + /// message if it has changed when using raw passthrough.*/ + std::vector 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 > signals_; ///< signals_ - Vector holding signal_t object which share the same arbitration ID */ + +public: + //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, + message_format_t format, + frequency_clock_t frequency_clock, + bool force_send_changed, + const std::vector >& signals); + message_definition_t(const std::string bus, + uint32_t id, + std::string name, + uint32_t length, + bool is_fd, + message_format_t format, + frequency_clock_t frequency_clock, + bool force_send_changed, + const std::vector >& 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>& get_signals(); + + void set_parent(std::shared_ptr parent); + void set_last_value(std::shared_ptr m); +}; diff --git a/low-can-binding/can/message-set.cpp b/low-can-binding/can/message-set.cpp new file mode 100644 index 00000000..69682e1a --- /dev/null +++ b/low-can-binding/can/message-set.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2015, 2016, 2017 "IoT.bzh" + * Author "Romain Forlot" + * Author "Loïc Collignon" + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "message-set.hpp" + +#include "../can/message-definition.hpp" + +message_set_t::message_set_t( + uint8_t index, + const std::string& name, + const std::vector >& messages_definition, + const std::vector >& diagnostic_messages) + : index_{index} + , name_{name} + , 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>& message_set_t::get_messages_definition() +{ + return messages_definition_; +} + +std::vector> message_set_t::get_all_signals() const +{ + std::vector > signals; + for(const auto& cmd: messages_definition_) + { + std::vector> cmd_signals = cmd->get_signals(); + signals.insert( signals.end(), + cmd_signals.begin(), + cmd_signals.end() + ); + } + + return signals; +} + +/// @brief Returns a vector holding all diagnostic message definitions which are handled by this message set. +std::vector>& message_set_t::get_diagnostic_messages() +{ + return diagnostic_messages_; +} diff --git a/low-can-binding/can/message-set.hpp b/low-can-binding/can/message-set.hpp new file mode 100644 index 00000000..4af97fa6 --- /dev/null +++ b/low-can-binding/can/message-set.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015, 2016, 2017 "IoT.bzh" + * Author "Romain Forlot" + * Author "Loïc Collignon" + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +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 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 > messages_definition_; ///< Vector holding all message definitions handled by the message set. + std::vector > diagnostic_messages_; ///< Vector holding all diagnostics messages from JSON signals description file. First vector map to message set + +public: + message_set_t( + uint8_t index, + const std::string& name, + const std::vector >& messages_definition, + const std::vector >& diagnostic_messages); + + std::vector>& get_messages_definition(); + std::vector> get_all_signals() const; + std::vector>& 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& 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_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 data; @@ -109,17 +109,17 @@ std::shared_ptr 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& 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& 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& 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::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 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& 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& 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& 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 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& data, uint64_t timestamp); + message_t(uint8_t length, message_format_t format, std::vector& 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/signals.cpp b/low-can-binding/can/signals.cpp new file mode 100644 index 00000000..e843bedb --- /dev/null +++ b/low-can-binding/can/signals.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2015, 2016 "IoT.bzh" + * Author "Romain Forlot" + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "signals.hpp" + +#include "../binding/application.hpp" +#include "../utils/signals.hpp" +#include "can-decoder.hpp" +#include "message/can-message.hpp" +#include "can-bus.hpp" +#include "../diagnostic/diagnostic-message.hpp" +#include "canutil/write.h" + +std::string signal_t::prefix_ = "messages"; + +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 states, + bool writable, + signal_decoder decoder, + signal_encoder encoder, + bool received, + std::pair multiplex, + bool is_big_endian, + bool is_signed, + std::string unit) + : parent_{nullptr}, + 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} + , last_value_{.0f} + , multiplex_{multiplex} + , is_big_endian_{is_big_endian} + , is_signed_{is_signed} + , unit_{unit} +{} + +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 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 signal_t::get_message() const +{ + return parent_; +} + +const std::string signal_t::get_generic_name() const +{ + return generic_name_; +} + +const std::string signal_t::get_name() const +{ + return prefix_ + "." + generic_name_; +} + +uint8_t signal_t::get_bit_position() const +{ + return bit_position_; +} + +uint8_t signal_t::get_bit_size() const +{ + return bit_size_; +} + +float signal_t::get_factor() const +{ + return factor_; +} + +float signal_t::get_offset() const +{ + return offset_; +} + +frequency_clock_t& signal_t::get_frequency() +{ + return frequency_; +} + +bool signal_t::get_send_same() const +{ + return send_same_; +} + +const std::string signal_t::get_states(uint8_t value) +{ + if ( states_.count(value) > 0 ) + return states_[value]; + return std::string(); +} + +uint64_t signal_t::get_states(const std::string& value) const +{ + uint64_t ret = -1; + for( const auto& state: states_) + { + if(state.second == value) + { + ret = (uint64_t)state.first; + break; + } + } + return ret; +} + +bool signal_t::get_writable() const +{ + return writable_; +} + +signal_decoder& signal_t::get_decoder() +{ + return decoder_; +} + +signal_encoder& signal_t::get_encoder() +{ + return encoder_; +} + +bool signal_t::get_received() const +{ + return received_; +} + +float signal_t::get_last_value() const +{ + return last_value_; +} + +std::pair signal_t::get_last_value_with_timestamp() const +{ + return std::make_pair(last_value_, frequency_.get_last_tick()); +} + +void signal_t::set_parent(std::shared_ptr parent) +{ + parent_ = parent; +} + +void signal_t::set_received(bool r) +{ + received_ = r; +} + +void signal_t::set_last_value(float val) +{ + last_value_ = val; +} + +void signal_t::set_timestamp(uint64_t timestamp) +{ + frequency_.tick(timestamp); +} + +std::pair 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/signals.hpp b/low-can-binding/can/signals.hpp new file mode 100644 index 00000000..2507fd2a --- /dev/null +++ b/low-can-binding/can/signals.hpp @@ -0,0 +1,177 @@ +/// +/// Copyright (C) 2015, 2016 "IoT.bzh" +/// Author "Romain Forlot" +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +#pragma once + +#include +#include +#include +#include +#include + +#include "openxc.pb.h" +#include "message-definition.hpp" +#include "../utils/timer.hpp" +#include "../utils/socketcan-bcm.hpp" +#include "message/can-message.hpp" +#include "../diagnostic/diagnostic-message.hpp" + +#define MESSAGE_SET_ID 0 + +class signal_t; +/// +/// @brief The type signature for a CAN signal decoder. +/// +/// 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] signalCount - The length of the signals array. +/// @param[in] value - The CAN signal parsed from the message as a raw floating point +/// value. +/// @param[out] send - An output parameter. If decoding fails or CAN signal is +/// not sending, this should be flipped to false. +/// +/// @return a decoded value in an openxc_DynamicField struct. +/// +typedef openxc_DynamicField (*signal_decoder)(signal_t& signal, float value, bool* send); + +/// +/// @brief: The type signature for a CAN signal encoder. +/// +/// 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. +/// @param[in] value - The dynamic field to encode. +/// @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)(signal_t& signal, + const openxc_DynamicField& field, bool* send); + +class signal_t +{ +private: + std::shared_ptr 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.*/ + uint8_t bit_position_; /*!< bitPosition_ - The starting bit of the signal in its CAN message (assuming + * non-inverted bit numbering, i.e. the most significant bit of + * each byte is 0) */ + uint8_t bit_size_; /*!< bit_size_ - The width of the bit field in the CAN message. */ + float factor_; /*!< factor_ - The final value will be multiplied by this factor. Use 1 if you + * don't need a factor. */ + float offset_; /*!< offset_ - The final value will be added to this offset. Use 0 if you + * don't need an offset. */ + float min_value_; /*!< min_value_ - The minimum value for the processed signal.*/ + float max_value_; /*!< max_value_ - The maximum value for the processed signal. */ + frequency_clock_t frequency_; /*!< frequency_ - A frequency_clock_t struct to control the maximum frequency to + * process and send this signal. To process every value, set the + * clock's frequency to 0. */ + bool send_same_; /*!< send_same_ - If true, will re-send even if the value hasn't changed.*/ + bool force_send_changed_; /*!< force_send_changed_ - If true, regardless of the frequency, it will send the + * value if it has changed. */ + std::map states_; /*!< states_ - A map of CAN signal state describing the mapping + * 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.*/ + 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. */ + 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.*/ + float last_value_; /*!< lastValue_ - The last received value of the signal. If 'received' is false, + * this value is undefined. */ + std::pair 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: + + 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 states, + bool writable, + signal_decoder decoder, + signal_encoder encoder, + bool received, + std::pair 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, + float factor, + float offset, + float min_value, + float max_value, + frequency_clock_t frequency, + bool send_same, + bool force_send_changed, + std::map states, + bool writable, + signal_decoder decoder, + signal_encoder encoder, + bool received); + + + std::shared_ptr get_message() const; + const std::string get_generic_name() const; + const std::string get_name() const; + uint8_t get_bit_position() const; + uint8_t get_bit_size() const; + float get_factor() const; + float get_offset() const; + frequency_clock_t& get_frequency(); + bool get_send_same() const; + const std::string get_states(uint8_t value); + uint64_t get_states(const std::string& value) const; + bool get_writable() const; + signal_decoder& get_decoder(); + signal_encoder& get_encoder(); + bool get_received() const; + float get_last_value() const; + std::pair get_last_value_with_timestamp() const; + std::pair get_multiplex() const; + bool get_is_big_endian() const; + bool get_is_signed() const; + const std::string get_unit() const; + + void set_parent(std::shared_ptr parent); + void set_received(bool r); + void set_last_value(float val); + void set_timestamp(uint64_t timestamp); +}; diff --git a/low-can-binding/diagnostic/diagnostic-manager.cpp b/low-can-binding/diagnostic/diagnostic-manager.cpp index 7c067c6a..fa1d87af 100644 --- a/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -526,7 +526,7 @@ openxc_VehicleMessage diagnostic_manager_t::find_and_decode_adr(std::shared_ptr< /// @return True if the active diagnostic request match the response. bool diagnostic_manager_t::is_diagnostic_response(std::shared_ptr m) { - if(m->get_msg_format() == can_message_format_t::STANDARD || m->get_msg_format() == can_message_format_t::EXTENDED) + if(m->get_msg_format() == message_format_t::STANDARD || m->get_msg_format() == message_format_t::EXTENDED) { if (m->get_id() >= 0x7e8 && m->get_id() <= 0x7ef) return true; diff --git a/low-can-binding/diagnostic/diagnostic-message.cpp b/low-can-binding/diagnostic/diagnostic-message.cpp index 6ebb6ab1..9b4733da 100644 --- a/low-can-binding/diagnostic/diagnostic-message.cpp +++ b/low-can-binding/diagnostic/diagnostic-message.cpp @@ -114,7 +114,7 @@ void diagnostic_message_t::set_supported(bool value) supported_ = value; } -void diagnostic_message_t::set_parent(std::shared_ptr parent) +void diagnostic_message_t::set_parent(std::shared_ptr parent) { parent_ = parent; } diff --git a/low-can-binding/diagnostic/diagnostic-message.hpp b/low-can-binding/diagnostic/diagnostic-message.hpp index 86149413..e7877d6e 100644 --- a/low-can-binding/diagnostic/diagnostic-message.hpp +++ b/low-can-binding/diagnostic/diagnostic-message.hpp @@ -21,7 +21,7 @@ #include #include "uds/uds.h" -#include "../can/can-message-set.hpp" +#include "../can/message-set.hpp" #include "../can/message/can-message.hpp" #include "active-diagnostic-request.hpp" @@ -45,7 +45,7 @@ class message_set_t; class diagnostic_message_t { private: - std::shared_ptr parent_; /*!< parent_ - Pointer to the CAN message set holding this diagnostic message */ + std::shared_ptr parent_; /*!< parent_ - Pointer to the CAN message set holding this diagnostic message */ uint8_t pid_; /*!< pid_ - The 1 byte PID.*/ std::string generic_name_; /*!< generic_name_ - A human readable name to use for this PID when published.*/ int min_; /*!< min_ - Minimum value that can take this pid */ @@ -97,7 +97,7 @@ class diagnostic_message_t void set_timestamp(uint64_t timestamp); void set_supported(bool value); - void set_parent(std::shared_ptr parent); + void set_parent(std::shared_ptr parent); const DiagnosticRequest build_diagnostic_request() const; bool is_obd2_response(const can_message_t& can_message); diff --git a/low-can-binding/utils/signals.cpp b/low-can-binding/utils/signals.cpp index 7011fa5a..4895395f 100644 --- a/low-can-binding/utils/signals.cpp +++ b/low-can-binding/utils/signals.cpp @@ -46,7 +46,7 @@ namespace utils /// /// @fn std::vector find_signals(const openxc_DynamicField &key) - /// @brief return signals name found searching through CAN_signals and OBD2 pid + /// @brief return signals name found searching through signals and OBD2 pid /// /// @param[in] key : can contain numeric or string value in order to search against /// can signals or obd2 signals name. @@ -60,18 +60,18 @@ namespace utils switch(key.type) { case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: - lookup_signals_by_name(key.string_value, application_t::instance().get_all_can_signals(), sf.can_signals); + lookup_signals_by_name(key.string_value, application_t::instance().get_all_signals(), sf.signals); lookup_signals_by_name(key.string_value, application_t::instance().get_diagnostic_messages(), sf.diagnostic_messages); break; case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: - lookup_signals_by_id(key.numeric_value, application_t::instance().get_all_can_signals(), sf.can_signals); + lookup_signals_by_id(key.numeric_value, application_t::instance().get_all_signals(), sf.signals); lookup_signals_by_id(key.numeric_value, application_t::instance().get_diagnostic_messages(), sf.diagnostic_messages); break; default: AFB_ERROR("wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); break; } - AFB_DEBUG("Found %d signal(s)", (int)(sf.can_signals.size() + sf.diagnostic_messages.size())); + AFB_DEBUG("Found %d signal(s)", (int)(sf.signals.size() + sf.diagnostic_messages.size())); return sf; } } diff --git a/low-can-binding/utils/signals.hpp b/low-can-binding/utils/signals.hpp index 10cb8ad0..84e81d03 100644 --- a/low-can-binding/utils/signals.hpp +++ b/low-can-binding/utils/signals.hpp @@ -23,7 +23,7 @@ #include "openxc.pb.h" #include "../binding/application.hpp" -#include "../can/can-signals.hpp" +#include "../can/signals.hpp" #include "../diagnostic/diagnostic-message.hpp" #include "../binding/low-can-subscription.hpp" @@ -32,7 +32,7 @@ namespace utils { struct signals_found { - std::vector > can_signals; + std::vector > signals; std::vector > diagnostic_messages; }; @@ -56,7 +56,7 @@ namespace utils struct signals_found find_signals(const openxc_DynamicField &key); void find_diagnostic_messages(const openxc_DynamicField &key, std::vector >& found_signals); - void find_can_signals(const openxc_DynamicField &key, std::vector >& found_signals); + void find_signals(const openxc_DynamicField &key, std::vector >& found_signals); template void lookup_signals_by_name(const std::string& key, std::vector > signals, std::vector >& found_signals) -- cgit 1.2.3-korg