Ejemplo n.º 1
0
	def handle_msg(self, msg):
		if(pmt.is_tuple(msg)):
			t = pmt.to_long(pmt.tuple_ref(msg, 0))
			m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
			de = DataEvent([t, m])
			wx.PostEvent(self.panel, de)
			del de
Ejemplo n.º 2
0
	def handle_msg(self, msg):
		if(pmt.is_tuple(msg)):
			t = pmt.to_long(pmt.tuple_ref(msg, 0))
			m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
			de = DataEvent([t, m])
			wx.PostEvent(self.panel, de)
			del de
Ejemplo n.º 3
0
    def msg_handler(self, msg):
        if pmt.is_tuple(msg):
            msg_type = pmt.to_long(pmt.tuple_ref(msg, 0))
            type_name = rds_message_types[msg_type]
            msg = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
            changed = False
            if type_name not in self.data:
                # We haven't seen this field before, add it to the cache
                if type_name == "alternative_frequencies":
                    # There can be more than one alternative freq, so split
                    self.data[type_name] = set(msg.split(', '))
                else:
                    self.data[type_name] = msg
                changed = True
            else:
                # we know this field, let's check if it changed
                # Alternative frequencies change often, so we keep all of them
                # (perhaps we should filter those with kHz because they're AM)
                if type_name == "alternative_frequencies":
                    for frequency in msg.split(', '):
                        if frequency not in self.data[type_name]:
                            # an alternative frequency we haven't seen yet
                            self.data[type_name].add(frequency)
                            changed = True
                elif self.data[type_name] != msg:
                    # The check is much simpler for any other field
                    changed = True
                    self.data[type_name] = msg

            if self.callback is not None and changed:
                # fire callback if we have new data
                self.callback(type_name, self.data[type_name])
Ejemplo n.º 4
0
    def handle_msg(self, msg):
        if(pmt.is_tuple(msg)):
            t = pmt.to_long(pmt.tuple_ref(msg, 0))
            m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))

            if (t==0):     #program information
                msg = unicode(m, errors='replace')
                self.stationID = msg
Ejemplo n.º 5
0
 def handle_msg(self, msg):
     f = open("songs.txt", "w")
     if(pmt.is_tuple(msg)):
         t = pmt.to_long(pmt.tuple_ref(msg, 0))
         m = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
         print("message:", m)
         de = DataEvent([t, m])
         f.write(de,"w"); 
         del de
     f.close()
Ejemplo n.º 6
0
    def handle_msg(self, msg):

        if (not pmt.is_tuple(msg)):
            return

        msg_type = pmt.to_long(pmt.tuple_ref(msg, 0))
        msg = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
        msg = msg

        self.msg_signal.emit(msg_type, msg)
Ejemplo n.º 7
0
    def process_measurement(self, msg):
        if pmt.is_tuple(msg):
            key = pmt.symbol_to_string(pmt.tuple_ref(msg, 0))
            if key == "freq_offset":
                freq_offset = pmt.to_double(pmt.tuple_ref(msg, 1))
                ppm = -freq_offset / self.fc * 1.0e6
                state = pmt.symbol_to_string(pmt.tuple_ref(msg, 2))

                self.last_state = state

                if abs(ppm) > 100:  #safeguard against flawed measurements
                    ppm = 0
                    self.reset()

                if state == "fcch_search":
                    msg_ppm = pmt.from_double(ppm)
                    self.message_port_pub(pmt.intern("ppm"), msg_ppm)
                    self.timer.cancel()
                    self.timer = Timer(0.5, self.timed_reset)
                    self.timer.start()
                elif state == "synchronized":
                    self.timer.cancel()
                    if self.first_measurement:
                        self.ppm_estimate = ppm
                        self.first_measurement = False
                    else:
                        self.ppm_estimate = (
                            1 -
                            self.alfa) * self.ppm_estimate + self.alfa * ppm

                    if self.counter == 5:
                        self.counter = 0
                        if abs(self.last_ppm_estimate -
                               self.ppm_estimate) > 0.1:
                            msg_ppm = pmt.from_double(ppm)
                            self.message_port_pub(pmt.intern("ppm"), msg_ppm)
                            self.last_ppm_estimate = self.ppm_estimate
                    else:
                        self.counter = self.counter + 1
                elif state == "sync_loss":
                    self.reset()
                    msg_ppm = pmt.from_double(0.0)
                    self.message_port_pub(pmt.intern("ppm"), msg_ppm)
