id: sdrplay3_rsp1a
label: 'SDRplay: RSP1A'
category: '[sdrplay3]'
flags: [python, cpp, throttle]


templates:
  imports: from gnuradio import sdrplay3
  make: |
    sdrplay3.rsp1a(
        ${rsp_selector},
        stream_args=sdrplay3.stream_args(
            output_type='${output_type}',
            channels_size=1
        ),
    )
    self.${id}.set_sample_rate(${sample_rate}, ${synchronous_updates})
    self.${id}.set_center_freq(${center_freq}, ${synchronous_updates})
    self.${id}.set_bandwidth(${bandwidth})
    self.${id}.set_gain_mode(${AGC})
    self.${id}.set_gain(-(${if_gRdB}), 'IF', ${synchronous_updates})
    % if rf_gR_mode == 'dB':
    self.${id}.set_gain(-(${rf_gRdB}), 'RF', ${synchronous_updates})
    % elif rf_gR_mode == 'LNA':
    self.${id}.set_gain(${rf_gRLNA}, 'LNAstate', ${synchronous_updates})
    % endif
    self.${id}.set_freq_corr(${freq_corr})
    self.${id}.set_dc_offset_mode(${dc_offset_mode})
    self.${id}.set_iq_balance_mode(${iq_balance_mode})
    self.${id}.set_agc_setpoint(${agc_set_point})
    self.${id}.set_rf_notch_filter(${rf_notch_filter})
    self.${id}.set_dab_notch_filter(${dab_notch_filter})
    self.${id}.set_biasT(${biasT})
    self.${id}.set_debug_mode(${debug_mode})
    self.${id}.set_sample_sequence_gaps_check(${sample_sequence_gaps_check})
    self.${id}.set_show_gain_changes(${show_gain_changes})
  callbacks:
  - set_sample_rate(${sample_rate}, ${synchronous_updates})
  - set_center_freq(${center_freq}, ${synchronous_updates})
  - set_bandwidth(${bandwidth})
  - set_gain_mode(${AGC})
  - set_gain(-(${if_gRdB}), 'IF', ${synchronous_updates})
  - |
    % if rf_gR_mode == 'dB':
    set_gain(-(${rf_gRdB}), 'RF', ${synchronous_updates})
    % elif rf_gR_mode == 'LNA':
    set_gain(${rf_gRLNA}, 'LNAstate', ${synchronous_updates})
    % endif
  - set_freq_corr(${freq_corr})
  - set_dc_offset_mode(${dc_offset_mode})
  - set_iq_balance_mode(${iq_balance_mode})
  - set_agc_setpoint(${agc_set_point})
  - set_rf_notch_filter(${rf_notch_filter})
  - set_dab_notch_filter(${dab_notch_filter})
  - set_biasT(${biasT})
  - set_debug_mode(${debug_mode})
  - set_sample_sequence_gaps_check(${sample_sequence_gaps_check})
  - set_show_gain_changes(${show_gain_changes})


cpp_templates:
  includes: [ '#include <sdrplay3/rsp1a.h>' ]
  declarations: 'gr::sdrplay3::rsp1a::sptr ${id};'
  make: |
    this->${id} = gr::sdrplay3::rsp1a::make(
        "${rsp_selector.strip('"\'')}",
        ::sdrplay3::stream_args_t("${output_type}", 1)
    );
    this->${id}->set_sample_rate(${sample_rate}, ${synchronous_updates});
    this->${id}->set_center_freq(${center_freq}, ${synchronous_updates});
    this->${id}->set_bandwidth(${bandwidth});
    this->${id}->set_gain_mode(${AGC});
    this->${id}->set_gain(-(${if_gRdB}), "IF", ${synchronous_updates});
    % if rf_gR_mode == 'dB':
    this->${id}->set_gain(-(${rf_gRdB}), "RF", ${synchronous_updates});
    % elif rf_gR_mode == 'LNA':
    this->${id}->set_gain(${rf_gRLNA}, "LNAstate", ${synchronous_updates});
    % endif
    this->${id}->set_freq_corr(${freq_corr});
    this->${id}->set_dc_offset_mode(${dc_offset_mode});
    this->${id}->set_iq_balance_mode(${iq_balance_mode});
    this->${id}->set_agc_setpoint(${agc_set_point});
    this->${id}->set_rf_notch_filter(${rf_notch_filter});
    this->${id}->set_dab_notch_filter(${dab_notch_filter});
    this->${id}->set_biasT(${biasT});
    this->${id}->set_debug_mode(${debug_mode});
    this->${id}->set_sample_sequence_gaps_check(${sample_sequence_gaps_check});
    this->${id}->set_show_gain_changes(${show_gain_changes});
  link: ['gnuradio-sdrplay3 sdrplay_api.so.3']
  translations:
    "'": '"'
    'True': 'true'
    'False': 'false'
  callbacks:
  - set_sample_rate(${sample_rate}, ${synchronous_updates});
  - set_center_freq(${center_freq}, ${synchronous_updates});
  - set_bandwidth(${bandwidth});
  - set_gain_mode(${AGC});
  - set_gain(-(${if_gRdB}), "IF", ${synchronous_updates});
  - |
    % if rf_gR_mode == 'dB':
    set_gain(-(${rf_gRdB}), "RF", ${synchronous_updates});
    % elif rf_gR_mode == 'LNA':
    set_gain(${rf_gRLNA}, "LNAstate", ${synchronous_updates});
    % endif
  - set_freq_corr(${freq_corr});
  - set_dc_offset_mode(${dc_offset_mode});
  - set_iq_balance_mode(${iq_balance_mode});
  - set_agc_setpoint(${agc_set_point});
  - set_rf_notch_filter(${rf_notch_filter});
  - set_dab_notch_filter(${dab_notch_filter});
  - set_biasT(${biasT});
  - set_debug_mode(${debug_mode});
  - set_sample_sequence_gaps_check(${sample_sequence_gaps_check});
  - set_show_gain_changes(${show_gain_changes});


