Пример #1
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.emitter = pdu_utils.message_emitter()
     self.emitter2 = pdu_utils.message_emitter()
     self.pre = pdu_utils.pdu_preamble([], [], 8, 20, True)
     self.gmsk = pdu_utils.pdu_gmsk_fc(0.5, firdes.gaussian(1,4,0.35,9))
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.pre, 'pdu_in'))
     self.tb.msg_connect((self.emitter2, 'msg'), (self.gmsk, 'pdu_in'))
     self.tb.msg_connect((self.pre, 'pdu_out'), (self.gmsk, 'pdu_in'))
     self.tb.msg_connect((self.gmsk, 'pdu_out'), (self.debug, 'store'))
Пример #2
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.upsample = pdu_utils.upsample(4, False)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.upsample, 'pdu_in'))
     self.tb.msg_connect((self.upsample, 'pdu_out'), (self.debug, 'store'))
Пример #3
0
    def test_001_t(self):
        self.emitter = pdu_utils.message_emitter()
        self.qd = pdu_utils.pdu_quadrature_demod_cf(1)
        self.debug = blocks.message_debug()

        self.tb.msg_connect((self.emitter, 'msg'), (self.qd, 'cpdus'))
        self.tb.msg_connect((self.qd, 'fpdus'), (self.debug, 'store'))

        in_data1 = [1., 1.j, -1., -1.j, 1.]
        in_data2 = [7. + 7.j, -7. + 7.j, -7. - 7.j, 7. - 7.j, 7. + 7.j]
        expected_data = [PI / 2, PI / 2, PI / 2, PI / 2]
        in_pdu1 = pmt.cons(pmt.make_dict(),
                           pmt.init_c32vector(len(in_data1), in_data1))
        in_pdu2 = pmt.cons(pmt.make_dict(),
                           pmt.init_c32vector(len(in_data2), in_data2))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu1)
        time.sleep(.01)
        self.emitter.emit(in_pdu2)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))
        self.assertFloatTuplesAlmostEqual(out_data, expected_data, 4)
        out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(1)))
        self.assertFloatTuplesAlmostEqual(out_data, expected_data, 4)
Пример #4
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.add = pdu_utils.pdu_add_noise(0, 0, 1)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.add, 'pdu_in'))
     self.tb.msg_connect((self.add, 'pdu_out'), (self.debug, 'store'))
Пример #5
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.i_t = sandia_utils.invert_tune()
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.i_t, 'tune'))
     self.tb.msg_connect((self.i_t, 'tune'), (self.debug, 'store'))
Пример #6
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.emitter = pdu_utils.message_emitter()
     self.set = pdu_utils.pdu_set_m(pmt.intern('num'), pmt.from_long(4))
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.set, 'pdu_in'))
     self.tb.msg_connect((self.set, 'pdu_out'), (self.debug, 'store'))
Пример #7
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.combiner = pdu_utils.pdu_burst_combiner()
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.combiner, 'pdu_in'))
     self.tb.msg_connect((self.combiner, 'pdu_out'), (self.debug, 'store'))
