id: soapy_hackrf_sink
label: Soapy HackRF Sink
flags: [python, throttle]

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

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

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

  - id: bandwidth
    label: Bandwidth (0=auto)
    category: RF Options
    dtype: float
    default: '0'
    hide: part

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

  - id: amp
    label: 'Amp On (+14 dB)'
    category: RF Options
    dtype: bool
    default: 'False'
    hide: part

  - id: vga
    label: 'VGA Gain (0dB - 47dB)'
    category: RF Options
    dtype: real
    default: '16'
    hide: part

inputs:
  - domain: stream
    dtype: ${ type.type }
    multiplicity: 1

  - domain: message
    id: cmd
    optional: true

templates:
  imports: from gnuradio import soapy
  make: |
      None
      dev = 'driver=hackrf'
      stream_args = ''
      tune_args = ['']
      settings = ['']

      self.${id} = soapy.sink(dev, "${type}", 1, ${dev_args},
                                stream_args, tune_args, settings)
      self.${id}.set_sample_rate(0, ${samp_rate})
      self.${id}.set_bandwidth(0, ${bandwidth})
      self.${id}.set_frequency(0, ${center_freq})
      self.${id}.set_gain(0, 'AMP', ${amp})
      self.${id}.set_gain(0, 'VGA', min(max(${vga}, 0.0), 47.0))
  callbacks:
    - set_sample_rate(0, ${samp_rate})
    - set_bandwidth(0, ${bandwidth})
    - set_frequency(0, ${center_freq})
    - set_gain(0, 'AMP', ${amp})
    - set_gain(0, 'VGA', min(max(${vga}, 0.0), 47.0))

file_format: 1
