From 96f0057d65fbb90d9faa02a3ae4ae37b357094db Mon Sep 17 00:00:00 2001 From: fulup Date: Mon, 14 Aug 2017 00:58:57 +0200 Subject: Work in Progress --- conf.d/cmake/config.cmake | 1 + conf.d/project/config.d/onload-audio-control.json | 6 +- conf.d/project/lua.d/doscript-helloworld.lua | 36 +++++++++ conf.d/project/lua.d/helloworld-lua-script.lua | 41 ---------- conf.d/project/lua.d/onload-audio-controls.lua | 54 +++++++++++++ conf.d/project/lua.d/onload-audio-oncall.lua | 88 +++++++++++++++++++++ conf.d/project/lua.d/onload-audio-policy.lua | 49 ------------ conf.d/project/lua.d/onload-audio-samples.lua | 93 ----------------------- conf.d/project/lua.d/onload-audio-utils.lua | 32 ++++++++ 9 files changed, 214 insertions(+), 186 deletions(-) create mode 100644 conf.d/project/lua.d/doscript-helloworld.lua delete mode 100644 conf.d/project/lua.d/helloworld-lua-script.lua create mode 100644 conf.d/project/lua.d/onload-audio-controls.lua create mode 100644 conf.d/project/lua.d/onload-audio-oncall.lua delete mode 100644 conf.d/project/lua.d/onload-audio-policy.lua delete mode 100644 conf.d/project/lua.d/onload-audio-samples.lua create mode 100644 conf.d/project/lua.d/onload-audio-utils.lua (limited to 'conf.d') diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index 510eb70..ff8bf38 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -69,6 +69,7 @@ set (PKG_REQUIRED_LIST # --------------------------------------------------------- add_compile_options(-DCONTROL_ONLOAD_DEFAULT="onload-default") add_compile_options(-DCONTROL_MAXPATH_LEN=255) + add_compile_options(-DCONTROL_DOSCRIPT_PRE="doscript") add_compile_options(-DCONTROL_CONFIG_PRE="onload") add_compile_options(-DCONTROL_CONFIG_POST="control" ) add_compile_options(-DCONTROL_CONFIG_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/config.d:${CMAKE_INSTALL_PREFIX}/controler/config.d") diff --git a/conf.d/project/config.d/onload-audio-control.json b/conf.d/project/config.d/onload-audio-control.json index aecf1b3..c8f9be2 100644 --- a/conf.d/project/config.d/onload-audio-control.json +++ b/conf.d/project/config.d/onload-audio-control.json @@ -39,7 +39,7 @@ "actions": [{ "label": "multimedia-control-lua", "info": "Call Lua Script function Test_Lua_Engin", - "lua": "Audio_Set_Use_Case_Multimedia", + "lua": "Audio_Set_Multimedia", }] }, { "label": "navigation", @@ -61,13 +61,13 @@ }, { "label": "navigation-control-lua", "info": "Call Lua Script to set Navigation", - "lua": "Audio_Set_Use_Case_Navigation", + "lua": "Audio_Set_Navigation", }] }, { "label": "emergency", "actions": [{ "label": "emergency-control-ucm", - "lua": "Audio_Set_Use_Case_Emergency", + "lua": "Audio_Set_Emergency", }] } ], 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..b70ba8d --- /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:error ("LUA HelloWorld:FX query should not be empty"); + AFB:fail (request, "LUA HelloWorld: query should not be empty"); + else + AFB:error ("LUA HelloWorld:OK query=%s", query); + AFB:sucess (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"}); + end + +end \ No newline at end of file diff --git a/conf.d/project/lua.d/helloworld-lua-script.lua b/conf.d/project/lua.d/helloworld-lua-script.lua deleted file mode 100644 index 7dd0459..0000000 --- a/conf.d/project/lua.d/helloworld-lua-script.lua +++ /dev/null @@ -1,41 +0,0 @@ ---[[ - 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 ---]] - - -- retrieve calling arguments - args= ... - - print ("Helloworld script arguments:") - - - for key,value in pairs(args) - do - print("args: ", key,value) - end - - -- loop on script arguments - --for i=1,#args - --do - -- print(" -- ", i, args[i]) - --end - - - -- return two arguments on top of status - return true, 1234, "ABCD", 5678 - diff --git a/conf.d/project/lua.d/onload-audio-controls.lua b/conf.d/project/lua.d/onload-audio-controls.lua new file mode 100644 index 0000000..eb6a61b --- /dev/null +++ b/conf.d/project/lua.d/onload-audio-controls.lua @@ -0,0 +1,54 @@ +--[[ + 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 policy function for AGL Advance Audio Agent +--]] + +function Audio_Init_CB (status, result, context) + print ("***** result=", Dump_Table(result)) + print ("***** context=", Dump_Table(context)) + + -- AFB:notice ("--LUA:Audio_Init_Hal result=%s context=%s", result, context) + +end + +-- Function call at binding load time +function Audio_Init_Hal(args, query) + AFB:notice ("--LUA:Audio_Init_Hal args=%s query=%s", args, query); + + -- query asynchronously loaded HAL + AFB:service ('alsacore', 'hallist', {}, "Audio_Init_CB", {arg1=1234, arg2="toto"}) + +end + +function Audio_Set_Navigation(args, query) + + AFB:notice ("--LUA:Audio_Set_Use_Case args=%s query=%s", args, query); + + -- synchronous call to alsacore service + local error,data= AFB:callsync ('alsacore', 'ping', {}) + if (error) then + AFB:error ("--LUA:Audio_Set_Use_Case FAIL args=%s", args) + else + AFB:notice ("--LUA:Audio_Set_Use_Case DONE args=%s response=%s", args, data["response"]) + end + + -- return OK + return 0 +end + + diff --git a/conf.d/project/lua.d/onload-audio-oncall.lua b/conf.d/project/lua.d/onload-audio-oncall.lua new file mode 100644 index 0000000..22cba85 --- /dev/null +++ b/conf.d/project/lua.d/onload-audio-oncall.lua @@ -0,0 +1,88 @@ +--[[ + 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 + +-- Adjust Volume function of vehicle speed +function Oncall_Helloworld (request, args) + count=count+1 + + AFB:notice("LUA OnCall Helloworld count=%d args=%s", count, args); + AFB:success (request, {"count"=count}) +end + +function Test_Async_CB (request, result, context) + + AFB:notice ("Test_Async_CB result=%s context=%s", result, context) + AFB:success (request, {"response"=result, "context"=context}) +end + +function Test_Call_Async (request, args) + local context={ + "value1"="abcd", + "value2"=1234 + } + + AFB:notice ("Test_Call_Async args=%s", args) + AFB:service("alsacore","ping", args, "Test_Async_CB", context) +end + +function Test_Call_Sync (request, args) + + AFB:notice ("Test_Call_Sync args=%s", args) + local err, response= AFB:service_sync ("alsacore","ping", args) + if (err) then + AFB:fail ("AFB:service_call_sync fail"); + else + AFB:success (request, response) + end +end + +-- create a new event name +function Test_Event_Make (request, args) + + AFB:notice ("Test_Event_Make args=%s", args) + local err eventFD AFB:event (args["evtname"]) + if (err) then + AFB:fail ("AFB:Test_Event_Make fail event=%s", args["evtname"]); + else + AFB:success (request, {}) + end + + local evtData = { + val1="My 1st private Event", + val2=5678 + } + + AFB:notify (eventFD, evtData) +end + +-- send an event on default binder event +function Test_Event_Notify (request, args) + + AFB:notice ("Test_Event_Notify args=%s", args) + local err AFB:notify (args) + if (err) then + AFB:fail ("AFB:Test_Event_Make fail event=%s", args["evtname"]); + else + AFB:success (request, {}) + end +end diff --git a/conf.d/project/lua.d/onload-audio-policy.lua b/conf.d/project/lua.d/onload-audio-policy.lua deleted file mode 100644 index 0b7c358..0000000 --- a/conf.d/project/lua.d/onload-audio-policy.lua +++ /dev/null @@ -1,49 +0,0 @@ ---[[ - 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 policy function for AGL Advance Audio Agent ---]] - -function Audio_Init_CB (status, result, context) - print ("***** result=", Dump_Table(result)) - print ("***** context=", Dump_Table(context)) - - -- AFB:notice ("--LUA:Audio_Init_Hal result=%s context=%s", result, context) - -end - --- Function call at binding load time -function Audio_Init_Hal(args, query) - AFB:notice ("--LUA:Audio_Init_Hal args=%s query=%s", args, query); - - -- query asynchronously loaded HAL - AFB:service ('alsacore', 'hallist', {}, "Audio_Init_CB", {arg1=1234, arg2="toto"}) - -end - -function Audio_Set_Navigation(args, query) - - AFB:notice ("--LUA:Audio_Set_Use_Case args=%s query=%s", args, query, {myint=1234, mystring="abcd"}); - -- Print_Table("args", args) - - - - -- return OK - return 0 -end - - diff --git a/conf.d/project/lua.d/onload-audio-samples.lua b/conf.d/project/lua.d/onload-audio-samples.lua deleted file mode 100644 index 055a15d..0000000 --- a/conf.d/project/lua.d/onload-audio-samples.lua +++ /dev/null @@ -1,93 +0,0 @@ ---[[ - 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 policy function for AGL Advance Audio Agent ---]] - -count=0 - --- Adjust Volume function of vehicle speed -function Adjust_Volume_Speed (request, speed_meters_second) - - AFB:notice("In Adjust_Volume_Speed speed=%d", speed_meters_second); - - print (string.format("*****(From Lua) Adjust_Volume_Speed speed=%d count=%d", speed_meters_second, count)); - - -- compute volume - volume = speed_meters_second * 2 - count=count+1 - - AFB:success (request, 1234, volume, count, 5678) -end - - -function Test_Binder_CB (result, context) - - local myTable= { ["arg1"] = "myString", ["arg2"] = 1234, ["arg4"] = true, ["arg5"] = 3.1416 } - - AFB:notice ("In Test_Binder_CB", result, context) - - AFB:success (1234, "ABCD", myTable, 5678) - -end - -function Test_Binder_Call_Async () - - local query= { - ["arg1"] = "myString", - ["arg2"] = 1234, - ["arg4"] = true, - ["arg5"] = 3.1416, - } - - AFB:service("alsacore","ping", query, Test_Binder_CB, "myContext") - -end - -function Test_Binder_Call_Sync () - - local query= { - ["arg1"] = "myString", - ["arg2"] = 1234, - ["arg4"] = true, - ["arg5"] = 3.1416, - } - - err= AFB:service_sync ("alsacore","ping", query) - - if (err) then - AFB:fail ("AFB:service_call_sync fail"); - else - AFB:success (1234, "ABCD", myTable) - end - - -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 diff --git a/conf.d/project/lua.d/onload-audio-utils.lua b/conf.d/project/lua.d/onload-audio-utils.lua new file mode 100644 index 0000000..40ef8a3 --- /dev/null +++ b/conf.d/project/lua.d/onload-audio-utils.lua @@ -0,0 +1,32 @@ +--[[ + 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. + +--]] + + +-- 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 -- cgit 1.2.3-korg