aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/low-can.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-22 01:13:17 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-25 10:08:07 +0200
commit7f15ef65f420179b606f136ed805fae9d320b321 (patch)
treec4ef2dde841415ce4dedcaaa5f0edf7e258bc356 /plugins/low-can.cpp
parent3b08cec1ad06f313374bc1fd9cc64e1b28ce798d (diff)
Improved performance
Before value was translated to a C type variable two times, at the reception then at the emission. Now it just receives and sends the signal value without translation nor interpretation except if you ask for an average, minimum or maximum value. Then in those cases it interprets the json to return you a value or an error if there is no numeric values to compute. Remove unneeded log message at event reception. Improved signal search engine, will search in source's signals map by the signal ID not the event name which lead to a more direct map match. Bugs-AGL: SPEC-1612 Depends-On: I43e79ed73a507ac2ca7ed4cdc3f16ec009392194 Change-Id: Ie253c3fe1e8cde42dabe8832da74e9f9bf442c14 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'plugins/low-can.cpp')
-rw-r--r--plugins/low-can.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/plugins/low-can.cpp b/plugins/low-can.cpp
index 7bbe763..5153ee9 100644
--- a/plugins/low-can.cpp
+++ b/plugins/low-can.cpp
@@ -31,8 +31,8 @@ extern "C"
CTLP_CAPI_REGISTER("low-can");
typedef struct {
- bool door;
- bool window;
+ json_object* door;
+ json_object* window;
} doorT;
typedef struct {
@@ -47,11 +47,13 @@ struct pluginCtxT {
allDoorsCtxT allDoorsCtx;
};
-void setDoor(doorT* aDoor, const char* eventName, int eventStatus)
+void setDoor(doorT* aDoor, const char* eventName, json_object* eventStatus)
{
- if(strcasestr(eventName, "door")) {aDoor->door = eventStatus;}
- else if(strcasestr(eventName, "window")) {aDoor->window = eventStatus;}
- else {AFB_WARNING("Unexpected behavior, this '%s' is not a door ! ", eventName);}
+ if(json_object_is_type(eventStatus, json_type_boolean)) {
+ if(strcasestr(eventName, "door")) aDoor->door = eventStatus;
+ else if(strcasestr(eventName, "window")) aDoor->window = eventStatus;
+ else AFB_WARNING("Unexpected behavior, this '%s' is not a door ! ", eventName);
+ }
}
// Call at initialisation time
@@ -132,12 +134,12 @@ CTLP_CAPI (subscribeToLow, source, argsJ, eventJ) {
CTLP_CAPI (isOpen, source, argsJ, eventJ) {
const char *eventName = nullptr;
- int eventStatus;
+ json_object *eventStatus;
uint64_t timestamp;
struct signalCBT* context = reinterpret_cast<struct signalCBT*>(source->context);
struct pluginCtxT* pluginCtx = reinterpret_cast<struct pluginCtxT*>(context->pluginCtx);
- int err = wrap_json_unpack(eventJ, "{ss,sb,s?I}",
+ int err = wrap_json_unpack(eventJ, "{ss,so,s?I}",
"name", &eventName,
"value", &eventStatus,
"timestamp", &timestamp);
@@ -177,14 +179,14 @@ CTLP_CAPI (isOpen, source, argsJ, eventJ) {
source->uid,
argsJ ? json_object_to_json_string(argsJ):"",
eventJ ? json_object_to_json_string(eventJ):"",
- pluginCtx->allDoorsCtx.front_left.door ? "true":"false",
- pluginCtx->allDoorsCtx.front_left.window ? "true":"false",
- pluginCtx->allDoorsCtx.front_right.door ? "true":"false",
- pluginCtx->allDoorsCtx.front_right.window ? "true":"false",
- pluginCtx->allDoorsCtx.rear_left.door ? "true":"false",
- pluginCtx->allDoorsCtx.rear_left.window ? "true":"false",
- pluginCtx->allDoorsCtx.rear_right.door ? "true":"false",
- pluginCtx->allDoorsCtx.rear_right.window ? "true":"false"
+ json_object_get_string(pluginCtx->allDoorsCtx.front_left.door),
+ json_object_get_string(pluginCtx->allDoorsCtx.front_left.window),
+ json_object_get_string(pluginCtx->allDoorsCtx.front_right.door),
+ json_object_get_string(pluginCtx->allDoorsCtx.front_right.window),
+ json_object_get_string(pluginCtx->allDoorsCtx.rear_left.door),
+ json_object_get_string(pluginCtx->allDoorsCtx.rear_left.window),
+ json_object_get_string(pluginCtx->allDoorsCtx.rear_right.door),
+ json_object_get_string(pluginCtx->allDoorsCtx.rear_right.window)
);
return 0;