aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/low-can.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/low-can.cpp')
-rw-r--r--plugins/low-can.cpp59
1 files changed, 32 insertions, 27 deletions
diff --git a/plugins/low-can.cpp b/plugins/low-can.cpp
index 8d09eda..b8b84eb 100644
--- a/plugins/low-can.cpp
+++ b/plugins/low-can.cpp
@@ -45,11 +45,15 @@ typedef struct {
doorT rear_right;
} allDoorsCtxT;
-typedef struct {
- struct signalCBT* pluginHandle;
+struct pluginCtxT {
json_object *subscriptionBatch;
allDoorsCtxT allDoorsCtx;
-} lowCANCtxT;
+};
+
+struct pluginCtxT pluginCtx = {
+ json_object_new_array(),
+ {false, false, false, false, false, false, false, false}
+};
void setDoor(doorT* aDoor, const char* eventName, int eventStatus)
{
@@ -59,9 +63,10 @@ void setDoor(doorT* aDoor, const char* eventName, int eventStatus)
}
// Call at initialisation time
+/*
CTLP_ONLOAD(plugin, composerHandle)
{
- lowCANCtxT *pluginCtx= (lowCANCtxT*)calloc (1, sizeof(lowCANCtxT));
+ lowCANCtxT *pluginCtx = (lowCANCtxT*)calloc (1, sizeof(lowCANCtxT));
pluginCtx->pluginHandle = (struct signalCBT*)composerHandle;
pluginCtx->subscriptionBatch = json_object_new_array();
@@ -72,9 +77,9 @@ CTLP_ONLOAD(plugin, composerHandle)
return (void*)pluginCtx;
}
+*/
CTLP_CAPI (subscribeToLow, source, argsJ, eventJ) {
- lowCANCtxT *pluginCtx = (lowCANCtxT*)source->context;
json_object* dependsArrayJ = nullptr, *subscribeArgsJ = nullptr, *subscribeFilterJ = nullptr, *responseJ = nullptr, *filterJ = nullptr;
const char *id = nullptr, *event = nullptr, *unit = nullptr;
double frequency = 0;
@@ -83,7 +88,7 @@ CTLP_CAPI (subscribeToLow, source, argsJ, eventJ) {
if(eventJ)
{
err = wrap_json_unpack(eventJ, "{ss,s?s,s?o,s?s,s?F,s?o !}",
- "id", &id,
+ "uid", &id,
"event", &event,
"depends", &dependsArrayJ,
"unit", &unit,
@@ -111,14 +116,14 @@ CTLP_CAPI (subscribeToLow, source, argsJ, eventJ) {
AFB_ERROR("Error building subscription query object");
return err;
}
- json_object_array_add(pluginCtx->subscriptionBatch, subscribeArgsJ);
+ json_object_array_add(pluginCtx.subscriptionBatch, subscribeArgsJ);
}
else
{
- AFB_DEBUG("Calling subscribe with %s", json_object_to_json_string_ext(pluginCtx->subscriptionBatch, JSON_C_TO_STRING_PRETTY));
- err = afb_service_call_sync("low-can", "subscribe", pluginCtx->subscriptionBatch, &responseJ);
+ AFB_DEBUG("Calling subscribe with %s", json_object_to_json_string_ext(pluginCtx.subscriptionBatch, JSON_C_TO_STRING_PRETTY));
+ err = afb_service_call_sync("low-can", "subscribe", pluginCtx.subscriptionBatch, &responseJ);
if(err)
- {AFB_ERROR("Subscribe to '%s' responseJ:%s", json_object_to_json_string_ext(pluginCtx->subscriptionBatch, JSON_C_TO_STRING_PRETTY), json_object_to_json_string(responseJ));}
+ {AFB_ERROR("Subscribe to '%s' responseJ:%s", json_object_to_json_string_ext(pluginCtx.subscriptionBatch, JSON_C_TO_STRING_PRETTY), json_object_to_json_string(responseJ));}
}
return err;
@@ -128,7 +133,7 @@ CTLP_CAPI (isOpen, source, argsJ, eventJ) {
const char *eventName = nullptr;
int eventStatus;
uint64_t timestamp;
- lowCANCtxT *pluginCtx=(lowCANCtxT*)source->context;
+ signalCBT *sourceCtx=(signalCBT*)source->context;
int err = wrap_json_unpack(eventJ, "{ss,sb,s?F}",
"name", &eventName,
@@ -142,23 +147,23 @@ CTLP_CAPI (isOpen, source, argsJ, eventJ) {
if(strcasestr(eventName, "front_left"))
{
- pluginCtx->pluginHandle->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
- setDoor(&pluginCtx->allDoorsCtx.front_left, eventName, eventStatus);
+ sourceCtx->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
+ setDoor(&pluginCtx.allDoorsCtx.front_left, eventName, eventStatus);
}
else if(strcasestr(eventName, "front_right"))
{
- pluginCtx->pluginHandle->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
- setDoor(&pluginCtx->allDoorsCtx.front_right, eventName, eventStatus);
+ sourceCtx->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
+ setDoor(&pluginCtx.allDoorsCtx.front_right, eventName, eventStatus);
}
else if(strcasestr(eventName, "rear_left"))
{
- pluginCtx->pluginHandle->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
- setDoor(&pluginCtx->allDoorsCtx.rear_left, eventName, eventStatus);
+ sourceCtx->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
+ setDoor(&pluginCtx.allDoorsCtx.rear_left, eventName, eventStatus);
}
else if(strcasestr(eventName, "rear_right"))
{
- pluginCtx->pluginHandle->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
- setDoor(&pluginCtx->allDoorsCtx.rear_right, eventName, eventStatus);
+ sourceCtx->searchNsetSignalValue(eventName,(uint64_t)timestamp, eventStatus);
+ setDoor(&pluginCtx.allDoorsCtx.rear_right, eventName, eventStatus);
}
else
{
@@ -170,14 +175,14 @@ CTLP_CAPI (isOpen, source, argsJ, eventJ) {
source->uid,
json_object_to_json_string(argsJ),
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"
+ 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"
);
return 0;