comparison light8/potserver.py @ 88:238fbd5266ea

new server that sends levels like "55 25 47 35\n" on the port 'serpots'
author drewp
date Sat, 13 Jul 2002 02:28:18 +0000
parents 45b12307c695
children 7f273883de60
comparison
equal deleted inserted replaced
87:a5c0b7ac63cf 88:238fbd5266ea
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import socket,time 3 import socket
4 4
5 from io import * 5 from io import *
6 6
7 pots = SerialPots() 7 pots = SerialPots()
8 pots.golive() 8 pots.golive()
9 9
10 laste=""
11 lastlevs=(0,0,0,0)
12 dirs=[0,0,0,0]
13 samples=nsends=noises=0
14 watch=0
15 while 1: 10 while 1:
16 if samples > 30:
17 fps=1.0*samples/(time.time()-watch)
18 watch=time.time()
19 print "S"*nsends+"n"*noises+" "*(samples-nsends-noises),"%.1f Hz"%fps
20 samples=nsends=noises=0
21 samples+=1
22 l=pots.getlevels() 11 l=pots.getlevels()
23
24 # no change at all?
25 if l==lastlevs:
26 time.sleep(.01)
27 continue
28
29 report=0 # we only will report if a dimmer moves twice in the same direction
30 for i in range(0,4):
31 change = l[i]-lastlevs[i]
32 if change!=0:
33 thisdir = (change>0)-(change<0)
34 if thisdir==dirs[i]:
35 # a dimmer is moving in a constant direction
36 report=1
37 dirs[i]=thisdir
38
39 if report==0:
40 noises+=1
41 continue
42
43 lastlevs = l
44 nsends+=1
45
46 try: 12 try:
47 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) 13 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
48 #s.setblocking(1) 14 s.connect(("dash", socket.getservbyname('serpots','tcp')))
49 ret=s.connect_ex(("10.1.0.32", socket.getservbyname('rlslider','tcp'))) 15
50 # print ret
51 s.send("%d %d %d %d\n" % l) 16 s.send("%d %d %d %d\n" % l)
52 s.close() 17 s.close()
53 except Exception,e: 18 except Exception,e:
54 print str(e) 19 print "Exception: %s" % e
55 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
56 if ret==111:
57 print time.ctime(),"waiting for server"
58 time.sleep(3)
59 else:
60 print time.ctime(),e
61 20
62 21
63