Beispiel #1
0
 def msgTx(self, ):
     #~ print "py_msg_strobe.msgTx".center(80,"~")
     try:
         if self.msgOut is not None:
             #~ print "repr(msgOut):",repr(msgOut)
             self.message_port_pub(self.outPortName,
                                   pmt.cons(pmt.PMT_NIL, self.msgOut))
     except:
         traceback.print_exc()
Beispiel #2
0
    def test_001_t(self):
        for src_data, padding, expected_result in [
            (
                [],
                10,
                [],
            ),
            (
                [
                    [1, 0, 1],
                ],
                10,
                [
                    (1, 0, 1),
                ],
            ),
            (
                [
                    [1, 0, 1],
                    [0, 1, 0],
                ],
                1,
                [
                    (1, 0, 1),
                    (0, 1, 0),
                ],
            ),
        ]:
            # Set up flowgraph.
            source = habets.pn_source_f(padding)
            dst = habets.pn_decode_f(1, 0, 0, 1)
            dbg = blocks.message_debug()

            self.tb.connect(source, dst)
            self.tb.msg_connect(dst, "pdus", dbg, "store")

            for pack in src_data:
                source.to_basic_block()._post(
                    pmt.intern("pdus"),
                    pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(len(pack), pack)))
            self.tb.start()
            while dbg.num_messages() < len(expected_result):
                time.sleep(0.1)
            self.tb.stop()
            self.tb.wait()
            for n, msg in enumerate(expected_result):
                res = tuple(pmt.to_python(pmt.cdr(dbg.get_message(n))))
                try:
                    self.assertTupleEqual(expected_result[n], res)
                except AssertionError:
                    print "--"
                    print "Source:", msg
                    print "Padding:", padding
                    print "Want:  ", expected_result[n]
                    print "Got:   ", res
                    raise
Beispiel #3
0
    def _handle_msg(self, msg_pmt):
        meta = pmt.car(msg_pmt)
        bs = pmt.u8vector_elements(pmt.cdr(msg_pmt))
        fs = numpy.frombuffer(''.join([chr(x) for x in bs]),
                              dtype=numpy.float32)
        #print "Got msg of size %d" % len(fs)
        #print midpoint(fs)
        misc, data = wpcr(fs)
        meta = pmt.dict_add(meta, pmt.intern("magic_decoder"),
                            pmt.to_pmt(misc))
        self.message_port_pub(self.port_info, meta)

        # Send symbols.
        #vec = pmt.init_f32vector(len(data), data)
        vec = pmt.to_pmt([float(x) for x in data])
        self.message_port_pub(self.port_out_symbols, pmt.cons(meta, vec))

        # Send bits.
        bits = slice_bits(data)
        vec = pmt.init_u8vector(len(bits), [int(x) for x in bits])
        self.message_port_pub(self.port_out, pmt.cons(meta, vec))
Beispiel #4
0
 def test_001_t (self):
     for src_data, expected_result in (
             (
                 [],
                 [],
             ),
             (
                 [0],
                 [0,0,0,0,0,0,0,0],
             ),
             (
                 [128],
                 [1,0,0,0,0,0,0,0],
             ),
             (
                 [2],
                 [0,0,0,0,0,0,1,0],
             ),
             (
                 [128],
                 [1,0,0,0,0,0,0,0],
             ),
             (
                 [128, 64],
                 [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0],
             ),
     ):
         pack = habets.bitunpacker()
         dbg = blocks.message_debug()
         self.tb.msg_connect(pack, "out", dbg, "store")
         self.tb.start()
         pack.to_basic_block()._post(
             pmt.intern("in"),
             pmt.cons(
                 pmt.PMT_NIL,
                 pmt.init_u8vector(len(src_data), src_data)
             )
         )
         while dbg.num_messages() < 1:
             time.sleep(0.1)
         self.tb.stop()
         self.tb.wait()
         res = pmt.to_python(pmt.cdr(dbg.get_message(0)))
         try:
             self.assertFloatTuplesAlmostEqual(expected_result, res, 1)
         except AssertionError:
             print "--"
             print "Source:", src_data
             print "Want:  ", expected_result
             print "Got:   ", list(res)
             raise
