Ejemplo n.º 1
0
 def test_iterheaps(self):
     rx_tport = S.TransportFile(self.filename, 'r')
     heaps = [f for f in S.iterheaps(rx_tport)]
     self.assertEqual(len(heaps), 2)
     heap = heaps[0]
     ig = S.ItemGroup()
     ig.update(heap)
     self.assertEqual(ig['var1'], 1)
     self.assertEqual(ig['var2'], 2)
Ejemplo n.º 2
0
 def setUp(self):
     self.filename = 'junkspeadtestfile'
     self.tx = S.Transmitter(S.TransportFile(self.filename, 'w'))
     self.heap = {
         S.HEAP_CNT_ID: (S.IMMEDIATEADDR, '\x00\x00\x00\x00\x00\x0f'),
         0x123: (S.IMMEDIATEADDR, '\x00\x00\x00\x00\x00\x0f'),
         0x124: (S.IMMEDIATEADDR, '\x00\x00\x00\x00\x00\x0f'),
         0x125: (S.DIRECTADDR, struct.pack('>d', 15.15)),
     }
Ejemplo n.º 3
0
 def setUp(self):
     self.filename = 'junkspeadtestfile'
     ig = S.ItemGroup()
     ig.add_item(name='var1')
     ig['var1'] = 1
     ig.add_item(name='var2')
     ig['var2'] = 2
     tx = S.Transmitter(S.TransportFile(self.filename, 'w'))
     heap = ig.get_heap()
     tx.send_heap(heap)
     ig['var2'] = 3
     heap = ig.get_heap()
     tx.send_heap(heap)
     tx.end()
Ejemplo n.º 4
0
def receive():
    print 'RX: Initializing...'
    t = spead.TransportFile(FILENAME, 'r')
    ig = spead.ItemGroup()
    for heap in spead.iterheaps(t):
        ig.update(heap)
        print 'Got heap:', ig.heap_cnt
        for name in ig.keys():
            print '   ', name
            item = ig.get_item(name)
            print '      Description: ', item.description
            print '           Format: ', [item.format]
            print '            Shape: ', item.shape
            print '            Value: ', ig[name]
    print 'RX: Done.'
Ejemplo n.º 5
0
def transmit():
    #print 'TX: Initializing...'
    tx = spead.Transmitter(spead.TransportFile(sys.stdout))
    ig = spead.ItemGroup()
    ig.add_item(name='Var1',
                description='Description for Var1',
                shape=[],
                fmt=spead.mkfmt(('u', 32), ('u', 32), ('u', 32)),
                init_val=(1, 2, 3))
    tx.send_heap(ig.get_heap())
    ig['Var1'] = (4, 5, 6)
    tx.send_heap(ig.get_heap())
    ig.add_item(name='Var2',
                description='Description for Var2',
                shape=[100, 100],
                fmt=spead.mkfmt(('u', 32)))
    data = numpy.arange(100 * 100)
    data.shape = (100, 100)
    ig['Var2'] = data
    tx.send_heap(ig.get_heap())
    tx.end()
Ejemplo n.º 6
0
def transmit():
    print 'TX: Initializing...'
    tx = spead.Transmitter(spead.TransportFile(FILENAME, 'w'))
    ig = spead.ItemGroup()
    ig.add_item(name='Var1',
                description='Description for Var1',
                shape=[],
                fmt=spead.mkfmt(('u', 32), ('u', 32), ('u', 32)),
                init_val=(1, 2, 3))
    tx.send_heap(ig.get_heap())
    ig['Var1'] = (4, 5, 6)
    tx.send_heap(ig.get_heap())
    ig.add_item(name='Var2',
                description='Description for Var2',
                shape=[DIM, DIM],
                fmt=spead.mkfmt(('u', 32)))
    data = numpy.arange(DIM * DIM)
    data.shape = (DIM, DIM)
    ig['Var2'] = data
    tx.send_heap(ig.get_heap())
    tx.end()
    print 'TX: Done.'
Ejemplo n.º 7
0
 def setUp(self):
     self.filename1 = 'junkspeadtestfile1'
     self.filename2 = 'junkspeadtestfile2'
     open(self.filename1, 'w').write(example_pkt*5000 + term_pkt)
     self.t_file1 = S.TransportFile(self.filename1)
     self.t_file2 = S.TransportFile(self.filename2, 'w')