summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-26 18:36:47 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commitc22ad857bcd2f567d22f3239d91fa65720718713 (patch)
tree165407be42745a190672ff64fe27503074380735 /plugins
parent7f5a4ef3053eaac5c3f936b6294087d3d2b72c38 (diff)
lua2c completely operationnal
- Retrieve args from lua call correctly - Correctly push and set function pointer into plugin symbols Change-Id: I12d03e1101c458a042887a67a35a08082bd98f4c Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CMakeLists.txt2
-rw-r--r--plugins/low-can.cpp12
-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", &timestamp))
+ {
+ 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
+}