Пример #8
0
    def test_simple (self):
        self.emitter = pdu_utils.message_emitter()
        self.ctm2 = pdu_utils.pdu_complex_to_mag2()
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.ctm2, 'cpdus'))
        self.tb.msg_connect((self.ctm2, 'fpdus'), (self.debug, 'store'))

        # gnuradio uses single-precision floats by default
        i_vec = pmt.init_c32vector(3, [3+4j, 1+0j, 0+1j])
        e_vec = pmt.init_f32vector(3, [25, 1, 1])

        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print("test ctm2:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.to_python(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.debug = blocks.message_debug()
     self.compute = sandia_utils.compute_stats()
     self.tb.msg_connect((self.emitter, 'msg'), (self.compute, 'pdu_in'))
     self.tb.msg_connect((self.compute, 'pdu_out'), (self.debug, 'store'))
Пример #10
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     if not os.path.exists(QA_LOG_DIR):
         os.mkdir(QA_LOG_DIR)
     self.dut = pdu_utils.pdu_logger(QA_LOG_DIR + 'raw-')
     self.tb.msg_connect((self.emitter, 'msg'), (self.dut, 'pdu_in'))
Пример #11
0
    def setUp(self):
        self.tb = gr.top_block()

        self.emitter = pdu_utils.message_emitter()
        self.dut = sandia_utils.message_vector_raster_file_sink('/tmp/qa_message_vector_file_sink', 10)

        self.tb.msg_connect((self.emitter, 'msg'), (self.dut, 'in'))
Пример #12
0
    def test1_cleanup(self):
      '''
      All files should be deleted by the monitor when complete
      '''
      # open a dummy file
      fname = '/tmp/foo.txt'
      if os.path.exists(fname):
        os.remove(fname)
      Path(fname).touch()

      # PMT
      p = pmt.dict_add(pmt.make_dict(),pmt.intern('rx_freq'), pmt.from_double(915e6))
      p = pmt.dict_add(p,pmt.intern('rx_rate'),pmt.from_double(30.72e6))
      p = pmt.dict_add(p,pmt.intern('rx_time'),pmt.make_tuple(
        pmt.from_uint64(0),pmt.from_double(0)))
      p = pmt.dict_add(p,pmt.intern('fname'),pmt.intern(fname))

      # blocks
      emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
      debug = blocks.message_debug()
      monitor = file_monitor(10,'/tmp')

      # connect
      self.tb.msg_connect((emitter,'msg'),(monitor,'pdu'))

      # set up fg - terrible hacky way of doing this until we get
      # pdu utility message emitter working
      self.tb.start()
      emitter.emit(p)
      time.sleep(.05)
      self.tb.stop()
      self.tb.wait()

      # check data
      self.assertTrue(not os.path.exists(fname))
    def setUp(self):
        self.rate = 250000

        self.duration = int(self.rate * 4)
        self.start_time = .098765
        self.skey = pmt.intern("trigger_sample")
        self.tkey = pmt.intern("trigger_time")

        self.tb = gr.top_block()

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, self.rate)

        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.start_time = .098765
        self.utag = timing_utils.add_usrp_tags_c(1090e6, self.rate, 0,
                                                 self.start_time)
        #self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex*1, '', "");
        self.msg_dbg = blocks.message_debug()
        self.timer = timing_utils.interrupt_emitter_c(self.rate, True)

        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.utag, 0))
        #self.tb.connect((self.utag, 0), (self.tag_dbg, 0))
        self.tb.connect((self.utag, 0), (self.timer, 0))
        self.tb.msg_connect((self.emitter, "msg"), (self.timer, "set"))
        self.tb.msg_connect((self.timer, "trig"), (self.msg_dbg, "store"))
Пример #14
0
    def test_002_pass_empty (self):
        emitter = pdu_utils.message_emitter()
        split = pdu_utils.pdu_split(True)
        d1 = blocks.message_debug()
        d2 = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (split, 'pdu_in'))
        self.tb.msg_connect((split, 'dict'), (d1, 'store'))
        self.tb.msg_connect((split, 'data'), (d2, 'store'))

        in_meta1 = pmt.dict_add(pmt.make_dict(), pmt.intern('num'), pmt.from_long(4))
        in_meta2 = pmt.dict_add(pmt.make_dict(), pmt.intern('n'), pmt.from_long(99))
        in_pdu = pmt.cons(in_meta1, pmt.init_u8vector(6, range(6)))

        self.tb.start()
        time.sleep(.001)
        emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        emitter.emit(pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(2, range(2))))
        time.sleep(.001)
        emitter.emit(pmt.cons(in_meta2, pmt.init_u8vector(0, [])))
        time.sleep(.001)
        emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(d1.get_message(0), pmt.PMT_NIL))
        self.assertTrue(pmt.equal(d1.get_message(1), in_meta2))
        self.assertTrue(pmt.equal(d1.get_message(2), in_meta1))
        self.assertTrue(pmt.equal(d2.get_message(0), pmt.init_u8vector(2, range(2))))
        self.assertTrue(pmt.equal(d2.get_message(1), pmt.init_u8vector(0, [])))
        self.assertTrue(pmt.equal(d2.get_message(2), pmt.init_u8vector(6, range(6))))
