diff options
Diffstat (limited to 'signal-composer-binding')
-rw-r--r-- | signal-composer-binding/signal-composer-binding.cpp | 4 | ||||
-rw-r--r-- | signal-composer-binding/signal-composer.cpp | 62 | ||||
-rw-r--r-- | signal-composer-binding/signal.cpp | 139 | ||||
-rw-r--r-- | signal-composer-binding/signal.hpp | 45 | ||||
-rw-r--r-- | signal-composer-binding/source.cpp | 2 |
5 files changed, 102 insertions, 150 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp index 0d9c8e3..f7c8c73 100644 --- a/signal-composer-binding/signal-composer-binding.cpp +++ b/signal-composer-binding/signal-composer-binding.cpp @@ -32,10 +32,8 @@ /// @param[in] object - eventual data that comes with the event void onEvent(const char *event, json_object *object) { - Composer& composer = Composer::instance(); - AFB_NOTICE("event: %s", json_object_to_json_string(object)); + std::vector<std::shared_ptr<Signal>> signals { Composer::instance().searchSignals(event) }; - std::vector<std::shared_ptr<Signal>> signals = composer.searchSignals(event); if(!signals.empty()) { // If there is more than 1 element then maybe we can find a more diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp index 99129b4..f7c1971 100644 --- a/signal-composer-binding/signal-composer.cpp +++ b/signal-composer-binding/signal-composer.cpp @@ -21,7 +21,7 @@ #include "clientApp.hpp" -extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, struct signalValue value) +extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, json_object* value) { std::vector<std::shared_ptr<Signal>> signals = Composer::instance().searchSignals(aName); if(!signals.empty()) @@ -31,7 +31,7 @@ extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestam } } -extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, struct signalValue value) +extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, json_object* value) { Signal* sig = static_cast<Signal*>(aSignal); sig->set(timestamp, value); @@ -380,47 +380,25 @@ void Composer::processOptions(const std::map<std::string, int>& opts, std::share { avg = true; double value = sig->average(o.second); - json_object_object_add(response, "value", - json_object_new_double(value)); + json_object_object_add(response, "value", json_object_new_double(value)); } else if (o.first.compare("minimum") && !min) { min = true; double value = sig->minimum(); - json_object_object_add(response, "value", - json_object_new_double(value)); + json_object_object_add(response, "value", json_object_new_double(value)); } else if (o.first.compare("maximum") && !max) { max = true; double value = sig->maximum(); - json_object_object_add(response, "value", - json_object_new_double(value)); + json_object_object_add(response, "value", json_object_new_double(value)); } else if (o.first.compare("last") && !last) { last = true; - struct signalValue value = sig->last_value(); - if(value.hasBool) - { - json_object_object_add(response, "value", - json_object_new_boolean(value.boolVal)); - } - else if(value.hasNum) - { - json_object_object_add(response, "value", - json_object_new_double(value.numVal)); - } - else if(value.hasStr) - { - json_object_object_add(response, "value", - json_object_new_string(value.strVal.c_str())); - } - else - { - json_object_object_add(response, "value", - json_object_new_string("No recorded value so far.")); - } + json_object* value = sig->last_value(); + json_object_object_add(response, "value", value); } else { @@ -568,8 +546,9 @@ std::vector<std::shared_ptr<Signal>> Composer::searchSignals(const std::string& if(sep != std::string::npos) { api = aName.substr(0, sep); + std::string signal_id = aName.substr(sep + 1, std::string::npos); std::shared_ptr<SourceAPI> source = getSourceAPI(api); - return source->searchSignals(aName); + return source->searchSignals(signal_id); } else { @@ -603,27 +582,8 @@ json_object* Composer::getsignalValue(const std::string& sig, json_object* optio "signal", sig->id().c_str()); if (opts.empty()) { - struct signalValue value = sig->last_value(); - if(value.hasBool) - { - json_object_object_add(response, "value", - json_object_new_boolean(value.boolVal)); - } - else if(value.hasNum) - { - json_object_object_add(response, "value", - json_object_new_double(value.numVal)); - } - else if(value.hasStr) - { - json_object_object_add(response, "value", - json_object_new_string(value.strVal.c_str())); - } - else - { - json_object_object_add(response, "value", - json_object_new_string("No recorded value so far.")); - } + json_object* value = sig->last_value(); + json_object_object_add(response, "value", value); } else {processOptions(opts, sig, response);} diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp index 2f1aa57..14e85ba 100644 --- a/signal-composer-binding/signal.cpp +++ b/signal-composer-binding/signal.cpp @@ -148,9 +148,8 @@ json_object* Signal::toJSON() const if(timestamp_) json_object_object_add(sigJ, "timestamp", json_object_new_int64(timestamp_)); - if (value_.hasBool) {json_object_object_add(sigJ, "value", json_object_new_boolean(value_.boolVal));} - else if (value_.hasNum) {json_object_object_add(sigJ, "value", json_object_new_double(value_.numVal));} - else if (value_.hasStr) {json_object_object_add(sigJ, "value", json_object_new_string(value_.strVal.c_str()));} + if(value_) + json_object_object_add(sigJ, "value", value_); return sigJ; } @@ -198,19 +197,21 @@ json_object *Signal::getSignalsArgs() /// /// @param[in] timestamp - timestamp of occured signal /// @param[in] value - value of change -void Signal::set(uint64_t timestamp, struct signalValue& value) +void Signal::set(uint64_t timestamp, json_object*& value) { uint64_t diff = retention_+1; value_ = value; timestamp_ = timestamp; - history_[timestamp_] = value_; + history_[timestamp_] = json_object_get(value_); while(diff > retention_) { uint64_t first = history_.begin()->first; diff = (timestamp_ - first)/NANO; - if(diff > retention_) - {history_.erase(history_.cbegin());} + if(diff > retention_) { + json_object_put(history_.cbegin()->second); + history_.erase(history_.cbegin()); + } } notify(); @@ -253,37 +254,22 @@ void Signal::update(Signal* sig) /// @param[in] eventJ - json_object containing event data to process /// /// @return 0 if ok, -1 or others if not -void Signal::defaultReceivedCB(json_object *eventJ) +void Signal::defaultReceivedCB(Signal *signal, json_object *eventJ) { uint64_t ts = 0; - struct signalValue sv; + json_object* sv = nullptr; json_object_iterator iter = json_object_iter_begin(eventJ); json_object_iterator iterEnd = json_object_iter_end(eventJ); + while(!json_object_iter_equal(&iter, &iterEnd)) { std::string key = json_object_iter_peek_name(&iter); std::transform(key.begin(), key.end(), key.begin(), ::tolower); json_object *value = json_object_iter_peek_value(&iter); if (key.find("value") != std::string::npos || - key.find(id_) != std::string::npos) + key.find(signal->id()) != std::string::npos) { - switch (json_object_get_type(value)) { - case json_type_double: - sv = json_object_get_double(value); - break; - case json_type_int: - sv = json_object_get_int(value); - break; - case json_type_boolean: - sv = json_object_get_int(value); - break; - case json_type_string: - sv = json_object_get_string(value); - break; - default: - sv = signalValue(); - break; - } + sv = json_object_get(value); } else if (key.find("timestamp") != std::string::npos) { @@ -292,9 +278,9 @@ void Signal::defaultReceivedCB(json_object *eventJ) json_object_iter_next(&iter); } - if(!sv.hasBool && !sv.hasNum && !sv.hasStr) + if(!sv) { - AFB_ERROR("No data found to set signal %s in %s", id_.c_str(), json_object_to_json_string(eventJ)); + AFB_ERROR("No data found to set signal %s in %s", signal->id().c_str(), json_object_to_json_string(eventJ)); return; } else if(ts == 0) @@ -305,7 +291,7 @@ void Signal::defaultReceivedCB(json_object *eventJ) ts = (uint64_t)(t.tv_sec) * (uint64_t)NANO + (uint64_t)(t.tv_nsec); } - set(ts, sv); + signal->set(ts, sv); } /// @brief Notify observers that there is a change and execute callback defined @@ -343,7 +329,7 @@ void Signal::onReceivedCB(json_object *eventJ) if (onReceived_) ActionExecOne(&source, onReceived_, json_object_get(eventJ)); else - defaultReceivedCB(eventJ); + defaultReceivedCB(this, eventJ); } /// @brief Make a Signal observer observes Signals observables @@ -382,22 +368,31 @@ double Signal::average(int seconds) const double total = 0.0; int nbElt = 0; - for (const auto& val: history_) + for(const auto& val: history_) { - if(val.first >= end) - {break;} - if(val.second.hasNum) + if(val.first >= end) { + break; + } + if(val.second) { - total += val.second.numVal; + switch(json_object_get_type(val.second)) { + case json_type_int: + total += static_cast<double>(json_object_get_int64(val.second)); + break; + case json_type_double: + total += json_object_get_double(val.second); + break; + default: + AFB_ERROR("The stored value '%s' for the signal '%s' isn't numeric, it is not possible to compute an average value.", json_object_get_string(val.second), id_.c_str()); + break; + } nbElt++; } else { - AFB_ERROR("There isn't numerical value to compare with in that signal '%s'. Stored value : bool %d, num %lf, str: %s", + AFB_ERROR("There isn't numerical value to compare with in that signal '%s'. Stored value: %s", id_.c_str(), - val.second.boolVal, - val.second.numVal, - val.second.strVal.c_str()); + json_object_get_string(val.second)); break; } } @@ -416,21 +411,34 @@ double Signal::minimum(int seconds) const uint64_t end = seconds ? begin+(seconds*NANO) : history_.rbegin()->first; + double current = 0.0; double min = DBL_MAX; - for (auto& v : history_) + for(const auto& val : history_) { - if(v.first >= end) - {break;} - else if(v.second.hasNum && v.second.numVal < min) - {min = v.second.numVal;} + if(val.first >= end) { + break; + } + else if(val.second) { + switch(json_object_get_type(val.second)) { + case json_type_int: + current = static_cast<double>(json_object_get_int64(val.second)); + min = current < min ? current : min; + break; // SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2004
* Pierre Aubert, Staubli Faverges , <p.aubert@staubli.com>
* Copyright 2011 Freescale Semiconductor, Inc.
*/
/************************************************************************
Get Parameters for the video mode:
The default video mode can be defined in CONFIG_SYS_DEFAULT_VIDEO_MODE.
If undefined, default video mode is set to 0x301
Parameters can be set via the variable "videomode" in the environment.
2 diferent ways are possible:
"videomode=301" - 301 is a hexadecimal number describing the VESA
mode. Following modes are implemented:
Colors 640x480 800x600 1024x768 1152x864 1280x1024
--------+---------------------------------------------
8 bits | 0x301 0x303 0x305 0x161 0x307
15 bits | 0x310 0x313 0x316 0x162 0x319
16 bits | 0x311 0x314 0x317 0x163 0x31A
24 bits | 0x312 0x315 0x318 ? 0x31B
--------+---------------------------------------------
"videomode=bootargs"
- the parameters are parsed from the bootargs.
The format is "NAME:VALUE,NAME:VALUE" etc.
Ex.:
"bootargs=video=ctfb:x:800,y:600,depth:16,pclk:25000"
Parameters not included in the list will be taken from
the default mode, which is one of the following:
mode:0 640x480x24
mode:1 800x600x16
mode:2 1024x768x8
mode:3 960x720x24
mode:4 1152x864x16
mode:5 1280x1024x8
if "mode" is not provided within the parameter list,
mode:0 is assumed.
Following parameters are supported:
x xres = visible resolution horizontal
y yres = visible resolution vertical
pclk pixelclocks in pico sec
le left_marging time from sync to picture in pixelclocks
ri right_marging time from picture to sync in pixelclocks
up upper_margin time from sync to picture
lo lower_margin
hs hsync_len length of horizontal sync
vs vsync_len length of vertical sync
sync see FB_SYNC_*
vmode see FB_VMODE_*
depth Color depth in bits per pixel
All other parameters in the variable bootargs are ignored.
It is also possible to set the parameters direct in the
variable "videomode", or in another variable i.e.
"myvideo" and setting the variable "videomode=myvideo"..
****************************************************************************/
#include <common.h>
#include <edid.h>
#include <env.h>
#include <errno.h>
#include <fdtdec.h>
#include <linux/ctype.h>
#include "videomodes.h"
const struct ctfb_vesa_modes vesa_modes[VESA_MODES_COUNT] = {
{0x301, RES_MODE_640x480, 8},
{0x310, RES_MODE_640x480, 15},
{0x311, RES_MODE_640x480, 16},
{0x312, RES_MODE_640x480, 24},
{0x303, RES_MODE_800x600, 8},
{0x313, RES_MODE_800x600, 15},
{0x314, RES_MODE_800x600, 16},
{0x315, RES_MODE_800x600, 24},
{ |