コード例 #1
0
    def __init__(self, sample_rate, dict_key, origin_t_secs, origin_t_frac):
        gr.sync_block.__init__(self,
                               name="retune_uhd_to_timed_tag",
                               in_sig=[numpy.complex64],
                               out_sig=[numpy.complex64])

        self.set_sample_rate(sample_rate)
        self.set_ref_time(offset=0, secs=origin_t_secs, frac=origin_t_frac)

        # this is exposed as a member variable, but really should not be
        # modified as the downstream block respects this key
        self.set_tag_key(timing_utils.PMTCONSTSTR__set_freq())
        self.set_dict_key(dict_key)

        # time reference key
        self.time_key = timing_utils.PMTCONSTSTR__rx_time()

        self.message_port_register_in(timing_utils.PMTCONSTSTR__command())
        self.set_msg_handler(timing_utils.PMTCONSTSTR__command(),
                             self.handle_command)
        self.message_port_register_out(timing_utils.PMTCONSTSTR__freq())

        # queue for tune commands
        self.tune_commands = deque((), maxlen=64)

        self.lock = threading.Lock()
コード例 #2
0
    def handle_command(self, msg):
        with self.lock:
            # incoming message will be a dictionary that should contain the items
            # freq and lo_offset at a minimum - if this is met, issue a command
            # that can be handled by the freq_xlating_fir_filter_ccf block
            try:
                # print "got a message!"
                # we don't care about the frequency since we are CORDIC tuning
                lo_offset = pmt.dict_ref(msg, self.dict_key, pmt.PMT_NIL)
                if not pmt.eqv(lo_offset, pmt.PMT_NIL):
                    offset = pmt.to_python(lo_offset)
                    # print "lo offset is " + repr(offset*-1.0)
                    self.message_port_pub(
                        timing_utils.PMTCONSTSTR__freq(),
                        pmt.cons(timing_utils.PMTCONSTSTR__freq(),
                                 pmt.from_double(-1.0 * offset)))
                    # print "published msg, offset = " + repr(-1.0*offset)

                    # if the dictionary has a time value, use it
                    time_tag = pmt.dict_ref(msg,
                                            timing_utils.PMTCONSTSTR__time(),
                                            pmt.PMT_NIL)
                    if not pmt.eqv(time_tag, pmt.PMT_NIL):
                        secs = pmt.to_uint64(
                            pmt.car(time_tag)) - self.ref_time['secs']
                        frac = pmt.to_double(
                            pmt.cdr(time_tag)) - self.ref_time['frac']
                        tune_sample = int(secs * self.sample_rate) + int(
                            frac * self.sample_rate) + self.ref_time['offset']
                    else:
                        tune_sample = TAG_IMMEDIATELY

                    # we will also set the block to tag the output when it is time
                    if len(self.tune_commands) < self.tune_commands.maxlen:
                        self.tune_commands.append(
                            (tune_sample, pmt.from_double(-1.0 * offset)))

            except Exception as e:
                print("exception: " + repr(e))
コード例 #3
0
    def test_interned_string_constants(self):

        assert (pmt.eq(timing_utils.PMTCONSTSTR__time(), pmt.intern('time')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__trig(), pmt.intern('trig')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__set(), pmt.intern('set')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__disarm(),
                       pmt.intern('disarm')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__rx_time(),
                       pmt.intern('rx_time')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__rx_rate(),
                       pmt.intern('rx_rate')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__rx_freq(),
                       pmt.intern('rx_freq')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__rx_sample(),
                       pmt.intern('rx_sample')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__freq(), pmt.intern('freq')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__wall_clock_time(),
                       pmt.intern('wall_clock_time')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__pdu_out(),
                       pmt.intern('pdu_out')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__pdu_in(),
                       pmt.intern('pdu_in')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__trigger_time(),
                       pmt.intern('trigger_time')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__trigger_sample(),
                       pmt.intern('trigger_sample')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__trigger_now(),
                       pmt.intern('trigger_now')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__late_delta(),
                       pmt.intern('late_delta')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__command(),
                       pmt.intern('command')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__set_freq(),
                       pmt.intern('set_freq')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__in(), pmt.intern('in')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__dsp_freq(),
                       pmt.intern('dsp_freq')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__START(), pmt.intern('START')))
        assert (pmt.eq(timing_utils.PMTCONSTSTR__END(), pmt.intern('END')))