From 19bc13783a7451c81848ea132614a8df11c7740a Mon Sep 17 00:00:00 2001 From: "Forlot Romain [IoT.bzh]" Date: Mon, 4 Sep 2017 23:37:22 +0200 Subject: Initial commit Change-Id: I2bb38bffdd92602659670901b8442201b7c56214 Signed-off-by: Romain Forlot --- conf.d/project/CMakeLists.txt | 22 ++ conf.d/project/etc/CMakeLists.txt | 31 +++ conf.d/project/etc/sig-demoboard.json | 58 ++++ conf.d/project/etc/sig-doors.json | 85 ++++++ conf.d/project/etc/sig-geoloc.json | 294 +++++++++++++++++++++ conf.d/project/etc/sig-sources.json | 44 +++ conf.d/project/lua.d/00-viwi-low-can.lua | 27 ++ conf.d/project/lua.d/CMakeLists.txt | 32 +++ conf.d/project/lua.d/doscript-helloworld.lua | 36 +++ conf.d/project/lua.d/onload-daemon-00-utils.lua | 86 ++++++ conf.d/project/lua.d/onload-daemon-01-init.lua | 48 ++++ conf.d/project/lua.d/onload-daemon-03-controls.lua | 48 ++++ conf.d/project/lua.d/onload-daemon-04-oncall.lua | 70 +++++ conf.d/project/lua.d/onload-daemon-10-event.lua | 74 ++++++ 14 files changed, 955 insertions(+) create mode 100644 conf.d/project/CMakeLists.txt create mode 100644 conf.d/project/etc/CMakeLists.txt create mode 100644 conf.d/project/etc/sig-demoboard.json create mode 100644 conf.d/project/etc/sig-doors.json create mode 100644 conf.d/project/etc/sig-geoloc.json create mode 100644 conf.d/project/etc/sig-sources.json create mode 100644 conf.d/project/lua.d/00-viwi-low-can.lua create mode 100644 conf.d/project/lua.d/CMakeLists.txt create mode 100644 conf.d/project/lua.d/doscript-helloworld.lua create mode 100644 conf.d/project/lua.d/onload-daemon-00-utils.lua create mode 100644 conf.d/project/lua.d/onload-daemon-01-init.lua create mode 100644 conf.d/project/lua.d/onload-daemon-03-controls.lua create mode 100644 conf.d/project/lua.d/onload-daemon-04-oncall.lua create mode 100644 conf.d/project/lua.d/onload-daemon-10-event.lua (limited to 'conf.d/project') diff --git a/conf.d/project/CMakeLists.txt b/conf.d/project/CMakeLists.txt new file mode 100644 index 0000000..28a0609 --- /dev/null +++ b/conf.d/project/CMakeLists.txt @@ -0,0 +1,22 @@ +########################################################################### +# Copyright 2015, 2016, 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + + +# Include any directory not starting with _ +# ----------------------------------------------------- +PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN}) diff --git a/conf.d/project/etc/CMakeLists.txt b/conf.d/project/etc/CMakeLists.txt new file mode 100644 index 0000000..1ff98b1 --- /dev/null +++ b/conf.d/project/etc/CMakeLists.txt @@ -0,0 +1,31 @@ +########################################################################### +# Copyright 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + +################################################## +# Control Policy Config file +################################################## +PROJECT_TARGET_ADD(signal-composer-config) + + file(GLOB CONF_FILES "*.json") + + add_input_files("${CONF_FILES}") + + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "BINDING-CONFIG" + OUTPUT_NAME ${TARGET_NAME} + ) diff --git a/conf.d/project/etc/sig-demoboard.json b/conf.d/project/etc/sig-demoboard.json new file mode 100644 index 0000000..4b81989 --- /dev/null +++ b/conf.d/project/etc/sig-demoboard.json @@ -0,0 +1,58 @@ +{ + "resources": [{ + "name": "/car/demoboard/", + "values": [{ + "name": "vehicleSpeed", + "additionnals_infos": { + "unit": "km/h", + "interval": 1000 + }, + "source": "CAN bus", + "class": "raw", + "type": "double", + "source_args": { + "event": "diagnostic_messages.vehicle.speed", + "filter": { + "frequency": "100", + "min": 10 + } + } + }, { + "name": "engineSpeed", + "additionnals_infos": { + "unit": "rpm", + "interval": 1000 + }, + "source":"CAN bus", + "class": "raw", + "type": "double", + "source_args": { + "event": "diagnostic_messages.engine.speed" + } + }, { + "name": "fuelLevel", + "additionnals_infos": { + "unit": "litre", + "interval": 1000 + }, + "class":"raw", + "source":"CAN bus", + "type": "double", + "source_args": { + "event": "diagnostic_messages.fuel.level" + } + }, { + "name": "engineLoad", + "additionnals_infos": { + "unit": "Nm", + "interval": 1000 + }, + "source":"CAN bus", + "type":"double", + "class":"raw", + "source_args": { + "event": "diagnostic_messages.engine.load" + } + }] + }] +} diff --git a/conf.d/project/etc/sig-doors.json b/conf.d/project/etc/sig-doors.json new file mode 100644 index 0000000..46d37cc --- /dev/null +++ b/conf.d/project/etc/sig-doors.json @@ -0,0 +1,85 @@ +{ + "signals": [ + { + "label": "low-can/messages.windows.front_left.open", + "actions": { + "label": "Door open event action", + "lua": "_Door_opened", + "args": { + "evtname": "messages.windows.front_left.open" + } + } + }, + { + "label": "low-can/messages.windows.front_right.open", + "actions": { + "label": "Door open event action", + "lua": "_Door_opened", + "args": { + "evtname": "messages.windows.front_right.open" + } + } + }, + { + "label": "low-can/messages.windows.rear_left.open", + "actions": { + "label": "Door open event action", + "lua": "_Door_opened", + "args": { + "evtname": "messages.windows.rear_left.open" + } + } + }, + { + "label": "low-can/messages.windows.rear_right.open", + "actions": { + "label": "Door open event action", + "lua": "_Door_opened", + "args": { + "evtname": "messages.windows.rear_right.open" + } + } + }], + "virtual_signals": [ + { + "label": "sig-orc/doors.open", + "depends_on": [ + "front_left_doors", + "front_left_windows", + "front_right_doors", + "front_right_windows", + "rear_left_doors", + "rear_left_windows", + "rear_right_doors", + "rear_right_windows" + ], + "actions": { + "label": "A door is open", + "lua": "_Door_opened", + "args": { + "evtname": "doors.open" + } + } + }, + { + "label": "sig-orc/doors.average", + "depends_on": [ + "front_left_doors", + "front_left_windows", + "front_right_doors", + "front_right_windows", + "rear_left_doors", + "rear_left_windows", + "rear_right_doors", + "rear_right_windows" + ], + "actions": { + "label": "A door is open", + "lua": "_Door_average", + "args": { + "evtname": "door.average", + "time": 120 + } + } + }] +} \ No newline at end of file diff --git a/conf.d/project/etc/sig-geoloc.json b/conf.d/project/etc/sig-geoloc.json new file mode 100644 index 0000000..6db766d --- /dev/null +++ b/conf.d/project/etc/sig-geoloc.json @@ -0,0 +1,294 @@ +{ + "resources": [{ + "group": "/car/geoloc/", + "values": [{ + "name": "latitude", + "additionnals_infos": { + "unit": "degree", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "longitude", + "additionnals_infos": { + "unit": "degree", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "altitude", + "additionnals_infos": { + "unit": "meter", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "heading", + "additionnals_infos": { + "unit": "degree", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "speed", + "additionnals_infos": { + "unit": "m/s", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "climb", + "additionnals_infos": { + "unit": "degree", + "interval": 1000 + }, + "source": "Sensors", + "class": "raw", + "type": "double", + "source_args": { + "sensor": "gyro" + } + }, + { + "name": "roll_rate", + "additionnals_infos": { + "unit": "degree/s", + "interval": 1000 + }, + "source": "Sensors", + "class": "raw", + "type": "double", + "source_args": { + "sensor": "roll_rate" + } + }, + { + "name": "roll_rate", + "additionnals_infos": { + "unit": "degree/s", + "interval": 1000 + }, + "source": "Sensors", + "class": "raw", + "type": "double", + "source_args": { + "sensor": "pitch_rate" + } + }, + { + "name": "roll_rate", + "additionnals_infos": { + "unit": "degree/s", + "interval": 1000 + }, + "source": "Sensors", + "class": "raw", + "type": "double", + "source_args": { + "sensor": "yaw_rate" + } + }, + { + "name": "pdop", + "additionnals_infos": { + "interval": 1000 + }, "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "hdop", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "vdop", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "location" + } + }, + { + "name": "used_satellites", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "uint8", + "source_args": { + "value": "configuration" + } + }, + { + "name": "tracked_satellites", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "uint8", + "source_args": { + "value": "configuration" + } + }, + { + "name": "visible_satellites", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "uint8", + "source_args": { + "value": "configuration" + } + }, + { + "name": "sigma_hposition", + "additionnals_infos": { + "unit": "meter", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "configuration" + } + }, + { + "name": "sigma_altitude", + "additionnals_infos": { + "unit": "meter", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "configuration" + } + }, + { + "name": "sigma_heading", + "additionnals_infos": { + "unit": "degree", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "configuration" + } + }, + { + "name": "sigma_speed", + "additionnals_infos": { + "unit": "m/s", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "configuration" + } + }, + { + "name": "sigma_climb", + "additionnals_infos": { + "unit": "degree", + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "double", + "source_args": { + "value": "configuration" + } + }, + { + "name": "gnss_fix_status", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "uint16", + "source_args": { + "value": "configuration" + } + }, + { + "name": "dr_status", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "boolean", + "source_args": { + "value": "configuration" + } + }, + { + "name": "reliabilty_index", + "additionnals_infos": { + "interval": 1000 + }, + "source": "GNSS/GPS", + "class": "raw", + "type": "uint8_t", + "source_args": { + "value": "configuration" + } + }] + }] +} diff --git a/conf.d/project/etc/sig-sources.json b/conf.d/project/etc/sig-sources.json new file mode 100644 index 0000000..076139f --- /dev/null +++ b/conf.d/project/etc/sig-sources.json @@ -0,0 +1,44 @@ +{ + "$schema": "ToBeDone", + "metadata": { + "label": "signal-composer", + "info": "Signal composer Configuration", + "name": "afb-signal-composer", + "version": "1.0" + }, + "onload": [{ + "label": "onload-signal-composer", + "info": "onload initialisation config", + "require": [ + { + "label": "CAN bus", + "api": "low-can", + "info": "Low level binding to handle CAN bus communications", + "callback": "c function to subscribe on signals", + "lua": "or a lua function to subscribe on signals", + "args": { + "arg": "first argument" + } + }, + { + "label": "GNSS/GPS", + "api": "gps", + "info": "Low level binding which retrieve Satellite positionning values", + "callback": "c function to subscribe on signals", + "lua": "or a lua function to subscribe on signals", + "args": { + "value" : "arg" + } + }, + { + "label": "Sensors", + "api": "mraa", + "info": "Low level binding which retrieve different values from several sensors like gyroscope, accelerometer, etc", + "callback": "c function to subscribe on signals", + "lua": "or a lua function to subscribe on signals", + "args": { + "sensor" : "eg" + } + }] + }] +} diff --git a/conf.d/project/lua.d/00-viwi-low-can.lua b/conf.d/project/lua.d/00-viwi-low-can.lua new file mode 100644 index 0000000..b13863a --- /dev/null +++ b/conf.d/project/lua.d/00-viwi-low-can.lua @@ -0,0 +1,27 @@ +--[[ + Copyright (C) 2017 "IoT.bzh" + Author Romain Forlot + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--]] + +function _SubscribeLowCan (request, args) + + AFB:notice ("_We gonna subscribe to %s", args) + local err, result= AFB:servsync ("low-can","subscribe", args) + if (err) then + AFB:fail ("AFB:service_call_sync fail"); + else + AFB:success (request, result["response"]) + end +end diff --git a/conf.d/project/lua.d/CMakeLists.txt b/conf.d/project/lua.d/CMakeLists.txt new file mode 100644 index 0000000..07d39af --- /dev/null +++ b/conf.d/project/lua.d/CMakeLists.txt @@ -0,0 +1,32 @@ +########################################################################### +# Copyright 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + + +################################################## +# Control Policy Config file +################################################## +PROJECT_TARGET_ADD(lua.d) + + file(GLOB LUA_FILES "*.lua") + + add_input_files("${LUA_FILES}") + + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "DATA" + OUTPUT_NAME ${TARGET_NAME} + ) diff --git a/conf.d/project/lua.d/doscript-helloworld.lua b/conf.d/project/lua.d/doscript-helloworld.lua new file mode 100644 index 0000000..e722db7 --- /dev/null +++ b/conf.d/project/lua.d/doscript-helloworld.lua @@ -0,0 +1,36 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + Simple API script to be use with AGL control LuaDoCall API + - After the script is loaded by lua_docall + - Controller start function=xxxx where xxxx is taken from script filename doscript-xxxx-anything + +--]] + +function _helloworld (request, query) + + AFB:notice ("LUA HelloWorld: Simple test query=%s", query); + + if (query == nil) then + AFB:notice ("LUA HelloWorld:FX query should not be empty"); + AFB:fail (request, "LUA HelloWorld: query should not be empty"); + else + AFB:notice ("LUA HelloWorld:OK query=%s", query); + AFB:success (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"}); + end + +end diff --git a/conf.d/project/lua.d/onload-daemon-00-utils.lua b/conf.d/project/lua.d/onload-daemon-00-utils.lua new file mode 100644 index 0000000..29d2c70 --- /dev/null +++ b/conf.d/project/lua.d/onload-daemon-00-utils.lua @@ -0,0 +1,86 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Note: this file should be called before any other to assert declare function + is loaded before anything else. + + References: + http://lua-users.org/wiki/DetectingUndefinedVariables + +--]] + + +--=================================================== +--= Niklas Frykholm +-- basically if user tries to create global variable +-- the system will not let them!! +-- call GLOBAL_lock(_G) +-- +--=================================================== +function GLOBAL_lock(t) + local mt = getmetatable(t) or {} + mt.__newindex = lock_new_index + setmetatable(t, mt) +end + +--=================================================== +-- call GLOBAL_unlock(_G) +-- to change things back to normal. +--=================================================== +function GLOBAL_unlock(t) + local mt = getmetatable(t) or {} + mt.__newindex = unlock_new_index + setmetatable(t, mt) +end + +function lock_new_index(t, k, v) + if (string.sub(k,1,1) ~= "_") then + GLOBAL_unlock(_G) + error("GLOBALS are locked -- " .. k .. + " must be declared local or prefix with '_' for globals.", 2) + else + rawset(t, k, v) + end +end + +function unlock_new_index(t, k, v) + rawset(t, k, v) +end + +-- return serialised version of printable table +function Dump_Table(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. Dump_Table(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + + +-- simulate C prinf function +printf = function(s,...) + io.write(s:format(...)) + io.write("\n") + return +end + +-- lock global variable +GLOBAL_lock(_G) diff --git a/conf.d/project/lua.d/onload-daemon-01-init.lua b/conf.d/project/lua.d/onload-daemon-01-init.lua new file mode 100644 index 0000000..26ff08a --- /dev/null +++ b/conf.d/project/lua.d/onload-daemon-01-init.lua @@ -0,0 +1,48 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--]] + +-- Global variable SHOULD start with _ +_Global_Context={} + +--[[ + This function is call during controller init phase as describe in onload-daemon-sample.json + It receives two argument 1st one is the source (here on load) second one is the arguments + as expose in config file. + + In this sample we create an event that take the name of args["zzzz"], the resulting handle + is save into _Global_Context for further use. + + Note: init functions are not call from a client and thus do not receive query + +--]] +function _Sample_Controller_Init(source, control) + + printf ("[-- Sample_Controller_Init --] source=%d control=%s", source, Dump_Table(control)) + + -- if no argument return now + if (control==nil or control["zzzz"]==nil) then + printf ("[-- Sample_Controller_Init --] no event name given") + return + end + + -- set a count to make more visible each call + _Global_Context["counter"]=0 + + -- just for fun create an event + _Global_Context["event"]=AFB:evtmake(control["zzzz"]) + +end diff --git a/conf.d/project/lua.d/onload-daemon-03-controls.lua b/conf.d/project/lua.d/onload-daemon-03-controls.lua new file mode 100644 index 0000000..cc13e0f --- /dev/null +++ b/conf.d/project/lua.d/onload-daemon-03-controls.lua @@ -0,0 +1,48 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Following function are called when a client activate a control with + controller api -> APi=control VERB=dispatch + arguments are + - source (0) when requesting the control (-1) when releasing + - control comme from config given with 'args' in onload-middlename-xxxxx.json + - client is the argument part of the query as providing by client requesting the control. + +--]] + + + +-- Simple Happy(granted) Control +function _Button_Happy(source, control, client) + + -- print argument to make sure we understant what we get + printf ("[-- _Button_Happy --] source=%d control=%s client=%s", source, Dump_Table(control), Dump_Table(client)) + + AFB:notice ("[-- _Button_Happy --] To Be Done") + + return 0 -- control granted +end + + +-- Simple UnHappy(debu) Control +function _Button_UnHappy(source, control, client) + + -- print argument to make sure we understant what we get + printf ("[-- _Button_UnHappy --] source=%d control=%s client=%s", source, Dump_Table(client), Dump_Table(control)) + + AFB:error ("[-- _Button_UnHappy --] To Be Done") + return 1 -- control is refused +end diff --git a/conf.d/project/lua.d/onload-daemon-04-oncall.lua b/conf.d/project/lua.d/onload-daemon-04-oncall.lua new file mode 100644 index 0000000..b450932 --- /dev/null +++ b/conf.d/project/lua.d/onload-daemon-04-oncall.lua @@ -0,0 +1,70 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + Provide sample LUA routines to be used with AGL control "lua_docall" API +--]] + +--global counter to keep track of calls +_count=0 + +-- Display receive arguments and echo them to caller +function _Simple_Echo_Args (request, args) + _count=_count+1 + AFB:notice("LUA OnCall Echo Args count=%d args=%s", count, args) + + print ("--inlua-- args=", Dump_Table(args)) + + local response={ + ["count"]=_count, + ["args"]=args, + } + + -- fulup Embdeded table ToeDone AFB:success (request, response) + AFB:success (request, {["func"]="Simple_Echo_Args", ["ret1"]=5678, ["ret2"]="abcd"}) +end + +local function Test_Async_CB (request, result, context) + response={ + ["result"]=result, + ["context"]=context, + } + + AFB:notice ("Test_Async_CB result=%s context=%s", result, context) + AFB:success (request, response) +end + +function _Test_Call_Async (request, args) + local context={ + ["value1"]="abcd", + ["value2"]=1234 + } + + AFB:notice ("Test_Call_Async args=%s cb=Test_Async_CB", args) + AFB:service("monitor","ping", "Test_Async_CB", context) +end + +function _Simple_Monitor_Call (request, args) + + AFB:notice ("_Simple_Server_Call args=%s", args) + local err, result= AFB:servsync ("monitor","get", args) + if (err) then + AFB:fail ("AFB:service_call_sync fail"); + else + AFB:success (request, result["response"]) + end +end + diff --git a/conf.d/project/lua.d/onload-daemon-10-event.lua b/conf.d/project/lua.d/onload-daemon-10-event.lua new file mode 100644 index 0000000..474ebe0 --- /dev/null +++ b/conf.d/project/lua.d/onload-daemon-10-event.lua @@ -0,0 +1,74 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + Provide Sample Timer Handing to push event from LUA +--]] + +-- Create event on Lua script load +_MyContext={} + +-- WARNING: call back are global and should start with '_' +function _Timer_Test_CB (timer, context) + + local evtinfo= AFB:timerget(timer) + printf ("[-- _Timer_Test_C --] evtInfo=%s", Dump_Table(evtinfo)) + + --send an event an event with count as value + AFB:evtpush (_MyContext["event"], {["label"]= evtinfo["label"], ["count"]=evtinfo["count"], ["info"]=context["info"]}) + + -- note when timerCB return!=0 timer is kill + return 0 + +end + +-- sendback event depending on count and delay +function _Simple_Timer_Test (request, client) + + local context = { + ["info"]="My 1st private Event", + } + + -- if event does not exit create it now. + if (_MyContext["event"] == nil) then + _MyContext["event"]= AFB:evtmake(client["label"]) + end + + -- if delay not defined default is 5s + if (client["delay"]==nil) then client["delay"]=5000 end + + -- if count is not defined default is 10 + if (client["count"]==nil) then client["count"]=10 end + + -- we could use directly client but it is a sample + local myTimer = { + ["label"]=client["label"], + ["delay"]=client["delay"], + ["count"]=client["count"], + } + AFB:notice ("Test_Timer myTimer=%s", myTimer) + + -- subscribe to event + AFB:subscribe (request, _MyContext["event"]) + + -- settimer take a table with delay+count as input (count==0 means infinite) + AFB:timerset (myTimer, "_Timer_Test_CB", context) + + -- nothing special to return send back + AFB:success (request, myTimer) + + return 0 +end -- cgit 1.2.3-korg