Mercurial > code > home > repos > light9
annotate light8/dmxserver.py @ 112:afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
dmx light output is now via a separate process which light8 talks to.
other programs can also submit dmx to the server
author | drewp |
---|---|
date | Wed, 11 Jun 2003 09:36:35 +0000 |
parents | 45b12307c695 |
children | 9ddea0c614ee |
rev | line source |
---|---|
0 | 1 """ |
2 | |
3 this is the only process to talk to the dmx hardware. other clients | |
4 can connect to this server and present dmx output, and this server | |
5 will max ('pile-on') all the client requests. | |
6 | |
7 this server has a level display which is the final set of values that | |
8 goes to the hardware. | |
9 | |
10 clients shall connect to the xmlrpc server and send: | |
11 | |
12 their PID (or some other cookie) | |
13 | |
14 a length-n list of 0..1 levels which will represent the channel | |
15 values for the n first dmx channels. | |
16 | |
17 server is port 8030; xmlrpc method is called outputlevels(pid,levellist). | |
18 | |
19 """ | |
20 | |
21 from __future__ import division | |
22 from twisted.internet import reactor | |
23 from twisted.web import xmlrpc, server | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
24 |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
25 import sys |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
26 sys.path.append("../light8") |
0 | 27 from io import ParportDMX |
28 | |
29 class XMLRPCServe(xmlrpc.XMLRPC): | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
30 def __init__(self): |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
31 self.clientlevels={} # clientPID : list of levels |
0 | 32 self.combinedlevels=[] # list of levels, after max'ing the clients |
33 self.clientschanged=1 # have clients sent anything since the last send? | |
34 | |
35 print "starting parport connection" | |
36 self.parportdmx=ParportDMX() | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
37 self.parportdmx.golive() |
0 | 38 |
39 # start the loop | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
40 self.numupdates=0 |
0 | 41 self.sendlevels() |
42 | |
43 def sendlevels(self): | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
44 reactor.callLater(.02,self.sendlevels) |
0 | 45 if self.clientschanged: |
46 # recalc levels | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
47 self.combinedlevels=[] |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
48 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
|
49 x=0 |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
50 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
|
51 if len(clientlist)>chan: |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
52 x=max(x,clientlist[chan]) |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
53 self.combinedlevels.append(x) |
0 | 54 |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
55 self.numupdates=self.numupdates+1 |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
56 if (self.numupdates%200)==0: |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
57 print self.combinedlevels |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
58 |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
59 # now send combinedlevels (they'll get divided by 100) |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
60 self.parportdmx.sendlevels([l*100 for l in self.combinedlevels]) |
0 | 61 |
62 def xmlrpc_echo(self,x): | |
63 return x | |
64 | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
65 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
|
66 self.clientlevels[pid]=levellist |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
67 self.clientschanged=1 |
0 | 68 return "ok" |
69 | |
112
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
70 print "starting server on 8030" |
afbdae5e1359
dmx light output is now via a separate process which light8 talks to.
drewp
parents:
0
diff
changeset
|
71 reactor.listenTCP(8030,server.Site(XMLRPCServe())) |
0 | 72 reactor.run() |
73 |