Mercurial > code > home > repos > light9
comparison bin/dmxserver @ 353:941cfe1e1691
lightsim now reads levels from dmxserver
author | drewp@bigasterisk.com |
---|---|
date | Mon, 11 Jun 2007 00:53:16 +0000 |
parents | 9d1f323fb3d3 |
children | 632539a8c30e |
comparison
equal
deleted
inserted
replaced
352:9d1f323fb3d3 | 353:941cfe1e1691 |
---|---|
76 purge_age=10 # seconds | 76 purge_age=10 # seconds |
77 | 77 |
78 reactor.callLater(1,self.purgeclients) | 78 reactor.callLater(1,self.purgeclients) |
79 | 79 |
80 now=time.time() | 80 now=time.time() |
81 cids=self.clientlevels.keys() | 81 cids = self.lastseen.keys() |
82 for cid in cids: | 82 for cid in cids: |
83 lastseen=self.lastseen[cid] | 83 lastseen=self.lastseen[cid] |
84 if lastseen<now-purge_age: | 84 if lastseen < now - purge_age: |
85 print ("forgetting client %s (no activity for %s sec)" % | 85 print ("forgetting client %s (no activity for %s sec)" % |
86 (cid,purge_age)) | 86 (cid,purge_age)) |
87 del self.clientlevels[cid] | 87 try: |
88 del self.clientlevels[cid] | |
89 except KeyError: | |
90 pass | |
88 del self.clientfreq[cid] | 91 del self.clientfreq[cid] |
89 del self.lastseen[cid] | 92 del self.lastseen[cid] |
90 | 93 |
91 def sendlevels(self): | 94 def sendlevels(self): |
92 | 95 |
165 """send a unique id for your client (name+pid maybe), then | 168 """send a unique id for your client (name+pid maybe), then |
166 the variable-length dmx levellist (scaled 0..1)""" | 169 the variable-length dmx levellist (scaled 0..1)""" |
167 if levellist!=self.clientlevels.get(cid,None): | 170 if levellist!=self.clientlevels.get(cid,None): |
168 self.clientlevels[cid]=levellist | 171 self.clientlevels[cid]=levellist |
169 self.clientschanged=1 | 172 self.clientschanged=1 |
170 if cid not in self.lastseen: | 173 self.trackClientFreq(cid) |
171 print "hello new client %s" % cid | 174 return "ok" |
172 self.clientfreq[cid]=Updatefreq() | 175 |
173 | 176 def xmlrpc_currentlevels(self, cid): |
177 """get a list of levels we're currently sending out. All | |
178 channels beyond the list you get back, they're at zero.""" | |
179 # if this is still too slow, it might help to return a single | |
180 # pickled string | |
181 self.trackClientFreq(cid) | |
182 trunc = self.combinedlevels[:] | |
183 i = len(trunc) - 1 | |
184 if i < 0: | |
185 return [] | |
186 while trunc[i] == 0 and i >= 0: | |
187 i -= 1 | |
188 if i < 0: | |
189 return [] | |
190 trunc = trunc[:i+1] | |
191 return trunc | |
192 | |
193 def trackClientFreq(self, cid): | |
194 if cid not in self.lastseen: | |
195 print "hello new client %s" % cid | |
196 self.clientfreq[cid]=Updatefreq() | |
174 self.lastseen[cid]=time.time() | 197 self.lastseen[cid]=time.time() |
175 self.clientfreq[cid].update() | 198 self.clientfreq[cid].update() |
176 return "ok" | 199 |
177 | |
178 def xmlrpc_currentlevels(self): | |
179 """get a list of levels we're currently sending out. All | |
180 channels beyond the list you get back, they're at zero.""" | |
181 return self.combinedlevels | |
182 | 200 |
183 parser=OptionParser() | 201 parser=OptionParser() |
184 parser.add_option("-f","--fast-updates",action='store_true', | 202 parser.add_option("-f","--fast-updates",action='store_true', |
185 help=('display all dmx output to stdout instead ' | 203 help=('display all dmx output to stdout instead ' |
186 'of the usual reduced output')) | 204 'of the usual reduced output')) |