---

id: soapy_source
label: Soapy Source
flags: [python, throttle]

parameters:
  - id: nchan
    label: Num Channels
    dtype: int
    default: '1'
    hide: part

  - id: devname
    label: Device Type
    dtype: enum
    default: 'rtlsdr'
    options: ['airspy', 'airspyhf', 'bladerf', 'hackrf', 'lime', 'plutosdr',
              'rtlsdr', 'sidekiq', 'sdrplay', 'uhd', 'xtrxsoapy', 'custom']
    option_labels: ['airspy', 'airspyhf', 'bladerf', 'hackrf', 'lime',
                    'plutosdr', 'rtlsdr', 'sidekiq', 'sdrplay', 'uhd',
                    'xtrxsoapy', 'custom']

  - id: dev
    label: Device String
    dtype: string
    default: 'driver=rtlsdr'
    hide: ${ 'none' if (devname == 'custom') else 'all' }

  - id: type
    label: Output Type
    dtype: enum
    options: [fc32, sc16, sc8]
    option_labels: [Complex Float32, Complex Int16, Complex Byte]
    option_attributes:
      type: [fc32, sc16, sc8]
    hide: part

  - id: samp_rate
    label: Sample Rate
    dtype: float
    default: 'samp_rate'

  - id: dev_args
    label: Device arguments
    dtype: string
    hide: ${'part' if not dev_args else 'none'}

  - id: stream_args
    label: Stream arguments
    dtype: string
    hide: ${'part' if not stream_args else 'none'}

  - id: clock_rate
    label: Master Clock Rate
    category: Advanced
    dtype: real
    default: '0'
    hide: ${ 'all' if (devname not in ['uhd', 'plutosdr'])
             else 'part' }

  - id: clock_source
    label: Clock Source
    category: Advanced
    dtype: string
    hide: ${ 'all' if (devname not in ['uhd', 'plutosdr'])
             else 'part' }

  - id: tune_args0
    label: 'Ch0: Tune arguments'
    category: RF Options
    dtype: string
    hide: ${'part' if not tune_args0 else 'none'}

  - id: settings0
    label: 'Ch0: Other settings'
    category: RF Options
    dtype: string
    hide: ${'part' if not settings0 else 'none'}

  - id: center_freq0
    label: 'Ch0: Center Freq (Hz)'
    category: RF Options
    dtype: real
    default: freq

  - id: nco_freq0
    label: 'Ch0: NCO Freq (Hz)'
    category: RF Options
    dtype: real
    default: '0'
    hide: ${ 'all' if (devname in ['uhd', 'plutosdr', 'airspy', 'airspyhf', 'rtlsdr'])
             else 'part' }

  - id: gain_mode0
    label: 'Ch0: Gain Mode'
    category: RF Options
    dtype: string
    options: ['Overall', 'Specific', 'Settings Field']
    option_labels:  [Overall, Specific, Settings Field]
    default: 'Overall'
    hide: part

  - id: overall_gain0
    label: 'Ch0: Overall Gain Value'
    category: RF Options
    dtype: real
    default: '10'
    hide: ${ 'none' if ( gain_mode0 == 'Overall') else 'all' }

  - id: pga_gain0
    label: 'Ch0: PGA Gain Value'
    category: RF Options
    dtype: float
    default: '24'
    hide: ${ 'none' if ( (devname in ['uhd', 'plutosdr', 'xtrxsoapy', 'lime'])
             and gain_mode0 == 'Specific' ) else 'all' }

  - id: lna_gain0
    label: 'Ch0: LNA Gain Value'
    category: RF Options
    dtype: float
    default: '10'
    hide: ${ 'none' if ( (devname in ['airspy', 'airspyhf', 'bladerf', 'lime', 'hackrf',
             'xtrxsoapy'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: tia_gain0
    label: 'Ch0: TIA Gain Value'
    category: RF Options
    dtype: float
    default: '0'
    hide: ${ 'none' if ( (devname in ['xtrxsoapy', 'lime'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: mix_gain0
    label: 'Ch0: MIX Gain Value'
    category: RF Options
    dtype: float
    default: '10'
    hide: ${ 'none' if ( (devname in ['airspy'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: rf_gain0
    label: 'Ch0: RF Gain Value'
    category: RF Options
    dtype: float
    default: '18'
    hide: ${ 'none' if ( (devname in ['airspyhf'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: vga_gain0
    label: 'Ch0: VGA Gain Value'
    category: RF Options
    dtype: float
    default: '10'
    hide: ${ 'none' if ( (devname in ['airspy', 'hackrf'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: tuner_gain0
    label: 'Ch0: TUNER Gain Value'
    category: RF Options
    dtype: float
    default: '10'
    hide: ${ 'none' if ( (devname in ['rtlsdr'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: amp_gain0
    label: 'Ch0: AMP Gain Value'
    category: RF Options
    dtype: float
    default: '0'
    hide: ${ 'none' if ( (devname in ['hackrf'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: ifgr_gain
    label: 'Ch0: IFGR Gain Value'
    category: RF Options
    dtype: float
    default: '59'
    hide: ${ 'none' if ( (devname in ['sdrplay'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: rfgr_gain
    label: 'Ch0: RFGR Gain Value'
    category: RF Options
    dtype: float
    default: '9'
    hide: ${ 'none' if ( (devname in ['sdrplay'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: rxvga1_gain
    label: 'Ch0: RXVGA1 Gain Value'
    category: RF Options
    dtype: float
    default: '5'
    hide: ${ 'none' if ( (devname in ['bladerf'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: rxvga2_gain
    label: 'Ch0: RXVGA2 Gain Value'
    category: RF Options
    dtype: float
    default: '0'
    hide: ${ 'none' if ( (devname in ['bladerf'])
             and gain_mode0 == 'Specific'  ) else 'all' }

  - id: ant0
    label: 'Ch0: Antenna'
    category: RF Options
    dtype: string
    default: 'RX'
    hide: ${ 'part' if nchan > 0 else 'all' }

  - id: bw0
    label: 'Ch0: Bandwidth (Hz)'
    category: RF Options
    dtype: real
    default: '0'
    hide: ${ 'part' if nchan > 0 else 'all' }

  - id: dc_removal0
    label: 'Ch0: Automatic DC Removal'
    category: RF Options
    dtype: bool
    default: 'True'

  - id: dc_offset0
    label: 'Ch0: DC Offset'
    category: RF Options
    dtype: complex
    default: '0'

  - id: correction0
    label: 'Ch0: Frequency Correction'
    category: RF Options
    dtype: real
    default: '0'

  - id: balance0
    label: 'Ch0: IQ Balance Correction'
    category: RF Options
    dtype: complex
    default: '0'

  - id: agc0
    label: 'Ch0: Automatic Gain Control'
    category: RF Options
    dtype: bool
    default: 'False'
    hide: ${ 'none' if (devname in ['airspy', 'airspyhf', 'plutosdr', 'sdrplay', 'uhd'])
             else ('all' if devname in ['lime', 'rtlsdr'] else 'part')}

  - id: sdrplay_if_mode
    label: IF Mode
    category: RF Options
    dtype: enum
    default: 'Zero-IF'
    options: ['Zero-IF', '450kHz', '1620kHz', '2048kHz']
    option_labels: [Zero-IF, 450kHz, 1620kHz, 2048kHz]
    hide: ${ 'none' if ( devname == 'sdrplay' ) else 'all' }

  - id: sdrplay_biastee
    label: Bias Tee
    category: RF Options
    dtype: bool
    default: 'False'
    hide: ${ 'none' if ( devname == 'sdrplay') else 'all' }

  - id: sdrplay_agc_setpoint
    label: AGC Setpoint (dBfs)
    category: RF Options
    dtype: int
    default: '-30'
    hide: ${ 'none' if ( devname == 'sdrplay' ) else 'all' }

  - id: sdrplay_rfnotch
    label: RF Notch Filter
    category: RF Options
    dtype: bool
    default: 'False'
    hide: ${ 'none' if ( devname == 'sdrplay' ) else 'all' }

  - id: sdrplay_dabnotch
    label: DAB Notch Filter
    category: RF Options
    dtype: bool
    default: 'False'
    hide: ${ 'none' if ( devname == 'sdrplay' ) else 'all' }

  - id: tune_args1
    label: 'Ch1: Tune arguments'
    category: RF Options
    dtype: string
    hide: ${ 'none' if nchan > 1 else 'all' }

  - id: settings1
    label: 'Ch1: Other settings'
    category: RF Options
    dtype: string
    hide: ${ 'none' if nchan > 1 else 'all' }

  - id: center_freq1
    label: 'Ch1: Center Freq (Hz)'
    category: RF Options
    dtype: real
    default: '0'
    hide: ${ 'none' if nchan > 1 else 'all' }

  - id: nco_freq1
    label: 'Ch1: NCO Freq (Hz)'
    category: RF Options
    dtype: real
    default: '0'
    hide: 'all'

  - id: gain_mode1
    label: 'Ch1: Gain Mode'
    category: RF Options
    dtype: string
    options: ['Overall', 'Specific', 'Settings Field']
    option_labels:  [Overall, Specific, Settings Field]
    default: 'Overall'
    hide: ${ 'all' if nchan < 2 else 'part' }

  - id: overall_gain1
    label: 'Ch1: Gain Value'
    category: RF Options
    dtype: real
    default: '10'
    hide: ${ 'none' if (gain_mode1 == 'Overall' and nchan > 1) else 'all' }

  - id: pga_gain1
    label: 'Ch1: PGA Gain Value'
    category: RF Options
    dtype: float
    default: '24'
    hide: ${ 'none' if ( (devname in ['uhd', 'xtrxsoapy', 'lime'])
             and gain_mode1 == 'Specific' and nchan > 1) else 'all' }

  - id: lna_gain1
    label: 'Ch1: LNA Gain Value'
    category: RF Options
    dtype: float
    default: '10'
    hide: ${ 'none' if ( (devname in ['lime', 'xtrxsoapy'])
             and gain_mode1 == 'Specific' and nchan > 1) else 'all' }

  - id: tia_gain1
    label: 'Ch1: TIA Gain Value'
    category: RF Options
    dtype: float
    default: '0'
    hide: ${ 'none' if ( (devname in ['xtrxsoapy', 'lime'])
          and gain_mode1 == 'Specific' and nchan > 1) else 'all' }

  - id: ant1
    label: 'Ch1: Antenna'
    category: RF Options
    dtype: string
    default: 'RX2'
    hide: ${ 'part' if nchan > 1 else 'all' }

  - id: bw1
    label: 'Ch1: Bandwidth (Hz)'
    category: RF Options
    dtype: real
    default: '0'
    hide: ${ 'part' if nchan > 1 else 'all' }

  - id: dc_removal1
    label: 'Ch1: Automatic DC Removal'
    category: RF Options
    dtype: string
    options: [False, True]
    option_labels: [False, True]
    default: True
    hide: ${ 'all' if nchan < 2 else 'none' }

  - id: dc_offset1
    label: 'Ch1: DC Offset'
    category: RF Options
    dtype: complex
    default: '0'
    hide: ${ 'all' if nchan < 2 else 'none' }

  - id: correction1
    label: 'Ch1: Frequency Correction'
    category: RF Options
    dtype: real
    default: '0'
    hide: ${ 'all' if nchan < 2 else 'none' }

  - id: balance1
    label: 'Ch1: IQ Balance Correction'
    category: RF Options
    dtype: complex
    default: '0'
    hide: ${ 'all' if nchan < 2 else 'none' }

  - id: agc1
    label: 'Ch1: Automatic Gain Control'
    category: RF Options
    dtype: bool
    default: 'False'
    hide: ${ 'all' if ( nchan < 2 or (devname in ['airspy', 'airspyhf', 'rtlsdr', 'plutosdr', 'sdrplay']))
             else 'none'}
inputs:
  - domain: message
    id: cmd
    optional: true

outputs:
  - domain: stream
    dtype: ${ type.type }
    multiplicity: ${ nchan }
asserts:
  - ${ nchan > 0 }
  - ${ gain_mode0 == "Overall" or gain_mode0 == "Specific" or
       gain_mode0 == "Settings Field" }
  - ${ 'True' if (nchan < 2) else (gain_mode1 == "Overall" or
       gain_mode1 == "Specific" or
       gain_mode1 == "Settings Field") }

templates:
    imports: |-
      from gnuradio import soapy
    make: |
        None
        # Make sure that the gain mode is valid
        if(${gain_mode0} not in ['Overall', 'Specific', 'Settings Field']):
            raise ValueError("Wrong gain mode on channel 0. Allowed gain modes: "
                  "['Overall', 'Specific', 'Settings Field']")
        % if context.get('nchan')() > 1:
        if(${gain_mode1} not in ['Overall', 'Specific', 'Settings Field']):
            raise ValueError("Wrong gain mode on channel 1. Allowed gain modes: "
                  "['Overall', 'Specific', 'Settings Field']")
        % endif
        <%! import SoapySDR %>
        % if context.get('devname')() == 'custom':
        dev = ${dev}
        % else:
        dev = 'driver=${devname}'
        % endif

        # Stream arguments
        stream_args = ${stream_args}

        # Tune arguments for every activated stream
        % if context.get('nchan')() == 1:
        tune_args = [${tune_args0}]
        settings = [${settings0}]
        % else:
        tune_args = [${tune_args0}, ${tune_args1}]
        settings = [${settings0}, ${settings1}]
        % endif

        # Setup the device arguments
        % if context.get('devname')() == 'sdrplay':
        <%
          sdrplay_kwargs = {}
          sdrplay_kwargs['if_mode'] = context.get('sdrplay_if_mode')()
          sdrplay_kwargs['agc_setpoint'] = str(context.get('sdrplay_agc_setpoint')())
          sdrplay_kwargs['biasT_ctrl'] = str( context.get('sdrplay_biastee')()).lower()
          sdrplay_kwargs['rfnotch_ctrl'] = str(context.get('sdrplay_rfnotch')()).lower()
          sdrplay_kwargs['dabnotch_ctrl'] = str(context.get('sdrplay_dabnotch')()).lower()
          ## The user defined parameters will always have priority,
          ## thus they overwrite the graphically set device arguments
          ## like filters, biasT etc
          tmp = SoapySDR.KwargsFromString(context.get('dev_args')())
          sdrplay_kwargs.update(tmp)
          sdrplay_kwargs_str = ', '.join('%s=%s' % x for x in sdrplay_kwargs.items())
        %>
        dev_args = "${sdrplay_kwargs_str}"
        % else:
        dev_args = ${dev_args}
        % endif

        self.${id} = soapy.source(dev, "${type}", ${nchan}, dev_args,
                                  stream_args, tune_args, settings)

        self.${id}.set_sample_rate(0, ${samp_rate})
        % if context.get('nchan')() > 1:
        self.${id}.set_sample_rate(1, ${samp_rate})
        % endif

        % if context.get('clock_rate')() != 0:
        self.${id}.set_master_clock_rate(${clock_rate})
        % endif

        % if len(context.get('clock_source')()) > 0:
        self.${id}.set_clock_source(${clock_source})
        % endif

        self.${id}.set_dc_offset_mode(0,${dc_removal0})
        % if context.get('nchan')() > 1:
        self.${id}.set_dc_offset_mode(1,${dc_removal1})
        % endif

        # Set up DC offset. If set to (0, 0) internally the source block
        # will handle the case if no DC offset correction is supported
        self.${id}.set_dc_offset(0,${dc_offset0})
        % if context.get('nchan')() > 1:
        self.${id}.set_dc_offset(1,${dc_offset1})
        % endif

        # Setup IQ Balance. If set to (0, 0) internally the source block
        # will handle the case if no IQ balance correction is supported
        self.${id}.set_iq_balance(0,${balance0})
        % if context.get('nchan')() > 1:
        self.${id}.set_iq_balance(1,${balance1})
        % endif

        self.${id}.set_gain_mode(0,${agc0})
        % if context.get('nchan')() > 1:
        self.${id}.set_gain_mode(1,${agc1})
        % endif

        # generic frequency setting should be specified first
        self.${id}.set_frequency(0, ${center_freq0})
        % if context.get('nchan')() > 1:
        self.${id}.set_frequency(1, ${center_freq1})
        % endif

        self.${id}.set_frequency(0,"BB",${nco_freq0})
        % if context.get('nchan')() > 1:
        self.${id}.set_frequency(1,"BB",${nco_freq1})
        % endif

        # Setup Frequency correction. If set to 0 internally the source block
        # will handle the case if no frequency correction is supported
        self.${id}.set_frequency_correction(0,${correction0})
        % if context.get('nchan')() > 1:
        self.${id}.set_frequency_correction(1,${correction1})
        % endif

        self.${id}.set_antenna(0,${ant0})
        % if context.get('nchan')() > 1:
        self.${id}.set_antenna(1,${ant1})
        % endif

        self.${id}.set_bandwidth(0,${bw0})
        % if context.get('nchan')() > 1:
        self.${id}.set_bandwidth(1,${bw1})
        % endif

        if(${gain_mode0} != 'Settings Field'):
            # pass is needed, in case the template does not evaluare anything
            pass
        % if context.get('gain_mode0')() == 'Overall':
            self.${id}.set_gain(0,${overall_gain0})
        % elif context.get('gain_mode0')() == 'Specific':
            % if context.get('devname')() in  ['uhd', 'plutosdr', 'xtrxsoapy', 'lime']:
            self.${id}.set_gain(0,"PGA", ${pga_gain0})
            % endif
            % if context.get('devname')() in ['airspy', 'airspyhf', 'bladerf', 'lime', 'hackrf', 'xtrxsoapy']:
            self.${id}.set_gain(0,"LNA", ${lna_gain0})
            % endif
            % if context.get('devname')() in ['xtrxsoapy', 'lime']:
            self.${id}.set_gain(0,"TIA", ${tia_gain0})
            % endif
            % if context.get('devname')() in ['airspy']:
            self.${id}.set_gain(0,"MIX", ${mix_gain0})
            % endif
            % if context.get('devname')() in ['airspyhf']:
            self.${id}.set_gain(0,"RF", ${rf_gain0})
            % endif
            % if context.get('devname')() in ['airspy', 'hackrf']:
            self.${id}.set_gain(0,"VGA", ${vga_gain0})
            % endif
            % if context.get('devname')() in ['rtlsdr']:
            self.${id}.set_gain(0,"TUNER", ${tuner_gain0})
            % endif
            % if context.get('devname')() in ['hackrf']:
            self.${id}.set_gain(0,"AMP", ${amp_gain0})
            % endif
            % if context.get('devname')() in ['sdrplay']:
            self.${id}.set_gain(0,"IFGR", ${ifgr_gain})
            self.${id}.set_gain(0,"RFGR", ${rfgr_gain})
            % endif
            % if context.get('devname')() in ['bladerf']:
            self.${id}.set_gain(0,"rxvga1", ${rxvga1_gain})
            self.${id}.set_gain(0,"rxvga2", ${rxvga2_gain})
            % endif
        % endif


        % if context.get('nchan')() > 1:
        if(${gain_mode1} != 'Settings Field'):
            # pass is needed, in case the template does not evaluare anything
            pass
        % if context.get('gain_mode1')() == 'Overall':
            self.${id}.set_gain(1,${overall_gain1})
        % elif context.get('gain_mode1')() == 'Specific':
            % if context.get('devname')() in  ['uhd', 'xtrxsoapy', 'lime']:
            self.${id}.set_gain(1,"PGA", ${pga_gain1})
            % endif
            % if context.get('devname')() in ['lime', 'xtrxsoapy']:
            self.${id}.set_gain(1,"LNA", ${lna_gain1})
            % endif
            % if context.get('devname')() in ['xtrxsoapy', 'lime']:
            self.${id}.set_gain(1,"TIA", ${tia_gain1})
            % endif
        % endif
        % endif

    callbacks:
        # RF Frequency
        - set_frequency(0, ${center_freq0})
        - |
          % if context.get('nchan')() > 1:
          set_frequency(1, ${center_freq1})
          % endif

        # Baseband Frequency
        - set_frequency(0,"BB",${nco_freq0})
        - |
          % if context.get('nchan')() > 1:
          set_frequency(1,"BB",${nco_freq1})
          % endif

        # Antenna
        - set_antenna(0,${ant0})
        - |
          % if context.get('nchan')() > 1:
          set_antenna(1,${ant1})
          % endif

        # Bandwith filter
        - set_bandwidth(0,${bw0})
        - |
          % if context.get('nchan')() > 1:
          set_bandwidth(1,${bw1})
          % endif

        # Gain settings
        - |
          % if context.get('gain_mode0')() == 'Overall':
          set_gain(0, ${overall_gain0})
          % endif

        - |
          % if context.get('gain_mode1')() == 'Overall' and \
               context.get('nchan')() > 1:
          set_gain(1, ${overall_gain1})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['uhd', 'plutosdr', 'xtrxsoapy', 'lime']:
          set_gain(0,"PGA", ${pga_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['airspy', 'airspyhf', 'bladerf', 'lime', 'hackrf', 'xtrxsoapy']:
          set_gain(0,"LNA", ${lna_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['xtrxsoapy', 'lime']:
          set_gain(0,"TIA", ${tia_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['airspy']:
          set_gain(0,"MIX", ${mix_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['airspyhf']:
          set_gain(0,"RF", ${rf_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['airspy', 'hackrf']:
          set_gain(0,"VGA", ${vga_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['rtlsdr']:
          set_gain(0,"TUNER", ${tuner_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['hackrf']:
          set_gain(0,"AMP", ${amp_gain0})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['sdrplay']:
          set_gain(0,"IFGR", ${ifgr_gain})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['sdrplay']:
          set_gain(0,"RFGR", ${rfgr_gain})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['bladerf']:
          set_gain(0,"rxvga1", ${rxvga1_gain})
          % endif

        - |
          % if context.get('gain_mode0')() == 'Specific' and \
               context.get('devname')() in ['bladerf']:
          set_gain(0,"rxvga2", ${rxvga2_gain})
          % endif

        - |
          % if context.get('nchan')() > 1 and \
               context.get('gain_mode1')() == 'Specific' and \
               context.get('devname')() in  ['uhd', 'xtrxsoapy', 'lime']:
          set_gain(1,"PGA", ${pga_gain1})
          % endif

        - |
          % if context.get('nchan')() > 1 and \
               context.get('gain_mode1')() == 'Specific' and \
               context.get('devname')() in ['lime', 'xtrxsoapy']:
          set_gain(1,"LNA", ${lna_gain1})
          % endif
        - |
          % if context.get('nchan')() > 1 and \
               context.get('gain_mode1')() == 'Specific' and \
               context.get('devname')() in ['xtrxsoapy', 'lime']:
          self.${id}.set_gain(1,"TIA", ${tia_gain1})
          % endif

        # Frequency correction
        - set_frequency_correction(0,${correction0})
        - |
          % if context.get('nchan')() > 1:
          set_frequency_correction(1,${correction1})
          % endif

        # DC removal
        - set_dc_removal(0,${dc_removal0})
        - |
          % if context.get('nchan')() > 1:
          set_dc_removal(1,${dc_removal1})
          % endif

        # DC offset
        - set_dc_offset(0,${dc_offset0})
        - |
          % if context.get('nchan')() > 1:
          set_dc_offset(1,${dc_offset1})
          % endif

        # IQ Imbalance (complex)
        - set_iq_balance(0,${balance0})
        - |
          % if context.get('nchan')() > 1:
          set_iq_balance(1,${balance1})
          % endif

        # AGC
        - set_gain_mode(0,${agc0})
        - |
          % if context.get('nchan')() > 1:
          set_gain_mode(1,${agc1})
          % endif

documentation: |-
    Soapy Source Block:
    Device:
    The device argument is a comma delimited string used to create a device
    instance that uses the specified driver. Device driver should always be
    specified.

    Usage examples:
      device: driver=lime
      device: driver=uhd,type=b200
      device: driver=uhd,serial=12345678

    Device Arguments:
    Comma delimited list of key-word dictionary arguments specific for each
    ndevice. Device driver handles internally invalid arguments.

    Usage examples:
      device: driver=lime
      dev_args: skipCal=True

      device: driver=airspy
      dev_args: biastee=True

    Sample Rate:
    The sample rate is the number of samples per second input by this block.
    If the requested rate is not possible the driver handles it internally

    Center frequency:
    The center frequency of the RF chain. If the device cannot tune to the
    specified frequency the driver decides internally how to handle it.

    Master Clock Rate:
    The rate of the master clock. Can be assigned zero for automatic tuning.

    Clock Source:
    Specifies a valid external clock source. Can be left empty.

    Input Type:
    This parameter controls the data type of the stream in GNU-Radio.

    Gain:
    Depending the device driver specified in the Device field various gain
    parameters can be configured. If a driver is not explicitly supported from
    the block an Overal Gain parameter can be configured.
      E.g 1:
        Gain Value: 10
      E.g 2:
        Device: driver=uhd
        PGA Gain: 10

    Antenna:
    Specified antenna used in RF chain. Can be left empty for auto assignment,
    else it must correspond to an antenna name of the device used.

    Bandwidth:
    The digital filter bandwidth of the RF chain.
    Can be left empty for auto assignment, else it must be a correct filter
    bandwidth of the device.

file_format: 1
