-
Notifications
You must be signed in to change notification settings - Fork 3
/
mws.py
executable file
·89 lines (68 loc) · 2.41 KB
/
mws.py
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
import os.path
current_dir = os.path.dirname(os.path.abspath(__file__))
from msi import *
import serial
import cherrypy
from cherrypy.lib.static import serve_file
print "****************************"
print "Starting Marantz Web Service"
print 'MSW: Python Version : ' + platform.python_version()
print 'MSW: PySerial Version : ' + serial.VERSION
serialIn = serial.Serial('/dev/ttyS0', 9600, bytesize=8, parity='N', stopbits=1, timeout=0)
print 'MSW: Connection success - Port: ' + serialIn.portstr
marantzSerialInt = MarantzSerialInterface(serialIn)
marantzSerialInt.start()
class WebApp:
def index(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
return open(os.path.join(current_dir, 'html', 'mobileInterface.html'))
index.exposed = True
@cherrypy.expose
@cherrypy.tools.json_out()
def status(self, **kwargs):
aStatus = marantzSerialInt.status()
return {"power" : aStatus.pwr, "source" : aStatus.src, "volume": aStatus.vol, "mute" : aStatus.mute, "attenuate" : aStatus.att, "treble" : aStatus.treble, "bass" : aStatus.bass}
@cherrypy.expose
@cherrypy.tools.json_out()
def powerOn(self, **kwargs):
marantzSerialInt.cmdMeta('powerOn')
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def powerOff(self, **kwargs):
marantzSerialInt.cmdMeta('powerOff')
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def volumeUp(self, **kwargs):
marantzSerialInt.cmdMeta('volumeUp')
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def volumeDown(self, **kwargs):
marantzSerialInt.cmdMeta('volumeDown')
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def muteOn(self, **kwargs):
marantzSerialInt.cmdMeta('muteOn')
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def muteOff(self, **kwargs):
marantzSerialInt.cmdMeta('muteOff')
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def changeSource(self, src):
marantzSerialInt.cmd('SRC', src + "" + src)
return {"message" : "ACK"}
@cherrypy.expose
@cherrypy.tools.json_out()
def listSources(self, **kwargs):
return marantzSerialInt.sources()
#cherrypy.config.update('prod.conf')
#cherrypy.config.update({'server.socket_host': '0.0.0.0',
#'server.socket_port': 9999,
#})
cherrypy.quickstart(WebApp(), '/', 'webservice.cfg')