Beispiel #5
0
    def test_001_t(self):
        try:
            fs = open("jt65.floats").read()
        except IOError:
            print "Test input not found; skipping unit test"
            return
        fs = list(struct.unpack("f" * (len(fs) / 4), fs))
        rnd = lambda x: [random.randint(-120, 120) for _ in range(x)]

        for name, src_data, expected_result in (
            ('clean', fs, "CQ M0THC IO91"),
            ('random-prefix', rnd(44100 * 2) + fs, "CQ M0THC IO91"),
        ):
            # print 'Making data'
            pmt_data = pmt.cons(
                pmt.PMT_NIL, pmt.init_f32vector(len(src_data), list(src_data)))

            # print 'Making flowgraph'
            dec = habets.jt65_decode(44100, int(44100 * 0.372), 10, 8192, 10.8)
            dbg = blocks.message_debug()
            self.tb.msg_connect(dec, "out", dbg, "store")

            # print 'Starting flowgraph'
            self.tb.start()

            # print 'Posting message'
            dec.to_basic_block()._post(
                pmt.intern("in"),
                pmt_data,
            )

            # print 'Waiting for message'
            while dbg.num_messages() < 1:
                time.sleep(0.1)

            # print 'Stopping flowgraph'
            self.tb.stop()
            self.tb.wait()
            # print 'Getting reply'
            res = pmt.to_python(pmt.cdr(dbg.get_message(0)))
            res = ''.join([chr(x) for x in res])
            try:
                # print res
                assert res == expected_result
                print "%s OK" % name
            except AssertionError:
                print "--"
                print "Want:  ", expected_result
                print "Got:   ", res
                raise
 def test_001_t(self):
     for src_data, expected_result in (
         (
             [],
             [],
         ),
         (
             [0],
             [],
         ),
         (
             [1],
             [],
         ),
         (
             [0, 1, 0, 1, 0, 0, 1],
             [0, 0, 1],
         ),
         (  # Garbage beginning.
             [1, 1, 0, 1, 0, 1, 0, 0, 1],
             [0, 0, 1],
         ),
         (  # Pick last preamble.
             [0, 1, 0, 1, 0, 1, 0, 0, 1],
             [0, 0, 1],
         ),
     ):
         if not expected_result:
             continue
         strip = preamble_stripper(prefix=[0, 1, 0, 1])
         dbg = blocks.message_debug()
         self.tb.msg_connect(strip, "out", dbg, "store")
         self.tb.start()
         strip.to_basic_block()._post(
             pmt.intern("in"),
             pmt.cons(pmt.PMT_NIL,
                      pmt.init_u8vector(len(src_data), src_data)))
         while dbg.num_messages() < 1:
             time.sleep(0.1)
         self.tb.stop()
         self.tb.wait()
         res = pmt.to_python(pmt.cdr(dbg.get_message(0)))
         try:
             self.assertFloatTuplesAlmostEqual(expected_result, res, 1)
         except AssertionError:
             print "--"
             print "Source:", src_data
             print "Want:  ", expected_result
             print "Got:   ", list(res)
             raise
Beispiel #7
0
    def _handle_msg(self, msg_pmt):
        bits = pmt.u8vector_elements(pmt.cdr(msg_pmt))

        found = None
        for i in range(self.search - 1, -1, -1):
            candidate = list(bits[i:i + len(self.prefix)])
            if candidate == self.prefix:
                found = i
                break
        if found is None:
            return
        bits = bits[found + len(self.prefix):]
        vec = pmt.init_u8vector(len(bits), bits)
        self.message_port_pub(pmt.intern('out'),
                              pmt.cons(pmt.car(msg_pmt), vec))
