Esempio n. 1
0
    def __init__(self, protocol, context, multimon_demod_args):
        gr.hier_block2.__init__(
            self,
            '%s(%r, %r)' %
            (type(self).__name__, multimon_demod_args, protocol),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )

        # Subprocess
        # using /usr/bin/env because twisted spawnProcess doesn't support path search
        process = reactor.spawnProcess(
            protocol,
            '/usr/bin/env',
            env=None,  # inherit environment
            args=['env', 'multimon-ng', '-t', 'raw'] + multimon_demod_args +
            ['-v', '10', '-'],
            childFDs={
                0: 'w',
                1: 'r',
                2: 2
            })
        sink = make_sink_to_process_stdin(process, itemsize=gr.sizeof_short)

        # Output
        to_short = blocks.float_to_short(vlen=1, scale=int_scale)
        self.connect(
            self,
            # blocks.complex_to_float(),
            to_short,
            sink)
        # Audio copy output
        unconverter = blocks.short_to_float(vlen=1, scale=int_scale)
        self.connect(to_short, unconverter)
        self.connect(unconverter, self)
Esempio n. 2
0
 def __init__(self, protocol, context, multimon_demod_args):
     gr.hier_block2.__init__(
         self, b'%s(%r, %r)' % (type(self).__name__, multimon_demod_args, protocol),
         gr.io_signature(1, 1, gr.sizeof_float * 1),
         gr.io_signature(1, 1, gr.sizeof_float * 1),
     )
     
     # Subprocess
     # using /usr/bin/env because twisted spawnProcess doesn't support path search
     process = reactor.spawnProcess(
         protocol,
         '/usr/bin/env',
         env=None,  # inherit environment
         args=['env', 'multimon-ng', '-t', 'raw'] + multimon_demod_args + ['-v', '10', '-'],
         childFDs={
             0: 'w',
             1: 'r',
             2: 2
         })
     sink = make_sink_to_process_stdin(process, itemsize=gr.sizeof_short)
     
     # Output
     to_short = blocks.float_to_short(vlen=1, scale=int_scale)
     self.connect(
         self,
         # blocks.complex_to_float(),
         to_short,
         sink)
     # Audio copy output
     unconverter = blocks.short_to_float(vlen=1, scale=int_scale)
     self.connect(to_short, unconverter)
     self.connect(unconverter, self)
Esempio n. 3
0
 def __init__(self, mode='433', input_rate=0, context=None):
     assert input_rate > 0
     assert context is not None
     gr.hier_block2.__init__(
         self, type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_gr_complex),
         gr.io_signature(0, 0, 0))
     
     # The input bandwidth chosen is not primarily determined by the bandwidth of the input signals, but by the frequency error of the transmitters. Therefore it is not too critical, and we can choose the exact rate to make the filtering easy.
     if input_rate <= upper_preferred_demod_rate:
         # Skip having a filter at all.
         self.__band_filter = None
         demod_rate = input_rate
     else:
         # TODO: This gunk is very similar to the stuff that MultistageChannelFilter does. See if we can share some code.
         lower_rate = input_rate
         lower_rate_prev = None
         while lower_rate > upper_preferred_demod_rate and lower_rate != lower_rate_prev:
             lower_rate_prev = lower_rate
             if lower_rate % 5 == 0 and lower_rate > upper_preferred_demod_rate * 3:
                 lower_rate /= 5
             elif lower_rate % 2 == 0:
                 lower_rate /= 2
             else:
                 # non-integer ratio
                 lower_rate = upper_preferred_demod_rate
                 break
         demod_rate = lower_rate
         
         self.__band_filter = MultistageChannelFilter(
             input_rate=input_rate,
             output_rate=demod_rate,
             cutoff_freq=demod_rate * 0.4,
             transition_width=demod_rate * 0.2)
     
     # Subprocess
     # using /usr/bin/env because twisted spawnProcess doesn't support path search
     # pylint: disable=no-member
     process = the_reactor.spawnProcess(
         RTL433ProcessProtocol(context.output_message),
         '/usr/bin/env',
         env=None,  # inherit environment
         args=[
             'env', 'rtl_433',
             '-F', 'json',
             '-r', '-',  # read from stdin
             '-m', '3',  # complex float input
             '-s', str(demod_rate),
         ],
         childFDs={
             0: 'w',
             1: 'r',
             2: 2
         })
     sink = make_sink_to_process_stdin(process, itemsize=gr.sizeof_gr_complex)
     
     agc = analog.agc2_cc(reference=dB(-4))
     agc.set_attack_rate(200 / demod_rate)
     agc.set_decay_rate(200 / demod_rate)
     
     if self.__band_filter:
         self.connect(
             self,
             self.__band_filter,
             agc)
     else:
         self.connect(
             self,
             agc)
     self.connect(agc, sink)
Esempio n. 4
0
    def __init__(self, mode='433', input_rate=0, context=None):
        assert input_rate > 0
        assert context is not None
        gr.hier_block2.__init__(self,
                                type(self).__name__,
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))

        # The input bandwidth chosen is not primarily determined by the bandwidth of the input signals, but by the frequency error of the transmitters. Therefore it is not too critical, and we can choose the exact rate to make the filtering easy.
        if input_rate <= upper_preferred_demod_rate:
            # Skip having a filter at all.
            self.__band_filter = None
            demod_rate = input_rate
        else:
            # TODO: This gunk is very similar to the stuff that MultistageChannelFilter does. See if we can share some code.
            lower_rate = input_rate
            lower_rate_prev = None
            while lower_rate > upper_preferred_demod_rate and lower_rate != lower_rate_prev:
                lower_rate_prev = lower_rate
                if lower_rate % 5 == 0 and lower_rate > upper_preferred_demod_rate * 3:
                    lower_rate /= 5
                elif lower_rate % 2 == 0:
                    lower_rate /= 2
                else:
                    # non-integer ratio
                    lower_rate = upper_preferred_demod_rate
                    break
            demod_rate = lower_rate

            self.__band_filter = MultistageChannelFilter(
                input_rate=input_rate,
                output_rate=demod_rate,
                cutoff_freq=demod_rate * 0.4,
                transition_width=demod_rate * 0.2)

        # Subprocess
        # using /usr/bin/env because twisted spawnProcess doesn't support path search
        # pylint: disable=no-member
        process = the_reactor.spawnProcess(
            RTL433ProcessProtocol(context.output_message),
            '/usr/bin/env',
            env=None,  # inherit environment
            args=[
                b'env',
                b'rtl_433',
                b'-F',
                b'json',
                b'-r',
                b'-',  # read from stdin
                b'-m',
                b'3',  # complex float input
                b'-s',
                str(demod_rate),
            ],
            childFDs={
                0: 'w',
                1: 'r',
                2: 2
            })
        sink = make_sink_to_process_stdin(process,
                                          itemsize=gr.sizeof_gr_complex)

        agc = analog.agc2_cc(reference=dB(-4))
        agc.set_attack_rate(200 / demod_rate)
        agc.set_decay_rate(200 / demod_rate)

        if self.__band_filter:
            self.connect(self, self.__band_filter, agc)
        else:
            self.connect(self, agc)
        self.connect(agc, sink)