diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-16 19:52:41 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | 5bbc6cb56995d23cb8a4eb584ef0161be092da1f (patch) | |
tree | 0a63676d64a67f4323ed5e7fce1be147f95c2e69 /signal-composer-binding/signal-composer.cpp | |
parent | de24d7de2b87f5d8164f49fb130f8693b32362a0 (diff) |
Adding new verb, implemented basic signal method
Change-Id: I453ddc0ca374436275e7d76cdc27b3d843a2770f
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer.cpp')
-rw-r--r-- | signal-composer-binding/signal-composer.cpp | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp index 3158797..9288e56 100644 --- a/signal-composer-binding/signal-composer.cpp +++ b/signal-composer-binding/signal-composer.cpp @@ -285,7 +285,7 @@ std::shared_ptr<Signal> bindingApp::searchSignal(const std::string& aName) std::vector<std::shared_ptr<Signal>> allSignals = getAllSignals(); for (std::shared_ptr<Signal>& sig : allSignals) { - if(sig->id() == aName) + if(*sig == aName) {return sig;} } } @@ -321,3 +321,60 @@ int bindingApp::execSubscription() const } return err; } + +json_object* bindingApp::getSignalValue(const std::string& sig, json_object* options) +{ + const char **opts = nullptr; + json_object *response = nullptr; + + wrap_json_unpack(options, "{s?s?s?s?!}", + &opts[0], + &opts[1], + &opts[2], + &opts[3]); + + std::shared_ptr<Signal> sigP = searchSignal(sig); + wrap_json_pack(&response, "{ss}", + "signal", sigP->id().c_str()); + for(int idx=0; idx < sizeof(opts); idx++) + { + bool avg = false, min = false, max = false, last = false; + if (strcasestr(opts[idx], "average") && !avg) + { + avg = true; + double value = sigP->average(); + json_object_object_add(response, "average", + json_object_new_double(value)); + } + if (strcasestr(opts[idx], "min") && !min) + { + min = true; + double value = sigP->minimum(); + json_object_object_add(response, "min", + json_object_new_double(value)); + } + if (strcasestr(opts[idx], "max") && !max) + { + max = true; + double value = sigP->maximum(); + json_object_object_add(response, "max", + json_object_new_double(value)); + } + if (strcasestr(opts[idx], "last") && !last) + { + last = true; + double value = sigP->last(); + json_object_object_add(response, "last", + json_object_new_double(value)); + } + } + + if (!opts) + { + double value = sigP->last(); + json_object_object_add(response, "last", + json_object_new_double(value)); + } + + return response; +} |