Beginning of work on obd2 object and
authorRomain Forlot <romain.forlot@iot.bzh>
Mon, 6 Mar 2017 21:28:50 +0000 (22:28 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:05:17 +0000 (17:05 +0100)
files reorganization.

Change-Id: Idaa7ad05c45d734ce771506fd6e41f1a09a6ac66
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
18 files changed:
src/can/can-bus.cpp [moved from src/can-bus.cpp with 100% similarity]
src/can/can-bus.hpp [moved from src/can-bus.hpp with 100% similarity]
src/can/can-command.hpp [moved from src/can-command.hpp with 100% similarity]
src/can/can-decoder.cpp [moved from src/can-decoder.cpp with 100% similarity]
src/can/can-decoder.hpp [moved from src/can-decoder.hpp with 100% similarity]
src/can/can-message.cpp [moved from src/can-message.cpp with 100% similarity]
src/can/can-message.hpp [moved from src/can-message.hpp with 100% similarity]
src/can/can-signals.cpp [moved from src/can-signals.cpp with 100% similarity]
src/can/can-signals.hpp [moved from src/can-signals.hpp with 100% similarity]
src/diagnostic/diagnostic-message.cpp [moved from src/obd2-signals.cpp with 62% similarity]
src/diagnostic/diagnostic-message.hpp [moved from src/obd2-signals.hpp with 55% similarity]
src/low-can-binding.cpp
src/utils/openxc-utils.cpp [moved from src/openxc-utils.cpp with 100% similarity]
src/utils/openxc-utils.hpp [moved from src/openxc-utils.hpp with 100% similarity]
src/utils/signals.cpp [moved from src/signals.cpp with 100% similarity]
src/utils/signals.hpp [moved from src/signals.hpp with 100% similarity]
src/utils/timer.cpp [moved from src/timer.cpp with 100% similarity]
src/utils/timer.hpp [moved from src/timer.hpp with 100% similarity]

similarity index 100%
rename from src/can-bus.cpp
rename to src/can/can-bus.cpp
similarity index 100%
rename from src/can-bus.hpp
rename to src/can/can-bus.hpp
similarity index 100%
rename from src/can-command.hpp
rename to src/can/can-command.hpp
similarity index 100%
rename from src/can-decoder.cpp
rename to src/can/can-decoder.cpp
similarity index 100%
rename from src/can-decoder.hpp
rename to src/can/can-decoder.hpp
similarity index 100%
rename from src/can-message.cpp
rename to src/can/can-message.cpp
similarity index 100%
rename from src/can-message.hpp
rename to src/can/can-message.hpp
similarity index 100%
rename from src/can-signals.cpp
rename to src/can/can-signals.cpp
similarity index 100%
rename from src/can-signals.hpp
rename to src/can/can-signals.hpp
similarity index 62%
rename from src/obd2-signals.cpp
rename to src/diagnostic/diagnostic-message.cpp
index 1a562d0..bfca85b 100644 (file)
@@ -35,28 +35,45 @@ const char *UNIT_NAMES[10] = {
 /*
 * Pre-defined OBD-II PIDs to query for if supported by the vehicle.
 */
- std::vector<Obd2Pid> 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<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}
 };
 
+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}
+{
+}
+
+void obd2_signals_t::init_diagnostic_shims(can_bus_dev_t& can_bus_dev)
+{
+       DiagnosticShims shims_ = diagnostic_init_shims(shims_logger, can_bus_dev.send_can_message, NULL);
+
+       int n_pids_, i_;
+
+       n_pids_ = size(Obd2Pid);
+       for(i_=0; i_<=n_pids_; i_++)
+       {
+       }
+}
+
 /**
  * @fn std::vector<std::string> find_signals(const openxc_DynamicField &key)
  * @brief return signals name found searching through CAN_signals and OBD2 pid
@@ -66,7 +83,7 @@ const char *UNIT_NAMES[10] = {
  *
  * @return std::vector<std::string> Vector of signals name found. 
  */
