aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/builtin.cpp14
-rw-r--r--plugins/gps.cpp2
-rw-r--r--plugins/low-can.cpp34
3 files changed, 24 insertions, 26 deletions
diff --git a/plugins/builtin.cpp b/plugins/builtin.cpp
index e56d413..28bcba7 100644
--- a/plugins/builtin.cpp
+++ b/plugins/builtin.cpp
@@ -32,27 +32,23 @@ CTLP_LUA_REGISTER("builtin");
CTLP_LUA2C (setSignalValueWrap, source, argsJ, responseJ)
{
const char* name = nullptr;
- double resultNum;
+ json_object* resultNumJ;
uint64_t timestamp;
struct signalCBT* ctx = (struct signalCBT*)source->context;
- if(! wrap_json_unpack(argsJ, "{ss, sF, sI? !}",
+ if(! wrap_json_unpack(argsJ, "{ss, so, sI? !}",
"name", &name,
- "value", &resultNum,
+ "value", &resultNumJ,
"timestamp", &timestamp))
{
- *responseJ = json_object_new_string("Fail to unpack JSON arguments value");
return -1;
}
- *responseJ = json_object_new_string(json_object_to_json_string(argsJ));
-
- struct signalValue result = resultNum;
if(ctx->aSignal)
- {ctx->setSignalValue(ctx->aSignal, timestamp*NANO, result);}
+ ctx->setSignalValue(ctx->aSignal, timestamp*NANO, resultNumJ);
else
- {ctx->searchNsetSignalValue(name, timestamp*NANO, result);}
+ ctx->searchNsetSignalValue(name, timestamp*NANO, resultNumJ);
return 0;
}
diff --git a/plugins/gps.cpp b/plugins/gps.cpp
index 646754a..4913f31 100644
--- a/plugins/gps.cpp
+++ b/plugins/gps.cpp
@@ -59,7 +59,7 @@ CTLP_CAPI (getHeading, source, argsJ, eventJ) {
if(coordUpdated) {
heading = round(r2d * atan2((curLon - prvLon) * cos(d2r * curLat), curLat - prvLat));
- ctx->setSignalValue(ctx->aSignal, 0, heading);
+ ctx->setSignalValue(ctx->aSignal, 0, json_object_new_double(heading));
}
AFB_NOTICE("======== Heading: %f", heading);
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;