Beispiel #8
0
 def test_001_t(self):
     for src_data, expected_result in (
             #(
             #    [],
             #    [],
             #),
         (  # Three samples per step.
             [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0],
             [1.0, 1.0, 2.0, 3.0],
         ),
         (  # Discard initial crap.
             [
                 -1, 1, -1, 1, -1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0,
                 2.0, 3.0, 3.0, 3.0
             ],
             [1.0, 1.0, 2.0, 3.0],
         ),
         (  # Three samples per step, but with one garbage in between.
             [
                 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 2.0, 2.0, 2.0, 0.5, 3.0,
                 3.0, 3.0
             ],
             [1.0, 1.0, 2.0, 3.0],
         ),
     ):
         stair = habets.stairclocker(3, 3, 0.02)
         dbg = blocks.message_debug()
         self.tb.msg_connect(stair, "out", dbg, "store")
         self.tb.start()
         stair.to_basic_block()._post(
             pmt.intern("in"),
             pmt.cons(pmt.PMT_NIL,
                      pmt.init_f32vector(len(src_data), src_data)))
         while dbg.num_messages() < 1:
             time.sleep(0.1)
         self.tb.stop()
         self.tb.wait()
         res = pmt.to_python(pmt.cdr(dbg.get_message(0)))
         res = struct.unpack('f' * (len(res) / 4), res)
         try:
             self.assertFloatTuplesAlmostEqual(expected_result, res, 1)
         except AssertionError:
             print "--"
             print "Source:", src_data
             print "Want:  ", expected_result
             print "Got:   ", res
             raise
Beispiel #9
0
 def test_001_t (self):
     for src_data, expected_result in (
             (
                 [],
                 [0,1,0,1],
             ),
             (
                 [0],
                 [0,1,0,1,0],
             ),
             (
                 [1],
                 [0,1,0,1,1],
             ),
             (
                 [0,1,0,1,0,0,1],
                 [0,1,0,1,0,1,0,1,0,0,1],
             ),
     ):
         adder = preamble_adder(preamble=[0,1,0,1])
         dbg = blocks.message_debug()
         self.tb.msg_connect(adder, "out", dbg, "store")
         self.tb.start()
         vec = pmt.init_u8vector(len(src_data), src_data)
         adder.to_basic_block()._post(
             pmt.intern("in"),
             pmt.cons(
                 pmt.PMT_NIL,
                 pmt.init_u8vector(len(src_data), src_data),
             )
         )
         while dbg.num_messages() < 1:
             time.sleep(0.1)
         self.tb.stop()
         self.tb.wait()
         res = pmt.to_python(pmt.cdr(dbg.get_message(0)))
         try:
             self.assertFloatTuplesAlmostEqual(expected_result, res, 1)
         except AssertionError:
             print "--"
             print "Source:", src_data
             print "Want:  ", expected_result
             print "Got:   ", res
             raise
Beispiel #10
0
 def emit(self):
     if not len(self.packet):
         return
     payload = None
     for i in range(len(self.packet)):
         if self.packet[i:i + len(self.prefix)] == self.prefix:
             payload = self.packet[i:]
             break
     if payload:
         b = list(bits_to_bytes(payload))
         data = pmt.make_u8vector(len(b), ord(' '))
         for i in range(len(b)):
             pmt.u8vector_set(data, i, b[i])
         self.message_port_pub(pmt.intern('pdus'),
                               pmt.cons(pmt.PMT_NIL, data))
     else:
         pass
         #print self.packet
     self.packet = []
Beispiel #11
0
 def _handle_msg(self, msg_pmt):
     bits = list(self.preamble) + list(
         pmt.u8vector_elements(pmt.cdr(msg_pmt)))
     vec = pmt.init_u8vector(len(bits), bits)
     self.message_port_pub(pmt.intern("out"), pmt.cons(pmt.PMT_NIL, vec))
 def _sendPmtPair(self, port, key, value):
     a = pmt.intern(key)
     b = pmt.to_pmt(value)
     msg = pmt.cons(a, b)
     self.message_port_pub(port, msg)