diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CMakeLists.txt | 2 | ||||
-rw-r--r-- | plugins/low-can.cpp | 12 | ||||
-rw-r--r-- | plugins/lua2c-interface.cpp (renamed from plugins/lua2c-interface.c) | 33 |
3 files changed, 33 insertions, 14 deletions
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c0d7225..2c37be7 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -19,7 +19,7 @@ PROJECT_TARGET_ADD(lua2c-interface) # Define targets - ADD_LIBRARY(${TARGET_NAME} MODULE ${TARGET_NAME}.c) + ADD_LIBRARY(${TARGET_NAME} MODULE ${TARGET_NAME}.cpp) # Alsa Plugin properties SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES diff --git a/plugins/low-can.cpp b/plugins/low-can.cpp index c4f79d2..18138b5 100644 --- a/plugins/low-can.cpp +++ b/plugins/low-can.cpp @@ -46,7 +46,7 @@ typedef struct { } allDoorsCtxT; typedef struct { - struct pluginCBT* pluginHandle; + struct signalCBT* pluginHandle; json_object *subscriptionBatch; allDoorsCtxT allDoorsCtx; } lowCANCtxT; @@ -63,7 +63,7 @@ CTLP_ONLOAD(plugin, composerHandle) { lowCANCtxT *pluginCtx= (lowCANCtxT*)calloc (1, sizeof(lowCANCtxT)); - pluginCtx->pluginHandle = (struct pluginCBT*)composerHandle; + pluginCtx->pluginHandle = (struct signalCBT*)composerHandle; pluginCtx->subscriptionBatch = json_object_new_array(); AFB_NOTICE ("Low-can plugin: label='%s' version='%s' info='%s'", @@ -148,22 +148,22 @@ CTLP_CAPI (isOpen, source, argsJ, eventJ, context) { }; if(strcasestr(eventName, "front_left")) { - pluginCtx->pluginHandle->setsignalValue(eventName,(long long int)timestamp, value); + pluginCtx->pluginHandle->setSignalValue(eventName,(uint64_t)timestamp, value); setDoor(&pluginCtx->allDoorsCtx.front_left, eventName, eventStatus); } else if(strcasestr(eventName, "front_right")) { - pluginCtx->pluginHandle->setsignalValue(eventName,(long long int)timestamp, value); + pluginCtx->pluginHandle->setSignalValue(eventName,(uint64_t)timestamp, value); setDoor(&pluginCtx->allDoorsCtx.front_right, eventName, eventStatus); } else if(strcasestr(eventName, "rear_left")) { - pluginCtx->pluginHandle->setsignalValue(eventName,(long long int)timestamp, value); + pluginCtx->pluginHandle->setSignalValue(eventName,(uint64_t)timestamp, value); setDoor(&pluginCtx->allDoorsCtx.rear_left, eventName, eventStatus); } else if(strcasestr(eventName, "rear_right")) { - pluginCtx->pluginHandle->setsignalValue(eventName,(long long int)timestamp, value); + pluginCtx->pluginHandle->setSignalValue(eventName,(uint64_t)timestamp, value); setDoor(&pluginCtx->allDoorsCtx.rear_right, eventName, eventStatus); } else diff --git a/plugins/lua2c-interface.c b/plugins/lua2c-interface.cpp index 1da8f17..76f61cc 100644 --- a/plugins/lua2c-interface.c +++ b/plugins/lua2c-interface.cpp @@ -16,8 +16,6 @@ * */ -#define _GNU_SOURCE // needed for vasprintf - #define AFB_BINDING_VERSION 2 #include <afb/afb-binding.h> #include <systemd/sd-event.h> @@ -25,20 +23,26 @@ #include <stdbool.h> #include <string.h> +#include "signal-composer.hpp" #include "ctl-config.h" #include "wrap-json.h" +extern "C" +{ + CTLP_LUALOAD CTLP_REGISTER("lua2c-interface"); -typedef struct { - struct pluginCBT* pluginHandle; +typedef struct CtxS { + struct signalCBT* pluginHandle; } CtxT; +static CtxT *pluginCtx = NULL; + // Call at initialisation time CTLP_ONLOAD(plugin, handle) { - CtxT *pluginCtx= (CtxT*)calloc (1, sizeof(CtxT)); - pluginCtx->pluginHandle = (struct pluginCBT*)handle; + pluginCtx = (CtxT*)calloc (1, sizeof(CtxT)); + pluginCtx->pluginHandle = (struct signalCBT*)handle; AFB_NOTICE ("Low-can plugin: label='%s' version='%s' info='%s'", plugin->label, @@ -50,7 +54,22 @@ CTLP_ONLOAD(plugin, handle) { CTLP_LUA2C (setSignalValueWrap, label, argsJ) { - AFB_NOTICE("label: %s, argsJ: %s", label, json_object_to_json_string(argsJ)); + const char* name = nullptr; + double resultNum; + uint64_t timestamp; + if(! wrap_json_unpack(argsJ, "{ss, sF, sF? !}", + "name", &name, + "value", &resultNum, + "timestamp", ×tamp)) + { + AFB_ERROR("Fail to set value for label: %s, argsJ: %s", label, json_object_to_json_string(argsJ)); + return -1; + } + struct signalValue result = {0,0,1, resultNum, 0, ""}; + pluginCtx->pluginHandle->setSignalValue(name, timestamp, result); return 0; } + +// extern "C" closure +} |