-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.py
More file actions
94 lines (81 loc) · 2.7 KB
/
control.py
File metadata and controls
94 lines (81 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python -u
#
# WEIO Web Of Things Platform
# Copyright (C) 2013 Nodesign.net, Uros PETREVSKI, Drasko DRASKOVIC
# All rights reserved
#
# ## ## ######## #### #######
# ## ## ## ## ## ## ##
# ## ## ## ## ## ## ##
# ## ## ## ###### ## ## ##
# ## ## ## ## ## ## ##
# ## ## ## ## ## ## ##
# ### ### ######## #### #######
#
# Web Of Things Platform
#
# This file is part of WEIO and is published under BSD license.
# All rights not explicitly granted in the BSD license are reserved.
# See the included LICENSE file for more details.
#
###
from weioLib import weioRunnerGlobals, weioParser, weioUserApi, weioIO, weioGpio
import signal
# User main
import main
import subprocess
class WeioControl(object):
###
# Connect to UPER
###
def __init__(self):
# User main PID
self.proc = None
###
# Connect to UPER
###
def init(self):
# Install signal handlers
signal.signal(signal.SIGTERM, self.stop)
signal.signal(signal.SIGINT, self.stop)
# Init GPIO object for uper communication
if (weioRunnerGlobals.WEIO_SERIAL_LINKED == False):
try:
weioIO.gpio = weioGpio.WeioGpio()
except:
print "LPC coprocessor is not present"
weioIO.gpio = None
###
# Load user module and start threads
###
def start(self):
# Add user callback handlers for events
for key in weioUserApi.attach.events:
weioParser.addUserEvent(weioUserApi.attach.events[key].event,
weioUserApi.attach.events[key].handler)
# Launching subprocess
self.proc = subprocess.Popen(["python", "main.py"])
weioRunnerGlobals.WEIO_SERIAL_LINKED = True
###
# execute()
###
def execute(self, req):
if req['request'] in weioParser.weioSpells or req['request'] in weioParser.weioUserSpells:
if req['request'] in weioParser.weioSpells:
res = weioParser.weioSpells[req['request']](req['data'])
elif req['request'] in weioParser.weioUserSpells:
res = weioParser.weioUserSpells[req['request']](req['data'])
else:
res = None
return res
###
# stop()
###
def stop(self):
print("closing process")
if (self.proc.poll() == None):
self.proc.terminate()
if (weioIO.gpio != None):
if (weioRunnerGlobals.WEIO_SERIAL_LINKED == True):
weioIO.gpio.stopReader()
weioIO.gpio.reset()