Пример #15
0
    def test_002_uint8_metadata_header(self):
        emitter = pdu_utils.message_emitter()
        writer = csv_writer('/tmp/file.csv', True, '', 'uint8')

        # generate pdu
        metadata = pmt.dict_add(pmt.make_dict(), pmt.intern('a'),
                                pmt.intern('a'))
        metadata = pmt.dict_add(metadata, pmt.intern('b'), pmt.from_long((0)))
        data = pmt.init_u8vector(5, [11, 12, 13, 14, 15])
        pdu = pmt.cons(metadata, data)

        # expected will only have intern strings
        metadata = pmt.dict_add(pmt.make_dict(), pmt.intern('a'),
                                pmt.intern('a'))
        metadata = pmt.dict_add(metadata, pmt.intern('b'), pmt.intern('0'))
        expected = pmt.cons(metadata, data)

        # run
        tb = gr.top_block()
        tb.msg_connect((emitter, 'msg'), (writer, 'in'))
        tb.start()
        emitter.emit(expected)
        time.sleep(.5)
        tb.stop()
        tb.wait()

        # read in csv
        self.assertTrue(
            self.check_file('/tmp/file.csv', expected, has_header=True))
Пример #16
0
    def test_008_time_tuple(self):
        emitter = pdu_utils.message_emitter()
        writer = csv_writer('/tmp/file.csv',
                            True,
                            'time(time_tuple)',
                            'uint8',
                            precision=4)

        # generate time pair pdu
        time_tuple = pmt.make_tuple(pmt.from_uint64(1), pmt.from_double(0.0))
        metadata = pmt.dict_add(pmt.make_dict(), pmt.intern('time'),
                                time_tuple)
        expected = pmt.cons(metadata, pmt.PMT_NIL)

        # run
        tb = gr.top_block()
        tb.msg_connect((emitter, 'msg'), (writer, 'in'))
        tb.start()
        emitter.emit(expected)
        time.sleep(.5)
        tb.stop()
        tb.wait()

        # read in csv
        self.assertTrue(
            self.check_file('/tmp/file.csv',
                            expected,
                            data_type='uint8',
                            has_header=True))
Пример #17
0
    def test_006_precision(self):
        emitter = pdu_utils.message_emitter()
        writer = csv_writer('/tmp/file.csv', False, '', 'float', precision=4)

        # generate pdu
        metadata = pmt.PMT_NIL
        data = pmt.init_f32vector(2, [1.111111] * 2)
        sent = pmt.cons(metadata, data)
        expected = pmt.cons(pmt.PMT_NIL, pmt.init_f32vector(2, [1.1111] * 2))

        # run
        tb = gr.top_block()
        tb.msg_connect((emitter, 'msg'), (writer, 'in'))
        tb.start()
        emitter.emit(expected)
        time.sleep(.5)
        tb.stop()
        tb.wait()

        # read in csv
        self.assertTrue(
            self.check_file('/tmp/file.csv',
                            expected,
                            data_type='float',
                            has_header=False))
Пример #18
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.emitter = pdu_utils.message_emitter()
     self.pack = pdu_utils.pack_unpack(pdu_utils.MODE_PACK_BYTE, pdu_utils.BIT_ORDER_MSB_FIRST)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.pack, 'pdu_in'))
     self.tb.msg_connect((self.pack, 'pdu_out'), (self.debug, 'store'))
    def XX_test_002_tag_immediately(self):
        # tune message
        tune = pmt.dict_add(pmt.make_dict(), pmt.intern('freq'),
                            pmt.from_double(100))

        # blocks
        src = blocks.null_source(gr.sizeof_gr_complex * 1)
        throttle = blocks.throttle(gr.sizeof_gr_complex * 1, 32000, True)
        retuner = timing_utils.timed_tag_retuner(1e6, pmt.intern("freq"), 1,
                                                 0.1)
        debug = sandia_utils.sandia_tag_debug(gr.sizeof_gr_complex * 1, '', "",
                                              True)
        emitter = pdu_utils.message_emitter()
        debug.set_display(True)
        self.tb.connect(src, throttle)
        self.tb.connect(throttle, retuner)
        self.tb.connect(retuner, debug)
        self.tb.msg_connect((emitter, 'msg'), (retuner, 'command'))

        self.tb.start()
        time.sleep(.1)
        emitter.emit(tune)
        time.sleep(.1)
        self.tb.stop()

        # assert
        self.assertEqual(debug.num_tags(), 1)
        tag = debug.get_tag(0)
        self.assertTrue(pmt.equal(tag.key, pmt.intern('set_freq')))
        freq = pmt.to_double(tag.value)
        self.assertAlmostEqual(-100, freq)