Ejemplo n.º 8
0
 def process_measurement(self,msg):
     if pmt.is_tuple(msg):
         key = pmt.symbol_to_string(pmt.tuple_ref(msg,0))
         if key == "freq_offset":
             freq_offset = pmt.to_double(pmt.tuple_ref(msg,1))
             ppm = -freq_offset/self.fc*1.0e6
             state = pmt.symbol_to_string(pmt.tuple_ref(msg,2))
             
             self.last_state = state
             
             if abs(ppm) > 100: #safeguard against flawed measurements
                 ppm = 0
                 self.reset()
                 
             if state == "fcch_search":
                 msg_ppm = pmt.from_double(ppm)
                 self.message_port_pub(pmt.intern("ppm"), msg_ppm)
                 self.timer.cancel()
                 self.timer = Timer(0.5, self.timed_reset)
                 self.timer.start()
             elif state == "synchronized":
                 self.timer.cancel()
                 if self.first_measurement:
                     self.ppm_estimate = ppm
                     self.first_measurement = False
                 else:
                     self.ppm_estimate = (1-self.alfa)*self.ppm_estimate+self.alfa*ppm
                 
                 if self.counter == 5:
                     self.counter = 0
                     if abs(self.last_ppm_estimate-self.ppm_estimate) > 0.1:
                         msg_ppm = pmt.from_double(ppm)
                         self.message_port_pub(pmt.intern("ppm"), msg_ppm)
                         self.last_ppm_estimate = self.ppm_estimate
                 else:
                     self.counter=self.counter+1
             elif state == "sync_loss":
                 self.reset()
                 msg_ppm = pmt.from_double(0.0)
                 self.message_port_pub(pmt.intern("ppm"), msg_ppm)
Ejemplo n.º 9
0
    def test_tuple(self):
        cs = starcoder.command_source()
        snk = blocks.message_debug()
        self.tb.msg_connect((cs, 'out'), (snk, 'store'))

        msg = starcoder_pb2.BlockMessage()
        v = msg.list_value.value.add()
        v.symbol_value = "testtransmission"
        v = msg.list_value.value.add()
        v.double_value = 23.2
        msg.list_value.type = starcoder_pb2.List.TUPLE

        expected = pmt.make_tuple(pmt.intern("testtransmission"),
                                  pmt.from_double(23.2))

        self.tb.start()
        cs.push(msg.SerializeToString())
        time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(snk.num_messages(), 1)
        self.assertTrue(pmt.is_tuple(snk.get_message(0)))
        self.assertTrue(pmt.equal(snk.get_message(0), expected))
Ejemplo n.º 10
0
 def handle_msg(self, msg):
     if (pmt.is_tuple(msg)):
         type = pmt.to_long(pmt.tuple_ref(msg, 0))
         message = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
         if type == 4:  #radio_text
             self.radio_text = message
Ejemplo n.º 11
0
    parser = argparse.ArgumentParser()
    parser.add_argument("--server", "-s", default="127.0.0.1", help="remote server")
    parser.add_argument("--port", "-p", default=6000, type=int, help="remote port")
    args = parser.parse_args()

    # Socket to talk to server
    context = zmq.Context()
    socket = context.socket(zmq.SUB)

    print "Collecting updates from radio server at {} port {}...".format(args.server, args.port)
    socket.connect("tcp://{}:{}".format(args.server, args.port))

    socket.setsockopt(zmq.SUBSCRIBE, "")
    data = RBDSData()
    try:
        while True:
            gnr_message_pmt = pmt.deserialize_str(socket.recv())
            if pmt.is_tuple(gnr_message_pmt):
                msg_type = pmt.to_long(pmt.tuple_ref(gnr_message_pmt, 0))
                msg = pmt.symbol_to_string(pmt.tuple_ref(gnr_message_pmt, 1))
                data.update(msg_type, msg)
                print ansi_erase_display(2) + repr(data) + ansi_move_to(1, 1)
            else:
                print "Encountered Data I Did Not Understand"

    except KeyboardInterrupt:
        print ansi_erase_display(2) + ansi_move_to(1, 1) + "Shutdown requested...exiting"
    except Exception:
        traceback.print_exc(file=sys.stdout)
    sys.exit(0)