-void find_signals(const openxc_DynamicField &key, std::vector<Obd2Pid*>& found_signals)
+void obd2_signals_t::find_obd2_signals(const openxc_DynamicField &key, std::vector<Obd2Pid*>& found_signals)
 {
        switch(key.type)
        {
@@ -102,7 +119,7 @@ void shims_timer()
 {
 }
 
-bool is_obd2_response(can_message_t can_message)
+bool obd2_signals_t::is_obd2_response(can_message_t can_message)
 {
        if(can_message.get_id() >= 0x7E8 && can_message.get_id() <= 0x7EF)
        {
@@ -116,7 +133,7 @@ bool is_obd2_response(can_message_t can_message)
                message.diagnostic_response.has_message_id = true;
                //7DF should respond with a random message id between 7e8 and 7ef
                //7E0 through 7E7 should respond with a id that is 8 higher (7E0->7E8)
-               if(commandRequest->message_id == 0x7DF)
+               if(can_message.get_id() == 0x7DF)
                {
                        message.diagnostic_response.message_id = rand()%(0x7EF-0x7E8 + 1) + 0x7E8;
                }
@@ -141,41 +158,49 @@ bool is_obd2_response(can_message_t can_message)
                status=false;
 };
 
-/*
- * Will scan for supported Obd2 pids
- *
-obd2_handler_t::obd2_handler_t()
-{
-       DiagnosticShims shims_ = diagnostic_init_shims(shims_logger, can_bus.send_can_message, NULL);
-
-       int n_pids_, i_;
-
-       n_pids_ = size(Obd2Pid);
-       for(i_=0; i_<=n_pids_; i_++)
-       {
-       }
-}
-
-void obd2_handler_t::add_request(int pid)
+void obd2_signals_t::add_request(int pid)
 {
        DiagnosticRequest request = {
        arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
        mode: 0x1, has_true, pid};
 }
 
-bool obd2_handler_t::is_obd2_request(DiagnosticRequest* request)
+/**
+* @brief Check if a request is an OBD-II PID request.
+*
+* @return true if the request is a mode 1 request and it has a 1 byte PID.
+*/
+bool obd2_signals_t::is_obd2_request(DiagnosticRequest* request)
 {
        return request->mode == 0x1 && request->has_pid && request->pid < 0xff;
 }
 
-bool obd2_handler_t::is_obd2_signal(const char *name)
+/**
+* @brief Check if requested signal name is an obd2 pid
+* 
+* @return true if name began with obd2 else false.
+*/
+bool obd2_signals_t::is_obd2_signal(const char *name)
 {
        if(fnmatch("obd2.*", name, FNM_CASEFOLD) == 0)
                return true;
        return false;
 }
 
-bool obd2_handler_t::decode_obd2_response(DiagnosticResponse* responce)
+/**
+* @brief Decode the payload of an OBD-II PID.
+*
+* This function matches the type signature for a DiagnosticResponseDecoder, so
+* it can be used as the decoder for a DiagnosticRequest. It returns the decoded
+* value of the PID, using the standard formulas (see
+* http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01).
+*
+* @param[in] DiagnosticResponse response - the received DiagnosticResponse (the data is in response.payload,
+*  a byte array). This is most often used when the byte order is
+*  signiticant, i.e. with many OBD-II PID formulas.
+* @param[in] float parsed_payload - the entire payload of the response parsed as an int.
+*/
+float obd2_signals_t::decode_obd2_response(const DiagnosticResponse* response, float parsedPayload)
 {
        return diagnostic_decode_obd2_pid(response);
-}*/
\ No newline at end of file
+}
\ No newline at end of file
similarity index 55%
rename from src/obd2-signals.hpp
rename to src/diagnostic/diagnostic-message.hpp
index c9fa4f6..a8f21e0 100644 (file)
@@ -61,54 +61,34 @@ typedef struct _Obd2Pid {
        bool supported;
 } Obd2Pid;
 
-std::vector<Obd2Pid>& get_obd2_signals();
-uint32_t get_signal_id(const Obd2Pid& sig);
-void find_obd2_signals(const openxc_DynamicField &key, std::vector<Obd2Pid*>& found_signals);
-
-bool is_obd2_response(can_message_t can_message);
-
 /**
  * @brief - Object to handle obd2 session with pre-scan of supported pid
  * then request them regularly
  */
-class obd2_handler_t {
+class obd2_signals_t {
        private:
+               uint8_t pid_;
+               const char* generic_name_;
+               const int min_;
+               const int max_;
+               enum UNIT unit_;
+               int frequency_;
+               bool supported_;
 
        public:
-               obd2_handler_t();
-               /**
-                * @brief:
-                *
-                * Returns
-                */
-               void find_obd2_pid(const char *name, std::vector<Obd2Pid> *pids);
+               obd2_signals_t(uint8_t pid, const char* generic_name, const int min_, const int max_, enum UNIT unit, int frequency, bool supported);
 
-               /**
-                * @brief Check if a request is an OBD-II PID request.
-                *
-                * @return true if the request is a mode 1 request and it has a 1 byte PID.
-                */
-               bool is_obd2_request(DiagnosticRequest *request);
+               void init_diagnostic_shims(can_bus_dev_t& can_bus_dev)
+               void add_request(int pid);
+               std::vector<Obd2Pid>& get_obd2_signals();
 
-               /**
-               * @brief Check if requested signal name is an obd2 pid
-               * 
-               * @return true if name began with obd2 else false.
-               */
+               uint32_t get_signal_id(const Obd2Pid& sig);
+               void find_obd2_signals(const openxc_DynamicField &key, std::vector<Obd2Pid*>& found_signals);
+
+
+               bool is_obd2_response(can_message_t can_message);
+               bool is_obd2_request(DiagnosticRequest *request);
                bool is_obd2_signal(const char *name);
 
-               /**
-               * @brief Decode the payload of an OBD-II PID.
-               *
-               * This function matches the type signature for a DiagnosticResponseDecoder, so
-               * it can be used as the decoder for a DiagnosticRequest. It returns the decoded
-               * value of the PID, using the standard formulas (see
-               * http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01).
-               *
-               * @param[in] DiagnosticResponse response - the received DiagnosticResponse (the data is in response.payload,
-               *  a byte array). This is most often used when the byte order is
-               *  signiticant, i.e. with many OBD-II PID formulas.
-               * @param[in] float parsed_payload - the entire payload of the response parsed as an int.
-               */
-               float handle_obd2_pid(const DiagnosticResponse* response, float parsedPayload);
+               float decode_obd2_response(const DiagnosticResponse* response, float parsedPayload);
 };
\ No newline at end of file
index b9fb27d..043261f 100644 (file)
@@ -119,33 +119,33 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
  *
  * @return Number of correctly subscribed signal
  */
-static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, std::vector<std::string>& signals)
+static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, const std::vector<std::string>& signals)
 {
        int rets = 0;
 
-       for(auto& signal_i : signals)
+       for(auto& sig : signals)
        {
-               int ret = subscribe_unsubscribe_signal(request, subscribe, signal_i);
+               int ret = subscribe_unsubscribe_signal(request, subscribe, sig);
                if(ret <= 0)
                        return ret;
                rets++;
-               DEBUG(binder_interface, "Signal: %s subscribed", signal_i.c_str());
+               DEBUG(binder_interface, "Signal: %s subscribed", sig.c_str());
        }
        return rets;
 }
 
 static int subscribe_unsubscribe_name(struct afb_req request, bool subscribe, const char *name)
 {
-       std::vector<std::string> sig;
+       std::vector<std::string> signals;
        int ret = 0;
 
        openxc_DynamicField search_key = build_DynamicField(std::string(name));
-       sig = find_signals(search_key);
-       if (sig.empty())
+       signals = find_signals(search_key);
+       if (signalssig.empty())
                ret = 0;
 
-       ret = subscribe_unsubscribe_signals(request, subscribe, sig);
-       NOTICE(binder_interface, "Subscribed correctly to %d/%d signal(s).", ret, (int)sig.size());
+       ret = subscribe_unsubscribe_signals(request, subscribe, signals);
+       NOTICE(binder_interface, "Subscribed correctly to %d/%d signal(s).", ret, (int)signals.size());
 
        return ret;
 }
similarity index 100%
rename from src/signals.cpp
rename to src/utils/signals.cpp
similarity index 100%
rename from src/signals.hpp
rename to src/utils/signals.hpp
similarity index 100%
rename from src/timer.cpp
rename to src/utils/timer.cpp
similarity index 100%
rename from src/timer.hpp
rename to src/utils/timer.hpp