Пример #20
0
    def test_coerce(self):
        samp_rate = 1e6
        freq_offset = -400e3
        center_freq = 911e6

        # blocks
        self.emitter = pdu_utils.message_emitter()
        self.cf = fhss_utils.cf_estimate(fhss_utils.COERCE,
                                         [x * 1e6 for x in range(900, 930)])
        self.debug = blocks.message_debug()

        # connections
        self.tb.msg_connect((self.emitter, 'msg'), (self.cf, 'in'))
        self.tb.msg_connect((self.cf, 'out'), (self.debug, 'store'))

        # data
        in_data = (1 + 0j, ) * 2048
        i_vec = pmt.init_c32vector(len(in_data), in_data)
        out_data = np.exp(1j *
                          np.arange(0,
                                    2 * np.pi *
                                    (freq_offset / samp_rate * len(in_data)),
                                    2 * np.pi * (freq_offset / samp_rate),
                                    dtype=np.complex64))
        e_vec = pmt.init_c32vector(len(out_data), out_data.tolist(
        ))  # pmt doesn't play nice with numpy sometimes, convert to list

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, pmt.intern("sample_rate"),
                            pmt.from_float(samp_rate))
        meta = pmt.dict_add(meta, pmt.intern("center_frequency"),
                            pmt.from_float(center_freq + freq_offset))
        in_pdu = pmt.cons(meta, i_vec)
        e_pdu = pmt.cons(meta, e_vec)

        # flowgraph
        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        # parse output
        #print "got ", list(pmt.to_python(pmt.cdr(self.debug.get_message(0))))
        #print "got ", self.debug.get_message(0)
        rcv = self.debug.get_message(0)
        rcv_meta = pmt.car(rcv)
        rcv_data = pmt.cdr(rcv)
        rcv_cf = pmt.dict_ref(rcv_meta, pmt.intern("center_frequency"),
                              pmt.PMT_NIL)

        # asserts
        self.assertComplexTuplesAlmostEqual(
            tuple(pmt.c32vector_elements(rcv_data)), tuple(out_data), 2)
        self.assertTrue(pmt.equal(rcv_cf, pmt.from_float(911e6)))
    def test_monte_carlo(self):
      emitter = pdu_utils.message_emitter()
      clock_rec = pdu_utils.pdu_clock_recovery(True)
      msg_debug = blocks.message_debug()

      # make connections
      self.tb.msg_connect((emitter,'msg'),(clock_rec,'pdu_in'))
      self.tb.msg_connect((clock_rec,'pdu_out'),(msg_debug,'store'))

      # run
      self.tb.start()
      time.sleep(.05)

      # generate and emit
      for i in range(100):
        n_symbols = 100
        sps = 8
        noise_power = 0.02 * i
        original_bits = np.random.randint(0,2,n_symbols)
        original_samples = original_bits*2-1
        sample_rate = 1e6
        symbol_rate = sample_rate/sps
        data = np.repeat(original_samples, sps) + (np.random.rand(n_symbols*sps)*np.sqrt(noise_power))

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, self.pmt_sample_rate, pmt.from_double(1e6))
        vector = pmt.init_f32vector(len(data), data)

        emitter.emit(pmt.cons(meta,vector))

        time.sleep(.05)

        result = msg_debug.get_message(i)
        result_meta = pmt.car(result)
        result_vector = pmt.to_python(pmt.cdr(result))
        n_errors = sum(original_bits[:len(result_vector)] ^ result_vector[:len(original_bits)])
        result_rate = pmt.to_double(pmt.dict_ref(result_meta, self.pmt_symbol_rate, pmt.PMT_NIL))

        #print("result is ", result_rate)
        #print("we expected ", symbol_rate)
        #print("result vector is", result_vector)
        #print("we expected ", original_bits)
        #print("num errors", n_errors)

        # assert some stuff
        if n_errors != 0:
          print ("got bad data", i)
        if (result_rate - symbol_rate) > 100:
          print ("got bad rate", i)
        

      # shut down
      self.tb.stop()
      self.tb.wait()

      self.assertTrue(True)