Ejemplo n.º 12
0
    def handler(self, pdu):
      if not pmt.is_pdu(pdu):
        print('input is not a PDU!, dropping')

      # there are two basic modes here: tags_to_pdu or fft burst detector
      # in either case we need to extract the following fields for the annotation:
      #     - sob:    start sample of the burst
      #     - eob:    end sample of the burst
      #     - freq:   center frequency of the burst in hz
      #     - bw:     bandwidth of the burst in hz
      #     - b_id:   unique Identifier for the burst or `None`
      #     - snr:    signal to noise ratio of annotation or 'None'
      #
      # how these are obtained differs between the two modes.

      meta = pmt.car(pdu)

      time_pmt = pmt.dict_ref(meta, pmt.intern('burst_time'), pmt.PMT_NIL)
      if pmt.is_tuple(time_pmt):
        # tags_to_pdu mode
        try:
          burst_time = pmt.to_double(pmt.tuple_ref(time_pmt, 1)) + pmt.to_uint64(pmt.tuple_ref(time_pmt, 0))
          pdu_rate = pmt.to_double(pmt.dict_ref(meta, pmt.intern('sample_rate'), pmt.from_double(self.rate)))
          freq = pmt.to_double(pmt.dict_ref(meta, pmt.intern('center_frequency'), pmt.from_double(self.freq)))
          bw = pmt.to_double(pmt.dict_ref(meta, pmt.intern('bandwidth'), pmt.from_double(self.bw_min)))
          
          if bw < self.bw_min:
              bw = self.bw_min

          # these can be `None` so use to_python()
          snr = pmt.to_python(pmt.dict_ref(meta, pmt.intern('snr_db'), pmt.PMT_NIL))
          b_id = pmt.to_python(pmt.dict_ref(meta, pmt.intern('pdu_num'), pmt.PMT_NIL))

          anno_len = int(pmt.length(pmt.cdr(pdu)) * (self.rate / pdu_rate))
          sob = int(self.rate * burst_time)
          eob = sob + anno_len

        except Exception as e:
          print('could not parse required data from message', pmt.car(pdu), ':',e)
          return

      else:
        # fft burst detector mode
        try:
          sob = pmt.to_uint64(pmt.dict_ref(meta, pmt.intern('start_offset'), pmt.PMT_NIL))
          eob = pmt.to_uint64(pmt.dict_ref(meta, pmt.intern('end_offset'), pmt.PMT_NIL))
          freq = pmt.to_double(pmt.dict_ref(meta, pmt.intern('center_frequency'), pmt.PMT_NIL))
          bw = pmt.to_double(pmt.dict_ref(meta, pmt.intern('bandwidth'), pmt.from_double(self.bw_min)))

          if bw < self.bw_min:
              bw = self.bw_min

          # these can be `None` so use to_python()
          snr = pmt.to_python(pmt.dict_ref(meta, pmt.intern('snr_db'), pmt.PMT_NIL))
          b_id = pmt.to_python(pmt.dict_ref(meta, pmt.intern('burst_id'), pmt.PMT_NIL))

        except Exception as e:
          print('could not parse required data from message', pmt.car(pdu), ':',e)
          return


      label = self.label
      if self.label == 'use_burst_id':
        if b_id is None:
          label = ''
        else:
          label = 'burst' + str(b_id)

      elif self.label == 'use_snr_db':
        # this probably isnt in here so it will end up blank...
        label = str(snr) + 'dB'

      # append the annotation
      try:
        if isnan(snr):
          print("Got illegal SNR value in",meta)
          self.d_dict['annotations'].append({'core:sample_start': sob-self.soo,
                      'core:sample_count': eob-sob, 'core:freq_upper_edge': int(freq+bw/2),
                      'core:freq_lower_edge': int(freq-bw/2), 'core:description': label})
        else:
          self.d_dict['annotations'].append({'core:sample_start': sob-self.soo,
                      'core:sample_count': eob-sob, 'core:freq_upper_edge': int(freq+bw/2),
                      'core:freq_lower_edge': int(freq-bw/2), 'core:description': label,
                      'capture_details:SNRdB': snr})
      except Exception as e:
        print('could not form annotation from message', pmt.car(pdu), ':', e)
Ejemplo n.º 13
0
                        help='remote port')
    args = parser.parse_args()

    # Socket to talk to server
    context = zmq.Context()
    socket = context.socket(zmq.SUB)

    print 'Collecting updates from radio server at {} port {}...'.format(
        args.server, args.port)
    socket.connect('tcp://{}:{}'.format(args.server, args.port))

    socket.setsockopt(zmq.SUBSCRIBE, '')
    data = RBDSData()
    try:
        while True:
            gnr_message_pmt = pmt.deserialize_str(socket.recv())
            if pmt.is_tuple(gnr_message_pmt):
                msg_type = pmt.to_long(pmt.tuple_ref(gnr_message_pmt, 0))
                msg = pmt.symbol_to_string(pmt.tuple_ref(gnr_message_pmt, 1))
                data.update(msg_type, msg)
                print ansi_erase_display(2) + repr(data) + ansi_move_to(1, 1)
            else:
                print 'Encountered Data I Did Not Understand'

    except KeyboardInterrupt:
        print ansi_erase_display(2) + ansi_move_to(
            1, 1) + "Shutdown requested...exiting"
    except Exception:
        traceback.print_exc(file=sys.stdout)
    sys.exit(0)