summaryrefslogtreecommitdiffhomepage
path: root/host/proto/test/asserv.py
blob: e578d9dd3bf0bf5987cd790f2b2c8aac548b8ea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
sys.path.append (sys.path[0] + '/..')

import proto
from fio import IO
import time, select, os

# Pass program name as argument.
fout, fin = os.popen2 (sys.argv[1:], 't', 1)
time.sleep (0.5)
io = IO (fin, fout)

def log (x):
    print x

p = proto.Proto (io, time.time, 0.5, log)

done = 0

def reset ():
    print 'reset'

def counter_stat (left, right, aux0):
    print 'counter %u, %u, %u' % (left, right, aux0)
    global done
    done += 1

p.register ('z', '', reset)
p.register ('C', 'HHH', counter_stat)

p.send ('C', 'B', 255)

while not p.sync () or done != 3:
    fds = select.select ((p,), (), (), 0.1)[0]
    for i in fds:
	i.read ()