summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-13 09:45:01 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:15:55 +0100
commitb606db2b74d5c92d33a126071062c9eb2a548beb (patch)
tree26e0edc377c35521bba345a5f162809894751376
parent37bf83a16cbd07b168b8c4f5a2c05cbf281d8fad (diff)
Change the way to check signal type making prefix_
attribute as static with a static class method which will check that the beginning of string argument matches the prefix. Change-Id: Idb129c7179391da61447996560957b2791aa9383 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--src/can/can-signals.cpp2
-rw-r--r--src/can/can-signals.hpp2
-rw-r--r--src/diagnostic/diagnostic-message.cpp10
-rw-r--r--src/diagnostic/diagnostic-message.hpp8
-rw-r--r--src/low-can-binding.cpp4
5 files changed, 14 insertions, 12 deletions
diff --git a/src/can/can-signals.cpp b/src/can/can-signals.cpp
index 00b6ee07..27a7df9c 100644
--- a/src/can/can-signals.cpp
+++ b/src/can/can-signals.cpp
@@ -25,6 +25,8 @@
#include "../obd2/obd2-signals.hpp"
#include "../low-can-binding.hpp"
+std::string can_signal_t::prefix_ = "messages.";
+
can_message_definition_t& can_signal_t::get_message()
{
return message_;
diff --git a/src/can/can-signals.hpp b/src/can/can-signals.hpp
index c1d07eee..7708461f 100644
--- a/src/can/can-signals.hpp
+++ b/src/can/can-signals.hpp
@@ -77,7 +77,7 @@ class can_signal_t
private:
can_message_definition_t message_; /*!< message_ - The message this signal is a part of. */
std::string generic_name_; /*!< generic_name_ - The name of the signal to be output.*/
- std::string prefix_ = "messages."; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
+ static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
* which make easier to sort message when the come in.*/
uint8_t bit_position_; /*!< bitPosition_ - The starting bit of the signal in its CAN message (assuming
* non-inverted bit numbering, i.e. the most significant bit of
diff --git a/src/diagnostic/diagnostic-message.cpp b/src/diagnostic/diagnostic-message.cpp
index c9035eb0..8b2273ef 100644
--- a/src/diagnostic/diagnostic-message.cpp
+++ b/src/diagnostic/diagnostic-message.cpp
@@ -33,6 +33,8 @@ const char *UNIT_NAMES[10] = {
"NM"
};
+std::string obd2_signal_t::prefix_ = "diagnostic_messages.";
+
obd2_signal_t::obd2_signal_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}
{
@@ -53,7 +55,7 @@ const std::string obd2_signal_t::get_name() const
return prefix_ + "." + generic_name_;
}
-const std::string& obd2_signal_t::get_prefix() const
+const std::string& obd2_signal_t::get_prefix()
{
return prefix_;
}
@@ -63,7 +65,7 @@ int obd2_signal_t::get_frequency() const
return frequency_;
}
-void obd2_signal_t::set_prefix(std::string val)
+void obd2_signal_t::set_prefix(const std::string& val)
{
prefix_ = val;
}
@@ -144,9 +146,9 @@ bool obd2_signal_t::is_obd2_request(DiagnosticRequest* request)
*
* @return true if name began with obd2 else false.
*/
-bool obd2_signal_t::is_obd2_signal(const char *name)
+bool obd2_signal_t::is_obd2_signal(const std::string& name)
{
- if(fnmatch("obd2.*", name, FNM_CASEFOLD) == 0)
+ if(name.find_first_of(prefix_.c_str(), 0, prefix_.size()))
return true;
return false;
}
diff --git a/src/diagnostic/diagnostic-message.hpp b/src/diagnostic/diagnostic-message.hpp
index 02c6a9f6..ec4521f1 100644
--- a/src/diagnostic/diagnostic-message.hpp
+++ b/src/diagnostic/diagnostic-message.hpp
@@ -46,7 +46,7 @@ class obd2_signal_t {
private:
uint8_t pid_; /*!< pid - The 1 byte PID.*/
std::string generic_name_; /*!< generic_name_ - A human readable name to use for this PID when published.*/
- std::string prefix_ = "diagnostic_messages."; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
+ static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
* which make easier to sort message when the come in.*/
int min_; /*!< min_ - Minimum value that can take this pid */
int max_; /*!< max_ - Maximum value that can take this pid */
@@ -61,16 +61,16 @@ class obd2_signal_t {
uint32_t get_pid();
const std::string& get_generic_name() const;
const std::string get_name() const;
- const std::string& get_prefix() const;
+ static const std::string& get_prefix();
int get_frequency() const;
- void set_prefix(std::string val);
+ static void set_prefix(const std::string& val);
const DiagnosticRequest build_diagnostic_request();
bool is_obd2_response(can_message_t can_message);
bool is_obd2_request(DiagnosticRequest *request);
- bool is_obd2_signal(const char *name);
+ static bool is_obd2_signal(const std::string& name);
static 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 e7d8530f..0c418fe8 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -128,13 +128,11 @@ 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.
- /// const std::string& can_prefix = configuration_t::instance().get_can_signals().front().get_prefix();
- const std::string& obd2_prefix = configuration_t::instance().get_obd2_signals().front().get_prefix();
for(const std::string& sig : signals)
{
int ret;
- if (sig.find_first_of(obd2_prefix.c_str(), 0, obd2_prefix.size()))
+ if (obd2_signal_t::is_obd2_signal(sig))
{
std::vector<obd2_signal_t*> found;
configuration_t::instance().find_obd2_signals(build_DynamicField(sig), found);