Пример #22
0
    def setUp(self):
        self.tb = gr.top_block()

        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.dut = timing_utils.time_delta(pmt.intern("time_delta_ms"),
                                           pmt.intern("wall_clock_time"))
        self.debug = blocks.message_debug()

        self.tb.msg_connect((self.emitter, 'msg'), (self.dut, 'pdu_in'))
        self.tb.msg_connect((self.dut, 'pdu_out'), (self.debug, 'store'))
Пример #23
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.ht = pdu_utils.pdu_head_tail(pdu_utils.INPUTTYPE_UNPACKED_BYTE,
                                       16, 1)
     self.d_head = blocks.message_debug()
     self.d_tail = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.ht, 'pdu_in'))
     self.tb.msg_connect((self.ht, 'head'), (self.d_head, 'store'))
     self.tb.msg_connect((self.ht, 'tail'), (self.d_tail, 'store'))
Пример #24
0
 def setUp(self):
     self.tb = gr.top_block()
     self.emitter = pdu_utils.message_emitter()
     self.drop = pdu_utils.msg_drop_random(0.5, 1)
     self.debug = blocks.message_debug()
     self.tb.msg_connect((self.emitter, 'msg'), (self.drop, 'pdu_in'))
     self.tb.msg_connect((self.drop, 'pdu_out'), (self.debug, 'store'))
     self.in_msg = pmt.PMT_T
     self.n_msgs = 10000
     self.tolerance = self.n_msgs * 0.01
Пример #25
0
    def setUp(self):
        self.tb = gr.top_block()

        self.emitter = pdu_utils.message_emitter()
        self.wall_clock_time = timing_utils.wall_clock_time(pmt.intern('wall_clock_time'))
        self.debug = blocks.message_debug()

        # make connections
        self.tb.msg_connect((self.emitter, 'msg'), (self.wall_clock_time, 'pdu_in'))
        self.tb.msg_connect((self.wall_clock_time, 'pdu_out'), (self.debug, 'store'))
Пример #26
0
    def setUp(self):
        self.tb = gr.top_block()
        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.p2b = pdu_utils.pdu_to_bursts_c(
            pdu_utils.EARLY_BURST_BEHAVIOR__APPEND, 64)
        self.vs = blocks.vector_sink_c(1)
        self.tag_debug = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        self.tag_debug.set_display(True)

        self.tb.msg_connect((self.emitter, 'msg'), (self.p2b, 'bursts'))
        self.tb.connect((self.p2b, 0), (self.vs, 0))
        self.tb.connect((self.p2b, 0), (self.tag_debug, 0))
