diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-06 22:28:50 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-16 17:05:17 +0100 |
commit | de8fb10e1d8e98a85dfba6fc8966266dbf5e42c6 (patch) | |
tree | 0eab1a766f80b7498d63fb8ecd36486c13b633a2 | |
parent | 4fd376fac5b1d47eed3f22467ae5b5e35f1ec610 (diff) |
Beginning of work on obd2 object and
files reorganization.
Change-Id: Idaa7ad05c45d734ce771506fd6e41f1a09a6ac66
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | src/can/can-bus.cpp (renamed from src/can-bus.cpp) | 0 | ||||
-rw-r--r-- | src/can/can-bus.hpp (renamed from src/can-bus.hpp) | 0 | ||||
-rw-r--r-- | src/can/can-command.hpp (renamed from src/can-command.hpp) | 0 | ||||
-rw-r--r-- | src/can/can-decoder.cpp (renamed from src/can-decoder.cpp) | 0 | ||||
-rw-r--r-- | src/can/can-decoder.hpp (renamed from src/can-decoder.hpp) | 0 | ||||
-rw-r--r-- | src/can/can-message.cpp (renamed from src/can-message.cpp) | 0 | ||||
-rw-r--r-- | src/can/can-message.hpp (renamed from src/can-message.hpp) | 0 | ||||
-rw-r--r-- | src/can/can-signals.cpp (renamed from src/can-signals.cpp) | 0 | ||||
-rw-r--r-- | src/can/can-signals.hpp (renamed from src/can-signals.hpp) | 0 | ||||
-rw-r--r-- | src/diagnostic/diagnostic-message.cpp (renamed from src/obd2-signals.cpp) | 111 | ||||
-rw-r--r-- | src/diagnostic/diagnostic-message.hpp (renamed from src/obd2-signals.hpp) | 58 | ||||
-rw-r--r-- | src/low-can-binding.cpp | 18 | ||||
-rw-r--r-- | src/utils/openxc-utils.cpp (renamed from src/openxc-utils.cpp) | 0 | ||||
-rw-r--r-- | src/utils/openxc-utils.hpp (renamed from src/openxc-utils.hpp) | 0 | ||||
-rw-r--r-- | src/utils/signals.cpp (renamed from src/signals.cpp) | 0 | ||||
-rw-r--r-- | src/utils/signals.hpp (renamed from src/signals.hpp) | 0 | ||||
-rw-r--r-- | src/utils/timer.cpp (renamed from src/timer.cpp) | 0 | ||||
-rw-r--r-- | src/utils/timer.hpp (renamed from src/timer.hpp) | 0 |
18 files changed, 96 insertions, 91 deletions
diff --git a/src/can-bus.cpp b/src/can/can-bus.cpp index d46092bf..d46092bf 100644 --- a/src/can-bus.cpp +++ b/src/can/can-bus.cpp diff --git a/src/can-bus.hpp b/src/can/can-bus.hpp index bc2bb04c..bc2bb04c 100644 --- a/src/can-bus.hpp +++ b/src/can/can-bus.hpp diff --git a/src/can-command.hpp b/src/can/can-command.hpp index 62b56c1e..62b56c1e 100644 --- a/src/can-command.hpp +++ b/src/can/can-command.hpp diff --git a/src/can-decoder.cpp b/src/can/can-decoder.cpp index 03471398..03471398 100644 --- a/src/can-decoder.cpp +++ b/src/can/can-decoder.cpp diff --git a/src/can-decoder.hpp b/src/can/can-decoder.hpp index e7dfff86..e7dfff86 100644 --- a/src/can-decoder.hpp +++ b/src/can/can-decoder.hpp diff --git a/src/can-message.cpp b/src/can/can-message.cpp index ad032021..ad032021 100644 --- a/src/can-message.cpp +++ b/src/can/can-message.cpp diff --git a/src/can-message.hpp b/src/can/can-message.hpp index 9f6a36da..9f6a36da 100644 --- a/src/can-message.hpp +++ b/src/can/can-message.hpp diff --git a/src/can-signals.cpp b/src/can/can-signals.cpp index 07689a01..07689a01 100644 --- a/src/can-signals.cpp +++ b/src/can/can-signals.cpp diff --git a/src/can-signals.hpp b/src/can/can-signals.hpp index 250ff197..250ff197 100644 --- a/src/can-signals.hpp +++ b/src/can/can-signals.hpp diff --git a/src/obd2-signals.cpp b/src/diagnostic/diagnostic-message.cpp index 1a562d06..bfca85bc 100644 --- a/src/obd2-signals.cpp +++ b/src/diagnostic/diagnostic-message.cpp @@ -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 diff --git a/src/obd2-signals.hpp b/src/diagnostic/diagnostic-message.hpp index c9fa4f61..a8f21e09 100644 --- a/src/obd2-signals.hpp +++ b/src/diagnostic/diagnostic-message.hpp @@ -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 diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp index b9fb27df..043261fa 100644 --- a/src/low-can-binding.cpp +++ b/src/low-can-binding.cpp @@ -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; } diff --git a/src/openxc-utils.cpp b/src/utils/openxc-utils.cpp index 40745a06..40745a06 100644 --- a/src/openxc-utils.cpp +++ b/src/utils/openxc-utils.cpp diff --git a/src/openxc-utils.hpp b/src/utils/openxc-utils.hpp index b7fa7884..b7fa7884 100644 --- a/src/openxc-utils.hpp +++ b/src/utils/openxc-utils.hpp diff --git a/src/signals.cpp b/src/utils/signals.cpp index 6e2f396a..6e2f396a 100644 --- a/src/signals.cpp +++ b/src/utils/signals.cpp diff --git a/src/signals.hpp b/src/utils/signals.hpp index 81ed4248..81ed4248 100644 --- a/src/signals.hpp +++ b/src/utils/signals.hpp diff --git a/src/timer.cpp b/src/utils/timer.cpp index 01fd7636..01fd7636 100644 --- a/src/timer.cpp +++ b/src/utils/timer.cpp diff --git a/src/timer.hpp b/src/utils/timer.hpp index 7d0e4669..7d0e4669 100644 --- a/src/timer.hpp +++ b/src/utils/timer.hpp |