summaryrefslogtreecommitdiffstats
path: root/src/signals.hpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-06 16:57:14 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-06 16:57:14 +0100
commit239729c759948d4574de625a84cff6f9c1338adf (patch)
tree4f5635d50c5704a0753586d4fea4b3822eee0e51 /src/signals.hpp
parent217690559c27646c7e412aaeacfa2064a9e7e6e4 (diff)
Change way to find signals to make it a little bit more generic.
Now we have basically 3 functions : - one for subscription which return signal name into a vector - one to find from CanSignal vector - a last to find from Obd2Pid vector Name of some function has been changed. May be reworked later. Change-Id: Ie72969fd20503fc1f9291958dc2ac5d827a6be59 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/signals.hpp')
-rw-r--r--src/signals.hpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/signals.hpp b/src/signals.hpp
new file mode 100644
index 00000000..53d19d51
--- /dev/null
+++ b/src/signals.hpp
@@ -0,0 +1,56 @@
+
+#pragma once
+
+#include <vector>
+#include <string>
+#include <fnmatch.h>
+
+#include "openxc.pb.h"
+#include "can-signals.hpp"
+#include "obd2-signals.hpp"
+
+template <typename T>
+void lookup_signals_by_name(const std::string& key, std::vector<T>& signals, std::vector<T*>& found_signals)
+{
+ for(T& s : signals)
+ {
+ if(::fnmatch(key.c_str(), s.generic_name, FNM_CASEFOLD) == 0)
+ found_signals.push_back(&s);
+ }
+}
+
+template <typename T>
+void lookup_signals_by_name(const std::string& key, std::vector<T>& signals, std::vector<std::string>& found_signals_name)
+{
+ for(const T& s : signals)
+ {
+ if(::fnmatch(key.c_str(), s.generic_name, FNM_CASEFOLD) == 0)
+ found_signals_name.push_back(s.generic_name);
+ }
+}
+
+template <typename T>
+void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector<T*>& found_signals)
+{
+ for(T& s : signals)
+ {
+ if(get_signal_id(s) == key)
+ {
+ found_signals.push_back(&s);
+ }
+ }
+}
+
+template <typename T>
+void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector<std::string>& found_signals_name)
+{
+ for(T& s : signals)
+ {
+ if(get_signal_id(s) == key)
+ {
+ found_signals_name.push_back(s.generic_name);
+ }
+ }
+}
+
+std::vector<std::string> find_signals(const openxc_DynamicField &key);