From eafde4cec4fc026444501ed3a096a12e6eb8fc90 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 30 May 2017 17:00:44 +0200 Subject: Renaming configuration to application It is more accurate to name it application because all its members aren't modifiable at runtime (without talking of last_value_ member and few others). Change-Id: Ica0d33dfd9c26cfdea019c2f41ed07777fb36d39 Signed-off-by: Romain Forlot --- .../examples/toyota/configuration-generated.cpp | 6 +- CAN-binder/low-can-binding/CMakeLists.txt | 4 +- .../binding/application-generated.cpp | 486 +++++++++++++++++++++ CAN-binder/low-can-binding/binding/application.cpp | 96 ++++ CAN-binder/low-can-binding/binding/application.hpp | 106 +++++ .../binding/configuration-generated.cpp | 486 --------------------- .../low-can-binding/binding/configuration.cpp | 96 ---- .../low-can-binding/binding/configuration.hpp | 109 ----- CAN-binder/low-can-binding/binding/low-can-cb.cpp | 4 +- CAN-binder/low-can-binding/binding/low-can-hat.cpp | 6 +- CAN-binder/low-can-binding/can/can-bus.cpp | 4 +- .../low-can-binding/can/can-message-definition.cpp | 4 +- CAN-binder/low-can-binding/can/can-signals.cpp | 2 +- .../diagnostic/active-diagnostic-request.cpp | 2 +- .../diagnostic/diagnostic-manager.cpp | 8 +- .../diagnostic/diagnostic-message.cpp | 2 +- CAN-binder/low-can-binding/utils/openxc-utils.cpp | 4 +- CAN-binder/low-can-binding/utils/signals.cpp | 8 +- CAN-binder/low-can-binding/utils/signals.hpp | 4 +- 19 files changed, 717 insertions(+), 720 deletions(-) create mode 100644 CAN-binder/low-can-binding/binding/application-generated.cpp create mode 100644 CAN-binder/low-can-binding/binding/application.cpp create mode 100644 CAN-binder/low-can-binding/binding/application.hpp delete mode 100644 CAN-binder/low-can-binding/binding/configuration-generated.cpp delete mode 100644 CAN-binder/low-can-binding/binding/configuration.cpp delete mode 100644 CAN-binder/low-can-binding/binding/configuration.hpp (limited to 'CAN-binder') diff --git a/CAN-binder/examples/toyota/configuration-generated.cpp b/CAN-binder/examples/toyota/configuration-generated.cpp index 4ffc902..95b5087 100644 --- a/CAN-binder/examples/toyota/configuration-generated.cpp +++ b/CAN-binder/examples/toyota/configuration-generated.cpp @@ -1,7 +1,7 @@ -#include "configuration.hpp" +#include "application.hpp" #include "can/can-decoder.hpp" -configuration_t::configuration_t() +application_t::application_t() : can_message_set_{{0, "example", 0, 1, 5, 0, 19}} , can_message_definition_ { @@ -331,7 +331,7 @@ configuration_t::configuration_t() { } -const std::string configuration_t::get_diagnostic_bus() const +const std::string application_t::get_diagnostic_bus() const { return "can0"; } diff --git a/CAN-binder/low-can-binding/CMakeLists.txt b/CAN-binder/low-can-binding/CMakeLists.txt index 276097f..3c7ee2a 100644 --- a/CAN-binder/low-can-binding/CMakeLists.txt +++ b/CAN-binder/low-can-binding/CMakeLists.txt @@ -24,8 +24,8 @@ PROJECT_TARGET_ADD(low-can) add_library(${TARGET_NAME} MODULE binding/${TARGET_NAME}-hat.cpp binding/${TARGET_NAME}-cb.cpp - binding/configuration.cpp - binding/configuration-generated.cpp + binding/application.cpp + binding/application-generated.cpp can/can-bus.cpp can/can-message-set.cpp can/can-message-definition.cpp diff --git a/CAN-binder/low-can-binding/binding/application-generated.cpp b/CAN-binder/low-can-binding/binding/application-generated.cpp new file mode 100644 index 0000000..318dd76 --- /dev/null +++ b/CAN-binder/low-can-binding/binding/application-generated.cpp @@ -0,0 +1,486 @@ +#include "application.hpp" +#include "../can/can-decoder.hpp" + +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,"example", + { // beginning can_message_definition_ vector + {std::make_shared(can_message_definition_t{"hs",0x3D9,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, + { // beginning can_signals vector + {std::make_shared (can_signal_t{ + "engine.speed", + 16, + 16, + 0.250000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + nullptr, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "fuel.level.low", + 55, + 1, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "fuel.level", + 8, + 8, + 0.392157f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + nullptr, + nullptr, + false + })} + } // end can_signals vector + })} // end can_message_definition entry +, {std::make_shared(can_message_definition_t{"hs",0x3E9,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, + { // beginning can_signals vector + {std::make_shared (can_signal_t{ + "vehicle.average.speed", + 0, + 15, + 0.0156250f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + nullptr, + nullptr, + false + })} + } // end can_signals vector + })} // end can_message_definition entry +, {std::make_shared(can_message_definition_t{"hs",0x4D1,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, + { // beginning can_signals vector + {std::make_shared (can_signal_t{ + "engine.oil.temp", + 16, + 8, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + nullptr, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "engine.oil.temp.high", + 7, + 1, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })} + } // end can_signals vector + })} // end can_message_definition entry +, {std::make_shared(can_message_definition_t{"hs",0x620,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, + { // beginning can_signals vector + {std::make_shared (can_signal_t{ + "doors.boot.open", + 56, + 1, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "doors.front_left.open", + 46, + 1, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "doors.front_right.open", + 47, + 1, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "doors.rear_left.open", + 54, + 1, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })}, + {std::make_shared (can_signal_t{ + "doors.rear_right.open", + 53, + 4, + 1.00000f, + 0.00000, + 0, + 0, + frequency_clock_t(0.00000f), + true, + false, + { + }, + false, + decoder_t::booleanDecoder, + nullptr, + false + })} + } // end can_signals vector + })} // end can_message_definition entry + }, // end can_message_definition vector + { // beginning diagnostic_messages_ vector + {std::make_shared(diagnostic_message_t{ + 4, + "engine.load", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 5, + "engine.coolant.temperature", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 10, + "fuel.pressure", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 11, + "intake.manifold.pressure", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 12, + "engine.speed", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 13, + "vehicle.speed", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 15, + "intake.air.temperature", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 16, + "mass.airflow", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 17, + "throttle.position", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 31, + "running.time", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 45, + "EGR.error", + 0, + 0, + UNIT::INVALID, + 0.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 47, + "fuel.level", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 51, + "barometric.pressure", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 70, + "ambient.air.temperature", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 76, + "commanded.throttle.position", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 82, + "ethanol.fuel.percentage", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 90, + "accelerator.pedal.position", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 91, + "hybrid.battery-pack.remaining.life", + 0, + 0, + UNIT::INVALID, + 5.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 92, + "engine.oil.temperature", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 94, + "engine.fuel.rate", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} +, {std::make_shared(diagnostic_message_t{ + 99, + "engine.torque", + 0, + 0, + UNIT::INVALID, + 1.00000f, + decoder_t::decode_obd2_response, + nullptr, + true + })} + } // end diagnostic_messages_ vector + })} // end can_message_set entry + } // end can_message_set vector +{ + for(auto& cms: can_message_set_) + { + std::vector >& can_messages_definition = cms->get_can_message_definition(); + for(auto& cmd : can_messages_definition) + { + cmd->set_parent(cms.get()); + std::vector >& can_signals = cmd->get_can_signals(); + for(auto& sig: can_signals) + { + sig->set_parent(cmd.get()); + } + } + + std::vector >& diagnostic_messages = cms->get_diagnostic_messages(); + for(auto& dm : diagnostic_messages) + { + dm->set_parent(cms.get()); + } + } +} + +const std::string application_t::get_diagnostic_bus() const +{ + return "hs"; +} + + diff --git a/CAN-binder/low-can-binding/binding/application.cpp b/CAN-binder/low-can-binding/binding/application.cpp new file mode 100644 index 0000000..b916523 --- /dev/null +++ b/CAN-binder/low-can-binding/binding/application.cpp @@ -0,0 +1,96 @@ +/* + * 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 "application.hpp" + +#include "../utils/signals.hpp" +#include "../utils/openxc-utils.hpp" + +/// @brief Return singleton instance of configuration object. +application_t& application_t::instance() +{ + static application_t config; + return config; +} + +can_bus_t& application_t::get_can_bus_manager() +{ + return can_bus_manager_; +} + +diagnostic_manager_t& application_t::get_diagnostic_manager() +{ + return diagnostic_manager_; +} + +uint8_t application_t::get_active_message_set() const +{ + return active_message_set_; +} + +std::vector > application_t::get_can_message_set() +{ + return can_message_set_; +} + +std::vector > application_t::get_all_can_signals() +{ + return can_message_set_[active_message_set_]->get_all_can_signals(); +} + +std::vector >& application_t::get_diagnostic_messages() +{ + return can_message_set_[active_message_set_]->get_diagnostic_messages(); +} + +std::vector >& application_t::get_can_message_definition() +{ + return can_message_set_[active_message_set_]->get_can_message_definition(); +} + +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 +{ + return sig.get_message()->get_id(); +} + +void application_t::set_active_message_set(uint8_t id) +{ + active_message_set_ = id; +} + + +std::shared_ptr application_t::get_diagnostic_message(const std::string& message_name) const +{ + struct utils::signals_found found; + found = utils::signals_manager_t::instance().find_signals(build_DynamicField(message_name)); + if(! found.diagnostic_messages.empty()) + return found.diagnostic_messages.front(); + return nullptr; +} + +DiagnosticRequest* application_t::get_request_from_diagnostic_message(const std::string& message_name) const +{ + std::shared_ptr diag_msg = get_diagnostic_message(message_name); + if( diag_msg != nullptr && diag_msg->get_supported()) + return new DiagnosticRequest(diag_msg->build_diagnostic_request()); + return nullptr; +} diff --git a/CAN-binder/low-can-binding/binding/application.hpp b/CAN-binder/low-can-binding/binding/application.hpp new file mode 100644 index 0000000..50b2375 --- /dev/null +++ b/CAN-binder/low-can-binding/binding/application.hpp @@ -0,0 +1,106 @@ +/* + * 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 "../can/can-bus.hpp" +#include "../can/can-message-set.hpp" +#include "../can/can-signals.hpp" +#include "../diagnostic/diagnostic-manager.hpp" + +#include "low-can-hat.hpp" + +/// +/// @brief Class representing a configuration attached to the binding. +/// +/// It regroups all needed objects instance from other class +/// that will be used along the binding life. It gets a global vision +/// on which signals are implemented for that binding. +/// Here, it is only the definition of the class with predefined accessors +/// methods used in the binding. +/// +/// It will be the reference point to needed objects. +/// +class application_t +{ + private: + can_bus_t can_bus_manager_; ///< instanciate the CAN bus manager. It's the one in charge of initialize the CAN bus devices. + 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 + + application_t(); ///< Private constructor with implementation generated by the AGL generator. + + public: + static application_t& instance(); + + can_bus_t& get_can_bus_manager(); + + const std::string get_diagnostic_bus() const; + + diagnostic_manager_t& get_diagnostic_manager() ; + + uint8_t get_active_message_set() const; + + std::vector > get_can_message_set(); + + std::vector > get_all_can_signals(); + + std::vector >& get_diagnostic_messages(); + + const std::vector& get_signals_prefix() const; + + std::vector >& get_can_message_definition(); + + uint32_t get_signal_id(diagnostic_message_t& sig) const; + + uint32_t get_signal_id(can_signal_t& sig) const; + + void set_active_message_set(uint8_t id); + + std::shared_ptr get_diagnostic_message(const std::string& message_name) const; + DiagnosticRequest* get_request_from_diagnostic_message(const std::string& message_name) const; +/* + /// TODO: implement this function as method into can_bus class + /// @brief Pre initialize actions made before CAN bus initialization + /// @param[in] bus A CanBus struct defining the bus's metadata + /// @param[in] writable Configure the controller in a writable mode. If false, it will be configured as "listen only" and will not allow writes or even CAN ACKs. + /// @param[in] buses An array of all CAN buses. + void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount); + /// TODO: implement this function as method into can_bus class + /// @brief Post-initialize actions made after CAN bus initialization + /// @param[in] bus A CanBus struct defining the bus's metadata + /// @param[in] writable Configure the controller in a writable mode. If false, it will be configured as "listen only" and will not allow writes or even CAN ACKs. + /// @param[in] buses An array of all CAN buses. + void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount); + /// TODO: implement this function as method into can_bus class + /// @brief Check if the device is connected to an active CAN bus, i.e. it's received a message in the recent past. + /// @return true if a message was received on the CAN bus within CAN_ACTIVE_TIMEOUT_S seconds. + void logBusStatistics(can_bus_dev_t* buses, const int busCount); + /// TODO: implement this function as method into can_bus class + /// @brief Log transfer statistics about all active CAN buses to the debug log. + /// @param[in] buses An array of active CAN buses. + bool isBusActive(can_bus_dev_t* bus); + */ +}; + diff --git a/CAN-binder/low-can-binding/binding/configuration-generated.cpp b/CAN-binder/low-can-binding/binding/configuration-generated.cpp deleted file mode 100644 index 2939fc8..0000000 --- a/CAN-binder/low-can-binding/binding/configuration-generated.cpp +++ /dev/null @@ -1,486 +0,0 @@ -#include "configuration.hpp" -#include "../can/can-decoder.hpp" - -configuration_t::configuration_t() - : can_bus_manager_{utils::config_parser_t{"/etc/dev-mapping.conf"}} - , can_message_set_{ - {std::make_shared(can_message_set_t{0,"example", - { // beginning can_message_definition_ vector - {std::make_shared(can_message_definition_t{"hs",0x3D9,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, - { // beginning can_signals vector - {std::make_shared (can_signal_t{ - "engine.speed", - 16, - 16, - 0.250000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - nullptr, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "fuel.level.low", - 55, - 1, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "fuel.level", - 8, - 8, - 0.392157f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - nullptr, - nullptr, - false - })} - } // end can_signals vector - })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{"hs",0x3E9,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, - { // beginning can_signals vector - {std::make_shared (can_signal_t{ - "vehicle.average.speed", - 0, - 15, - 0.0156250f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - nullptr, - nullptr, - false - })} - } // end can_signals vector - })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{"hs",0x4D1,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, - { // beginning can_signals vector - {std::make_shared (can_signal_t{ - "engine.oil.temp", - 16, - 8, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - nullptr, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "engine.oil.temp.high", - 7, - 1, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })} - } // end can_signals vector - })} // end can_message_definition entry -, {std::make_shared(can_message_definition_t{"hs",0x620,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true, - { // beginning can_signals vector - {std::make_shared (can_signal_t{ - "doors.boot.open", - 56, - 1, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "doors.front_left.open", - 46, - 1, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "doors.front_right.open", - 47, - 1, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "doors.rear_left.open", - 54, - 1, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })}, - {std::make_shared (can_signal_t{ - "doors.rear_right.open", - 53, - 4, - 1.00000f, - 0.00000, - 0, - 0, - frequency_clock_t(0.00000f), - true, - false, - { - }, - false, - decoder_t::booleanDecoder, - nullptr, - false - })} - } // end can_signals vector - })} // end can_message_definition entry - }, // end can_message_definition vector - { // beginning diagnostic_messages_ vector - {std::make_shared(diagnostic_message_t{ - 4, - "engine.load", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 5, - "engine.coolant.temperature", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 10, - "fuel.pressure", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 11, - "intake.manifold.pressure", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 12, - "engine.speed", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 13, - "vehicle.speed", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 15, - "intake.air.temperature", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 16, - "mass.airflow", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 17, - "throttle.position", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 31, - "running.time", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 45, - "EGR.error", - 0, - 0, - UNIT::INVALID, - 0.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 47, - "fuel.level", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 51, - "barometric.pressure", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 70, - "ambient.air.temperature", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 76, - "commanded.throttle.position", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 82, - "ethanol.fuel.percentage", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 90, - "accelerator.pedal.position", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 91, - "hybrid.battery-pack.remaining.life", - 0, - 0, - UNIT::INVALID, - 5.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 92, - "engine.oil.temperature", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 94, - "engine.fuel.rate", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} -, {std::make_shared(diagnostic_message_t{ - 99, - "engine.torque", - 0, - 0, - UNIT::INVALID, - 1.00000f, - decoder_t::decode_obd2_response, - nullptr, - true - })} - } // end diagnostic_messages_ vector - })} // end can_message_set entry - } // end can_message_set vector -{ - for(auto& cms: can_message_set_) - { - std::vector >& can_messages_definition = cms->get_can_message_definition(); - for(auto& cmd : can_messages_definition) - { - cmd->set_parent(cms.get()); - std::vector >& can_signals = cmd->get_can_signals(); - for(auto& sig: can_signals) - { - sig->set_parent(cmd.get()); - } - } - - std::vector >& diagnostic_messages = cms->get_diagnostic_messages(); - for(auto& dm : diagnostic_messages) - { - dm->set_parent(cms.get()); - } - } -} - -const std::string configuration_t::get_diagnostic_bus() const -{ - return "hs"; -} - - diff --git a/CAN-binder/low-can-binding/binding/configuration.cpp b/CAN-binder/low-can-binding/binding/configuration.cpp deleted file mode 100644 index 8e6ddde..0000000 --- a/CAN-binder/low-can-binding/binding/configuration.cpp +++ /dev/null @@ -1,96 +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 "configuration.hpp" - -#include "../utils/signals.hpp" -#include "../utils/openxc-utils.hpp" - -/// @brief Return singleton instance of configuration object. -configuration_t& configuration_t::instance() -{ - static configuration_t config; - return config; -} - -can_bus_t& configuration_t::get_can_bus_manager() -{ - return can_bus_manager_; -} - -diagnostic_manager_t& configuration_t::get_diagnostic_manager() -{ - return diagnostic_manager_; -} - -uint8_t configuration_t::get_active_message_set() const -{ - return active_message_set_; -} - -std::vector > configuration_t::get_can_message_set() -{ - return can_message_set_; -} - -std::vector > configuration_t::get_all_can_signals() -{ - return can_message_set_[active_message_set_]->get_all_can_signals(); -} - -std::vector >& configuration_t::get_diagnostic_messages() -{ - return can_message_set_[active_message_set_]->get_diagnostic_messages(); -} - -std::vector >& configuration_t::get_can_message_definition() -{ - return can_message_set_[active_message_set_]->get_can_message_definition(); -} - -uint32_t configuration_t::get_signal_id(diagnostic_message_t& sig) const -{ - return sig.get_pid(); -} - -uint32_t configuration_t::get_signal_id(can_signal_t& sig) const -{ - return sig.get_message()->get_id(); -} - -void configuration_t::set_active_message_set(uint8_t id) -{ - active_message_set_ = id; -} - - -std::shared_ptr configuration_t::get_diagnostic_message(const std::string& message_name) const -{ - struct utils::signals_found found; - found = utils::signals_manager_t::instance().find_signals(build_DynamicField(message_name)); - if(! found.diagnostic_messages.empty()) - return found.diagnostic_messages.front(); - return nullptr; -} - -DiagnosticRequest* configuration_t::get_request_from_diagnostic_message(const std::string& message_name) const -{ - std::shared_ptr diag_msg = get_diagnostic_message(message_name); - if( diag_msg != nullptr && diag_msg->get_supported()) - return new DiagnosticRequest(diag_msg->build_diagnostic_request()); - return nullptr; -} diff --git a/CAN-binder/low-can-binding/binding/configuration.hpp b/CAN-binder/low-can-binding/binding/configuration.hpp deleted file mode 100644 index fc53d38..0000000 --- a/CAN-binder/low-can-binding/binding/configuration.hpp +++ /dev/null @@ -1,109 +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 "../can/can-bus.hpp" -#include "../can/can-message-set.hpp" -#include "../can/can-signals.hpp" -#include "../diagnostic/diagnostic-manager.hpp" - -#include "low-can-hat.hpp" - -/// -/// @brief Class representing a configuration attached to the binding. -/// -/// It regroups all needed objects instance from other class -/// that will be used along the binding life. It gets a global vision -/// on which signals are implemented for that binding. -/// Here, it is only the definition of the class with predefined accessors -/// methods used in the binding. -/// -/// It will be the reference point to needed objects. -/// -class configuration_t -{ - private: - can_bus_t can_bus_manager_; ///< instanciate the CAN bus manager. It's the one in charge of initialize the CAN bus devices. - 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> can_message_definition_; ///< Vector of vector holding all can message definition from JSON signals description file. This describe a CAN message. First vector map to message set - //std::vector> can_signals_; ///< Vector of vector holding all can signasl from JSON signals description file. A CAN signal is a part of a CAN message. First vector map to message set - //std::vector > > diagnostic_messages_; ///< Vector of vector holding all diagnostics messages from JSON signals description file. First vector map to message set - - configuration_t(); ///< Private constructor with implementation generated by the AGL generator. - - public: - static configuration_t& instance(); - - can_bus_t& get_can_bus_manager(); - - const std::string get_diagnostic_bus() const; - - diagnostic_manager_t& get_diagnostic_manager() ; - - uint8_t get_active_message_set() const; - - std::vector > get_can_message_set(); - - std::vector > get_all_can_signals(); - - std::vector >& get_diagnostic_messages(); - - const std::vector& get_signals_prefix() const; - - std::vector >& get_can_message_definition(); - - uint32_t get_signal_id(diagnostic_message_t& sig) const; - - uint32_t get_signal_id(can_signal_t& sig) const; - - void set_active_message_set(uint8_t id); - - std::shared_ptr get_diagnostic_message(const std::string& message_name) const; - DiagnosticRequest* get_request_from_diagnostic_message(const std::string& message_name) const; -/* - /// TODO: implement this function as method into can_bus class - /// @brief Pre initialize actions made before CAN bus initialization - /// @param[in] bus A CanBus struct defining the bus's metadata - /// @param[in] writable Configure the controller in a writable mode. If false, it will be configured as "listen only" and will not allow writes or even CAN ACKs. - /// @param[in] buses An array of all CAN buses. - void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount); - /// TODO: implement this function as method into can_bus class - /// @brief Post-initialize actions made after CAN bus initialization - /// @param[in] bus A CanBus struct defining the bus's metadata - /// @param[in] writable Configure the controller in a writable mode. If false, it will be configured as "listen only" and will not allow writes or even CAN ACKs. - /// @param[in] buses An array of all CAN buses. - void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount); - /// TODO: implement this function as method into can_bus class - /// @brief Check if the device is connected to an active CAN bus, i.e. it's received a message in the recent past. - /// @return true if a message was received on the CAN bus within CAN_ACTIVE_TIMEOUT_S seconds. - void logBusStatistics(can_bus_dev_t* buses, const int busCount); - /// TODO: implement this function as method into can_bus class - /// @brief Log transfer statistics about all active CAN buses to the debug log. - /// @param[in] buses An array of active CAN buses. - bool isBusActive(can_bus_dev_t* bus); - */ -}; - diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.cpp b/CAN-binder/low-can-binding/binding/low-can-cb.cpp index 0dcff1d..8141c3d 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp @@ -27,7 +27,7 @@ #include #include "openxc.pb.h" -#include "configuration.hpp" +#include "application.hpp" #include "../can/can-bus.hpp" #include "../can/can-signals.hpp" #include "../can/can-message.hpp" @@ -187,7 +187,7 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, //TODO: Implement way to dynamically call the right function no matter // how much signals types we have. - configuration_t& conf = configuration_t::instance(); + application_t& conf = application_t::instance(); for(const auto& sig : signals.diagnostic_messages) { diff --git a/CAN-binder/low-can-binding/binding/low-can-hat.cpp b/CAN-binder/low-can-binding/binding/low-can-hat.cpp index 918625f..5cefc81 100644 --- a/CAN-binder/low-can-binding/binding/low-can-hat.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-hat.cpp @@ -24,7 +24,7 @@ #include #include -#include "configuration.hpp" +#include "application.hpp" #include "../can/can-bus.hpp" extern "C" @@ -66,7 +66,7 @@ extern "C" /// @return Exit code, zero if success. int afbBindingV1ServiceInit(struct afb_service service) { - can_bus_t& can_bus_manager = configuration_t::instance().get_can_bus_manager(); + can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager(); can_bus_manager.set_can_devices(); can_bus_manager.start_threads(); @@ -74,7 +74,7 @@ extern "C" /// Initialize Diagnostic manager that will handle obd2 requests. /// We pass by default the first CAN bus device to its Initialization. /// TODO: be able to choose the CAN bus device that will be use as Diagnostic bus. - if(configuration_t::instance().get_diagnostic_manager().initialize()) + if(application_t::instance().get_diagnostic_manager().initialize()) return 0; ERROR(binder_interface, "%s: There was something wrong with CAN device Initialization.", __FUNCTION__); diff --git a/CAN-binder/low-can-binding/can/can-bus.cpp b/CAN-binder/low-can-binding/can/can-bus.cpp index c296805..a35eecd 100644 --- a/CAN-binder/low-can-binding/can/can-bus.cpp +++ b/CAN-binder/low-can-binding/can/can-bus.cpp @@ -29,7 +29,7 @@ #include "can-signals.hpp" #include "can-decoder.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" #include "../utils/signals.hpp" #include "../utils/openxc-utils.hpp" @@ -61,7 +61,7 @@ int can_bus_t::process_can_signals(const can_message_t& can_message) struct utils::signals_found signals; openxc_DynamicField search_key, decoded_message; openxc_VehicleMessage vehicle_message; - configuration_t& conf = configuration_t::instance(); + application_t& conf = application_t::instance(); utils::signals_manager_t& sm = utils::signals_manager_t::instance(); // First we have to found which can_signal_t it is diff --git a/CAN-binder/low-can-binding/can/can-message-definition.cpp b/CAN-binder/low-can-binding/can/can-message-definition.cpp index e0f55a6..28d45fe 100644 --- a/CAN-binder/low-can-binding/can/can-message-definition.cpp +++ b/CAN-binder/low-can-binding/can/can-message-definition.cpp @@ -17,7 +17,7 @@ #include "can-message-definition.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" can_message_definition_t::can_message_definition_t(const std::string bus) : parent_{nullptr}, bus_{bus}, last_value_{CAN_MESSAGE_SIZE} @@ -75,7 +75,7 @@ const std::string can_message_definition_t::get_bus_name() const const std::string can_message_definition_t::get_bus_device_name() const { - return configuration_t::instance().get_can_bus_manager() + return application_t::instance().get_can_bus_manager() .get_can_device_name(bus_); } diff --git a/CAN-binder/low-can-binding/can/can-signals.cpp b/CAN-binder/low-can-binding/can/can-signals.cpp index e49c727..324cecc 100644 --- a/CAN-binder/low-can-binding/can/can-signals.cpp +++ b/CAN-binder/low-can-binding/can/can-signals.cpp @@ -19,7 +19,7 @@ #include "can-signals.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" #include "../utils/signals.hpp" #include "can-decoder.hpp" #include "can-message.hpp" diff --git a/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp b/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp index 28bf816..61775b8 100644 --- a/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp +++ b/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp @@ -20,7 +20,7 @@ #include "active-diagnostic-request.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" #define ERROR_PID 0xFF diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp index 31a3d23..e7931d9 100644 --- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -23,7 +23,7 @@ #include "../utils/openxc-utils.hpp" #include "../utils/signals.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" #define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10 #define MAX_SIMULTANEOUS_DIAG_REQUESTS 50 @@ -46,7 +46,7 @@ diagnostic_manager_t::diagnostic_manager_t() bool diagnostic_manager_t::initialize() { // Mandatory to set the bus before intialize shims. - bus_ = configuration_t::instance().get_diagnostic_bus(); + bus_ = application_t::instance().get_diagnostic_bus(); init_diagnostic_shims(); event_source_ = nullptr; @@ -135,7 +135,7 @@ int diagnostic_manager_t::add_rx_filter(uint32_t can_id) /// @return true if the CAN message was sent successfully. bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size) { - diagnostic_manager_t& dm = configuration_t::instance().get_diagnostic_manager(); + diagnostic_manager_t& dm = application_t::instance().get_diagnostic_manager(); active_diagnostic_request_t* current_adr = dm.get_last_recurring_requests(); utils::socketcan_bcm_t& tx_socket = current_adr->get_socket(); @@ -199,7 +199,7 @@ const std::string diagnostic_manager_t::get_bus_name() const const std::string diagnostic_manager_t::get_bus_device_name() const { - return configuration_t::instance().get_can_bus_manager() + return application_t::instance().get_can_bus_manager() .get_can_device_name(bus_); } diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-message.cpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-message.cpp index df093b0..dd39f88 100644 --- a/CAN-binder/low-can-binding/diagnostic/diagnostic-message.cpp +++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-message.cpp @@ -18,7 +18,7 @@ #include "diagnostic-message.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" #include "../utils/signals.hpp" const char *UNIT_NAMES[10] = { diff --git a/CAN-binder/low-can-binding/utils/openxc-utils.cpp b/CAN-binder/low-can-binding/utils/openxc-utils.cpp index 5f06504..adbadc6 100644 --- a/CAN-binder/low-can-binding/utils/openxc-utils.cpp +++ b/CAN-binder/low-can-binding/utils/openxc-utils.cpp @@ -18,7 +18,7 @@ #include "openxc-utils.hpp" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" /// /// @brief Build a specific VehicleMessage containing a DiagnosticResponse. @@ -34,7 +34,7 @@ openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value) { openxc_VehicleMessage message; - configuration_t& conf = configuration_t::instance(); + application_t& conf = application_t::instance(); message.has_type = true; message.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_DIAGNOSTIC; diff --git a/CAN-binder/low-can-binding/utils/signals.cpp b/CAN-binder/low-can-binding/utils/signals.cpp index 261f572..9dd3bfd 100644 --- a/CAN-binder/low-can-binding/utils/signals.cpp +++ b/CAN-binder/low-can-binding/utils/signals.cpp @@ -60,12 +60,12 @@ namespace utils switch(key.type) { case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: - lookup_signals_by_name(key.string_value, configuration_t::instance().get_all_can_signals(), sf.can_signals); - lookup_signals_by_name(key.string_value, configuration_t::instance().get_diagnostic_messages(), sf.diagnostic_messages); + 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_diagnostic_messages(), sf.diagnostic_messages); break; case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: - lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_all_can_signals(), sf.can_signals); - lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_diagnostic_messages(), sf.diagnostic_messages); + 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_diagnostic_messages(), sf.diagnostic_messages); break; default: ERROR(binder_interface, "%s: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.", __FUNCTION__); diff --git a/CAN-binder/low-can-binding/utils/signals.hpp b/CAN-binder/low-can-binding/utils/signals.hpp index 358ddbe..a0fa99d 100644 --- a/CAN-binder/low-can-binding/utils/signals.hpp +++ b/CAN-binder/low-can-binding/utils/signals.hpp @@ -22,7 +22,7 @@ #include #include "openxc.pb.h" -#include "../binding/configuration.hpp" +#include "../binding/application.hpp" #include "../can/can-signals.hpp" #include "../diagnostic/diagnostic-message.hpp" @@ -71,7 +71,7 @@ namespace utils { for(std::shared_ptr s : signals) { - if(configuration_t::instance().get_signal_id(*s) == key) + if(application_t::instance().get_signal_id(*s) == key) { found_signals.push_back(s); } -- cgit 1.2.3-korg