annotate light8/dmxserver.py @ 117:c071ada6ae2b

removed an extra import removed an extra import changed the shbang line to /usr/bin/python, which makes a better-looking sys.argv[0], which is used in the IPC
author drewp
date Fri, 13 Jun 2003 13:57:38 +0000
parents 9ddea0c614ee
children 2c25a69c084d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
1 #!/usr/bin/python
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
2 """
45b12307c695 Initial revision
drewp
parents:
diff changeset
3
45b12307c695 Initial revision
drewp
parents:
diff changeset
4 this is the only process to talk to the dmx hardware. other clients
45b12307c695 Initial revision
drewp
parents:
diff changeset
5 can connect to this server and present dmx output, and this server
45b12307c695 Initial revision
drewp
parents:
diff changeset
6 will max ('pile-on') all the client requests.
45b12307c695 Initial revision
drewp
parents:
diff changeset
7
45b12307c695 Initial revision
drewp
parents:
diff changeset
8 this server has a level display which is the final set of values that
45b12307c695 Initial revision
drewp
parents:
diff changeset
9 goes to the hardware.
45b12307c695 Initial revision
drewp
parents:
diff changeset
10
45b12307c695 Initial revision
drewp
parents:
diff changeset
11 clients shall connect to the xmlrpc server and send:
45b12307c695 Initial revision
drewp
parents:
diff changeset
12
45b12307c695 Initial revision
drewp
parents:
diff changeset
13 their PID (or some other cookie)
45b12307c695 Initial revision
drewp
parents:
diff changeset
14
45b12307c695 Initial revision
drewp
parents:
diff changeset
15 a length-n list of 0..1 levels which will represent the channel
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 values for the n first dmx channels.
45b12307c695 Initial revision
drewp
parents:
diff changeset
17
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 server is port 8030; xmlrpc method is called outputlevels(pid,levellist).
45b12307c695 Initial revision
drewp
parents:
diff changeset
19
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
20
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
21 todo:
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
22 save dmx on quit and restore on restart
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
23 if parport fails, run in dummy mode (and make an option for that too)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 """
45b12307c695 Initial revision
drewp
parents:
diff changeset
25
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 from __future__ import division
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 from twisted.internet import reactor
45b12307c695 Initial revision
drewp
parents:
diff changeset
28 from twisted.web import xmlrpc, server
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
29 import sys,time
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
30 from io import ParportDMX
45b12307c695 Initial revision
drewp
parents:
diff changeset
31
45b12307c695 Initial revision
drewp
parents:
diff changeset
32 class XMLRPCServe(xmlrpc.XMLRPC):
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
33 def __init__(self):
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
34
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
35 xmlrpc.XMLRPC.__init__(self)
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
36
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
37 self.clientlevels={} # clientPID : list of levels
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
38 self.combinedlevels=[] # list of levels, after max'ing the clients
45b12307c695 Initial revision
drewp
parents:
diff changeset
39 self.clientschanged=1 # have clients sent anything since the last send?
45b12307c695 Initial revision
drewp
parents:
diff changeset
40
45b12307c695 Initial revision
drewp
parents:
diff changeset
41 print "starting parport connection"
45b12307c695 Initial revision
drewp
parents:
diff changeset
42 self.parportdmx=ParportDMX()
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
43 self.parportdmx.golive()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
44
45b12307c695 Initial revision
drewp
parents:
diff changeset
45 # start the loop
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
46 self.num_unshown_updates=None
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 self.sendlevels()
45b12307c695 Initial revision
drewp
parents:
diff changeset
48
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
49
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
50 def sendlevels(self):
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
51 reactor.callLater(.02,self.sendlevels)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
52 if self.clientschanged:
45b12307c695 Initial revision
drewp
parents:
diff changeset
53 # recalc levels
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
54 oldlevels=self.combinedlevels[:]
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
55 self.combinedlevels=[]
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
56 for chan in range(0,self.parportdmx.dimmers):
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
57 x=0
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
58 for clientlist in self.clientlevels.values():
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
59 if len(clientlist)>chan:
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
60 x=max(x,clientlist[chan])
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
61 self.combinedlevels.append(x)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
62
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
63 if self.num_unshown_updates is None or (self.combinedlevels!=oldlevels and
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
64 self.num_unshown_updates>10):
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
65 self.num_unshown_updates=0
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
66 print "Levels:","".join(["% 2d "%x for x in self.combinedlevels])
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
67 else:
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
68 self.num_unshown_updates+=1
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
69
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
70 if (self.num_unshown_updates-1)%100==0:
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
71 sys.stdout.write("dmxserver up at %s \r"%time.strftime("%H:%M:%S"))
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
72 sys.stdout.flush()
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
73 # now send combinedlevels (they'll get divided by 100)
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
74 if self.parportdmx:
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
75 self.parportdmx.sendlevels([l*100 for l in self.combinedlevels])
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
76
45b12307c695 Initial revision
drewp
parents:
diff changeset
77 def xmlrpc_echo(self,x):
45b12307c695 Initial revision
drewp
parents:
diff changeset
78 return x
45b12307c695 Initial revision
drewp
parents:
diff changeset
79
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
80 def xmlrpc_outputlevels(self,pid,levellist):
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
81 self.clientlevels[pid]=levellist
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
82 self.clientschanged=1
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
83 return "ok"
45b12307c695 Initial revision
drewp
parents:
diff changeset
84
116
9ddea0c614ee much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents: 112
diff changeset
85 print "starting xmlrpc server on port 8030"
112
afbdae5e1359 dmx light output is now via a separate process which light8 talks to.
drewp
parents: 0
diff changeset
86 reactor.listenTCP(8030,server.Site(XMLRPCServe()))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
87 reactor.run()
45b12307c695 Initial revision
drewp
parents:
diff changeset
88