summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/can/can-bus.cpp4
-rw-r--r--src/configuration.cpp6
-rw-r--r--src/configuration.hpp9
-rw-r--r--src/diagnostic/diagnostic-manager.cpp2
-rw-r--r--src/low-can-binding.cpp5
-rw-r--r--src/utils/signals.cpp8
-rw-r--r--src/utils/signals.hpp4
7 files changed, 20 insertions, 18 deletions
diff --git a/src/can/can-bus.cpp b/src/can/can-bus.cpp
index 4ddf6c82..a8a474cf 100644
--- a/src/can/can-bus.cpp
+++ b/src/can/can-bus.cpp
@@ -81,7 +81,7 @@ void can_bus_t::can_decode_message()
/* First we have to found which can_signal_t it is */
search_key = build_DynamicField((double)can_message.get_id());
signals.clear();
- config->find_can_signals(search_key, signals);
+ configuration_t::instance().find_can_signals(search_key, signals);
/* Decoding the message ! Don't kill the messenger ! */
for(auto& sig : signals)
@@ -96,7 +96,7 @@ void can_bus_t::can_decode_message()
DEBUG(binder_interface, "Nb elt matched string: %d", (int)s.count(std::string(sig.generic_name)));*/
if( s.find(sig->get_generic_name()) != s.end() && afb_event_is_valid(s[sig->get_generic_name()]))
{
- decoded_message = decoder_t::translateSignal(*sig, can_message, config->get_can_signals());
+ decoded_message = decoder_t::translateSignal(*sig, can_message, configuration_t::instance().get_can_signals());
openxc_SimpleMessage s_message = build_SimpleMessage(sig->get_generic_name(), decoded_message);
vehicle_message = build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type::openxc_DynamicField_Type_NUM, s_message);
diff --git a/src/configuration.cpp b/src/configuration.cpp
index cfa728e7..123f8a1c 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -51,6 +51,12 @@ std::vector<std::vector<can_message_definition_t>> CAN_MESSAGES_DEFINTION;
std::vector<std::vector<can_signal_t>> SIGNALS;
+configuration_t& configuration_t::instance()
+{
+ static configuration_t config;
+ return config;
+}
+
configuration_t::configuration_t()
: can_message_set_{CAN_MESSAGE_SET}, can_signals_{SIGNALS}, obd2_signals_{OBD2_PIDS}, can_message_definition_{CAN_MESSAGES_DEFINTION}
{}
diff --git a/src/configuration.hpp b/src/configuration.hpp
index 981e69e4..9aaf41e5 100644
--- a/src/configuration.hpp
+++ b/src/configuration.hpp
@@ -45,9 +45,12 @@ class configuration_t
diagnostic_manager_t diagnostic_manager_;
uint8_t active_message_set_ = 0;
- public:
+ /// Private constructor with implementation generated by the AGL generator.
configuration_t();
+ public:
+ static configuration_t& instance();
+
std::vector<can_message_set_t> can_message_set_;
std::vector<std::vector<can_signal_t>> can_signals_;
std::vector<std::vector<obd2_signal_t>> obd2_signals_;
@@ -105,7 +108,3 @@ class configuration_t
bool isBusActive(can_bus_dev_t* bus);
*/
};
-
-// Make a global variable pointer
-extern configuration_t *config;
-
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp
index 5678dc49..92ce33b0 100644
--- a/src/diagnostic/diagnostic-manager.cpp
+++ b/src/diagnostic/diagnostic-manager.cpp
@@ -246,7 +246,7 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con
bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
{
- can_bus_dev_t *can_bus_dev = config->get_diagnostic_manager().get_can_bus_dev();
+ can_bus_dev_t *can_bus_dev = configuration_t::instance().get_diagnostic_manager().get_can_bus_dev();
return can_bus_dev->shims_send(arbitration_id, data, size);
}
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index 93574908..8411b65d 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -42,7 +42,6 @@ extern "C"
// Interface between the daemon and the binding
const struct afb_binding_interface *binder_interface;
-configuration_t *config;
/********************************************************************************
*
@@ -221,9 +220,7 @@ extern "C"
*/
int afbBindingV1ServiceInit(struct afb_service service)
{
- config = new configuration_t();
-
- can_bus_t& can_bus_manager = config->get_can_bus_manager();
+ can_bus_t& can_bus_manager = configuration_t::instance().get_can_bus_manager();
/* Open CAN socket */
if(can_bus_manager.init_can_dev() == 0)
diff --git a/src/utils/signals.cpp b/src/utils/signals.cpp
index 7393409b..9e719293 100644
--- a/src/utils/signals.cpp
+++ b/src/utils/signals.cpp
@@ -60,12 +60,12 @@ std::vector<std::string> find_signals(const openxc_DynamicField &key)
switch(key.type)
{
case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
- lookup_signals_by_name(key.string_value, config->get_can_signals(), found_signals_name);
- lookup_signals_by_name(key.string_value, config->get_obd2_signals(), found_signals_name);
+ lookup_signals_by_name(key.string_value, configuration_t::instance().get_can_signals(), found_signals_name);
+ lookup_signals_by_name(key.string_value, configuration_t::instance().get_obd2_signals(), found_signals_name);
break;
case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
- lookup_signals_by_id(key.numeric_value, config->get_can_signals(), found_signals_name);
- lookup_signals_by_id(key.numeric_value, config->get_obd2_signals(), found_signals_name);
+ lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_can_signals(), found_signals_name);
+ lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_obd2_signals(), found_signals_name);
break;
default:
ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
diff --git a/src/utils/signals.hpp b/src/utils/signals.hpp
index fe869539..4380045e 100644
--- a/src/utils/signals.hpp
+++ b/src/utils/signals.hpp
@@ -64,7 +64,7 @@ void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector
{
for(T& s : signals)
{
- if(config->get_signal_id(s) == key)
+ if(configuration_t::instance().get_signal_id(s) == key)
{
found_signals.push_back(&s);
}
@@ -76,7 +76,7 @@ void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector
{
for(T& s : signals)
{
- if(config->get_signal_id(s) == key)
+ if(configuration_t::instance().get_signal_id(s) == key)
{
found_signals_name.push_back(s.get_generic_name());
}