id: cariboulite_source
label: CaribouLite Source
flags: [python, throttle]

parameters:
  - 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: 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: gain
    label: 'IF Gain (0dB - 40dB)'
    category: RF Options
    dtype: real
    default: '16'
    hide: part

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

inputs:
  - domain: message
    id: cmd
    optional: true

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

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

      self.${id} = soapy.source(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, 'LNA', min(max(${gain}, 0.0), 40.0))
      self.${id}.set_gain(0, 'VGA', min(max(${vga}, 0.0), 62.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, 'LNA', min(max(${gain}, 0.0), 40.0))
    - set_gain(0, 'VGA', min(max(${vga}, 0.0), 62.0))

file_format: 1
