From b59d45196f14f2401e148bbe37c04b514850d859 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 14 Feb 2017 18:19:46 +0100 Subject: Implement GetSignals method Signed-off-by: Romain Forlot --- src/can-signals.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/can-signals.cpp b/src/can-signals.cpp index 13ff30b..7af957f 100644 --- a/src/can-signals.cpp +++ b/src/can-signals.cpp @@ -16,6 +16,7 @@ */ #include +#include #include "can-signals.h" bool match(const std::string &first, const std::string &second) @@ -23,18 +24,34 @@ bool match(const std::string &first, const std::string &second) } -CanSignal* getSignals(std::string name) +CanSignal* getSignals(openxc_DynamicField *key) { int n_signals, i; - CanSignal ret_signals[]; + std::vector ret_signals; - n_signals = size(SIGNALS); + n_signals = SIGNALS.size(); - for(i=0; i<=n_signals; i++) + switch(key->type): { - if(SIGNALS[i].generic_name == name) - return &SIGNALS[i]; - i++; + case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: + for(i=0; i<=n_signals; i++) + { + if(match((std::string*)key->string_value, (std::string*)SIGNALS[i]->genericName)) + ret_signals.insert(&SIGNALS[i]); + } + break; + case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: + for(i=0; i<=n_signals; i++) + { + CanMessageDefinition *msg_def = SIGNALS[i]->message; + if(msg_def->id == key->numeric_value) + ret_signals.insert(&SIGNALS[i]) + } + break; + default: + return NULL; + break; } - return 0; -} + + return &ret_signals; +} \ No newline at end of file -- cgit 1.2.3-korg