def setUp(self):
        self.tb = gr.top_block()
        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32e3
        self.preamble = preamble = get_random_bits(64 * 3)
        self.npreamble = len(self.preamble)
        # self.modulation = modulation = "QPSK"
        self.nbits = 16 * 3
        self.bits = get_random_bits(self.nbits)
        self.tag_preamble = gr.tag_t()
        self.tag_preamble.key = pmt.intern("pkt")
        self.tag_preamble.value = pmt.from_long(self.npreamble)
        self.tag_preamble.offset = 0
        self.tag_body = gr.tag_t()
        self.tag_body.key = pmt.intern("pkt")
        self.tag_body.value = pmt.from_long(self.nbits)

        ##################################################
        # Blocks
        ##################################################
        # self.modulator = modulator_classic(modulation)
        # self.demodulator = demodulator_neural(seed=0, hidden_layers=(64, ), bits_per_symbol=2, preamble=preamble)
        self.vector_source_preamble = blocks.vector_source_b(
            preamble, True, 1, [self.tag_preamble])
        self.vector_source_body = blocks.vector_source_b(
            self.bits, True, 1, [self.tag_body])
        self.tags_mux = blocks.tagged_stream_mux(gr.sizeof_char * 1, "pkt")
        self.strm_to_pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "pkt")
        self.pdu_to_strm = blocks.pdu_to_tagged_stream(blocks.byte_t, "pkt")
        self.vector_sink = blocks.vector_sink_b()
Beispiel #2
0
 def test_001_t(self):
     pkt_tag = gr.tag_t()
     pkt_tag.key = pmt.intern("pkt")
     mod_types = ('BPSK', 'QPSK', '8PSK', 'QAM16', 'QAM64')
     for mod_type in mod_types:
         print("Testing {}...".format(mod_type))
         modulator = modulator_classic(mod_type)
         demodulator = demodulator_classic(mod_type, 200)
         src_data = get_random_bits(1000 * modulator.bits_per_symbol)
         pkt_tag.value = pmt.to_pmt(len(src_data))
         src = blocks.vector_source_b(src_data, False, 1, [pkt_tag])
         snk = blocks.vector_sink_b()
         tag2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "pkt")
         pdu2tag = blocks.pdu_to_tagged_stream(blocks.byte_t, "pkt")
         self.tb.connect(src, tag2pdu)
         self.tb.msg_connect(tag2pdu, "pdus", modulator, "bits")
         self.tb.msg_connect(modulator, "symbols", demodulator, "symbols")
         self.tb.msg_connect(demodulator, "bits", pdu2tag, "pdus")
         self.tb.connect(pdu2tag, snk)
         self.tb.start()
         # check data
         while demodulator.packet_cnt < 1:
             time.sleep(0.1)
         self.tb.stop()
         self.tb.wait()
         result_data = snk.data()
         for i in range(1000 * modulator.bits_per_symbol):
             self.assertEqual(src_data[i], result_data[i])
 def test_001_t(self):
     print("Enable plotting to manually verify result of wrapping")
     body = get_random_bits(256)
     src = tvsb(body.astype(numpy.int8), None, True, "body")
     mod = modulator_classic("BPSK")
     wrapper = echo_packet_wrapper(self.nfreq_samps, self.freqs,
                                   self.corr_reps)
     sink = blocks.vector_sink_c()
     pdu2strm = blocks.pdu_to_tagged_stream(blocks.complex_t, "frame")
     strm2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "body")
     # Connect blocks
     self.tb.connect(src, strm2pdu)
     self.tb.connect(pdu2strm, sink)
     self.tb.msg_connect(strm2pdu, "pdus", mod, "bits")
     self.tb.msg_connect(mod, "symbols", wrapper, "body")
     self.tb.msg_connect(wrapper, "frame", pdu2strm, "pdus")
     # Run
     self.tb.start()
     while wrapper.npackets < 1:
         time.sleep(0.1)
     self.tb.stop()
     self.tb.wait()
     # check data
     result = sink.data()
     # self.plot_outcome(result)
     self.assertEqual(len(result),
                      self.nfreq_samps + 2 * self.corr_reps * 256 + 256,
                      "Incorrect number of output bits")
Beispiel #4
0
 def test_filtered_keep_t(self):
     print("Filtered Keep Test")
     bits = util_data.get_random_bits(100).astype(np.int8)
     source = tvsb(data=bits,
                   triggers=["DEBUG"],
                   initial_trigger=True,
                   tag_key=self.tag_key,
                   debug_key="DEBUG")
     sink = blocks.vector_sink_b()
     strm2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, self.tag_key)
     # Connect
     self.tb.connect(source, sink)
     self.tb.connect(source, strm2pdu)
     self.tb.msg_connect(strm2pdu, "pdus", source, "trigger")
     # Confirm
     self.tb.start()
     cycles = 0
     while source.ntriggers < 3 and cycles < 50:
         time.sleep(0.1)
         cycles += 1
     self.tb.stop()
     self.tb.wait()
     ntrigs = source.ntriggers
     result = sink.data()
     self.assertGreater(ntrigs, 2,
                        "Insufficient number of triggers {}".format(ntrigs))
     for i, r in enumerate(result):
         self.assertEqual(r, bits[i % len(bits)],
                          "Incorrect data out at index {}".format(i))
