summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-08 02:41:56 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:09:03 +0100
commit2049aca0927b55f2a256fd60ff686616b73eecb7 (patch)
treeeb4e195c796aa5cc69bdedd772a659b4f83fe9d9 /src
parent64d3ead0ce87091a3489dd9796a9f77f241c468b (diff)
Beginning of work of get central configuration object
that will be used by the binding to access generated elements. It will hold generated structure/objects and make a resume to the binding configuration. Idea is to have an object that can be inherited in the generated code to extend its functionnalities or change some of its behoviors. Change-Id: If2ce5cbe2eb98a74a8e3f13000ee02855674216f Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/can/can-message.hpp15
-rw-r--r--src/can/can-signals.cpp50
-rw-r--r--src/can/can-signals.hpp17
-rw-r--r--src/configuration.cpp71
-rw-r--r--src/configuration.hpp115
-rw-r--r--src/diagnostic/diagnostic-message.cpp37
-rw-r--r--src/diagnostic/diagnostic-message.hpp4
-rw-r--r--src/low-can-binding.cpp16
-rw-r--r--src/utils/signals.hpp11
9 files changed, 219 insertions, 117 deletions
diff --git a/src/can/can-message.hpp b/src/can/can-message.hpp
index b118ce72..38a8e598 100644
--- a/src/can/can-message.hpp
+++ b/src/can/can-message.hpp
@@ -130,6 +130,21 @@ typedef struct CanMessageDefinition CanMessageDefinition;
unsigned short commandCount; /*!< commandCount - The number of CanCommmands defined for this message set.*/
} CanMessageSet;
+class can_message_set_t
+{
+ private:
+ uint8_t index; /*!<index - A numerical ID for the message set, ideally the index in an array
+ * for fast lookup*/
+ const std::string name; /*!< name - The name of the message set.*/
+ uint8_t can_bus_count; /*!< busCount - The number of CAN buses defined for this message set.*/
+ unsigned short can_message_count; /*!< messageCount - The number of CAN messages (across all buses) defined for
+ * this message set.*/
+ unsigned short can_signal_count; /*!< signalCount - The number of CAN signals (across all messages) defined for
+ * this message set.*/
+ unsigned short can_command_count; /*!< commandCount - The number of CanCommmands defined for this message set.*/
+ unsigned short obd2_signal_count; /*!< commandCount - The number of obd2 signals defined for this message set.*/
+};
+
/** Public: Return the currently active CAN configuration. */
CanMessageSet* getActiveMessageSet();
diff --git a/src/can/can-signals.cpp b/src/can/can-signals.cpp
index 64980b04..bbd172b2 100644
--- a/src/can/can-signals.cpp
+++ b/src/can/can-signals.cpp
@@ -24,56 +24,6 @@
#include "obd2/obd2-signals.hpp"
#include "low-can-binding.hpp"
-std::vector<std::vector<CanMessageDefinition>> CAN_MESSAGES = {
- {
- {0x620, CanMessageFormat::STANDARD, {10, 0, nullptr}, false, (uint8_t)NULL},
- {0x442, CanMessageFormat::STANDARD, {10, 0, nullptr}, false, (uint8_t)NULL},
- },
-};
-
-/**
- * @brief Dumb SIGNALS array. It is composed by CanMessageSet
- * SIGNALS[MESSAGE_SET_ID][CanSignal]
- */
-std::vector<std::vector<CanSignal>> SIGNALS = {
- {
- {&(CAN_MESSAGES[MESSAGE_SET_ID][0]), "can.driver_door.open", 2, 4, 1.000000, 0.000000, 0.000000, 0.000000, {10, 0, nullptr}, false, true, nullptr, 0, false, decoder_t::booleanDecoder, nullptr, false, 0.0},
- {&(CAN_MESSAGES[MESSAGE_SET_ID][1]), "can.driver_door.close", 0, 4, 1.000000, 0.000000, 0.000000, 0.000000, {10, 0, nullptr}, false, true, nullptr, 0, false, decoder_t::booleanDecoder, nullptr, false, 0.0}
- },
-};
-
-/**
- * @fn std::vector<CanSignal>& get_can_signals()
- *
- * @return A reference to a vector of signals
- */
-std::vector<CanSignal>& get_can_signals()
-{
- return SIGNALS[MESSAGE_SET_ID];
-}
-
-/**
- * @fn size_t getSignalCount()
- *
- * @return the length of the array returned by get_can_signals().
- */
-size_t getSignalCount()
-{
- return SIGNALS[MESSAGE_SET_ID].size();
-}
-
-/**
- * @brief Retrieve can arbitration id of a given CanSignal
- *
- * @param[in] CanSignal& - a const reference to a CanSignal
- *
- * @return uint32_t - unsigned integer representing the arbitration id.
- */
-uint32_t get_signal_id(const CanSignal& sig)
-{
- return sig.message->id;
-}
-
/**
* @fn void find_can_signals(const openxc_DynamicField& key, std::vector<CanSignal*>& found_signals)
* @brief return signals name found searching through CAN_signals and OBD2 pid
diff --git a/src/can/can-signals.hpp b/src/can/can-signals.hpp
index b5b87eb4..17b189c6 100644
--- a/src/can/can-signals.hpp
+++ b/src/can/can-signals.hpp
@@ -37,17 +37,6 @@ extern "C"
#define MESSAGE_SET_ID 0
-extern std::mutex subscribed_signals_mutex;
-std::mutex& get_subscribed_signals_mutex();
-
-/**
- * @brief return the subscribed_signals map.
- *
- * return std::map<std::string, struct afb_event> - map of subscribed signals.
- */
-extern std::map<std::string, struct afb_event> subscribed_signals;
-std::map<std::string, struct afb_event>& get_subscribed_signals();
-
/**
* @brief The type signature for a CAN signal decoder.
*
@@ -133,10 +122,4 @@ struct CanSignal {
};
typedef struct CanSignal CanSignal;
-std::vector<CanSignal>& get_can_signals();
-
-size_t getSignalCount();
-
void find_can_signals(const openxc_DynamicField &key, std::vector<CanSignal*>& found_signals);
-
-uint32_t get_signal_id(const CanSignal& sig); \ No newline at end of file
diff --git a/src/configuration.cpp b/src/configuration.cpp
new file mode 100644
index 00000000..de06a65f
--- /dev/null
+++ b/src/configuration.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Author "Romain Forlot" <romain.forlot@iot.bzh>
+ *
+ * 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>
+
+#define OBD2_FUNCTIONAL_BROADCAST_ID 0x7df
+
+/*
+* Pre-defined OBD-II PIDs to query for if supported by the vehicle.
+*/
+ std::vector<obd2_signals_t> OBD2_PIDS = {
+ { 0x04, "obd2.engine.load", 0, 100, POURCENT, 5, false},
+ { 0x05, "obd2.engine.coolant.temperature", -40, 215, DEGREES_CELSIUS, 1, false},
+ { 0x0a, "obd2.fuel.pressure", 0, 765, KPA, 1, false},
+ { 0x0b, "obd2.intake.manifold.pressure", 0, 255, KPA, 1, false},
+ { 0x0c, "obd2.engine.speed", 0, 16383, RPM, 5, false},
+ { 0x0d, "obd2.vehicle.speed", 0, 255, KM_H, 5, false},
+ { 0x0f, "obd2.intake.air.temperature", -40, 215, DEGREES_CELSIUS, 1, false},
+ { 0x10, "obd2.mass.airflow", 0, 655, GRAMS_SEC, 5, false},
+ { 0x11, "obd2.throttle.position", 0, 100, POURCENT, 5, false},
+ { 0x1f, "obd2.running.time", 0, 65535, SECONDS, 1, false},
+ { 0x2d, "obd2.EGR.error", -100, 99, POURCENT, 0, false},
+ { 0x2f, "obd2.fuel.level", 0, 100, POURCENT, 1, false},
+ { 0x33, "obd2.barometric.pressure", 0, 255, KPA, 1, false},
+ { 0x4c, "obd2.commanded.throttle.position", 0, 100, POURCENT, 1, false},
+ { 0x52, "obd2.ethanol.fuel.percentage", 0, 100, POURCENT, 1, false},
+ { 0x5a, "obd2.accelerator.pedal.position", 0, 100, POURCENT, 5, false},
+ { 0x5b, "obd2.hybrid.battery-pack.remaining.life", 0, 100, POURCENT, 5, false},
+ { 0x5c, "obd2.engine.oil.temperature",-40, 210, DEGREES_CELSIUS, 1, false},
+ { 0x63, "obd2.engine.torque", 0, 65535, NM, 1, false}
+};
+
+std::vector<can_message_set_t> CAN_MESSAGE_SET =
+{
+ {0, "example_messages", 1, 2, 2, 0, 19},
+};
+
+std::vector<std::vector<can_message_definition_t>> CAN_MESSAGES_DEFINTION = {
+ {
+ {0x620, CanMessageFormat::STANDARD, {10, 0, nullptr}, false, (uint8_t)NULL},
+ {0x442, CanMessageFormat::STANDARD, {10, 0, nullptr}, false, (uint8_t)NULL},
+ },
+};
+
+/**
+ * @brief Dumb SIGNALS array. It is composed by CanMessageSet
+ * SIGNALS[MESSAGE_SET_ID][CanSignal]
+ */
+std::vector<std::vector<can_signal_t>> SIGNALS = {
+ {
+ {&(CAN_MESSAGES_DEFINTION[MESSAGE_SET_ID][0]), "can.driver_door.open", 2, 4, 1.000000, 0.000000, 0.000000, 0.000000, {10, 0, nullptr}, false, true, nullptr, 0, false, decoder_t::booleanDecoder, nullptr, false, 0.0},
+ {&(CAN_MESSAGES_DEFINTION[MESSAGE_SET_ID][1]), "can.driver_door.close", 0, 4, 1.000000, 0.000000, 0.000000, 0.000000, {10, 0, nullptr}, false, true, nullptr, 0, false, decoder_t::booleanDecoder, nullptr, false, 0.0}
+ },
+};
+
+configuration_t::configuration_t()
+ : obd2_signals_{OBD2_PIDS}, can_message_set_{CAN_MESSAGE_SET}, can_signals_{SIGNALS}, can_message_definition_{CAN_MESSAGES_DEFINTION} \ No newline at end of file
diff --git a/src/configuration.hpp b/src/configuration.hpp
new file mode 100644
index 00000000..2fd59e5f
--- /dev/null
+++ b/src/configuration.hpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Author "Romain Forlot" <romain.forlot@iot.bzh>
+ *
+ * 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 <vector>
+
+#include "can/can-bus.hpp"
+#include "can/can-signals.hpp"
+#include "obd2/diagnostic-manager.hpp"
+
+/**
+ * @brief Class representing a configuration attached to the binding.
+ *
+ * @desc 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.
+ */
+
+#include "low-can-binding.hpp"
+
+class configuration_t
+{
+ private:
+ can_bus_t can_bus_manager_(afb_daemon_rootdir_open_locale(binder_interface->daemon, "can_buses.json", O_RDONLY, NULL));
+ diagnostic_manager_t diagnostic_manager_;
+ uint8_t active_message_set_ = 0;
+
+ public:
+ const std::vector<obd2_signals_t> obd2_signals_;
+ const std::vector<can_message_set_t> can_message_set_;
+ const std::vector<std::vector<can_signal_t>> can_signals_;
+ const std::vector<std::vector<can_message_definition_t>> can_message_definition_;
+
+ configuration_t& get_configuration()
+ {
+ return this;
+ }
+
+ can_bus_t& get_can_bus_manager()
+ {
+ return can_bus_manager_;
+ }
+
+ diagnostic_manager_t& get_diagnostic_manager()
+ {
+ return diagnostic_manager_;
+ }
+
+ uint8_t get_active_message_set()
+ {
+ return active_message_set_;
+ }
+
+ std::vector<can_message_set>& get_can_message_set()
+ {
+ return can_message_set_;
+ }
+
+ std::vector<can_signal>& get_can_signals()
+ {
+ return can_signal_[active_message_set_];
+ }
+
+ std::vector<CanSignal>& get_can_signals()
+ {
+ return SIGNALS[active_message_set_];
+ }
+
+ std::vector<can_message_definition>& get_can_message_definition()
+ {
+ return can_message_definition_[active_message_set_];
+ }
+
+ std::vector<obd2_signals_t>& get_obd2_signals()
+ {
+ return obd2_signals_;
+ }
+
+ std::vector<obd2_signals_t>& get_obd2_signals()
+ {
+ return OBD2_PIDS;
+ }
+
+ uint32_t get_signal_id(obd2_signals_t& sig)
+ {
+ return sig.get_pid();
+ }
+
+ uint32_t get_signal_id(const CanSignal& sig)
+ {
+ return sig.message->id;
+ }
+
+ void set_active_message_set(uint8_t id)
+ {
+ active_message_set_ = id;
+ }
+}; \ No newline at end of file
diff --git a/src/diagnostic/diagnostic-message.cpp b/src/diagnostic/diagnostic-message.cpp
index 15fe0944..656a868c 100644
--- a/src/diagnostic/diagnostic-message.cpp
+++ b/src/diagnostic/diagnostic-message.cpp
@@ -19,8 +19,6 @@
#include "utils/signals.hpp"
-#define OBD2_FUNCTIONAL_BROADCAST_ID 0x7df
-
const char *UNIT_NAMES[10] = {
"POURCENT",
"DEGREES_CELSIUS",
@@ -34,41 +32,6 @@ const char *UNIT_NAMES[10] = {
"NM"
};
-/*
-* Pre-defined OBD-II PIDs to query for if supported by the vehicle.
-*/
- std::vector<obd2_signals_t> OBD2_PIDS = {
- { 0x04, "obd2.engine.load", 0, 100, POURCENT, 5, false},
- { 0x05, "obd2.engine.coolant.temperature", -40, 215, DEGREES_CELSIUS, 1, false},
- { 0x0a, "obd2.fuel.pressure", 0, 765, KPA, 1, false},
- { 0x0b, "obd2.intake.manifold.pressure", 0, 255, KPA, 1, false},
- { 0x0c, "obd2.engine.speed", 0, 16383, RPM, 5, false},
- { 0x0d, "obd2.vehicle.speed", 0, 255, KM_H, 5, false},
- { 0x0f, "obd2.intake.air.temperature", -40, 215, DEGREES_CELSIUS, 1, false},
- { 0x10, "obd2.mass.airflow", 0, 655, GRAMS_SEC, 5, false},
- { 0x11, "obd2.throttle.position", 0, 100, POURCENT, 5, false},
- { 0x1f, "obd2.running.time", 0, 65535, SECONDS, 1, false},
- { 0x2d, "obd2.EGR.error", -100, 99, POURCENT, 0, false},
- { 0x2f, "obd2.fuel.level", 0, 100, POURCENT, 1, false},
- { 0x33, "obd2.barometric.pressure", 0, 255, KPA, 1, false},
- { 0x4c, "obd2.commanded.throttle.position", 0, 100, POURCENT, 1, false},
- { 0x52, "obd2.ethanol.fuel.percentage", 0, 100, POURCENT, 1, false},
- { 0x5a, "obd2.accelerator.pedal.position", 0, 100, POURCENT, 5, false},
- { 0x5b, "obd2.hybrid.battery-pack.remaining.life", 0, 100, POURCENT, 5, false},
- { 0x5c, "obd2.engine.oil.temperature",-40, 210, DEGREES_CELSIUS, 1, false},
- { 0x63, "obd2.engine.torque", 0, 65535, NM, 1, false}
-};
-
-uint32_t get_signal_id(obd2_signals_t& sig)
-{
- return sig.get_pid();
-}
-
-std::vector<obd2_signals_t>& get_obd2_signals()
-{
- return OBD2_PIDS;
-}
-
obd2_signals_t::obd2_signals_t(uint8_t pid, const char* generic_name, const int min, const int max, enum UNIT unit, int frequency, bool supported)
: pid_{pid}, generic_name_{generic_name}, min_{min}, max_{max}, unit_{unit}, frequency_{frequency}, supported_{supported}
{
diff --git a/src/diagnostic/diagnostic-message.hpp b/src/diagnostic/diagnostic-message.hpp
index 5adbde59..ac6ca18e 100644
--- a/src/diagnostic/diagnostic-message.hpp
+++ b/src/diagnostic/diagnostic-message.hpp
@@ -68,7 +68,7 @@ typedef struct _Obd2Pid {
class obd2_signals_t {
private:
uint8_t pid_; /*!< pid - The 1 byte PID.*/
- const char* generic_name_; /*!< generic_name_ - A human readable name to use for this PID when published.*/
+ const std::string generic_name_; /*!< generic_name_ - A human readable name to use for this PID when published.*/
const int min_; /*!< min_ - Minimum value that can take this pid */
const int max_; /*!< max_ - Maximum value that can take this pid */
enum UNIT unit_; /*!< unit_ : Which unit system is used by that pid. See enum UNIT above.*/
@@ -76,7 +76,7 @@ class obd2_signals_t {
bool supported_; /*!< supported_ - boolean indicating whether this pid is supported by the vehicle or not.*/
public:
- const char* generic_name = generic_name_;
+ const char* generic_name = generic_name_.c_str();
obd2_signals_t(uint8_t pid, const char* generic_name, const int min_, const int max_, enum UNIT unit, int frequency, bool supported);
uint32_t get_pid();
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index 41a6ab63..79b16914 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -40,13 +40,9 @@ extern "C"
#include <afb/afb-service-itf.h>
};
-/*
- * Interface between the daemon and the binding
- */
+// Interface between the daemon and the binding
const struct afb_binding_interface *binder_interface;
-can_bus_t *can_bus_handler;
-
/********************************************************************************
*
* Subscription and unsubscription
@@ -224,16 +220,14 @@ extern "C"
*/
int afbBindingV1ServiceInit(struct afb_service service)
{
- int fd_conf;
- fd_conf = afb_daemon_rootdir_open_locale(binder_interface->daemon, "can_buses.json", O_RDONLY, NULL);
+ configuration_t config;
- /* Initialize the CAN bus handler */
- can_bus_handler = new can_bus_t(fd_conf);
+ can_bus_manager = config.get_can_bus_manager();
/* Open CAN socket */
- if(can_bus_handler->init_can_dev() == 0)
+ if(can_bus_manager.init_can_dev() == 0)
{
- can_bus_handler->start_threads();
+ can_bus_manager.start_threads();
return 0;
}
ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe");
diff --git a/src/utils/signals.hpp b/src/utils/signals.hpp
index 8e15bd21..e575bd15 100644
--- a/src/utils/signals.hpp
+++ b/src/utils/signals.hpp
@@ -25,6 +25,17 @@
#include "can/can-signals.hpp"
#include "obd2/obd2-signals.hpp"
+extern std::mutex subscribed_signals_mutex;
+std::mutex& get_subscribed_signals_mutex();
+
+/**
+ * @brief return the subscribed_signals map.
+ *
+ * return std::map<std::string, struct afb_event> - map of subscribed signals.
+ */
+extern std::map<std::string, struct afb_event> subscribed_signals;
+std::map<std::string, struct afb_event>& get_subscribed_signals();
+
template <typename T>
void lookup_signals_by_name(const std::string& key, std::vector<T>& signals, std::vector<T*>& found_signals)
{