Example #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)
Example #2
0
 def __init__(
     self,
     msgq,
     access_code=None,
     threshold=0
     ):
     """
     Create a new packet deframer.
     @param access_code: AKA sync vector
     @type access_code: string of 1's and 0's
     @param threshold: detect access_code with up to threshold bits wrong
     @type threshold: int
     """
     gr.hier_block2.__init__(
         self,
         "packet_deframer",
         gr.io_signature(1, 1, 1),
         gr.io_signature(0, 0, 0)
     )
     
     if not 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,)
     
     if threshold < 0:
         raise ValueError, "Invalid threshold value %d" % (threshold)
     
     #default_access_code = conv_packed_binary_string_to_1_0_string('\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC')
     #default_preamble = conv_packed_binary_string_to_1_0_string('\xA4\xF2')
     
     self.msgq = msgq
     self.correlator = gr_digital.correlate_access_code_bb(access_code, threshold)
     self.framer_sink = gr_digital.framer_sink_1(self.msgq)
     self.connect(self, self.correlator, self.framer_sink)
Example #3
0
    def __init__(self, packet_sink=None):
        #initialize hier2
        gr.hier_block2.__init__(
            self,
            "ofdm_mod",
            gr.io_signature(1, 1, 1),  # Input signature
            gr.io_signature(1, 1, 1)  # Output signature
        )
        #create blocks
        """msg_source = blocks.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT)
        self._msgq_out = msg_source.msgq()
        #connect
        self.connect(self, packet_sink)
        """
        ##self.connect(self, packet_sink)
        #self.connect(packet_sink,self)

        msg_in = blocks.message_source(1, DEFAULT_MSGQ_LIMIT)
        msgq = msg_in.msgq()

        #msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
        correlator = digital.correlate_access_code_bb(packet_sink._access_code,
                                                      packet_sink._threshold)
        framer_sink = digital.framer_sink_1(msgq)
        self.connect(self, packet_sink)
        self.connect(packet_sink, self)
Example #4
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)
Example #5
0
    def __init__(self, access_code=None, threshold=-1):
        """
        Create a new packet deframer.
        @param access_code: AKA sync vector
        @type access_code: string of 1's and 0's
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int
        """

        gr.hier_block2.__init__(
            self,
            "demod_pkts2",
            gr.io_signature(1, 1, 1),
            gr.io_signature(1, 1, 1),
        )

        if not 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,)

        if threshold == -1:
            threshold = 12              # FIXME raise exception

        msgq = gr.msg_queue(4)          # holds packets from the PHY
        self.correlator = gr_digital.correlate_access_code_bb(access_code, threshold)

        self.framer_sink = digital.framer_sink_1(msgq)
        self.connect(self, self.correlator, self.framer_sink)
        self._queue_to_blob = _queue_to_blob(msgq)
        self.connect(self._queue_to_blob, self)
Example #6
0
    def __init__(self, callback=None):
        """
        packet_demod constructor.

        Args:
            station_id: The ID of the station that we are trying to decode the data from.
        """
        # access code
        self._threshold = DEFAULT_THRESHOLD
        access_code = STATION_CODES["default"]

        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

        # 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)
Example #7
0
    def test_002(self):

        code = tuple(string_to_1_0_list(default_access_code))
        access_code = to_1_0_string(code)
        header = tuple(
            2 * [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0])  # len=2
        pad = (0, ) * 100
        src_data = code + header + \
            (0, 1, 0, 0, 1, 0, 0, 0) + (0, 1, 0, 0, 1, 0, 0, 1) + pad
        expected_data = b'HI'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data)
        correlator = digital.correlate_access_code_bb(access_code, 0)
        framer_sink = digital.framer_sink_1(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

        self.tb.connect(src, correlator, framer_sink)
        self.tb.connect(correlator, vsnk)
        self.tb.run()

        result_data = rcvd_pktq.delete_head()
        result_data = result_data.to_string()
        self.assertEqual(expected_data, result_data)
Example #8
0
    def __init__(self, packet_sink=None):
        #initialize hier2
        gr.hier_block2.__init__(
            self,
            "ofdm_mod",
            gr.io_signature(1, 1, 1), # Input signature
            gr.io_signature(1, 1, 1) # Output signature
        )
        #create blocks
        """msg_source = blocks.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT)
        self._msgq_out = msg_source.msgq()
        #connect
        self.connect(self, packet_sink)
        """
	##self.connect(self, packet_sink)
	#self.connect(packet_sink,self)



        msg_in = blocks.message_source(1, DEFAULT_MSGQ_LIMIT)
        msgq = msg_in.msgq()


	#msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
	correlator = digital.correlate_access_code_bb(packet_sink._access_code, packet_sink._threshold)
        framer_sink = digital.framer_sink_1(msgq)
        self.connect(self, packet_sink)
        self.connect(packet_sink, self)
Example #9
0
    def test_002(self):

        code = tuple(string_to_1_0_list(default_access_code))
        access_code = to_1_0_string(code)
        header = tuple(2*[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]) # len=2
        pad = (0,) * 100
        src_data = code + header + (0,1,0,0,1,0,0,0) + (0,1,0,0,1,0,0,1) + pad
        expected_data = 'HI'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data)
        correlator = digital.correlate_access_code_bb(access_code, 0)
        framer_sink = digital.framer_sink_1(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

        self.tb.connect(src, correlator, framer_sink)
        self.tb.connect(correlator, vsnk)
        self.tb.run()

        result_data = rcvd_pktq.delete_head()
        result_data = result_data.to_string()
        self.assertEqual(expected_data, result_data)