Пример #27
0
    def test_rms(self):
        self.emitter = pdu_utils.message_emitter()
        self.cf = fhss_utils.cf_estimate(fhss_utils.RMS, [])
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.cf, 'in'))
        self.tb.msg_connect((self.cf, 'out'), (self.debug, 'store'))

        # original data
        in_data = np.exp(1j * np.array(np.linspace(0, 1 * np.pi * .02, 20)))
        i_vec = pmt.init_c32vector(len(in_data), in_data)

        out_data = [(1 + 0j), (0.9999966 + 0.0026077442j),
                    (0.9999864 + 0.0052154697j), (0.9999694 + 0.007823161j),
                    (0.99994564 + 0.010430798j), (0.99991506 + 0.013038365j),
                    (0.99987763 + 0.015645843j), (0.99983346 + 0.018253215j),
                    (0.99978244 + 0.020860463j), (0.9997247 + 0.023467569j),
                    (0.99966 + 0.026074518j), (0.99958867 + 0.028681284j),
                    (0.9995105 + 0.03128786j), (0.9994256 + 0.033894222j),
                    (0.99933374 + 0.03650035j), (0.99923515 + 0.03910623j),
                    (0.9991298 + 0.04171185j), (0.99901766 + 0.044317182j),
                    (0.9988987 + 0.046922214j), (0.9987729 + 0.04952693j)]
        e_vec = pmt.init_c32vector(len(out_data), out_data)

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, pmt.intern("sample_rate"),
                            pmt.from_float(1e6))
        meta = pmt.dict_add(meta, pmt.intern("center_frequency"),
                            pmt.from_float(910.6e6))
        in_pdu = pmt.cons(meta, i_vec)
        e_pdu = pmt.cons(meta, e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        # parse output
        #print("got ", list(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        #print("got ", self.debug.get_message(0))
        rcv = self.debug.get_message(0)
        rcv_meta = pmt.car(rcv)
        rcv_data = pmt.cdr(rcv)
        rcv_cf = pmt.to_double(
            pmt.dict_ref(rcv_meta, pmt.intern("center_frequency"),
                         pmt.PMT_NIL))

        # asserts
        self.assertComplexTuplesAlmostEqual(
            tuple(pmt.c32vector_elements(rcv_data)), tuple(out_data), 2)
        self.assertTrue(abs(rcv_cf - 910.6001e6) < 100)
Пример #28
0
    def test_half_power(self):
        self.emitter = pdu_utils.message_emitter()
        self.cf = fhss_utils.cf_estimate(fhss_utils.HALF_POWER, [])
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.cf, 'in'))
        self.tb.msg_connect((self.cf, 'out'), (self.debug, 'store'))

        # original data
        in_data = np.exp(1j * np.array(np.linspace(0, 1 * np.pi * .02, 20)))
        i_vec = pmt.init_c32vector(len(in_data), in_data)

        out_data = [(1 + 0j), (0.9999945 + 0.0033069337j),
                    (0.9999781 + 0.006613831j), (0.99995077 + 0.009920656j),
                    (0.9999125 + 0.013227372j), (0.9998633 + 0.016533945j),
                    (0.9998032 + 0.019840335j), (0.9997321 + 0.02314651j),
                    (0.99965006 + 0.026452431j), (0.99955714 + 0.029758062j),
                    (0.99945325 + 0.03306337j), (0.99933845 + 0.036368314j),
                    (0.99921274 + 0.039672863j), (0.99907607 + 0.042976975j),
                    (0.9989285 + 0.04628062j), (0.99877 + 0.049583755j),
                    (0.99860054 + 0.05288635j), (0.9984202 + 0.056188367j),
                    (0.9982289 + 0.059489768j), (0.9980267 + 0.06279052j)]
        e_vec = pmt.init_c32vector(len(out_data), out_data)

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, pmt.intern("sample_rate"),
                            pmt.from_float(1e6))
        meta = pmt.dict_add(meta, pmt.intern("center_frequency"),
                            pmt.from_float(910.6e6))
        in_pdu = pmt.cons(meta, i_vec)
        e_pdu = pmt.cons(meta, e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        # parse output
        #print "got ", list(pmt.to_python(pmt.cdr(self.debug.get_message(0))))
        #print "got ", self.debug.get_message(0)
        rcv = self.debug.get_message(0)
        rcv_meta = pmt.car(rcv)
        rcv_data = pmt.cdr(rcv)
        rcv_cf = pmt.to_double(
            pmt.dict_ref(rcv_meta, pmt.intern("center_frequency"),
                         pmt.PMT_NIL))

        # asserts
        self.assertComplexTuplesAlmostEqual(
            tuple(pmt.c32vector_elements(rcv_data)), tuple(out_data), 2)
        self.assertTrue(abs(rcv_cf - 910.6e6) < 100)
Пример #29
0
    def test_coerce(self):
        self.emitter = pdu_utils.message_emitter()
        self.cf = fhss_utils.cf_estimate(fhss_utils.COERCE,
                                         [x * 1e6 for x in range(900, 930)])
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.cf, 'in'))
        self.tb.msg_connect((self.cf, 'out'), (self.debug, 'store'))

        # original data
        in_data = np.exp(1j * np.array(np.linspace(0, 10 * np.pi * 2, 20)))
        i_vec = pmt.init_c32vector(len(in_data), in_data)

        out_data = [(1 + 0j), (-0.9863691 - 0.16454819j),
                    (0.9458478 + 0.32461047j), (-0.8795409 - 0.47582325j),
                    (0.7892561 + 0.61406416j), (-0.67745465 - 0.7355646j),
                    (0.54718447 + 0.8370121j), (-0.40199703 - 0.915641j),
                    (0.24585037 + 0.9693079j), (-0.083001345 - 0.9965495j),
                    (-0.08211045 + 0.99662334j), (0.24498378 - 0.96952736j),
                    (-0.4011784 + 0.9160001j), (0.5464361 - 0.83750105j),
                    (-0.6767969 + 0.73617005j), (0.78870696 - 0.6147696j),
                    (-0.87911534 + 0.47660938j), (0.94555736 - 0.3254559j),
                    (-0.9862217 + 0.16542989j), (0.9999997 - 0.00089395075j)]
        e_vec = pmt.init_c32vector(len(out_data), out_data)

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, pmt.intern("sample_rate"),
                            pmt.from_float(1e3))
        meta = pmt.dict_add(meta, pmt.intern("center_frequency"),
                            pmt.from_float(910.6e6))
        in_pdu = pmt.cons(meta, i_vec)
        e_pdu = pmt.cons(meta, e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        # parse output
        #print "got ", list(pmt.to_python(pmt.cdr(self.debug.get_message(0))))
        #print "got ", self.debug.get_message(0)
        rcv = self.debug.get_message(0)
        rcv_meta = pmt.car(rcv)
        rcv_data = pmt.cdr(rcv)
        rcv_cf = pmt.dict_ref(rcv_meta, pmt.intern("center_frequency"),
                              pmt.PMT_NIL)

        # asserts
        self.assertComplexTuplesAlmostEqual(
            tuple(pmt.c32vector_elements(rcv_data)), tuple(out_data), 2)
        self.assertTrue(pmt.equal(rcv_cf, pmt.from_float(911e6)))
Пример #30
0
    def test_middle_out_metadata(self):
        samp_rate = 1e6
        rot_offset = 1.0 / 16.0
        self.emitter = pdu_utils.message_emitter()
        self.cf = fhss_utils.cf_estimate(fhss_utils.MIDDLE_OUT, [])
        self.sm = self.simple_modulator()
        self.rt = self.pdu_rotate(rot_offset)
        self.debug = blocks.message_debug()

        self.tb.msg_connect((self.emitter, 'msg'), (self.sm, 'in'))
        #self.tb.msg_connect((self.cf, 'debug'), (self.debug, 'print'))
        self.tb.msg_connect((self.sm, 'out'), (self.rt, 'in'))
        self.tb.msg_connect((self.rt, 'out'), (self.cf, 'in'))
        self.tb.msg_connect((self.cf, 'out'), (self.debug, 'store'))

        # original data
        in_data = [0xAA] * 10 + [0x69] * 10 + [
            0x55
        ] * 10  # 30 bytes = 240 bits = 1920 samples
        i_vec = pmt.init_u8vector(len(in_data), in_data)
        fc = 100e6

        meta = pmt.make_dict()
        meta = pmt.dict_add(meta, pmt.intern("sample_rate"),
                            pmt.from_float(1e6))
        meta = pmt.dict_add(meta, pmt.intern("center_frequency"),
                            pmt.from_float(fc))
        meta = pmt.dict_add(meta, pmt.intern("noise_density"),
                            pmt.from_float(-105.0))
        in_pdu = pmt.cons(meta, i_vec)

        self.tb.start()
        time.sleep(.1)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        # parse output
        rcv = self.debug.get_message(0)
        rcv_meta = pmt.car(rcv)
        rcv_data = pmt.cdr(rcv)

        # asserts
        rcv_cf = pmt.to_double(
            pmt.dict_ref(rcv_meta, pmt.intern("center_frequency"),
                         pmt.PMT_NIL))
        expected_cf = 100e6 + samp_rate * rot_offset  # we rotated the burst 62500 Hz off
        max_diff = samp_rate / 256 / 2  # half an FFT bin error allowed
        #print("M-O: got ", rcv_cf - fc, " expected ", expected_cf-fc, "(diff ", rcv_cf-expected_cf, ")")
        self.assertTrue(abs(rcv_cf - expected_cf) < max_diff)