Example #1
0
    def __init__(self,
                 modulator,
                 preamble=None,
                 access_code=None,
                 msgq_limit=2,
                 pad_for_usrp=True,
                 use_whitener_offset=False,
                 modulate=True):
        """
	Hierarchical block for sending packets

        Packets to be sent are enqueued by calling send_pkt.
        The output is the complex modulated signal at baseband.

        Args:
            modulator: instance of modulator class (gr_block or hier_block2) (complex baseband out)
            access_code: AKA sync vector (string of 1's and 0's between 1 and 64 long)
            msgq_limit: maximum number of messages in message queue (int)
            pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
            use_whitener_offset: If true, start of whitener XOR string is incremented each packet
        
        See gmsk_mod for remaining parameters
        """

        gr.hier_block2.__init__(
            self,
            "mod_pkts",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        self._modulator = modulator
        self._pad_for_usrp = pad_for_usrp
        self._use_whitener_offset = use_whitener_offset
        self._whitener_offset = 0

        if access_code is None:
            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

        if preamble is None:
            preamble = packet_utils.default_preamble
        if not packet_utils.is_1_0_string(preamble):
            raise ValueError, "Invalid preamble %r. Must be string of 1's and 0's" % (
                preamble, )
        self._preamble = preamble

        # accepts messages from the outside world
        self._pkt_input = blocks.message_source(gr.sizeof_char, msgq_limit)
        self.connect(self._pkt_input, self._modulator, self)
Example #2
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
        """

        gras.HierBlock.__init__(self, "PacketDeframer")

        try:
            import packet_utils
        except ImportError:
            from gnuradio.digital import packet_utils

        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

        try:
            import digital_swig as gr_digital
        except ImportError:
            import gnuradio.digital as gr_digital
        self.correlator = gr_digital.correlate_access_code_bb(access_code, threshold)
        self.framer_sink = gras.make('/grex/framer_sink_1')
        self._queue_to_datagram = _queue_to_datagram()
        self.connect(self, self.correlator, self.framer_sink, self._queue_to_datagram, self)
Example #3
0
    def __init__(self, demodulator, access_code=None, callback=None, threshold=-1):
        """
	Hierarchical block for demodulating and deframing packets.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

        Args:
            demodulator: instance of demodulator class (gr_block or hier_block2) (complex baseband in)
            access_code: AKA sync vector (string of 1's and 0's)
            callback: function of two args: ok, payload (ok: bool; payload: string)
            threshold: detect access_code with up to threshold bits wrong (-1 -> use default) (int)
	"""

        gr.hier_block2.__init__(
            self, "demod_pkts", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)  # Input signature
        )  # Output signature

        self._demodulator = demodulator
        if access_code is None:
            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

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

        self._rcvd_pktq = gr.msg_queue()  # holds packets from the PHY
        self.correlator = digital.correlate_access_code_bb(access_code, threshold)

        self.framer_sink = digital.framer_sink_1(self._rcvd_pktq)
        self.connect(self, self._demodulator, self.correlator, self.framer_sink)

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
Example #4
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
        """

        gras.HierBlock.__init__(self, "PacketDeframer")

        try:
            import packet_utils
        except ImportError:
            from gnuradio.digital import packet_utils

        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

        try:
            import digital_swig as gr_digital
        except ImportError:
            import gnuradio.digital as gr_digital
        self.correlator = gr_digital.correlate_access_code_bb(
            access_code, threshold)
        self.framer_sink = gras.make('/grex/framer_sink_1')
        self._queue_to_datagram = _queue_to_datagram()
        self.connect(self, self.correlator, self.framer_sink,
                     self._queue_to_datagram, self)
Example #5
0
    def __init__(self, samples_per_symbol, bits_per_symbol, preamble='',
                 access_code='', pad_for_usrp=True, repeat=1, interleave=None,
                 debug=False):
        """
        packet_mod constructor.

        Args:
            samples_per_symbol: number of samples per symbol
            bits_per_symbol: number of bits per symbol
            preamble: string of ascii 0's and 1's
            access_code: AKA sync vector
            pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
        """
        #setup parameters
        self._samples_per_symbol = samples_per_symbol
        self._bits_per_symbol = bits_per_symbol
        self._pad_for_usrp = pad_for_usrp
        self._repeat = repeat
        self._interleave = interleave
        self._debug = debug

        if not preamble: #get preamble
            preamble = packet_utils.default_preamble
        if not access_code: #get access code
            access_code = packet_utils.default_access_code
        if not packet_utils.is_1_0_string(preamble):
            raise ValueError, "Invalid preamble %r. Must be string of 1's and 0's" % (preamble,)
        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._preamble = preamble
        self._access_code = access_code
        self._pad_for_usrp = pad_for_usrp
        #create blocks
        msg_source = blocks.message_source(gr.sizeof_char, DEFAULT_MSGQ_LIMIT)
        self._msgq_out = msg_source.msgq()
        #initialize hier2
        gr.hier_block2.__init__(
            self,
            "packet_encoder",
            gr.io_signature(0, 0, 0), # Input signature
            gr.io_signature(1, 1, gr.sizeof_char) # Output signature
        )
        #connect
        self.connect(msg_source, self)
Example #6
0
    def __init__(self, modulator, preamble=None, access_code=None, msgq_limit=2,
                 pad_for_usrp=True, use_whitener_offset=False, modulate=True):
        """
	Hierarchical block for sending packets

        Packets to be sent are enqueued by calling send_pkt.
        The output is the complex modulated signal at baseband.

        Args:
            modulator: instance of modulator class (gr_block or hier_block2) (complex baseband out)
            access_code: AKA sync vector (string of 1's and 0's between 1 and 64 long)
            msgq_limit: maximum number of messages in message queue (int)
            pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
            use_whitener_offset: If true, start of whitener XOR string is incremented each packet
        
        See gmsk_mod for remaining parameters
        """

	gr.hier_block2.__init__(self, "mod_pkts",
				gr.io_signature(0, 0, 0),                    # Input signature
				gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

        self._modulator = modulator
        self._pad_for_usrp = pad_for_usrp
        self._use_whitener_offset = use_whitener_offset
        self._whitener_offset = 0
        
        if access_code is None:
            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
        
        if preamble is None:
            preamble = packet_utils.default_preamble
        if not packet_utils.is_1_0_string(preamble):
            raise ValueError, "Invalid preamble %r. Must be string of 1's and 0's" % (preamble,)
        self._preamble = preamble

        # accepts messages from the outside world
        self._pkt_input = blocks.message_source(gr.sizeof_char, msgq_limit)
        self.connect(self._pkt_input, self._modulator, self)
Example #7
0
    def __init__(self,
                 demodulator,
                 access_code=None,
                 callback=None,
                 threshold=-1):
        """
	Hierarchical block for demodulating and deframing packets.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

        @param demodulator: instance of demodulator class (gr_block or hier_block2)
        @type demodulator: complex baseband in
        @param access_code: AKA sync vector
        @type access_code: string of 1's and 0's
        @param callback:  function of two args: ok, payload
        @type callback: ok: bool; payload: string
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int
	"""

        gr.hier_block2.__init__(
            self,
            "demod_pkts",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(0, 0, 0))  # Output signature

        self._demodulator = demodulator
        if access_code is None:
            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

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

        self._rcvd_pktq = gr.msg_queue()  # holds packets from the PHY
        self.correlator = digital_swig.correlate_access_code_bb(
            access_code, threshold)

        self.framer_sink = gr.framer_sink_1(self._rcvd_pktq)
        self.connect(self, self._demodulator, self.correlator,
                     self.framer_sink)

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
Example #8
0
    def __init__(self, access_code='', threshold=-1, callback=None, repeat=1,
                 interleave=None, debug=False):
        """
        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
        """
        self._repeat = repeat
        self._interleave = interleave
        self._debug = debug

        #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, repeat, interleave, debug)