if cmd == 'BufferSocket':
        while True: b = BufferSocket(pkt_count=8192)
    elif cmd.split('.')[1] == 'callback':
        b = BufferSocket(pkt_count=8192)
        def callback(pkt): pass
        b.set_callback(callback)
        b.start(53000)
        tx = S.TransportUDPtx('localhost', 53000)
        while True: tx.write(pkt)
elif cmd.startswith('pack'):
    d = [[0]] * 1024*1024
    while True: s = pack('u\x00\x00\x20', d)
elif cmd.startswith('unpack'):
    s = '\x00' * 1024
    while True: d = unpack('u\x00\x00\x20', s, cnt=-1)
elif cmd.startswith('ItemGroup'):
    ig1, ig2 = S.ItemGroup(), S.ItemGroup()
    ig1.add_item('var1', fmt='f\x00\x00\x40', shape=-1)
    while True:
        ig1['var1'] = [[0]] * 1024
        s = ''.join([p for p in S.iter_genpackets(ig1.get_frame())])
        tport = S.TransportString(s)
        for f in S.iterframes(tport): ig2.update(f)
elif cmd.startswith('iter_genpackets'):
    ig1 = S.ItemGroup()
    ig1.add_item('var1', fmt='f\x00\x00\x40', shape=-1)
    ig1['var1'] = [[0]] * 1024
    f = ig1.get_frame()
    while True: s = ''.join([p for p in S.iter_genpackets(f)])
else: ValueError(cmd)
示例#2
0
o = optparse.OptionParser()
o.add_option('-p', '--port', type='int', help='UDP port to listen to.')
opts, args = o.parse_args(sys.argv[1:])

ig = spead.ItemGroup()
dbuf = {}
aa, cat, tx, ig_tx = None, None, None, None

f64 = spead.mkfmt(('f', 64))
i40 = spead.mkfmt(('i', 40))

while True:
    tport = spead.TransportUDPrx(opts.port, pkt_count=1024)
    print 'waiting for a connection'
    for frame in spead.iterframes(tport):
        ig.update(frame)
        if ig['command'] == CMD_FLUSH:
            #print 'flushing'
            continue
        if ig['command'] == CMD_CLEARALL:
            print 'clearing all'
            dbuf, aa, cat, ig_tx = {}, None, None, None
        if ig['command'] == CMD_CLEARCACHE:
            print 'clearing cache'
            dbuf = {}
        elif ig['command'] == CMD_CACHE:
            print 'caching data'
            cal = ig['cal'].tostring()
            if aa is None:
                aa = a.cal.get_aa(cal, ig['sdf'], ig['sfreq'], ig['nchan'])
示例#3
0
opts, args = o.parse_args(sys.argv[1:])

# Parse command-line options
opts.ant += ',cross'
if opts.maxiter < 0: opts.maxiter = n.Inf
# Process daemons
def parsehostport(hostport):
    host, port = hostport.split(':')
    return (host, int(port))
daemon_ip_ports = [parsehostport(w) for w in opts.daemons.split(',')]
NDAEMONS = len(daemon_ip_ports)
_igs = [spead.ItemGroup() for i in range(NDAEMONS)]
_txs = [spead.Transmitter(spead.TransportUDPtx(*ip_port)) for ip_port in daemon_ip_ports]
_igrxs = [spead.ItemGroup() for i in range(NDAEMONS)]
_iters = [spead.iterframes(spead.TransportUDPrx(opts.baserx+i)) for i in range(NDAEMONS)]

def igs(key, value, num=None):
    if num is None:
        for ig in _igs: ig[key] = value
    else: _igs[num][key] = value
def add_items(*args, **kwargs):
    num = kwargs.pop('num', None)
    if num is None:
        for ig in _igs: ig.add_item(*args, **kwargs)
    else: _igs[num].add_item(*args, **kwargs)
def send_frames(num=None):
    if num is None:
        for ig,tx in zip(_igs,_txs): tx.send_frame(ig.get_frame())
    else: _txs[num].send_frame(_igs[num].get_frame())
def ends(num=None):
示例#4
0
# Process daemons
def parsehostport(hostport):
    host, port = hostport.split(':')
    return (host, int(port))


daemon_ip_ports = [parsehostport(w) for w in opts.daemons.split(',')]
NDAEMONS = len(daemon_ip_ports)
_igs = [spead.ItemGroup() for i in range(NDAEMONS)]
_txs = [
    spead.Transmitter(spead.TransportUDPtx(*ip_port))
    for ip_port in daemon_ip_ports
]
_igrxs = [spead.ItemGroup() for i in range(NDAEMONS)]
_iters = [
    spead.iterframes(spead.TransportUDPrx(opts.baserx + i))
    for i in range(NDAEMONS)
]


def igs(key, value, num=None):
    if num is None:
        for ig in _igs:
            ig[key] = value
    else:
        _igs[num][key] = value


def add_items(*args, **kwargs):
    num = kwargs.pop('num', None)
    if num is None:
示例#5
0
o = optparse.OptionParser()
o.add_option("-p", "--port", type="int", help="UDP port to listen to.")
opts, args = o.parse_args(sys.argv[1:])

ig = spead.ItemGroup()
dbuf = {}
aa, cat, tx, ig_tx = None, None, None, None

f64 = spead.mkfmt(("f", 64))
i40 = spead.mkfmt(("i", 40))

while True:
    tport = spead.TransportUDPrx(opts.port, pkt_count=1024)
    print "waiting for a connection"
    for frame in spead.iterframes(tport):
        ig.update(frame)
        if ig["command"] == CMD_FLUSH:
            # print 'flushing'
            continue
        if ig["command"] == CMD_CLEARALL:
            print "clearing all"
            dbuf, aa, cat, ig_tx = {}, None, None, None
        if ig["command"] == CMD_CLEARCACHE:
            print "clearing cache"
            dbuf = {}
        elif ig["command"] == CMD_CACHE:
            print "caching data"
            cal = ig["cal"].tostring()
            if aa is None:
                aa = a.cal.get_aa(cal, ig["sdf"], ig["sfreq"], ig["nchan"])
示例#6
0
        b.start(53000)
        tx = S.TransportUDPtx('localhost', 53000)
        while True:
            tx.write(pkt)
elif cmd.startswith('pack'):
    d = [[0]] * 1024 * 1024
    while True:
        s = pack('u\x00\x00\x20', d)
elif cmd.startswith('unpack'):
    s = '\x00' * 1024
    while True:
        d = unpack('u\x00\x00\x20', s, cnt=-1)
elif cmd.startswith('ItemGroup'):
    ig1, ig2 = S.ItemGroup(), S.ItemGroup()
    ig1.add_item('var1', fmt='f\x00\x00\x40', shape=-1)
    while True:
        ig1['var1'] = [[0]] * 1024
        s = ''.join([p for p in S.iter_genpackets(ig1.get_frame())])
        tport = S.TransportString(s)
        for f in S.iterframes(tport):
            ig2.update(f)
elif cmd.startswith('iter_genpackets'):
    ig1 = S.ItemGroup()
    ig1.add_item('var1', fmt='f\x00\x00\x40', shape=-1)
    ig1['var1'] = [[0]] * 1024
    f = ig1.get_frame()
    while True:
        s = ''.join([p for p in S.iter_genpackets(f)])
else:
    ValueError(cmd)