Beispiel #1
0
    def test_pdu(self):
        cs = starcoder.command_source()
        snk = blocks.message_debug()
        self.tb.msg_connect((cs, 'out'), (snk, 'store'))

        msg = starcoder_pb2.BlockMessage()
        md = msg.pair_value.car.dict_value.entry.add()
        md.key.symbol_value = 'metadata_1'
        md.value.integer_value = -2
        md = msg.pair_value.car.dict_value.entry.add()
        md.key.symbol_value = 'metadata_2'
        md.value.symbol_value = 'val'

        msg.pair_value.cdr.uniform_vector_value.f64_value.value.extend(
            [2.4, -12.3, 21.2])

        pmt_dict = pmt.make_dict()
        pmt_dict = pmt.dict_add(pmt_dict, pmt.intern('metadata_1'),
                                pmt.from_long(-2))
        pmt_dict = pmt.dict_add(pmt_dict, pmt.intern('metadata_2'),
                                pmt.intern('val'))
        expected = pmt.cons(pmt_dict,
                            pmt.init_f64vector(3, [2.4, -12.3, 21.2]))

        self.tb.start()
        cs.push(msg.SerializeToString())
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.is_dict(snk.get_message(0)))
        self.assertTrue(pmt.equal(snk.get_message(0), expected))