Beispiel #5
0
    def test_001_t(self):
        # set up fg
        pkt_tag = gr.tag_t()
        pkt_tag.key = pmt.intern("pkt")
        mod_types = ['BPSK', 'QPSK', '8PSK', 'QAM16', 'QAM64']
        for mod_type in mod_types:
            print("Testing {}...".format(mod_type))
            modulator = modulator_classic(mod_type)
            src_data = get_random_bits(100 * modulator.bits_per_symbol)
            pkt_tag.value = pmt.to_pmt(len(src_data))
            expected_data = modulator.modulate(
                bits_to_integers(data_b=src_data,
                                 bits_per_symbol=modulator.bits_per_symbol))
            src = blocks.vector_source_b(src_data, False, 1, [pkt_tag])
            tag2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "pkt")
            pdu2tag = blocks.pdu_to_tagged_stream(blocks.complex_t, "pkt")
            snk = blocks.vector_sink_c()
            self.tb.connect(src, tag2pdu)
            self.tb.msg_connect(tag2pdu, "pdus", modulator, "bits")
            self.tb.msg_connect(modulator, "symbols", pdu2tag, "pdus")
            self.tb.connect(pdu2tag, snk)

            self.tb.start()
            while modulator.packet_cnt < 1:
                time.sleep(0.1)
            self.tb.stop()
            self.tb.wait()
            # check data
            result_data = snk.data()
            self.assertComplexTuplesAlmostEqual(expected_data, result_data, 6)
Beispiel #6
0
 def test_awgn_channel_t(self):
     print("AWGN Channel")
     body = get_random_bits(256)
     src = tvsb(body.astype(numpy.int8), None, True, "body")
     mod = modulator_classic("BPSK")
     wrapper = echo_packet_wrapper(self.nfreq_samps, self.freqs,
                                   self.corr_reps)
     unwrapper = echo_packet_unwrapper(self.nfreq_samps, self.freqs,
                                       self.corr_reps)
     demod = demodulator_classic("BPSK")
     sink = blocks.vector_sink_b()
     pdu2strm = blocks.pdu_to_tagged_stream(blocks.byte_t, "body")
     strm2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "body")
     # Connect blocks
     self.tb.connect(src, strm2pdu)
     self.tb.connect(pdu2strm, sink)
     self.tb.msg_connect(strm2pdu, "pdus", mod, "bits")
     self.tb.msg_connect(mod, "symbols", wrapper, "body")
     self.tb.msg_connect(wrapper, "frame", self.channel_in, "pdus")
     self.tb.msg_connect(self.channel_out, "pdus", unwrapper, "frame")
     self.tb.msg_connect(unwrapper, "body", demod, "symbols")
     self.tb.msg_connect(demod, "bits", pdu2strm, "pdus")
     # Run
     self.tb.start()
     while unwrapper.npackets < 1:
         print("wrapped:", wrapper.npackets)
         time.sleep(0.1)
     self.tb.stop()
     self.tb.wait()
     # check data
     result = sink.data()
     self.assertEqual(
         len(result), body.size,
         "Received {} bits, expected {}".format(len(result), body.size))
     for i in range(body.size):
         self.assertEqual(
             body[i], result[i],
             "Received bit {} at {} does not match transmitted bit {}".
             format(result[i], i, body[i]))
Beispiel #7
0
 def test_filtered_drop_t(self):
     print("Filtered Drop Test")
     bits = util_data.get_random_bits(100).astype(np.int8)
     source = tvsb(data=bits,
                   triggers=["dropme"],
                   initial_trigger=True,
                   tag_key=self.tag_key,
                   debug_key="DEBUG")
     sink = blocks.vector_sink_b()
     strm2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, self.tag_key)
     # Connect
     self.tb.connect(source, sink)
     self.tb.connect(source, strm2pdu)
     self.tb.msg_connect(strm2pdu, "pdus", source, "trigger")
     # Confirm
     self.tb.start()
     time.sleep(0.5)
     self.tb.stop()
     self.tb.wait()
     ntrigs = source.ntriggers
     self.assertEqual(ntrigs, 1,
                      "Only one trigger should have been received")
Beispiel #8
0
 def test_unfiltered_t(self):
     print("Unfiltered Test")
     # Construct
     bits = util_data.get_random_bits(100).astype(np.int8)
     source = tvsb(data=bits,
                   triggers=None,
                   initial_trigger=True,
                   tag_key=self.tag_key,
                   debug_key="DEBUG")
     sink = blocks.vector_sink_b()
     strm2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, self.tag_key)
     # Connect
     self.tb.connect(source, sink)
     self.tb.connect(source, strm2pdu)
     self.tb.msg_connect(strm2pdu, "pdus", source, "trigger")
     # Confirm
     self.tb.start()
     cycles = 0
     while source.ntriggers < 3 and cycles < 50:
         time.sleep(0.1)
         cycles += 1
     self.tb.stop()
     self.tb.wait()
     ntrigs = source.ntriggers
     result = sink.data()
     self.assertGreater(ntrigs, 2,
                        "Insufficient triggers {}".format(ntrigs))
     # The data from the final trigger might not have made it to the sink before we halted the top block,
     # so allow the last trigger's data to be missing
     self.assertEqual(
         len(result),
         ntrigs * len(bits) or len(result) == (ntrigs - 1) * len(bits),
         "Incorrect samples out, actual {} != {} expected".format(
             len(result), ntrigs * len(bits)))
     for i, r in enumerate(result):
         self.assertEqual(r, bits[i % len(bits)],
                          "Incorrect data out at index {}".format(i))