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
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
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
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) bits = slice_bits(data) vec = pmt.init_u8vector(len(bits), [int(x) for x in bits]) meta = pmt.dict_add(meta, pmt.intern("magic_decoder"), pmt.to_pmt(misc)) self.message_port_pub(self.port_out, pmt.cons(meta, vec)) self.message_port_pub(self.port_info, meta)
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
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))
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))