summaryrefslogtreecommitdiffstats
path: root/god/Reaktor/lib
diff options
context:
space:
mode:
authortv <tv@xso>2011-09-01 02:20:34 +0200
committertv <tv@xso>2011-09-01 02:20:34 +0200
commit4fb37da707279faf92cc8a054c646336f23dfdbe (patch)
tree77b9d7bd053486c022d8a128c480646ea9cec728 /god/Reaktor/lib
parent5e7bbf0c4b53a73e3f0bb7e53cbd8bb97c3187cd (diff)
//god/Reaktor/index: initial commit
This wrapper script downloads and configures jsonbot as necessary.
Diffstat (limited to 'god/Reaktor/lib')
-rwxr-xr-xgod/Reaktor/lib/listener.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/god/Reaktor/lib/listener.py b/god/Reaktor/lib/listener.py
new file mode 100755
index 00000000..9708d9bc
--- /dev/null
+++ b/god/Reaktor/lib/listener.py
@@ -0,0 +1,50 @@
+#! /usr/bin/env python2
+# coding=UTF-8
+
+location = 'shackspace'
+host = '0.0.0.0'
+port = 2342
+
+map = {
+ 'shackspace': {
+ 'device': {
+ 0: 'Licht0, Zickenzone; Fenster',
+ 1: 'Licht1, Sofaecke; Fenster',
+ 2: 'Licht2, Zickenzone; Ghetto',
+ 3: 'Licht3, Sofaecke; Ghetto',
+ 4: 'Licht4, Richtung Getränkelager',
+ 5: 'Licht5, Porschekonsole',
+ 6: 'Licht6, Tomatenecke',
+ 7: 'Licht7, Ghetto',
+ 10: 'Hauptschalter'
+ },
+ 'state': {
+ 0: 'aus',
+ 1: 'an',
+ 2: 'aus in T-10s'
+ },
+ '->': 'ist'
+ }
+}
+
+import socket
+from string import join
+from struct import unpack
+
+# create udp socket
+mysocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+
+# allow send/recieve from broacast address
+mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
+
+# allow the socket to be re-used
+mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
+mysocket.bind((host, port))
+
+map = map[location]
+
+while True:
+ did, sid = unpack('BB', mysocket.recv(2))
+ device, state = map['device'][did], map['state'][sid]
+ arrow = map['->']
+ print join([device, arrow, state], ' ')