parameters:

- id: rsp_selector
  label: RSP Selector
  dtype: string
  default: ''

- id: sample_rate
  label: Sample rate (Sps)
  dtype: real
  default: samp_rate

- id: center_freq
  label: Center Freq (Hz)
  dtype: real
  default: 0

- id: bandwidth
  label: Bandwidth (Hz)
  dtype: enum
  options: [0, 200e3, 300e3, 600e3, 1536e3, 5000e3, 6000e3, 7000e3, 8000e3]
  option_labels: [AUTO, 200k, 300k, 600k, 1.536M, 5M, 6M, 7M, 8M]
  default: 0

# Gain options
- id: AGC
  label: AGC
  category: Gain Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: if_gRdB
  label: IF Attenuation (dB)
  category: Gain Options
  dtype: real
  default: 40
  hide: part

- id: rf_gR_mode
  label: 'RF Attenuation mode: dB/LNA state'
  category: Gain Options
  dtype: enum
  default: 'dB'
  options: ['dB', 'LNA']
  option_labels: [dB, LNA state]
  hide: part
- id: rf_gRdB
  label: RF Attenuation (dB)
  category: Gain Options
  dtype: real
  default: 0
  hide: ${'part' if rf_gR_mode == 'dB' else 'all'}
- id: rf_gRLNA
  label: RF Attenuation (LNA state)
  category: Gain Options
  dtype: int
  default: 0
  hide: ${'part' if rf_gR_mode == 'LNA' else 'all'}

- id: agc_set_point
  label: AGC set point (dBfs)
  category: Gain Options
  dtype: real
  default: -30
  hide: part

# Other options
- id: freq_corr
  label: Frequency correction (ppm)
  category: Other Options
  dtype: real
  default: 0
  hide: part

- id: dc_offset_mode
  label: DC offset correction
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: iq_balance_mode
  label: IQ imbalance correction
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: rf_notch_filter
  label: RF notch filter
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: dab_notch_filter
  label: DAB notch filter
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: biasT
  label: Bias-T
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: output_type
  label: Output Type
  category: Other Options
  dtype: enum
  options: [fc32, sc16]
  option_labels: [Complex float32, Complex int16]
  hide: part

- id: synchronous_updates
  label: Synchronous Updates
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Asynchronous, Synchronous]
  hide: part

# Debug options
- id: debug_mode
  label: SDRplay API debug mode (DEBUG)
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: sample_sequence_gaps_check
  label: Sample gaps check (DEBUG)
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part

- id: show_gain_changes
  label: Show IF gain changes (DEBUG)
  category: Other Options
  dtype: bool
  default: 'False'
  options: ['False', 'True']
  option_labels: [Disabled, Enabled]
  hide: part


outputs:
- dtype: ${output_type}


documentation: |-
    The SDRplay RSP1A Source Block:

    Device Selector:
    The device selector is a delimited string used to locate SDRplay devices on your system. \
    If left blank, the first SDRplay RSP found will be used. \
    Use the device serial number to specify a specific device.
    Example: 1234567890

    Sample rate:
    The sample rate is the number of samples per second from this block.

    Center frequency:
    The center frequency is the center frequency of the tuner.

    Bandwidth:
    RX bandwidth (AUTO chooses the largest bandwidth compatible with the sample rate)

    AGC:
    Enables/disables the AGC

    IF Attenuation:
    IF attenuation in dB [20-59]

    RF Attenuation:
    - dB: RF attenuation in dB [0-dBMax] where dbMax depends on frequency band and antenna type (see LNAstate table in the Users Guide)
    - LNA state: RF attenuation as LNA state [0-LNAstateMax]

    AGC set point (dBfs)


    Other options:

        Frequency correction (ppm)

        DC offset correction

        IQ imbalance correction

        RF notch filter

        DAB notch filter

        Bias-T

        Output Type:
        This parameter controls the data type of the stream in gnuradio.
        Valid selections are:
        Complex float
        Complex short (native)

        Synchronous Updates:
        Wait for the requested parameter change to be completed before returning from the function.
        Applies only to changes to sample rate, center frequency, and gains.

        Debug mode (DEBUG)
        Enable (or disable) debug mode for SDRplay API

        Sample gaps check (DEBUG)
        Enable (or disable) check for gaps in sample sequence numbers

        Show IF gain changes (DEBUG)
        If enabled logs a message every time the IF gain changes (can be very noisy when AGC is enabled)


file_format: 1