Beispiel #2
0
    def test23_absolute_serialization_float_uvecs(self):
        # f32_vector SERDES
        in_vec = [0x01020304, 2.1, 3.1415, 1e-9]
        # old serialization (f32 serialized as f64):
        # in_str = b'\n\x08\x00\x00\x00\x04\x01\x00Ap 0@\x00\x00\x00@\x00\xcc\xcc\xc0\x00\x00\x00@\t!\xca\xc0\x00\x00\x00>\x11.\x0b\xe0\x00\x00\x00'
        in_str = b'\n\x08\x00\x00\x00\x04\x01\x00K\x81\x01\x82@\x06ff@I\x0eV0\x89p_'
        out_str = pmt.serialize_str(pmt.init_f32vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        # old serialization (f32 serialized as f64):
        # in_str = b'\n\x08\x00\x00\x00\x04\x01\x00?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\xbf\xc0\x00\x00\x00\x00\x00\x00@\xfe$\x00\x00\x00\x00\x00'
        in_str = b'\n\x08\x00\x00\x00\x04\x01\x00?\x80\x00\x00@\x00\x00\x00\xbe\x00\x00\x00G\xf1 \x00'
        in_vec = [1., 2., -0.125, 123456.0]
        out_vec = pmt.f32vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # f64_vector SERDES
        in_vec = [0x010203040506, 2.1, 1e-9]
        in_str = b'\n\t\x00\x00\x00\x03\x01\x00Bp 0@P`\x00@\x00\xcc\xcc\xcc\xcc\xcc\xcd>\x11.\x0b\xe8&\xd6\x95'
        out_str = pmt.serialize_str(pmt.init_f64vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\t\x00\x00\x00\x04\x01\x00?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\xbf\xc0\x00\x00\x00\x00\x00\x00A\x9do4T\x00\x00\x00'
        in_vec = [1., 2., -0.125, 123456789.0]
        out_vec = pmt.f64vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # c32_vector SERDES
        in_vec = [0x01020304 - 1j, 3.1415 + 99.99j]
        # old serialization (c32 serialized as c64):
        # in_str = b'\n\n\x00\x00\x00\x02\x01\x00Ap 0@\x00\x00\x00\xbf\xf0\x00\x00\x00\x00\x00\x00@\t!\xca\xc0\x00\x00\x00@X\xff\\ \x00\x00\x00'
        in_str = b'\n\n\x00\x00\x00\x02\x01\x00\xbf\x80\x00\x00K\x81\x01\x82B\xc7\xfa\xe1@I\x0eV'
        out_str = pmt.serialize_str(pmt.init_c32vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        # old serialization (c32 serialized as c64):
        # in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00'
        in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\x80\x00\x00?\x80\x00\x00\xcb\x18\x96\x7f>\x00\x00\x00'
        in_vec = [1 + 1j, .125 - 9999999j]
        out_vec = pmt.c32vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # c64_vector SERDES
        in_vec = [0xffffffff, .9j]
        in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00A\xef\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xec\xcc\xcc\xcc\xcc\xcc\xcd'
        out_str = pmt.serialize_str(pmt.init_c64vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00'
        in_vec = [1 + 1j, .125 - 9999999j]
        out_vec = pmt.c64vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)
Beispiel #3
0
    def test_f64_vector(self):
        cs = starcoder.command_source()
        snk = blocks.message_debug()
        self.tb.msg_connect((cs, 'out'), (snk, 'store'))

        msg = starcoder_pb2.BlockMessage()
        msg.uniform_vector_value.f64_value.value.extend([2.4, -12.3, 21.2])

        expected = pmt.init_f64vector(3, [2.4, -12.3, 21.2])

        self.tb.start()
        cs.push(msg.SerializeToString())
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.is_f64vector(snk.get_message(0)))
        self.assertTrue(pmt.equal(snk.get_message(0), expected))
Beispiel #4
0
 def test04(self):
     v = pmt.init_f64vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
Beispiel #5
0
 def test04(self):
     v = pmt.init_f64vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
Beispiel #6
0
    def __init__(self,
                 fname='',
                 has_header=True,
                 data_type='uint8',
                 period=1000,
                 start_delay=0,
                 repeat=True):
        gr.sync_block.__init__(self, "CSV Reader", in_sig=None, out_sig=None)
        self.file = fname
        self.has_header = has_header
        self.data_type = data_type
        self.period = period
        self.repeat = repeat
        self.start_delay = start_delay

        # setup logger
        logger_name = 'gr_log.' + self.to_basic_block().alias()
        if logger_name in gr.logger_get_names():
            self.log = gr.logger(logger_name)
        else:
            self.log = gr.logger('log')

        # metadata field mappings
        self.metadata_mappings = {
            'string':
            lambda x: pmt.intern(x),
            'bool':
            lambda x: pmt.from_bool(bool(x)),
            'long':
            lambda x: pmt.from_long(int(x)),
            'uint64':
            lambda x: pmt.from_uint64(int(x)),
            'float':
            lambda x: pmt.from_float(float(x)),
            'double':
            lambda x: pmt.from_double(float(x)),
            'complex':
            lambda x: pmt.from_complex(complex(x)),
            'time':
            lambda x: pmt.cons(pmt.from_uint64(int(math.modf(float(x))[1])),
                               pmt.from_double(math.modf(float(x))[0])),
            'time_tuple':
            lambda x: pmt.make_tuple(
                pmt.from_uint64(int(math.modf(float(x))[1])),
                pmt.from_double(math.modf(float(x))[0]))
        }

        self.data_type_mappings = {
            'uint8':
            lambda x: pmt.init_u8vector(len(x), [int(y) for y in x]),
            'int8':
            lambda x: pmt.init_s8vector(len(x), [int(y) for y in x]),
            'uint16':
            lambda x: pmt.init_u16vector(len(x), [int(y) for y in x]),
            'int16':
            lambda x: pmt.init_s16vector(len(x), [int(y) for y in x]),
            'uint32':
            lambda x: pmt.init_u32vector(len(x), [int(y) for y in x]),
            'int32':
            lambda x: pmt.init_s32vector(len(x), [int(y) for y in x]),
            'float':
            lambda x: pmt.init_f32vector(len(x), [float(y) for y in x]),
            'complex float':
            lambda x: pmt.init_c32vector(len(x), [complex(y) for y in x]),
            'double':
            lambda x: pmt.init_f64vector(len(x), [float(y) for y in x]),
            'complex double':
            lambda x: pmt.init_c64vector(len(x), [complex(y) for y in x])
        }

        # ensure valid data type
        if self.data_type not in self.data_type_mappings.keys():
            raise ValueError('Invalid data type {}'.format(data_type))

        # set file name
        self.set_fname(self.file)

        self.message_port_name = pmt.intern('out')
        self.message_port_register_out(self.message_port_name)

        # flag for when to stop
        self.stop_signal_called = False

        # no timer yet
        self.timer = None

        # file lock
        self.lock = threading.Lock()