aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conf.d/project/lua.d/init-daemon-04-oncall.lua12
-rw-r--r--controller/ctl-lua.c4
-rw-r--r--controller/ctl-lua.h10
-rw-r--r--controller/ctl-plugin.c3
-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
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp1
-rw-r--r--signal-composer-binding/signal-composer.cpp10
-rw-r--r--signal-composer-binding/signal.hpp5
10 files changed, 54 insertions, 38 deletions
diff --git a/conf.d/project/lua.d/init-daemon-04-oncall.lua b/conf.d/project/lua.d/init-daemon-04-oncall.lua
index 04b6080..7dc4669 100644
--- a/conf.d/project/lua.d/init-daemon-04-oncall.lua
+++ b/conf.d/project/lua.d/init-daemon-04-oncall.lua
@@ -42,8 +42,6 @@ function _Unit_Converter(source, args, event)
local sourcei, targeti = _positions[sourceunits], _positions[targetunits]
assert(sourcei and targeti)
- AFB:notice("LUA OnCall Echo Args source=%s args=%s event=%s", source, args, event)
-
if sourcei<targeti then
local base=1
@@ -51,10 +49,9 @@ function _Unit_Converter(source, args, event)
base=base*_interval[i][2]
end
- print("Value in", targetunits, "is", value/base)
- _result["result"] = value/base
+ event["value"] = value/base
- lua2c["setSignalValueWrap"](source, _result)
+ lua2c["setSignalValueWrap"](source, event)
elseif sourcei>targeti then
@@ -63,10 +60,9 @@ function _Unit_Converter(source, args, event)
base=base*interval[i][2]
end
- print("Value in ", targetunits, "is", value*base)
- _result["result"] = value/base
+ event["value"] = value/base
- lua2c["setSignalValueWrap"](source, _result)
+ lua2c["setSignalValueWrap"](source, event)
else
print("No conversion")
diff --git a/controller/ctl-lua.c b/controller/ctl-lua.c
index 518ff85..f694e58 100644
--- a/controller/ctl-lua.c
+++ b/controller/ctl-lua.c
@@ -610,9 +610,9 @@ STATIC int LuaAfbEventMake(lua_State* luaState) {
}
// Function call from LUA when lua2c plugin L2C is used
-int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback) {
+int Lua2cWrapper(lua_State* luaState, const char *funcname, Lua2cFunctionT callback) {
- json_object *argsJ= LuaPopArgs(luaState, LUA_FIST_ARG+1);
+ json_object *argsJ = LuaPopArgs(luaState, LUA_FIST_ARG);
int response = (*callback) (funcname, argsJ);
// push response to LUA
diff --git a/controller/ctl-lua.h b/controller/ctl-lua.h
index d41c6a5..0b8de45 100644
--- a/controller/ctl-lua.h
+++ b/controller/ctl-lua.h
@@ -59,13 +59,13 @@ extern "C" {
int LuaLibInit ();
-typedef int (*Lua2cFunctionT)(char *funcname, json_object *argsJ);
-typedef int (*Lua2cWrapperT) (lua_State* luaState, char *funcname, Lua2cFunctionT callback);
+typedef int (*Lua2cFunctionT)(const char *funcname, json_object *argsJ);
+typedef int (*Lua2cWrapperT) (lua_State* luaState, const char *funcname, Lua2cFunctionT callback);
#define CTLP_LUALOAD Lua2cWrapperT Lua2cWrap;
-#define CTLP_LUA2C(FuncName, label,argsJ) static int FuncName(char*label,json_object*argsJ);\
+#define CTLP_LUA2C(FuncName, label, argsJ) static int FuncName(const char*label,json_object*argsJ);\
int lua2c_ ## FuncName(lua_State* luaState){return((*Lua2cWrap)(luaState, MACRO_STR_VALUE(FuncName), FuncName));};\
- static int FuncName(char* label, json_object* argsJ)
+ static int FuncName(const char* label, json_object* argsJ)
typedef enum {
LUA_DOCALL,
@@ -76,7 +76,7 @@ typedef enum {
int LuaConfigLoad();
int LuaConfigExec();
void LuaL2cNewLib(const char *label, luaL_Reg *l2cFunc, int count);
-int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback);
+int Lua2cWrapper(lua_State* luaState, const char *funcname, Lua2cFunctionT callback);
int LuaCallFunc (CtlActionT *action, json_object *queryJ) ;
void ctlapi_lua_docall (afb_req request);
void ctlapi_lua_dostring (afb_req request);
diff --git a/controller/ctl-plugin.c b/controller/ctl-plugin.c
index 1be97d4..9e4e419 100644
--- a/controller/ctl-plugin.c
+++ b/controller/ctl-plugin.c
@@ -65,11 +65,10 @@ int PluginGetCB (CtlActionT *action , json_object *callbackJ) {
OnErrorExit:
return 1;
-
}
// Wrapper to Lua2c plugin command add context and delegate to LuaWrapper
-STATIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT callback) {
+STATIC int DispatchOneL2c(lua_State* luaState, const char *funcname, Lua2cFunctionT callback) {
#ifndef CONTROL_SUPPORT_LUA
AFB_ERROR("CTL-ONE-L2C: LUA support not selected (cf:CONTROL_SUPPORT_LUA) in config.cmake");
return 1;
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
+}
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 3c16ad3..36d0c9d 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -32,7 +32,6 @@
/// @param[in] object - eventual data that comes with the event
void onEvent(const char *event, json_object *object)
{
- AFB_NOTICE("Received event json: %s", json_object_to_json_string(object));
Composer& composer = Composer::instance();
std::vector<std::shared_ptr<Signal>> signals = composer.searchSignals(event);
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index f0a625b..89d442d 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -21,15 +21,13 @@
#include "clientApp.hpp"
-extern "C" void setsignalValueHandle(const char* aName, long long int timestamp, struct signalValue value)
+extern "C" void setSignalValueHandle(const char* aName, uint64_t timestamp, struct signalValue value)
{
std::vector<std::shared_ptr<Signal>> signals = Composer::instance().searchSignals(aName);
if(!signals.empty())
{
for(auto& sig: signals)
- {
- sig->set(timestamp, value);
- }
+ {sig->set(timestamp, value);}
}
}
@@ -41,8 +39,8 @@ bool startsWith(const std::string& str, const std::string& pattern)
return false;
}
-static struct pluginCBT pluginHandle = {
- .setsignalValue = setsignalValueHandle,
+static struct signalCBT pluginHandle = {
+ .setSignalValue = setSignalValueHandle,
};
CtlSectionT Composer::ctlSections_[] = {
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 7bc6b4a..aa974da 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -86,3 +86,8 @@ public:
int initialRecursionCheck();
int recursionCheck(Signal* obs);
};
+
+struct signalCBT
+{
+ void (*setSignalValue)(const char* aName, uint64_t timestamp, struct signalValue value);
+};