aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-26 18:38:44 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit6b492d666ed1faeeec5f761105f473956b426cc9 (patch)
tree35b292414e134f280d9616be0e0dcc6b3e7f6bd4
parentc22ad857bcd2f567d22f3239d91fa65720718713 (diff)
Introduce retention setting in place of class
Be able to tweak retention value for each signal in seconds Change-Id: I1cabe48a2660cdeb2e9b32b277e7c819c6b49bd9 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--conf.d/project/etc/sig-demoboard.json8
-rw-r--r--conf.d/project/etc/sig-geoloc.json10
-rw-r--r--signal-composer-binding/signal-composer.cpp16
-rw-r--r--signal-composer-binding/signal-composer.hpp7
-rw-r--r--signal-composer-binding/signal.cpp34
-rw-r--r--signal-composer-binding/signal.hpp11
-rw-r--r--signal-composer-binding/source.cpp4
-rw-r--r--signal-composer-binding/source.hpp2
8 files changed, 50 insertions, 42 deletions
diff --git a/conf.d/project/etc/sig-demoboard.json b/conf.d/project/etc/sig-demoboard.json
index 6e4815e..3b82bfe 100644
--- a/conf.d/project/etc/sig-demoboard.json
+++ b/conf.d/project/etc/sig-demoboard.json
@@ -3,7 +3,7 @@
{
"id": "vehicle_speed",
"event": "low-can/diagnostic_messages.vehicle.speed",
- "class": "temporal",
+ "retention": 30,
"unit": "km/h",
"frequency": 1,
"getSignalsArgs": {
@@ -21,21 +21,21 @@
{
"id": "engine_speed",
"event": "low-can/diagnostic_messages.engine.speed",
- "class": "temporal",
+ "retention": 30,
"unit": "rpm",
"frequency": 1
},
{
"id": "fuel_level",
"event": "low-can/diagnostic_messages.fuel.level",
- "class":"temporal",
+ "retention":30,
"unit": "liter",
"frequency": 1
},
{
"id": "engine_load",
"event": "low-can/diagnostic_messages.engine.load",
- "class":"temporal",
+ "retention":30,
"unit": "Nm",
"frequency": 1
}
diff --git a/conf.d/project/etc/sig-geoloc.json b/conf.d/project/etc/sig-geoloc.json
index 3b0e4eb..6bd18b6 100644
--- a/conf.d/project/etc/sig-geoloc.json
+++ b/conf.d/project/etc/sig-geoloc.json
@@ -33,7 +33,7 @@
"latitude",
"longitude"
],
- "class": "state",
+ "retention": 30,
"unit": "degree",
"frequency": 1,
"actions": {
@@ -45,7 +45,7 @@
{
"id": "speed",
"event": "gps/location",
- "class": "temporal",
+ "retention": 30,
"unit": "m/s",
"frequency": 1
},
@@ -124,7 +124,7 @@
{
"id": "sigma_speed",
"event": "gps/location",
- "class": "temporal",
+ "retention": 30,
"unit": "m/s",
"frequency": 1
},
@@ -142,13 +142,13 @@
{
"id": "dr_status",
"event": "gps/location",
- "class": "state",
+ "retention": 30,
"frequency": 1
},
{
"id": "reliabilty_index",
"event": "gps/location",
- "class": "temporal",
+ "retention": 30,
"frequency": 1
}
]
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 89d442d..2247ba9 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -214,30 +214,30 @@ int Composer::loadOneSignal(json_object* signalJ)
CtlActionT* onReceivedCtl;
const char *id = nullptr,
*event = nullptr,
- *sClass = nullptr,
*unit = nullptr;
+ int retention;
double frequency=0.0;
std::string api;
std::vector<std::string> dependsV;
ssize_t sep;
- int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?s,s?s,s?F,s?o !}",
+ int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?F,s?s,s?F,s?o !}",
"id", &id,
"event", &event,
"depends", &dependsJ,
"getSignalsArgs", &getSignalsArgs,
- "class", &sClass,
+ "retention", &retention,
"unit", &unit,
"frequency", &frequency,
"onReceived", &onReceivedJ);
if (err)
{
- AFB_ERROR("Missing something id|[event|depends]|[getSignalsArgs]|[class]|[unit]|[frequency]|[onReceived] in %s", json_object_get_string(signalJ));
+ AFB_ERROR("Missing something id|[event|depends]|[getSignalsArgs]|[retention]|[unit]|[frequency]|[onReceived] in %s", json_object_get_string(signalJ));
return err;
}
- // Set default sClass is not specified
- sClass = !sClass ? "state" : sClass;
+ // Set default retention is not specified
+ retention = !retention ? 30 : retention;
unit = !unit ? "" : unit;
// Get an action handler
@@ -246,7 +246,7 @@ int Composer::loadOneSignal(json_object* signalJ)
// event or depends field manadatory
if( (!event && !dependsJ) || (event && dependsJ) )
{
- AFB_ERROR("Missing something id|[event|depends]|[getSignalsArgs]|[class]|[unit]|[frequency]|[onReceived] in %s. Or you declare event AND depends, only one of them is needed.", json_object_get_string(signalJ));
+ AFB_ERROR("Missing something id|[event|depends]|[getSignalsArgs]|[retention]|[unit]|[frequency]|[onReceived] in %s. Or you declare event AND depends, only one of them is needed.", json_object_get_string(signalJ));
return -1;
}
@@ -299,7 +299,7 @@ int Composer::loadOneSignal(json_object* signalJ)
SourceAPI* src = getSourceAPI(api) ? getSourceAPI(api):getSourceAPI("signal-composer");
if(src != nullptr)
- {src->addSignal(id, event, dependsV, sClass, unit, frequency, onReceivedCtl, getSignalsArgs);}
+ {src->addSignal(id, event, dependsV, retention, unit, frequency, onReceivedCtl, getSignalsArgs);}
else
{err = -1;}
diff --git a/signal-composer-binding/signal-composer.hpp b/signal-composer-binding/signal-composer.hpp
index a5ee0f1..de7a799 100644
--- a/signal-composer-binding/signal-composer.hpp
+++ b/signal-composer-binding/signal-composer.hpp
@@ -60,10 +60,3 @@ public:
int execSignalsSubscription();
};
-
-struct pluginCBT
-{
- void (*setsignalValue)(const char* aName, long long int timestamp, struct signalValue value);
-};
-
-extern "C" void setsignalValueHandle(const char* aName, long long int timestamp, struct signalValue value);
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 51e16f9..2ec9908 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -20,7 +20,7 @@
#include "signal.hpp"
#include "signal-composer.hpp"
-#define MICRO 1000000
+#define MICRO 1000000000
Signal::Signal()
:id_(""),
@@ -28,6 +28,7 @@ Signal::Signal()
dependsSigV_(),
timestamp_(0.0),
value_({0,0,0,0,0,""}),
+ retention_(0),
frequency_(0),
unit_(""),
onReceived_(nullptr),
@@ -35,12 +36,13 @@ Signal::Signal()
subscribed_(false)
{}
-Signal::Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
+Signal::Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, int retention, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
:id_(id),
event_(event),
dependsSigV_(depends),
timestamp_(0.0),
value_({0,0,0,0,0,""}),
+ retention_(retention),
frequency_(frequency),
unit_(unit),
onReceived_(onReceived),
@@ -51,6 +53,7 @@ Signal::Signal(const std::string& id, const std::string& event, std::vector<std:
Signal::Signal(const std::string& id,
std::vector<std::string>& depends,
const std::string& unit,
+ int retention,
double frequency,
CtlActionT* onReceived)
:id_(id),
@@ -58,6 +61,7 @@ Signal::Signal(const std::string& id,
dependsSigV_(depends),
timestamp_(0.0),
value_({0,0,0,0,0,""}),
+ retention_(retention),
frequency_(frequency),
unit_(unit),
onReceived_(onReceived),
@@ -134,11 +138,21 @@ json_object* Signal::toJSON() const
///
/// @param[in] timestamp - timestamp of occured signal
/// @param[in] value - value of change
-void Signal::set(long long int timestamp, struct signalValue& value)
+/// @param[in] unit - optionnal string to change the signal unit
+void Signal::set(uint64_t timestamp, struct signalValue& value)
{
- timestamp_ = timestamp;
+ uint64_t diff = retention_+1;
value_ = value;
+ timestamp_ = timestamp;
history_[timestamp_] = value_;
+
+ while(diff > retention_)
+ {
+ uint64_t first = history_.begin()->first;
+ diff = (timestamp_ - first)/MICRO;
+ if(diff > retention_)
+ {history_.erase(history_.cbegin());}
+ }
}
/// @brief Observer method called when a Observable Signal has changes.
@@ -191,8 +205,8 @@ void Signal::attachToSourceSignals(Composer& composer)
/// @return Average value
double Signal::average(int seconds) const
{
- long long int begin = history_.begin()->first;
- long long int end = !seconds ?
+ uint64_t begin = history_.begin()->first;
+ uint64_t end = !seconds ?
begin+(seconds*MICRO) :
history_.rbegin()->first;
double total = 0.0;
@@ -228,8 +242,8 @@ double Signal::average(int seconds) const
/// @return Minimum value contained in the history
double Signal::minimum(int seconds) const
{
- long long int begin = history_.begin()->first;
- long long int end = !seconds ?
+ uint64_t begin = history_.begin()->first;
+ uint64_t end = !seconds ?
begin+(seconds*MICRO) :
history_.rbegin()->first;
@@ -260,8 +274,8 @@ double Signal::minimum(int seconds) const
/// @return Maximum value contained in the history
double Signal::maximum(int seconds) const
{
- long long int begin = history_.begin()->first;
- long long int end = !seconds ?
+ uint64_t begin = history_.begin()->first;
+ uint64_t end = !seconds ?
begin+(seconds*MICRO) :
history_.rbegin()->first;
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index aa974da..36479f6 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -52,9 +52,10 @@ private:
std::string id_;
std::string event_;
std::vector<std::string> dependsSigV_;
- long long int timestamp_;
+ uint64_t timestamp_;
struct signalValue value_;
- std::map<long long int, struct signalValue> history_; ///< history_ - Hold signal value history in map with <timestamp, value>
+ std::map<uint64_t, struct signalValue> history_; ///< history_ - Hold signal value history in map with <timestamp, value>
+ int retention_;
double frequency_;
std::string unit_;
CtlActionT* onReceived_;
@@ -63,8 +64,8 @@ private:
public:
bool subscribed_; ///< subscribed_ - boolean value telling if yes or no the signal has been subcribed to the low level binding.
Signal();
- Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
- Signal(const std::string& id, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived);
+ Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, int retention, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
+ Signal(const std::string& id, std::vector<std::string>& depends, const std::string& unit, int retention, double frequency, CtlActionT* onReceived);
explicit operator bool() const;
bool operator==(const Signal& other) const;
@@ -73,7 +74,7 @@ public:
const std::string id() const;
json_object* toJSON() const;
- void set(long long int timestamp, struct signalValue& value);
+ void set(uint64_t timestamp, struct signalValue& value);
void update(Signal* sig);
int onReceivedCB(json_object *queryJ);
void attachToSourceSignals(Composer& composer);
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index 63709a1..5989dac 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -40,9 +40,9 @@ std::string SourceAPI::api() const
return api_;
}
-void SourceAPI::addSignal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& sClass, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
+void SourceAPI::addSignal(const std::string& id, const std::string& event, std::vector<std::string>& depends, int retention, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
{
- std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, frequency, onReceived, getSignalsArgs);
+ std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, retention, frequency, onReceived, getSignalsArgs);
signalsMap_[id] = sig;
}
diff --git a/signal-composer-binding/source.hpp b/signal-composer-binding/source.hpp
index 57836e7..01bb08d 100644
--- a/signal-composer-binding/source.hpp
+++ b/signal-composer-binding/source.hpp
@@ -34,7 +34,7 @@ public:
int init();
std::string api() const;
- void addSignal(const std::string& id, const std::string& event, std::vector<std::string>& sources, const std::string& sClass, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
+ void addSignal(const std::string& id, const std::string& event, std::vector<std::string>& sources, int retention, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
std::vector<std::shared_ptr<Signal>> getSignals() const;
std::vector<std::shared_ptr<Signal>> searchSignals(const std::string& name);