Mercurial > code > home > repos > light9
annotate light8/dmxserver.py @ 116:9ddea0c614ee
much prettier stdout, including a clock (so you can tell the server's running)
much prettier stdout, including a clock (so you can tell the server's running)
and channel updates only when the levels change, and throttled to every 100 updates
even then.
author | drewp |
---|---|
date | Fri, 13 Jun 2003 06:15:28 +0000 |
parents | afbdae5e1359 |
children | 2c25a69c084d |
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 | 2 """ |
3 | |
4 this is the only process to talk to the dmx hardware. other clients | |
5 can connect to this server and present dmx output, and this server | |
6 will max ('pile-on') all the client requests. | |
7 | |
8 this server has a level display which is the final set of values that | |
9 goes to the hardware. | |
10 | |
11 clients shall connect to the xmlrpc server and send: | |
12 | |
13 their PID (or some other cookie) | |
14 | |
15 a length-n list of 0..1 levels which will represent the channel | |
16 values for the n first dmx channels. | |
17 | |
18 server is port 8030; xmlrpc method is called outputlevels(pid,levellist). | |
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 | 24 """ |
25 | |
26 from __future__ import division | |
27 from twisted.internet import reactor | |
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 | 30 from io import ParportDMX |
31 | |
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 | 38 self.combinedlevels=[] # list of levels, after max'ing the clients |
39 self.clientschanged=1 # have clients sent anything since the last send? | |
40 | |
41 print "starting parport connection" | |
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 | 44 |
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 | 47 self.sendlevels() |
48 | |
116
9ddea0c614ee
much prettier stdout, including a clock (so you can tell the server's running)
drewp
parents:
112
diff
changeset
|
49 |
0 | 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 | 52 if self.clientschanged: |
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 | 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 | 76 |
77 def xmlrpc_echo(self,x): | |
78 return x | |
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 | 83 return "ok" |
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 | 87 reactor.run() |
88 |