Skip to content
Snippets Groups Projects
Commit 96b15179 authored by jkerdreu's avatar jkerdreu
Browse files

Trunk is trunk


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/trunk@3248 b32b6428-25c9-4566-ad07-03861ab6144f
parents 07cc8162 7ee30366
Branches
No related tags found
No related merge requests found
Showing
with 1806 additions and 1079 deletions
Makefile 0 → 100644
TOPTARGETS := all clean proper
# SUBDIRS := $(wildcard */.)
SUBDIRS := libxaal demo baseservices libxaal_jc xaaws netprobe babbler \
xaal-stt generic-sender generic-feedback-renderer sound-measure \
libxaal_aux tts
$(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)
.PHONY: $(TOPTARGETS) $(SUBDIRS)
proper:
-rm -f *~
# Implementation of xAAL in C
Here are some piece of code in C to implement xAAL devices.
Each folder contains a README.TXT and a Makefile.
Each folder contains a README.TXT and a Makefile.
So, feel free to read those files and type make.
......@@ -18,23 +18,21 @@ So, feel free to read those files and type make.
Runnable on a text console on your PC, without the need of real devices.
A good starting point for discovering the marvels of xAAL.
- baseservices: Special xAAL devices (cache, metadata DB, shema repositroy,
automaton). Optional, but useful on a real home-automation facility.
- baseservices: Special xAAL devices (cache, metadata DB, automaton).
Optional, but useful on a real home-automation facility.
- xaaws: A generic user interface (using html websockets rest javascript)
Having above mentioned base services running on the xAAL bus may help, at
least a schema repository.
- xaajax: A generic user interface (using html ajax rest javascript)
Having above mentioned base services running on the xAAL bus may help, at
least a schema repository.
- netprobe: Monitor the xAAL multicast bus, collect some statistics about
- netprobe: Monitor the xAAL multicast bus, collect some statistics about
bandwidth usage, etc.
- babbler: Text to speech for xAAL. Listen to the xAAL bus and tell
notifications and events. Funny but rapidly boring. Also, a good example
about using the metadata DB.
- xaal-stt: Speech to text for xAAL. Listen of sentences of the user (such
as "Majordom, switch on the lamp of the kitchen."), try to guess what
he/she wants, and sends xAAL commands. Funny but also rapidly boring.
he/she wants, and sends xAAL commands. Funny but also rapidly boring.
Also, a good example about using the metadata DB.
- generic-sender: A simple generic xAAL device to ease integration with
......@@ -45,7 +43,7 @@ So, feel free to read those files and type make.
- generic-feedback-renderer: This device listen for "inform" xAAL request
with a text, and render it to the user (e.g. by placing a call with a tts,
by pushing a pop-up on a DLNA TV, etc.). More-or-less the counterpart of
the generic-sender.
the generic-sender.
- sound-measure: An example of a sensor that does not stupidly forward
measures continuously periodically. Yes, one can do smarter things!
......@@ -55,9 +53,14 @@ So, feel free to read those files and type make.
- xaafloor: Fall Detector using a SensFloor device.
- libxaal_aux: An auxiliary library with helpers to feed optional xAAL stuff.
- libxaal_jc: An auxiliary library with json2cbor and cbor2json transcoders.
Note that transcoding rules are specific to the xAAL context.
## Copyright
- Christophe Lohr - IMT Atlantique - 2017
- Christophe Lohr - IMT Atlantique - 2019
- Libraries are provided according to the termes of the
GNU Lesser General Public License v3.0 and following
- Applications are provided according to the terms of the
......
PROG = babbler
CFLAGS = -Wall -I. -g
LDLIBS = -L. -lxaal -ljson-c -luuid -lsodium -lespeak
CFLAGS = -Wall -I. -g -O0
LDLIBS = -L. -lxaal -lcbor -luuid -lsodium -lespeak
all: $(PROG)
......@@ -9,22 +9,24 @@ $(PROG).pot: $(PROG).c
xgettext --copyright-holder="Christophe Lohr" --package-name=babbler --package-version=1 --msgid-bugs-address=christophe.lohr@imt-atlantique.fr -o $@ $^
fr.po: $(PROG).pot
if [ -e $@ ]; then mv -f $@ old_$@; fi
msginit -i $< -o $@
if [ -e old_$@ ]; then msgcat -o $@ $@ old_$@; fi
-joe $@ || vi $@
fr.mo: fr.po
msgfmt -o $@ $<
clean:
-rm -f *.o *~
-rm -f *.o *~ old_fr.po
proper: clean uninstall
-rm -f $(PROG)
-rm -f $(PROG) xaal-$(PROG).service
test: all
LD_LIBRARY_PATH=. ./$(PROG) -a 224.0.29.200 -p 1234 -s my_secret
LD_LIBRARY_PATH=. ./$(PROG) -a 224.0.29.200 -p 1236 -s my_secret
.PHONY: all clean proper install uninstall svnignore test
.PHONY: all clean proper test install uninstall svnignore
.SUFFIXES: .service .service.in
......@@ -47,4 +49,3 @@ uninstall:
status:
-sudo systemctl --system --no-pager -l status xaal-$(PROG)
Babbler: passing xAAL notifications (attributesChange) to the espeak TTS.
Babbler: passing xAAL notifications (attributes_change) to the espeak TTS.
Depends on libxaal
and on debian packages: libespeak-dev mbrola mbrola-en1 mbrola-fr1
......@@ -11,3 +11,6 @@ For now this includes english and french.
Dedicated sentences are proposed for lamps and thermometers devices.
Other devices are announced with a kind of generic sentence template...
Metatdata DBs are query for words to tell in association to devices
(recorded with the key "tts")
This diff is collapsed.
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: babbler 1\n"
"Report-Msgid-Bugs-To: christophe.lohr@imt-atlantique.fr\n"
"POT-Creation-Date: 2017-04-12 15:00+0200\n"
"POT-Creation-Date: 2017-06-01 15:40+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -17,117 +17,154 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: babbler.c:74
#: babbler.c:83
#, c-format
msgid "null"
msgid "of %ld"
msgstr ""
#: babbler.c:79
#: babbler.c:87
#, c-format
msgid "true"
msgid "binary data"
msgstr ""
#: babbler.c:81
#: babbler.c:101 babbler.c:114
#, c-format
msgid " and "
msgstr ""
#: babbler.c:115
#, c-format
msgid " an attribute \"%s\" that is "
msgstr ""
#: babbler.c:126
#, c-format
msgid "none"
msgstr ""
#: babbler.c:129
#, c-format
msgid "false"
msgstr ""
#: babbler.c:85
#: babbler.c:132
#, c-format
msgid "of %g"
msgid "true"
msgstr ""
#: babbler.c:89
#: babbler.c:135 babbler.c:144
#, c-format
msgid "of %ld"
msgid "null"
msgstr ""
#: babbler.c:102 babbler.c:111
#: babbler.c:138 babbler.c:148
#, c-format
msgid " and "
msgid "undefined"
msgstr ""
#: babbler.c:112
#: babbler.c:142
#, c-format
msgid " an attribute \"%s\" that is "
msgid "of %g"
msgstr ""
#: babbler.c:164
#: babbler.c:171
#, c-format
msgid "New event from the lamp %s:\n"
msgstr ""
#: babbler.c:182
#, c-format
msgid "The lamp is on.\n"
msgstr ""
#: babbler.c:166
#: babbler.c:184
#, c-format
msgid "The lamp is off.\n"
msgstr ""
#: babbler.c:173
#: babbler.c:187
#, c-format
msgid "The dimmer of the lamp is %g percent.\n"
msgstr ""
#: babbler.c:179
#: babbler.c:196
#, c-format
msgid "The lamp has "
msgstr ""
#: babbler.c:203
#: babbler.c:220
#, c-format
msgid "New event from the thermometer %s:\n"
msgstr ""
#: babbler.c:230
#, c-format
msgid "It is %g degrees Celsius.\n"
msgstr ""
#: babbler.c:209
#: babbler.c:239
#, c-format
msgid "The thermometer has "
msgstr ""
#: babbler.c:234
#: babbler.c:264
#, c-format
msgid "New event from the roller shutter %s:\n"
msgstr ""
#: babbler.c:276
#, c-format
msgid "The roller shutter goes up.\n"
msgstr ""
#: babbler.c:236
#: babbler.c:278
#, c-format
msgid "The roller shutter goes down.\n"
msgstr ""
#: babbler.c:238
#: babbler.c:280
#, c-format
msgid "The roller shutter stops.\n"
msgstr ""
#: babbler.c:247
#: babbler.c:287
#, c-format
msgid "The roller shutter is closed.\n"
msgstr ""
#: babbler.c:249
#: babbler.c:289
#, c-format
msgid "The roller shutter is open.\n"
msgstr ""
#: babbler.c:254
#: babbler.c:299
#, c-format
msgid "The roller shutter has "
msgstr ""
#: babbler.c:277
#: babbler.c:322
#, c-format
msgid "New event from a device %s:\n"
msgstr ""
#: babbler.c:326
#, c-format
msgid "\"%.*s'.'%s\" has "
msgstr ""
#: babbler.c:279
#: babbler.c:328
#, c-format
msgid "\"%s\" has "
msgstr ""
#: babbler.c:349
#: babbler.c:670
#, c-format
msgid "Unknown argument %s\n"
msgstr ""
#: babbler.c:353
#: babbler.c:674
#, c-format
msgid "Usage: %s -a <addr> -p <port> [-h <hops>] -s <secret> [-l <locale>]\n"
msgid ""
"Usage: %s -a <addr> -p <port> [-h <hops>] -s <secret> [-u <uuid>] [-l "
"<locale>]\n"
msgstr ""
No preview for this file type
......@@ -4,12 +4,13 @@
# This file is distributed under the same license as the babbler package.
# Christophe Lohr <christophe.lohr@imt-atlantique.fr>, 2017.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: babbler 1\n"
"Project-Id-Version: babbler\n"
"Report-Msgid-Bugs-To: christophe.lohr@imt-atlantique.fr\n"
"POT-Creation-Date: 2017-04-12 15:00+0200\n"
"PO-Revision-Date: 2017-04-12 15:01+0200\n"
"POT-Creation-Date: 2017-06-01 15:40+0200\n"
"PO-Revision-Date: 2017-06-01 15:40+0200\n"
"Last-Translator: Christophe Lohr <christophe.lohr@imt-atlantique.fr>\n"
"Language-Team: French\n"
"Language: fr\n"
......@@ -18,40 +19,60 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: babbler.c:74
#: babbler.c:89
#, c-format
msgid "null"
msgstr "nul"
msgid "of %ld"
msgstr "de %ld"
#: babbler.c:79
#: babbler.c:87
#, c-format
msgid "true"
msgstr "vrai"
msgid "binary data"
msgstr "donnée binaire"
#: babbler.c:102 babbler.c:111
#, c-format
msgid " and "
msgstr " et "
#: babbler.c:112
#, c-format
msgid " an attribute \"%s\" that is "
msgstr " un attribut \"%s\" qui est "
#: babbler.c:126
#, c-format
msgid "none"
msgstr "aucun"
#: babbler.c:81
#, c-format
msgid "false"
msgstr "faux"
#: babbler.c:85
#: babbler.c:79
#, c-format
msgid "of %g"
msgstr "de %g"
msgid "true"
msgstr "vrai"
#: babbler.c:89
#: babbler.c:74
#, c-format
msgid "of %ld"
msgstr "de %ld"
msgid "null"
msgstr "nul"
#: babbler.c:102 babbler.c:111
#: babbler.c:138 babbler.c:148
#, c-format
msgid " and "
msgstr " et "
msgid "undefined"
msgstr "indéfini"
#: babbler.c:112
#: babbler.c:85
#, c-format
msgid " an attribute \"%s\" that is "
msgstr " un attribut \"%s\" qui est "
msgid "of %g"
msgstr "de %g"
#: babbler.c:171
#, c-format
msgid "New event from the lamp %s:\n"
msgstr "Nouvel événement de la lampe %s:\n"
#: babbler.c:164
#, c-format
......@@ -73,6 +94,11 @@ msgstr "Le variateur de la lampe est à %g pourcent.\n"
msgid "The lamp has "
msgstr "La lampe a "
#: babbler.c:220
#, c-format
msgid "New event from the thermometer %s:\n"
msgstr "Nouvel événement du thermomètre %s:\n"
#: babbler.c:203
#, c-format
msgid "It is %g degrees Celsius.\n"
......@@ -83,6 +109,11 @@ msgstr "Il fait %g degrés.\n"
msgid "The thermometer has "
msgstr "Le thermomètre a "
#: babbler.c:264
#, c-format
msgid "New event from the roller shutter %s:\n"
msgstr "Nouvel événement du volet roulant %s:\n"
#: babbler.c:234
#, c-format
msgid "The roller shutter goes up.\n"
......@@ -113,6 +144,11 @@ msgstr "Le volet roulant est ouvert.\n"
msgid "The roller shutter has "
msgstr "Le volet roulant a "
#: babbler.c:322
#, c-format
msgid "New event from a device %s:\n"
msgstr "Nouvel événement du device %s:\n"
#: babbler.c:277
#, c-format
msgid "\"%.*s'.'%s\" has "
......@@ -128,7 +164,7 @@ msgstr "\"%s\" a "
msgid "Unknown argument %s\n"
msgstr "Argument inconnu %s\n"
#: babbler.c:353
#: babbler.c:669
#, c-format
msgid "Usage: %s -a <addr> -p <port> [-h <hops>] -s <secret> [-l <locale>]\n"
msgstr "Usage: %s -a <addr> -p <port> [-h <hops>] -s <secret> [-l <locale>]\n"
msgid "Usage: %s -a <addr> -p <port> [-h <hops>] -s <secret> [-u <uuid>] [-l <locale>]\n"
msgstr "Usage: %s -a <addr> -p <port> [-h <hops>] -s <secret> [-u <uuid>] [-l <locale>]\n"
schemory
cache
metadatadb
automalua
schemaDumper
updateKV
metadatadbTester
schemory.o
cache.o
metadatadb.o
automalua.o
schemaDumper.o
updateKV.o
metadatadbTester.o
xaal-schemory.service
xaal-cache.service
xaal-metadatadb.service
xaal-automalua.service
......
DAEMONS = schemory cache metadatadb automalua
TESTER = schemaDumper updateKV metadatadbTester
DAEMONS = cache metadatadb automalua
TESTER = updateKV metadatadbTester
PROGS = $(DAEMONS) $(TESTER)
SERVICES = $(DAEMONS:%=xaal-%.service)
CFLAGS = -Wall -I. -g
LDLIBS = -L. -lxaal -ljson-c -luuid -lsodium
CFLAGS = -Wall -I. -g -O0
LDLIBS = -L. -lxaal -lcbor -ljson-c -luuid -lsodium
all: $(PROGS)
......@@ -22,7 +22,7 @@ automalua: automalua.c
clean:
-rm -f *.o *~
proper: clean uninstall
proper: clean
-rm -f $(PROGS) $(SERVICES)
......@@ -32,8 +32,7 @@ test: all
@echo " " You can test $(PROGS)
@echo " " First, do: export LD_LIBRARY_PATH+=:.
@echo " " Then, eg.:
@/bin/echo -e "" $(foreach i,$(PROGS)," ./$(i) -a 224.0.29.200 -p 1235 -s xaal\n")
# @/bin/echo -e "" $(foreach i,$(PROGS)," ./$(i) -a 224.0.29.200 -p 1234 -s my_secret\n")
@/bin/echo -e "" $(foreach i,$(PROGS)," ./$(i) -a 224.0.29.200 -p 1236 -s my_secret\n")
Makefile.dep: $(PROGS:=.c)
......@@ -41,7 +40,7 @@ Makefile.dep: $(PROGS:=.c)
include Makefile.dep
.PHONY: all clean proper install uninstall svnignore status test test2
.PHONY: all clean proper install uninstall test test2 svnignore
.SUFFIXES: .service .service.in
......
schemory.o: schemory.c xaal.h
cache.o: cache.c xaal.h
metadatadb.o: metadatadb.c xaal.h
automalua.o: automalua.c xaal.h
schemaDumper.o: schemaDumper.c xaal.h
updateKV.o: updateKV.c xaal.h
metadatadbTester.o: metadatadbTester.c xaal.h
# Base xAAL Services
A set of simple nodes providing base services on an xAAL bus
Conforms to xAAL specification v0.5r2
Conforms to xAAL specification v0.7
## Devices
Following applications are proposed as proof of concept:
- schemory: A simple schema repository
It sends schema, retrieved on a directory or from an url.
Dependencies: any libcurl4-*-dev (e.g., libcurl4-gnutls-dev flavor)
- schemaDumper: A dummy app to test schema repository.
Also, another practical example for sending a request to a set of targets.
- cache: A simple cache service.
Dependencies: libsqlite3-dev
- automalua: Automata with Lua scripts.
This simple automata engine is transparent and does not expose itself as
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.
xAAL_Lua_groupId: UUID of the group to which belong the automaton
xAAL_Lua_group_id: UUID of the group to which belong the automaton
xAAL_Lua_parameter: A string readed from the config file.
.Functions provided to Lua scripts:
xAAL_Lua_declare_device(): The Lua script must declare each device.
The expected parameter is a table with following keys:
addr(string) devType(string) vendorId(string) productId(string)
addr(string) dev_type(string) vendor_id(string) product_id(string)
version(string) url(string) info(string)
unsupportedAttributes(table of string)
unsupportedMethods(table of string)
unsupportedNotifications(table of string)
unsupported_attributes(table of string)
unsupported_methods(table of string)
unsupported_notifications(table of string)
Note: If there is no addr, the baseaddr is used for the first
registred device, and baseaddr++ for the following ones.
It retruns the address of the declared device.
xAAL_Lua_filter_broadcast_by_source():
First parameter is the address of the device that wants a filter.
Second parameter is a table of source addresses.
xAAL_Lua_filter_broadcast_by_devType():
xAAL_Lua_filter_broadcast_by_dev_type():
First parameter is the address of the device that wants a filter.
Second parameter is a table of devType.
Second parameter is a table of dev_type.
xAAL_Lua_set_alarm():
First parameter is the delay in seconds.
Second parameter is the address of the device that wants an alarm.
......@@ -45,7 +42,7 @@ Following applications are proposed as proof of concept:
.Function that must be declared in the Lua script, called by the middleware:
xAAL_Lua_receive_callback():
First parameter is the address of the device that receives the message.
Next parameters (strings) are the source, devType, msgType and action
Next parameters (strings) are the source, dev_type, msg_type and action
of the message
Last parameter is a table representing the body of the message.
xAAL_Lua_alarm_callback():
......@@ -54,10 +51,12 @@ Following applications are proposed as proof of concept:
TODO: use threads, use a restricted sandbox for lua scripts...
Dependencies: liblua5.2-dev
- metadatadb: A simple metadata database to store and retreive users tags
about devices of its home-automation facility.
Copyright
- Christophe Lohr - IMT Atlantique - 2017
## Copyright
- Christophe Lohr - IMT Atlantique - 2019
- The demo applications are provided according to the terms of the
GNU General Public License v3.0 and following
- Dual-licenses are accepted, contact us.
This diff is collapsed.
{
"addr": "224.0.29.200",
"port": "1235",
"port": "1234",
"hops": -1,
"passphrase": "xaal",
"passphrase": "my_secret",
"groupId": "70eff95f-4c82-496a-8cd2-1a0db3c6391d",
"conffile": "automalua.conf",
"immutable": false,
"immutable": true,
"daemon": false,
"logfile": "automalua.log",
"automata": [
{
"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,37 +2,62 @@
-- 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", devType="basic.basic",
vendorId="IHSEV Team", productId="blinking automaton", version="0.2",
url="http://recherche.telecom-bretagne.eu/xaal/documentation/",
unsupportedAttributes={}, unsupportedMethods={},
unsupportedNotifications={} }
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/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
assert(loadstring(xAAL_Lua_parameter))()
conf["lamp"] = xAAL_Lua_uuid_parse(conf["lamp"])
-- A filter accepting no one
xAAL_Lua_filter_broadcast_by_source(device["addr"], { "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF" })
xAAL_Lua_filter_broadcast_by_source(device["addr"], { xAAL_Lua_uuid_parse("00000000-0000-0000-0000-000000000000") })
-- Declare it, but empty (I do not expect messages)
function xAAL_Lua_receive_callback(dev, source, devType, msgType, action, body)
print("message!")
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, "request", "on", {}, { conf["lamp"] } )
xAAL_Lua_set_alarm(conf["period"], dev, "off")
else
xAAL_Lua_write_bus(dev, "request", "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
......
This diff is collapsed.
{
"addr": "224.0.29.200",
"port": "1235",
"port": "1234",
"hops": -1,
"passphrase": "xaal",
"passphrase": "my_secret",
"uuid": "df98ed82-41b1-49b5-84a5-0b7a10a68ae0",
"conffile": "cache.conf",
"immutable": false,
"logfile": "automalua.log"
"immutable": false
}
\ No newline at end of file
--
-- Lightswitch - Basic automaton to peer a button and a lamp
-- Lightswitch - Basic automaton to peer a switch and a lamp
--
---[[ -- Just for debuging
print("xAAL_Lua_baseaddr:")
print(xAAL_Lua_baseaddr)
print("xAAL_Lua_groupId:")
print(xAAL_Lua_groupId)
print("xAAL_Lua_parameter:")
print(xAAL_Lua_parameter)
--[[ -- 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))
print("xAAL_Lua_parameter: "..xAAL_Lua_parameter)
--]]
device = { info="Peering a button and lamp", devType="basic.basic",
vendorId="IHSEV Team", productId="Peering automaton", version="0.2",
url="http://recherche.telecom-bretagne.eu/xaal/documentation/",
unsupportedAttributes={}, unsupportedMethods={},
unsupportedNotifications={} }
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/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["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, devType, msgType, action, body)
---[[ -- Just for debuging
function xAAL_Lua_receive_callback(dev, source, dev_type, msg_type, action, body)
--[[ -- Just for debuging
local serpent = dofile("serpent.lua")
print(dev);
print(source);
print(devType);
print(msgType);
print(xAAL_Lua_uuid_unparse(dev));
print(xAAL_Lua_uuid_unparse(source));
print(dev_type);
print(msg_type);
print(action);
print(serpent.block(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, "request", "on", {}, { peering["lamp"] } )
xAAL_Lua_write_bus(dev, 1, "turn_on", {}, { peering["lamp"] } )
else
xAAL_Lua_write_bus(dev, "request", "off", {}, { peering["lamp"] } )
xAAL_Lua_write_bus(dev, 1, "turn_off", {}, { peering["lamp"] } )
end
end
end
No preview for this file type
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment