Exemple #1
0
 def __init__(self, access_code='', threshold=-1, callback=None):
     """
     packet_demod constructor.
     
     Args:
         access_code: AKA sync vector
         threshold: detect access_code with up to threshold bits wrong (0 -> use default)
         callback: a function of args: ok, payload
     """
     #access code
     if not access_code: #get access code
         access_code = packet_utils.default_access_code
     if not packet_utils.is_1_0_string(access_code):
         raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
     self._access_code = access_code
     #threshold
     if threshold < 0: threshold = DEFAULT_THRESHOLD
     self._threshold = threshold
     #blocks
     msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY
     correlator = digital.correlate_access_code_bb(self._access_code, self._threshold)
     framer_sink = digital.framer_sink_1(msgq)
     #initialize hier2
     gr.hier_block2.__init__(
         self,
         "packet_decoder",
         gr.io_signature(1, 1, gr.sizeof_char), # Input signature
         gr.io_signature(0, 0, 0) # Output signature
     )
     #connect
     self.connect(self, correlator, framer_sink)
     #start thread
     _packet_decoder_thread(msgq, callback)
Exemple #2
0
 def __init__(self, packet_source=None, payload_length=0):
     if not payload_length: #get payload length
         payload_length = DEFAULT_PAYLOAD_LEN
     if payload_length%self._item_size_in != 0:  #verify that packet length is a multiple of the stream size
         raise ValueError, 'The payload length: "%d" is not a mutiple of the stream size: "%d".'%(payload_length, self._item_size_in)
     #initialize hier2
     gr.hier_block2.__init__(
         self,
         "ofdm_mod",
         gr.io_signature(1, 1, self._item_size_in), # Input signature
         gr.io_signature(1, 1, packet_source._hb.output_signature().sizeof_stream_item(0)) # Output signature
     )
     #create blocks
     msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
     msg_sink = blocks.message_sink(self._item_size_in, msgq, False) #False -> blocking
     #connect
     self.connect(self, msg_sink)
     self.connect(packet_source, self)
     #start thread
     _packet_encoder_thread(msgq, payload_length, packet_source.send_pkt)
Exemple #3
0
 def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2):
     """
     Error rate constructor.
     
     Args:
         type: a string 'BER' or 'SER'
         win_size: the number of samples to calculate over
         bits_per_symbol: the number of information bits per symbol (BER only)
     """
     #init
     gr.hier_block2.__init__(
         self, 'error_rate',
         gr.io_signature(2, 2, gr.sizeof_char),
         gr.io_signature(1, 1, gr.sizeof_float),
     )
     assert type in ('BER', 'SER')
     self._max_samples = win_size
     self._bits_per_symbol = bits_per_symbol
     #setup message queue
     msg_source = blocks.message_source(gr.sizeof_float, 1)
     self._msgq_source = msg_source.msgq()
     msgq_sink = gr.msg_queue(2)
     msg_sink = blocks.message_sink(gr.sizeof_char, msgq_sink, False) #False -> blocking
     inter = blocks.interleave(gr.sizeof_char)
     #start thread
     self._num_errs = 0
     self._err_index = 0
     self._num_samps = 0
     self._err_array = numpy.zeros(self._max_samples, numpy.int8)
     if type == 'BER':
         input_watcher(msgq_sink, self._handler_ber)
     elif type == 'SER':
         input_watcher(msgq_sink, self._handler_ser)
     #connect
     self.connect(msg_source, self)
     self.connect((self, 0), (inter, 0))
     self.connect((self, 1), (inter, 1))
     self.connect(inter, msg_sink)