Skip to content
Snippets Groups Projects
Commit 13960ad6 authored by clohr's avatar clohr
Browse files

xAAL 0.7

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/branches/version-0.7@2438 b32b6428-25c9-4566-ad07-03861ab6144f
parent 4e66334e
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,8 @@ Following applications are proposed as proof of concept:
- automalua: Automata with Lua scripts.
This simple automata engine is transparent and does not expose itself as
an xAAL device (i.e. with the schema scenario.basic)
an xAAL device. This is the responsability of lua scripts to implement
an xAAL schema (scenario.basic is a good candidate).
A short introduction of the API:
.Variables provided to Lua scripts (readed from config file):
xAAL_Lua_baseaddr: An uuid, possibly of the first declared device.
......
......@@ -716,8 +716,8 @@ int xAAL_Lua_write_bus(lua_State* L) {
/* Helper for Lua script: xAAL_Lua_filter_broadcast_by_source() */
/* Expected parameters are:
* address(string) of the device concerned by the filter
* a table of source addresses (string)
* address(bytestring[16]) of the device concerned by the filter
* a table of source addresses (* bytestring[16])
* Returns nothing
*/
int xAAL_Lua_filter_broadcast_by_source(lua_State* L) {
......
......@@ -11,7 +11,7 @@
{
"script": "lightswitch.lua",
"baseaddr": "fb8b3b92-6ae0-4e2c-8fcd-5c10d63f29ee",
"parameter": "peering={button=\"f0ac77a0-1c4c-4fdd-8b69-a3988f290fc0\",lamp=\"b4f209f5-096c-4d84-a3f3-e722bc657923\"}"
"parameter": "peering={switch=\"f0ac77a0-1c4c-4fdd-8b69-a3988f290fc0\",lamp=\"b4f209f5-096c-4d84-a3f3-e722bc657923\"}"
},
{
"script": "blink.lua",
......
......@@ -2,15 +2,24 @@
-- Blink - Basic automaton to make a lamp blinking
--
--[[ -- Just for debuging
print("-- blink.lua --")
print("xAAL_Lua_baseaddr: "..xAAL_Lua_uuid_unparse(xAAL_Lua_baseaddr))
print("xAAL_Lua_group_id: "..xAAL_Lua_uuid_unparse(xAAL_Lua_group_id))
print("xAAL_Lua_parameter: "..xAAL_Lua_parameter)
--]]
device = { info="Blinker", dev_type="basic.basic",
vendor_id="IHSEV Team", product_id="blinking automaton", version="0.2",
device = { info="Blinker", dev_type="scenario.basic",
vendor_id="IHSEV Team", product_id="blinking automaton", version="0.3",
url="http://recherche.imt-atlantique.fr/xaal/documentation/",
schema="https://redmine.telecom-bretagne.eu/svn/xaal/schemas/branches/schemas-0.7/basic.basic",
unsupported_attributes={}, unsupported_methods={},
schema="https://redmine.telecom-bretagne.eu/svn/xaal/schemas/branches/schemas-0.7/scenario.basic",
unsupported_attributes={"properties"}, unsupported_methods={"run","abort"},
unsupported_notifications={} }
device["addr"] = xAAL_Lua_declare_device(device)
is_enabled = true
-- Assume xAAL_Lua_parameter contains a table named conf
-- with a period in seconds and a lamp address
......@@ -23,23 +32,35 @@ xAAL_Lua_filter_broadcast_by_source(device["addr"], { xAAL_Lua_uuid_parse("00000
-- Declare it, but empty (I do not expect messages)
function xAAL_Lua_receive_callback(dev, msg)
print("Unsollicited message (blink.lua)!")
function xAAL_Lua_receive_callback(dev, source, dev_type, msg_type, action, body)
if ( dev == device["addr"] ) then
if ( msg_type == 1 ) then
if ( action == "enable" ) then
is_enabled = true
xAAL_Lua_set_alarm(conf["period"], device["addr"], "on")
elseif ( action == "disable" ) then
is_enabled = false
elseif ( action == "get_attributes" ) then
xAAL_Lua_write_bus(dev, 2, "get_attributes", { enabled=is_enabled }, { source } )
end
end
end
end
-- Main of the job
function xAAL_Lua_alarm_callback(dev, parameter)
if ( parameter == "on" ) then
xAAL_Lua_write_bus(dev, 1, "on", {}, { conf["lamp"] } )
xAAL_Lua_set_alarm(conf["period"], dev, "off")
else
xAAL_Lua_write_bus(dev, 1, "off", {}, { conf["lamp"] } )
xAAL_Lua_set_alarm(conf["period"], dev, "on")
if ( is_enabled ) then
if ( parameter == "on" ) then
xAAL_Lua_write_bus(dev, 1, "turn_on", {}, { conf["lamp"] } )
xAAL_Lua_set_alarm(conf["period"], dev, "off")
else
xAAL_Lua_write_bus(dev, 1, "turn_off", {}, { conf["lamp"] } )
xAAL_Lua_set_alarm(conf["period"], dev, "on")
end
end
end
-- Bootstrap
xAAL_Lua_set_alarm(conf["period"], device["addr"], "on")
--
-- Lightswitch - Basic automaton to peer a button and a lamp
-- Lightswitch - Basic automaton to peer a switch and a lamp
--
---[[ -- Just for debuging
--[[ -- Just for debuging
print("-- lightswitch.lua --")
print("xAAL_Lua_baseaddr: "..xAAL_Lua_uuid_unparse(xAAL_Lua_baseaddr))
print("xAAL_Lua_group_id: "..xAAL_Lua_uuid_unparse(xAAL_Lua_group_id))
......@@ -10,30 +10,31 @@ print("xAAL_Lua_parameter: "..xAAL_Lua_parameter)
--]]
device = { info="Peering a button and lamp", dev_type="basic.basic",
vendor_id="IHSEV Team", product_id="Peering automaton", version="0.2",
device = { info="Peering a switch and lamp", dev_type="scenario.basic",
vendor_id="IHSEV Team", product_id="Peering automaton", version="0.3",
url="http://recherche.imt-atlantique.fr/xaal/documentation/",
schema="https://redmine.telecom-bretagne.eu/svn/xaal/schemas/branches/schemas-0.7/basic.basic",
unsupported_attributes={}, unsupported_methods={},
schema="https://redmine.telecom-bretagne.eu/svn/xaal/schemas/branches/schemas-0.7/scenario.basic",
unsupported_attributes={"properties"}, unsupported_methods={"run","abort"},
unsupported_notifications={} }
device["addr"] = xAAL_Lua_declare_device(device)
is_enabled = true
-- Assume xAAL_Lua_parameter contains a table named peering
-- with a button address and a lamp address
-- with a switch address and a lamp address
assert(loadstring(xAAL_Lua_parameter))()
peering["button"] = xAAL_Lua_uuid_parse(peering["button"])
peering["switch"] = xAAL_Lua_uuid_parse(peering["switch"])
peering["lamp"] = xAAL_Lua_uuid_parse(peering["lamp"])
-- Accept messages from the button
xAAL_Lua_filter_broadcast_by_source(device["addr"], { peering["button"] })
-- Accept messages from the switch
xAAL_Lua_filter_broadcast_by_source(device["addr"], { peering["switch"] })
-- Main of the job
function xAAL_Lua_receive_callback(dev, source, dev_type, msg_type, action, body)
---[[ -- Just for debuging
--[[ -- Just for debuging
local serpent = dofile("serpent.lua")
print(xAAL_Lua_uuid_unparse(dev));
print(xAAL_Lua_uuid_unparse(source));
......@@ -44,10 +45,21 @@ function xAAL_Lua_receive_callback(dev, source, dev_type, msg_type, action, body
print()
--]]
if ( dev == device.addr ) then
if ( msg_type == 1 ) then
if ( action == "enable" ) then
is_enabled = true
elseif ( action == "disable" ) then
is_enabled = false
elseif ( action == "get_attributes" ) then
xAAL_Lua_write_bus(dev, 2, "get_attributes", { enabled=is_enabled }, { source } )
end
end
end
if ( is_enabled and (source == peering["switch"]) and (msg_type == 0) and (action == "attributes_change") ) then
if ( body["position"] ) then
xAAL_Lua_write_bus(dev, 1, "on", {}, { peering["lamp"] } )
xAAL_Lua_write_bus(dev, 1, "turn_on", {}, { peering["lamp"] } )
else
xAAL_Lua_write_bus(dev, 1, "off", {}, { peering["lamp"] } )
xAAL_Lua_write_bus(dev, 1, "turn_off", {}, { peering["lamp"] } )
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment