WiNRADiO G315 API for Linux
Programming information
Functions

GetDeviceList
DestroyDeviceList
OpenDevice
CloseDevice
GetDeviceInfo
IsDeviceConnected

SetPower
SetFrequency
SetAGC
SetIFGain
SetAttenuator
SetRFAmplifier
SetRefClock
SetMode
SetIFShift
SetIFBandwidth
SetSoftAGC
SetCWTone
SetFMAFSquelchLevel
EnableNotchFilter
SetNotchFilter
SetNoiseBlanker
SetISBAudioChannel
EnableAudioFilter
SetAudioFilter
SetAudioGain

SetAudioCallback
SetIFCallback
SetIFSpectrumCallback

GetRawSignalStrength
GetSignalStrengthdBm
GetInternalRSSI
GetStatistics

GetPower
GetFrequency
GetAGC
GetIFGain
GetAttenuator
GetRFAmplifier
GetRefClock
GetMode
GetIFShift
GetIFBandwidth
GetSoftAGC
GetCWTone
GetFMAFSquelchLevel
GetNotchFilter
GetNoiseBlanker
GetISBAudioChannel
GetAudioFilter
GetAudioGain

StartScanning
StopScanning

LoadCalibrationFile
UnloadCalibrationFile

SetFrontPanelLED
GetFrontPanelLED

GetAPIVersion


Types

RADIO_INFO
STATISTICS

AUDIO_CALLBACK
IF_CALLBACK
IF_SPECTRUM_CALLBACK

SCANNING_DATA
SCANNING_CALLBACK


Example

Loading API
The G315 receiver API is implemented as a single shared dynamic library wrg315api.so. It provides functions for all communication with G315 receivers connected via USB or PCI.
All the function provided by the API are "thread-safe", i.e. they can be called from any thread.
C-calling conventions is used for all the API functions.


GetDeviceList

The GetDeviceList returns information about available G315 devices that can be opened.

Declaration

int32_t GetDeviceList(RADIO_INFO **List,uint32_t *Count);

Parameters

List
The pointer to a variable that receives a pointer to RADIO_INFO array containing information about available G315 devices. If no device is available, the received value is NULL. When you no longer need the array, call the DestroyDeviceList to delete it.
This parameter cannot be NULL.

Count
The pointer to a variable that contants the number of available G315 devices.

Return value

If the function succeeds, the return value is zero. Otherwise, the return value is less then zero.


DestroyDeviceList

The DestroyDeviceList frees the memory allocated by the GetDeviceList.

Declaration

void DestroyDeviceList(RADIO_INFO *List);

Parameter

List
Pointer to array allocated by the GetDeviceList.
This can be NULL, in which case the function does nothing.

Return value

No return value.


OpenDevice

The OpenDevice opens the G315 device to make it possible to control the device using API functions.

Declaration

int32_t OpenDevice(const char *Path);

Parameter

Path
Pointer to a null-terminated string that specifies the path to a G315 device. The path included in the RADIO_INFO, returned by the GetDeviceList, can be used for this purpose. The path related to the first G315 device is usually /dev/wrg3150, the next is /dev/wrg3151, etc.

Return value

If the function succeeds, the return value is a handle to an opened G315 device. If the function fails, the return value is less than zero.


CloseDevice

The function closes the handle of the opened G315 device and allows another program to access the device.

Declaration

void CloseDevice(int32_t hRadio);

Parameter

hRadio
Handle to an opened G315 device returned by OpenDevice.

Return value

No return value.


GetDeviceInfo

The function returns information about an opened G315 device.

Declaration

int32_t GetDeviceInfo(int32_t hRadio,RADIO_INFO *Info);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Info
Pointer to a structure that receives information about the device.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


IsDeviceConnected

Checks if the receiver is still connected to the computer. It is significant only for external receivers while the internal ones will always be reported as connected.

Declaration

int32_t IsDeviceConnected(int32_t hRadio,uint32_t *Connected);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Connected
Pointer to a variable that receives a receiver connection status.
If non zero, the receiver is connected; otherwise if zero, the receiver is not connected.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetPower

The function switches the device's power on or off. This function can be used to power down the receiver in portable applications to conserve battery power.

Declaration

int32_t SetPower(int32_t hRadio,uint32_t Power);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Power
If the value is other than zero, the radio's power is on; if the value is zero, the radio's power if off.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetPower

The GetPower function returns whether the receiver's power is on or off.

Declaration

int32_t GetPower(int32_t hRadio,uint32_t *Power);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Power
Pointer to a variable that receives the power state, non zero if the power is on, zero is the power is off.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetFrequency

The function sets the frequency the device is to be tuned to.

Declaration

int32_t SetFrequency(int32_t hRadio,uint32_t Frequency);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Frequency
Specifies the frequency in Hz to tune to receiver to. Minimum and maximum possible frequency is specified in the RADIO_INFO structure, members MinFreq and MaxFreq. If this value is out from the range, the function will fail.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetFrequency

The GetFrequency function retrieves the frequency the receiver is tuned to.

Declaration

int32_t GetFrequency(int32_t hRadio,uint32_t *Frequency);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Frequency
Pointer to a variable that receives the current receiver tuned frequency in Hz.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetAGC

The SetAGC function sets the AGC value for given receiver.

Declaration

int32_t SetAGC(int32_t hRadio,int32_t AGC);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

AGC
AGC value: 0 - off, 1 - slow, 2 - medium, 3 - fast.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetAGC

The GetAGC function returns current AGC value of radio device.

Declaration

int32_t GetAGC(int32_t hRadio,int32_t *AGC);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

AGC
Pointer to a variable that receives current AGC.
AGC value: 0 - off, 1 - slow, 2 - medium, 3 - fast.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetIFGain

The function sets IF gain value for the specified receiver.

Declaration

int32_t SetIFGain(int32_t hRadio,uint32_t Gain);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Gain
IF Gain value (in dB) to be set. Possible values are from 0 to 120.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetIFGain

Retrieves the IF gain value of the receiver.

Declaration

int32_t GetIFGain(int32_t hRadio,uint32_t *Gain);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Gain
Pointer to a variable that receives the current IF gain value (in dB) of the receiver.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetAttenuator

The function activates or deactivates the RF input attenuator. It is used to prevent overloading of the receiver with strong signals.

Declaration

int32_t SetAttenuator(int32_t hRadio,uint32_t Attenuator);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Attenuator
If non zero, the RF attenuator is on; otherwise if zero, the RF attenuator is off (more sensitive).

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetAttenuator

The function returns the RF input attenuator setting.

Declaration

int32_t GetAttenuator(int32_t hRadio,uint32_t *Attenuator);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Attenuator
Pointer to a variable that receives RF input attenuator state. If the value is non zero the attenuator is enabled, if the value is zero, the attenuator is disabled.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetRFAmplifier

The function activates or deactivates the RF preamplifier. It is used to improve receiving weak signals.

Declaration

int32_t SetRFAmplifier(int32_t hRadio,uint32_t RFAmplifier);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

RFAmplifier
If non zero, the RF preamplifier is on (more sensitive), otherwise if zero, the RF preamplifier is off.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetRFAmplifier

The function returns the RF input preamplifier setting.

Declaration

int32_t GetRFAmplifier(int32_t hRadio,uint32_t *RFAmplifier);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

RFAmplifier
Pointer to a variable that receives the RF input preamplifier state. If the value is non zero the preamplifier is on; if the value is zero, the preamplifier is off.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetRefClock

Specifies the reference clock frequency and allows switching between internal and external references.

Declaration

int32_t SetRefClock(int32_t hRadio,uint32_t RefClock);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

RefClock
The frequency (in Hz) of the external reference clock. If zero is specified, the internal reference clock is used.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetRefClock

Retrieves the current reference clock frequency.

Declaration

int32_t GetRefClock(int32_t hRadio,uint32_t *RefClock);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

RefClock
Pointer to a variable that receives the current reference clock frequency.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetMode

Function for selecting the desired demodulation mode.

Declaration

int32_t SetMode(int32_t hRadio,int32_t Mode);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Mode
The code for the demodulation mode.
Possible value is one of the following:
0 -CW
1 -AM
2 -FMN
3 -FMW
4 -LSB
5 -USB
8 -AMS
13 -DSB
14 -ISB

Note
FMW mode is supported by the G315 receiver when the HasFMW member of RADIO_INFO structure is non zero. Otherwise the FMW mode is not available.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetMode

The function returns the current demodulation mode.

Declaration

int32_t GetMode(int32_t hRadio,int32_t *Mode);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Mode
Pointer to a variable that receives code of the current demodulation mode. See the SetMode for more information about possible values.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetIFShift

Function for setting the IF shift. The specified value is added to the IF2 frequency and provides the actual receiving frequency. The resulting value must not exceed the IF hardware filter bandwidth (15 kHz), thus the accepted values are in the range -7500...+7500.

Declaration

int32_t SetIFShift(int32_t hRadio,int32_t IFShift);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

IFShift
IF shift value relative to the IF crystal filter center. Possible values are from -7500 to 7500.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetIFShift

The function returns the current IF shift value.

Declaration

int32_t GetIFShift(int32_t hRadio,int32_t *IFShift);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

IFShift
Pointer to a variable that receives current IF shift value.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetIFBandwidth

Function for setting the IF bandwidth. Through this API call the filters that come after the I and Q multipliers are controlled.

Declaration

int32_t SetIFBandwidth(int32_t hRadio,uint32_t IFBandwidth);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

IFBandwidth
The IF bandwidth value in Hz. Possible values are from 1 Hz to 15000 Hz.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetIFBandwidth

The function returns current IF bandwidth value.

Declaration

int32_t GetIFBandwidth(int32_t hRadio,uint32_t *IFBandwidth);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

IFBandwidth
Pointer to a variable that receives current IF bandwidth value.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetSoftAGC

Sets the software AGC. Software AGC is used to equalize the signal level for weak signals when the hardware AGC has not acted yet, or when hardware AGC is disabled (manual IF gain).

Declaration

int32_t SetSoftAGC(int32_t hRadio,int32_t AGC);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

AGC
AGC value: 0 - off, 1 - slow, 2 - medium, 3 - fast.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetSoftAGC

The function returns current value of software AGC.

Declaration

int32_t GetSoftAGC(int32_t hRadio,int32_t *AGC);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

AGC
Pointer to a variable that receives current software AGC value.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetVolume

Function for setting the audio volume.

Declaration

int32_t SetVolume(int32_t hRadio,uint32_t Volume);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Volume
The audio volume. Possible values are from 0 up to 31.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetVolume

The function returns current value of audio volume.

Declaration

int32_t GetVolume(int32_t hRadio,uint32_t *Volume);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Volume
Pointer to a variable that receives current value of audio volume.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetCWTone

Function for setting the frequency of the audible tone when receiving CW transmissions.

Declaration

int32_t SetCWTone(int32_t hRadio,uint32_t Frequency);

Parameter

hRadio
Handle to an opened G315 device returned by OpenDevice.

Frequency
The CW tone frequency in Hz.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetCWTone

The function returns current value of CW tone frequency.

Declaration

int32_t GetCWTone(int32_t hRadio,uint32_t *Frequency);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Frequency
Pointer to a variable that receives current value of CW tone frequency in Hz.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetFMAFSquelchLevel

The function allows to set the AF squelch while demodulating FM transmissions. The level corresponds to the minimum noise level that will mute the audio output.

Declaration

int32_t SetFMAFSquelchLevel(int32_t hRadio,uint32_t Level);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Level
The FM AF squelch level. Possible values are from 0 to 99. By specifying a value of 0 the AF squelch is disabled.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetFMAFSquelchLevel

The function returns current value of FM AF squelch level.

Declaration

int32_t GetFMAFSquelchLevel(int32_t hRadio,uint32_t *Level);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Level
Pointer to a variable that receives current value of FM AF squelch level.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


EnableNotchFilter

The function activates or deactivates the IF notch filter.

Declaration

int32_t EnableNotchFilter(int32_t hRadio,uint32_t Enabled);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Enabled
If non zero, the notch filter is on, otherwise if zero, the notch filter is off.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetNotchFilter

The function allows to configure the IF notch filter. The frequency is specified relatively to the IF frequency and is limited to the IF hardware filter bandwidth, meaning from -7500 to +7500.

Declaration

int32_t SetNotchFilter(int32_t hRadio,int32_t Frequency,uint32_t Bandwidth);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Frequency
The frequency offset [Hz] of the notch filter relative to the center of the crystal IF bandwidth filter. Possible values are from -7500 to 7500.

Bandwidth
The bandwidth of the notch filter in Hz. Possible values are from 1 to 3000.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetNotchFilter

The function returns current setting of notch filter.

Declaration

int32_t GetNotchFilter(int32_t hRadio,uint32_t *Enabled,int32_t *Frequency,uint32_t *Bandwidth);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Enabled
Pointer to a variable that receives current notch filter state, non zero if the filter is enabled, zero if the filter is disabled.
This parameter can be NULL if notch filter state is not required.

Frequency
Pointer to a variable that receives current central frequency of the filter.
This parameter can be NULL if the notch filter central frequency is not required.

Bandwidth
Pointer to a variable that receives current bandwidth of the filter.
This parameter can be NULL if the notch filter bandwidth is not required.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetNoiseBlanker

The function allows to configure the noise blanker. The threshold is given as percentage of the maximum acceptable input signal.

Declaration

int32_t SetNoiseBlanker(int32_t hRadio,uint32_t Enabled,uint32_t Threshold);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Enabled
If the values is non zero, the filter is on, if the values is zero, the filter is off.

Threshold
Noise blanking threshold level given as percent of the whole signal range (0..100).

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetNoiseBlanker

The function returns current settings of noise blanker.

Declaration

int32_t GetNoiseBlanker(int32_t hRadio,uint32_t *Enabled,uint32_t *Threshold);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Enabled
Pointer to a variable that receives current noise blanker state. If it is non zero the noise blanker is enabled, if it is zero the noise blanker is disabled.
This parameter can be NULL if the noise blanker state is not required.

Threshold
Pointer to a variable that receives current threshold of the noise blanker.
This parameter can be NULL if the noise blanker threshold is not required.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetISBAudioChannel

The function allows to specify the audio channel that should be sent to the audio output when demodulating ISB transmissions.

Declaration

int32_t SetISBAudioChannel(int32_t hRadio,uint32_t Channel);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Channel

The channel that is to be sent to the audio output. 0 stands for Left (LSB) and 1 for Right (USB).

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetISBAudioChannel

The function returns currently selected ISB audio channel.

Declaration

int32_t GetISBAudioChannel(int32_t hRadio,uint32_t *Channel);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Channel
Pointer to a variable that receives currently selected ISB audio channel.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


EnableAudioFilter

The function enables or disables audio (band-pass) filter of the demodulated audio.

Declaration

int32_t EnableAudioFilter(int32_t hRadio,uint32_t Enabled);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Enabled

If non zero, the audio filter is on, otherwise if zero, the audio filter is off.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetAudioFilter

The function allows to configure the audio (band-pass) filter.

Declaration

int32_t SetAudioFilter(int32_t hRadio,uint32_t CutOffLow,uint32_t CutOffHigh,float Deemphasis);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

CutOffLow

Cut-off low frequency.

CutOffHigh

Cut-off high frequency.

Deemphasis

Negative value in dB/octave. De-emphasis is usually necessary for use with FM modulation only.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetAudioFilter

The function returns current setting of audio filter.

Declaration

int32_t GetAudioFilter(int32_t hRadio,uint32_t *Enabled,uint32_t *CutOffLow,uint32_t *CutOffHigh,float *Deemphasis);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Enabled
Pointer to a variable that receives current audio filter state, non zero if the filter is enabled, zero if the filter is disabled.
This parameter can be NULL if the audio filter state is not required.

CutOffLow
Pointer to a variable that receives current cut-off low frequency.
This parameter can be NULL if the cut-off low frequency is not required.

CutOffHigh
Pointer to a variable that receives current cut-off high frequency.
This parameter can be NULL if the cut-off high frequency is not required.

Deemphasis
Pointer to a variable that receives current value of the de-emphasis.
This parameter can be NULL if the de-emphasis is not required.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetAudioGain

Function for setting the fixed audio gain. This value is used to provide a fixed audio amplification when the software AGC is disabled.

Declaration

int32_t SetAudioGain(int32_t hRadio,uint32_t Gain);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Gain
The fixed audio gain.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetAudioGain

The function returns current fixed audio gain.

Declaration

int32_t GetAudioGain(int32_t hRadio,uint32_t *Gain);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Gain
Pointer to a variable that receives current value of fixed audio gain.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetRawSignalStrength

The function returns the "raw" signal strength value.

Declaration

int32_t GetRawSignalStrength(int32_t hRadio,uint8_t *Raw,uint8_t *RawRMS);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Raw
Pointer to a variable that receives raw value of signal strength. Possible value is from 0 to 255.
This parameter can be NULL if the value is not required.

RawRMS
Pointer to a variable that receives raw value of RMS signal strength. Possible value is from 0 to 255.
If the FMW mode is selected, this value is not valid.
This parameter can be NULL if the value is not required.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetSignalStrengthdBm

The function returns the strength of the radio signal in dBm received by the radio device.

Declaration

int32_t GetSignalStrengthdBm(int32_t hRadio,float *dBm,float *RMSdBm);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

dBm
Pointer to a variable that receives aproximated value of the signal strength in dBm.
If a calibration file is loaded using the LoadCalibrationFile, the resulting signal strength is calibrated.
This parameter can be NULL if the value is not required.

RMSdBm
Pointer to a variable that receives aproximated RMS value of the signal strength in dBm.
If a calibration file is loaded using the LoadCalibrationFile, the resulting signal strength is calibrated.
If the FMW mode is selected, this value is not valid.
This parameter can be NULL if the value is not required.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetInternalRSSI

The function returns RSSI and AGC values read from receiver hardware.

Declaration

int32_t GetInternalRSSI(int32_t hRadio,int32_t *RSSI,int32_t *AGC);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

RSSI
Pointer to a variable that receives RSSI value.
This parameter can be NULL if the value is not required.

AGC
Pointer to a variable that receives AGC value.
This parameter can be NULL if the value is not required.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetStatistics

The function returns demodulator statistics.

Declaration

int32_t GetStatistics(int32_t hRadio,STATISTICS *Statistics);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Statistics
Pointer to a structure that receives demodulator statistics.
For more information see STATISTICS
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


StartScanning

The function starts frequency scanning using currently selected mode, IF shift, IF bandwidth, AGC, attenuator and RF amplifier.

Declaration

int32_t StartScanning(int32_t hRadio,uint32_t FirstFrequency,uint32_t SpectrumSize,uint32_t Settling,SCANNING_CALLBACK Callback,void *Data);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

FirstFrequency
First frequency to be tuned when the scanning is started.

SpectrumSize
Value that represents spectrum size calculated during scanning.
Possible value is one of the following:
ValueSpectrum sizeSpectrum resolution
032750 Hz
164375 Hz
2128187.5 Hz
325693.75 Hz
451246.875 Hz
5102423.4375 Hz
Settling
AGC settling time in ms to be used when measuring the signal strength during scanning.

Callback
Pointer to a user-defined callback function. For more information, see SCANNING_CALLBACK.
This parameter cannot be NULL.

Data
Specifies a user-defined value to be passed to the scanning callback function.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.

Note
When the scanning is running, other API functions that change receiver state (e.g. SetFrequency, SetMode, etc.) can fail. The scanning has to be stopped by StopScanning function before using such functions.
Audio, IF and IF spectrum callback functions are not called during scanning.



StopScanning

The function stops scanning previously started by StartScanning. If the scanning is not running the function does nothing.

Declaration

int32_t StopScanning(int32_t hRadio);

Parameter

hRadio
Handle to an opened G315 device returned by OpenDevice.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


LoadCalibrationFile

The function loads from file the calibration data used by the GetSignalStrengthdBm function.

Declaration

int32_t LoadCalibrationFile(int32_t hRadio,const char *FilePath);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

FilePath
Pointer to a null-terminated string that specified the path of the file that contains calibration data for G315 receiver.
If the file does not contain valid G315 calibration data, the function will fail.
This parameter cannot be NULL.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


UnloadCalibrationFile

The function unloads calibration data previously loaded by the LoadCalibrationFile function. If no calibration data were loaded, the function does nothing.

Declaration

int32_t UnloadCalibrationFile(int32_t hRadio);

Parameter

hRadio
Handle to an opened G315 device returned by OpenDevice.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetAudioCallback

Functions activates or deactivates audio stream callback function.

Declaration

int32_t SetAudioCallback(int32_t hRadio,AUDIO_CALLBACK Callback,void *Data);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Callback
Pointer to a user-defined callback function. For more information, see AUDIO_CALLBACK.
If the parameter is not NULL, the audio callback is activated, otherwise if the parameter is NULL, the audio callback is deactivated.

Data
Specifies a user-defined value to be passed to the audio callback function.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetIFCallback

Functions activates or deactivates IF stream callback function.

Declaration

int32_t SetIFCallback(int32_t hRadio,IF_CALLBACK Callback,void *Data);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Callback
Pointer to a user-defined callback function. For more information, see IF_CALLBACK.
If the parameter is not NULL, the IF callback is activated, otherwise if the parameter is NULL, the IF callback is deactivated.

Data
Specifies a user-defined value to be passed to the IF callback function.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetIFSpectrumCallback

Functions activates or deactivates IF spectrum callback function.

Declaration

int32_t SetIFSpectrumCallback(int32_t hRadio,IF_SPECTRUM_CALLBACK Callback,void *Data);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

Callback
Pointer to a user-defined callback function. For more information, see IF_SPECTRUM_CALLBACK.
If the parameter is not NULL, the IF spectrum callback is activated, otherwise if the parameter is NULL, the IF spectrum callback is deactivated.

Data
Specifies a user-defined value to be passed to the IF spectrum callback function.

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


SetFrontPanelLED

The function sets LED flashing for the external (USB) receivers.

Declaration

int32_t SetFrontPanelLED(int32_t hRadio,uint32_t LED);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

LED
Possible value is one of the following:
0 -LED is continuously off
1 -LED is continuously on
2 -diagnostic state

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetFrontPanelLED

The function returns value of current LED flashing setting for the external (USB) receivers.

Declaration

int32_t GetFrontPanelLED(int32_t hRadio,uint32_t *LED);

Parameters

hRadio
Handle to an opened G315 device returned by OpenDevice.

LED
Pointer to a variable that receives value of front panel LED setting.
This parameter cannot be NULL

Return value

If the function succeeds, the return value is zero; otherwise the return value is less than zero.


GetAPIVersion

The function returns version number of the API.

Declaration

uint32_t GetAPIVersion(void);

Parameters

No parameters

Return value

API version in format:
a.b.c.d
0..7 bits: d
8..15 bits: c
16..23 bits: b
24..31 bits: a


RADIO_INFO

Declaration

#pragma pack(push,1)
typedef struct
{
    uint32_t Size;
    uint8_t  InterfaceType;
    char     Path[64];
    uint8_t  HasFMW;
    uint8_t  USVersion;
    char     SerNum[9];
    char     Model[9];
    uint32_t MinFreq;
    uint32_t MaxFreq;
} RADIO_INFO;
#pragma pack(pop)

Members

Size
Specifies size of the structure. It must be filled before calling the GetDeviceInfo.

InterfaceType
Specifies how the device is connected to the computer. 0 via PCI (internal receiver), 1 via USB (external receiver).

Path
Null-terminated string that specifies path to he device file. This can be passed to the OpenDevice as parameter.

HasFMW
If non zero the receiver supports FMW mode; otherwise if zero, the receiver does not support FMW mode.

USVersion
If non zero, the receiver is a US version. In such case the receiver does not support frequencies in ranges from 824MHz to 849MHz and from 869MHz to 894MHz (FCC restricted frequencies).

SerNum
Null-terminated string that specifies serial number of the device.

Model
Null-terminated string that specifies device model.

MinFreq
Minimum frequency in Hz supported by the receiver.

MaxFreq
Maximum frequency in Hz supported by the receiver.


STATISTICS

Declaration

#pragma pack(push,1)
typedef struct
{
    uint32_t Size;
    float    AMDepth;
    int32_t  FMDeviation;
    float    TuneError;
    uint32_t NoiseLevel;
} STATISTICS;
#pragma pack(pop)

Members

Size
Specifies size of the structure. It must be filled before calling the GetStatistics.

AMDepth
Specifies AM depth [%] for current transmission.
Value of this member is valid only when AM or AMS mode is selected.

FMDeviation
Specifies FM deviation in Hz.
Value of this member is valid only when FMN or FMW mode is selected.

TuneError
Tuning error in Hz.
The value is valid only if the receiver is tuned to a transmissions and mode is not FMW.

NoiseLevel
Noise level as a percentage of white noise.


AUDIO_CALLBACK

The AUDIO_CALLBACK function is a user-defined callback function used in the SetAudioCallback function as parameter. It retrieves audio samples read from the G315 receiver.

Definition

typedef void (*AUDIO_CALLBACK)(int16_t *UnfilteredAudio,int16_t *FilteredAudio,uint32_t Count,void *Data);

Parameters

UnfilteredAudio
Pointer to a buffer with unfiltered audio samples that are not affected by audio filter and volume. Sample format is 16 bit signed and the sample rate is 32kHz. The pointer is valid only in current call of the callback function.

FilteredAudio
Pointer to a buffer with audio samples. Sample format is 16 bit signed and the sample rate is 32kHz. The pointer is valid only in current call of the callback function.

Count
Specifies number of samples in the buffers.

Data
Specifies the user-defined value given in the SetAudioCallback function.

Return value

No return value.

Note
The callback is called from thread created inside API. If any shared data are accessed inside the callback, the synchronization is required.
Do not call any G315 API function inside the callback, otherwise it will cause a deadlock.



IF_CALLBACK

The IF_CALLBACK function is a user-defined callback function used in the SetIFCallback function as parameter. It retrieves IF samples read from the G315 receiver.

Definition

typedef void (*IF_CALLBACK)(int16_t *IF,uint32_t Count,void *Data);

Parameters

IF
Pointer to a buffer with IF samples. Sample format is 16 bit signed and the sample rate is 48kHz. The pointer is valid only in current call of the callback function.

Count
Specifies number of samples in the buffer.

Data
Specifies the user-defined value given in the SetIFCallback function.

Return value

No return value.

Note
The callback is called from a thread created inside API. If any shared data are accessed inside the callback, the synchronization is required.
Do not call any G315 API function inside the callback, otherwise it will cause a deadlock.



IF_SPECTRUM_CALLBACK

The IF_SPECTRUM_CALLBACK function is a user-defined callback function used in the SetIFSpectrumCallback function as parameter. It retrieves IF spectrum calculated from IF signal read from the G315 receiver.

Definition

typedef void (*IF_SPECTRUM_CALLBACK)(float *IFSpectrum,uint32_t Count,void *Data);

Parameters

IFSpectrum
Pointer to a buffer containing spectrum data in dB. The buffer always contains whole IF spectrum. Spectrum is 24kHz wide.

Count
Specifies number of spectrum data items. The value should be always 512, this means the spectrum resolution is 46.875 Hz.

Data
Specifies the user-defined value given in the SetIFSpectrumCallback function.

Return value

No return value.

Note
The callback is called from a thread created inside API. If any shared data are accessed inside the callback, the synchronization is required.
Do not call any G315 API function inside the callback, otherwise it will cause a deadlock.



SCANNING_DATA

The structure is passed to scanning callback function during scanning started by StartScanning function.

Declaration

#pragma pack(push,1)
typedef struct
{
    uint32_t   Type;
    union
    {
        struct
        {
            uint32_t LastFrequency;
            uint32_t NextFreuency;
        } NextStep;
        struct
        {
            uint32_t Frequency;
            float    dBm;
            uint8_t  Raw;
            float   *Spectrum;
            uint32_t SpectrumSize;
        } Result;
    };
} SCANNING_DATA;
#pragma pack(pop)

Members

Type
Specifies which part of the structure is valid.
If 0, NextStep member structure is valid.
If 1, Result member structure is valid.

NextStep
Specifies information for next scanning step.

    LastFrequency
    Specifies frequency from the last scanning step.

    NextFrequency
    Specifies frequency for the next scanning step. It must be filled by the user
    when the callback function is called.

Result
Contains scanning result from the last scanning step.

    Frequency
Specifies frequency of the scanning step.

    dBm
    Specifies value of signal strength in dBm.
    This member is valid only if AGC is slow, medium or fast before scanning is started by the StartScanning function.

    Raw
    Specifies raw value of signal strength.
    This member is valid only if AGC is slow, medium of fast before scanning is started by the StartScanning function.

    Spectrum
    Pointer to buffer that contains spectrum data in dB.
    This member is valid only if mode is not FMW before scanning is started by the StartScanning function.

    SpectrumSize
    Specifies number of items in the spectrum buffer.
    This member is valid only if mode is not FMW before scanning is started by the StartScanning function.



Note
It is possible the the G315 API asks for the frequency of the next scanning step before it returns result of the current scanning step.


SCANNING_CALLBACK

The SCANNING_CALLBACK function is a user-defined callback function used in the StartScanning function as parameter. It retrieves scanning results and is used for scanning frequency selection.

Definition

typedef void (*SCANNING_CALLBACK)(SCANNING_DATA *ScanningData,void *Data);

Parameters

ScanningData
Pointer to structure that contains scanning data.

Data
Specifies the user-defined value given in the StartScanning function.

Return value

If non zero the scanning will continue, otherwise if zero, scanning will be aborted. In aby case, the StopScanning has to be called to proper scanning stop. It must not be called inside the scanning callback.

Note
The callback is called from thread created inside API. If any shared data are accessed inside the callback, the synchronization is required.
Do not call any G315 API function inside the callback, otherwise it will cause a deadlock.




Loading API


Header file wrg315api.h

#ifndef __WRG315API_H__
#define __WRG315API_H__

#include <stdint.h>

#pragma pack(push,1)

typedef struct
{
    uint32_t    Size;
    uint8_t     InterfaceType;
    char        Path[64];
    uint8_t     HasFMW;
    uint8_t     USVersion;
    char        SerNum[9];
    char        Model[9];
    uint32_t    MinFreq;
    uint32_t    MaxFreq;
} RADIO_INFO;

typedef struct
{
    uint32_t Type;
    union
    {
        struct
        {
            uint32_t LastFrequency;
            uint32_t NextFrequency;
        } NextStep;
        struct
        {
            uint32_t Frequency;
            float    Slevel;
            uint8_t  RAW;
            float   *Spectrum;
            uint32_t SpectrumSize; 
        } Result;
    };
} SCANNING_DATA;

typedef struct
{
    uint32_t Size;
    float    AMDepth;
    int32_t  FMDeviation;
    float    TuneError;
    uint32_t NoiseLevel;
} STATISTICS;

#pragma pack(pop)


#ifdef __cplusplus
extern "C"
{
#endif

typedef void (*AUDIO_CALLBACK)(int16_t *Audio,int16_t *FilteredAudio,uint32_t Count,void *Data);
typedef void (*IF_CALLBACK)(int16_t *IF,uint32_t Count,void *Data);
typedef void (*IF_SPECTRUM_CALLBACK)(float *Spectrum,uint32_t Count,void *Data);
typedef uint8_t (*SCANNING_CALLBACK)(SCANNING_DATA *ScanningData,void *Data);

typedef int32_t (*GET_DEVICE_LIST)(RADIO_INFO **List,uint32_t *Count);
typedef void (*DESTROY_DEVICE_LIST)(RADIO_INFO *List);
typedef int32_t (*OPEN_DEVICE)(const char *DevPath);
typedef void (*CLOSE_DEVICE)(int32_t Handle);
typedef int32_t (*GET_DEVICE_INFO)(int32_t Handle,RADIO_INFO *Info);
typedef int32_t (*GET_POWER)(int32_t Handle,uint32_t *Power);
typedef int32_t (*SET_POWER)(int32_t Handle,uint32_t Power);
typedef int32_t (*GET_FREQUENCY)(int32_t Handle,uint32_t *Frequency);
typedef int32_t (*SET_FREQUENCY)(int32_t Handle,uint32_t Frequency);
typedef int32_t (*GET_VOLUME)(int32_t Handle,uint32_t *Volume);
typedef int32_t (*SET_VOLUME)(int32_t Handle,uint32_t Volume);
typedef int32_t (*GET_MODE)(int32_t Handle,int32_t *Mode);
typedef int32_t (*SET_MODE)(int32_t Handle,int32_t Mode);
typedef int32_t (*SET_AUDIO_CALLBACK)(int32_t Handle,AUDIO_CALLBACK Callback,void *Data);
typedef int32_t (*SET_IF_CALLBACK)(int32_t Handle,IF_CALLBACK Callback,void *Data);
typedef int32_t (*SET_IF_SPECTRUM_CALLBACK)(int32_t Handle,IF_SPECTRUM_CALLBACK Callback,void *Data);
typedef int32_t (*GET_IF_SHIFT)(int32_t Handle,int32_t *Shift);
typedef int32_t (*SET_IF_SHIFT)(int32_t Handle,int32_t Shift);
typedef int32_t (*GET_IF_BANDWIDTH)(int32_t Handle,uint32_t *Bandwidth);
typedef int32_t (*SET_IF_BANDWIDTH)(int32_t Handle,uint32_t Bandwidth);
typedef int32_t (*GET_AGC)(int32_t Handle,int32_t *AGC);
typedef int32_t (*SET_AGC)(int32_t Handle,int32_t AGC);
typedef int32_t (*GET_IF_GAIN)(int32_t Handle,uint32_t *Gain);
typedef int32_t (*SET_IF_GAIN)(int32_t Handle,uint32_t Gain);
typedef int32_t (*ENABLE_AUDIO_FILTER)(int32_t Handle,uint32_t Enabled);
typedef int32_t (*GET_AUDIO_FILTER)(int32_t Handle,uint32_t *Enabled,uint32_t *CutOffLow,uint32_t *CutOffHigh,float *Deemphasis);
typedef int32_t (*SET_AUDIO_FILTER)(int32_t Handle,uint32_t CutOffLow,uint32_t CutOffHigh,float Deemphasis);
typedef int32_t (*GET_SOFT_AGC)(int32_t Handle,int32_t *AGC);
typedef int32_t (*SET_SOFT_AGC)(int32_t Handle,int32_t AGC);
typedef int32_t (*GET_NOTCH_FILTER)(int32_t Handle,uint32_t *Enabled,int32_t *Frequency,uint32_t *Bandwidth);
typedef int32_t (*SET_NOTCH_FILTER)(int32_t Handle,int32_t Frequency,uint32_t Bandwidth);
typedef int32_t (*ENABLE_NOTCH_FILTER)(int32_t Handle,uint32_t Enabled);
typedef int32_t (*GET_NOISE_BLANKER)(int32_t Handle,uint32_t *Enabled,uint32_t *Threshold);
typedef int32_t (*SET_NOISE_BLANKER)(int32_t Handle,uint32_t Enabled,uint32_t Threshold);
typedef int32_t (*LOAD_CALIBRATION_FILE)(int32_t Handle,const char *FilePath);
typedef int32_t (*UNLOAD_CALIBRATION_FILE)(int32_t Handle);
typedef int32_t (*GET_ATTENUATOR)(int32_t Handle,uint32_t *Attenuator);
typedef int32_t (*SET_ATTENUATOR)(int32_t Handle,uint32_t Attenuator);
typedef int32_t (*GET_RF_AMPLIFIER)(int32_t Handle,uint32_t *RFAmplifier);
typedef int32_t (*SET_RF_AMPLIFIER)(int32_t Handle,uint32_t RFAmplifier);
typedef int32_t (*GET_INTERNAL_RSSI)(int32_t Handle,int32_t *RSSI,int32_t *AGC);
typedef int32_t (*GET_RAW_SIGNAL_STRENGTH)(int32_t Handle,uint8_t *Raw,uint8_t *RawRMS);
typedef int32_t (*GET_SIGNAL_STRENGTH_DBM)(int32_t Handle,float *dBm,float *dBmRMS);
typedef int32_t (*GET_REF_CLOCK)(int32_t Handle,uint32_t *RefClock);
typedef int32_t (*SET_REF_CLOCK)(int32_t Handle,uint32_t RefClock);
typedef int32_t (*STOP_SCANNING)(int32_t Handle);
typedef int32_t (*START_SCANNING)(int32_t Handle,uint32_t FirstFrequency,uint32_t SpectrumSize,uint32_t Settling,SCANNING_CALLBACK Callback,void *Data);
typedef int32_t (*GET_FRONT_PANEL_LED)(int32_t Handle,uint32_t *Led);
typedef int32_t (*SET_FRONT_PANEL_LED)(int32_t Handle,uint32_t Led);
typedef int32_t (*IS_DEVICE_CONNECTED)(int32_t Handle,uint32_t *Connected);
typedef int32_t (*GET_AUDIO_GAIN)(int32_t Handle,uint32_t *Gain);
typedef int32_t (*SET_AUDIO_GAIN)(int32_t Handle,uint32_t Gain);
typedef int32_t (*GET_FMAF_SQUELCH_LEVEL)(int32_t Handle,uint32_t *Level);
typedef int32_t (*SET_FMAF_SQUELCH_LEVEL)(int32_t Handle,uint32_t Level);
typedef int32_t (*GET_ISB_AUDIO_CHANNEL)(int32_t Handle,uint32_t *Channel);
typedef int32_t (*SET_ISB_AUDIO_CHANNEL)(int32_t Handle,uint32_t Channel);
typedef int32_t (*GET_CW_TONE)(int32_t Handle,uint32_t *Frequency);
typedef int32_t (*SET_CW_TONE)(int32_t Handle,uint32_t Frequency);
typedef int32_t (*GET_STATISTICS)(int32_t Handle,STATISTICS *Statistics);
typedef uint32_t (*GET_API_VERSION)(void);

#ifdef __cplusplus
};
#endif


extern GET_DEVICE_LIST GetDeviceList;
extern DESTROY_DEVICE_LIST DestroyDeviceList;
extern OPEN_DEVICE OpenDevice;
extern CLOSE_DEVICE CloseDevice;
extern GET_DEVICE_INFO GetDeviceInfo;
extern GET_POWER GetPower;
extern SET_POWER SetPower;
extern GET_FREQUENCY GetFrequency;
extern SET_FREQUENCY SetFrequency;
extern GET_VOLUME GetVolume;
extern SET_VOLUME SetVolume;
extern GET_MODE GetMode;
extern SET_MODE SetMode;
extern SET_AUDIO_CALLBACK SetAudioCallback;
extern SET_IF_CALLBACK SetIFCallback;
extern SET_IF_SPECTRUM_CALLBACK SetIFSpectrumCallback;
extern GET_IF_SHIFT GetIFShift;
extern SET_IF_SHIFT SetIFShift;
extern GET_IF_BANDWIDTH GetIFBandwidth;
extern SET_IF_BANDWIDTH SetIFBandwidth;
extern GET_AGC GetAGC;
extern SET_AGC SetAGC;
extern GET_IF_GAIN GetIFGain;
extern SET_IF_GAIN SetIFGain;
extern ENABLE_AUDIO_FILTER EnableAudioFilter;
extern GET_AUDIO_FILTER GetAudioFilter;
extern SET_AUDIO_FILTER SetAudioFilter;
extern GET_SOFT_AGC GetSoftAGC;
extern SET_SOFT_AGC SetSoftAGC;
extern GET_NOTCH_FILTER GetNotchFilter;
extern SET_NOTCH_FILTER SetNotchFilter;
extern ENABLE_NOTCH_FILTER EnableNotchFilter;
extern GET_NOISE_BLANKER GetNoiseBlanker;
extern SET_NOISE_BLANKER SetNoiseBlanker;
extern LOAD_CALIBRATION_FILE LoadCalibrationFile;
extern UNLOAD_CALIBRATION_FILE UnloadCalibrationFile;
extern GET_ATTENUATOR GetAttenuator;
extern SET_ATTENUATOR SetAttenuator;
extern GET_RF_AMPLIFIER GetRFAmplifier;
extern SET_RF_AMPLIFIER SetRFAmplifier;
extern GET_INTERNAL_RSSI GetInternalRSSI;
extern GET_RAW_SIGNAL_STRENGTH GetRawSignalStrength;
extern GET_SIGNAL_STRENGTH_DBM GetSignalStrengthdBm;
extern GET_REF_CLOCK GetRefClock;
extern SET_REF_CLOCK SetRefClock;
extern STOP_SCANNING StopScanning;
extern START_SCANNING StartScanning;
extern GET_FRONT_PANEL_LED GetFrontPanelLED;
extern SET_FRONT_PANEL_LED SetFrontPanelLED;
extern IS_DEVICE_CONNECTED IsDeviceConnected;
extern GET_AUDIO_GAIN GetAudioGain;
extern SET_AUDIO_GAIN SetAudioGain;
extern GET_FMAF_SQUELCH_LEVEL GetFMAFSquelchLevel;
extern SET_FMAF_SQUELCH_LEVEL SetFMAFSquelchLevel;
extern GET_ISB_AUDIO_CHANNEL GetISBAudioChannel;
extern SET_ISB_AUDIO_CHANNEL SetISBAudioChannel;
extern GET_CW_TONE GetCWTone;
extern SET_CW_TONE SetCWTone;
extern GET_STATISTICS GetStatistics;
extern GET_API_VERSION GetAPIVersion;

#endif //__WRG315API_H__


C/C++ file

#include <dlfcn.h>
#include <stdio.h>
#include <errno.h>
#include "wrg315api.h"

GET_DEVICE_LIST GetDeviceList=NULL;
DESTROY_DEVICE_LIST DestroyDeviceList=NULL;
OPEN_DEVICE OpenDevice=NULL;
CLOSE_DEVICE CloseDevice=NULL;
GET_DEVICE_INFO GetDeviceInfo=NULL;
GET_POWER GetPower=NULL;
SET_POWER SetPower=NULL;
GET_FREQUENCY GetFrequency=NULL;
SET_FREQUENCY SetFrequency=NULL;
GET_VOLUME GetVolume=NULL;
SET_VOLUME SetVolume=NULL;
GET_MODE GetMode=NULL;
SET_MODE SetMode=NULL;
SET_AUDIO_CALLBACK SetAudioCallback=NULL;
SET_IF_CALLBACK SetIFCallback=NULL;
SET_IF_SPECTRUM_CALLBACK SetIFSpectrumCallback=NULL;
GET_IF_SHIFT GetIFShift=NULL;
SET_IF_SHIFT SetIFShift=NULL;
GET_IF_BANDWIDTH GetIFBandwidth=NULL;
SET_IF_BANDWIDTH SetIFBandwidth=NULL;
GET_AGC GetAGC=NULL;
SET_AGC SetAGC=NULL;
GET_IF_GAIN GetIFGain=NULL;
SET_IF_GAIN SetIFGain=NULL;
ENABLE_AUDIO_FILTER EnableAudioFilter=NULL;
GET_AUDIO_FILTER GetAudioFilter=NULL;
SET_AUDIO_FILTER SetAudioFilter=NULL;
GET_SOFT_AGC GetSoftAGC=NULL;
SET_SOFT_AGC SetSoftAGC=NULL;
GET_NOTCH_FILTER GetNotchFilter=NULL;
SET_NOTCH_FILTER SetNotchFilter=NULL;
ENABLE_NOTCH_FILTER EnableNotchFilter=NULL;
GET_NOISE_BLANKER GetNoiseBlanker=NULL;
SET_NOISE_BLANKER SetNoiseBlanker=NULL;
LOAD_CALIBRATION_FILE LoadCalibrationFile=NULL;
UNLOAD_CALIBRATION_FILE UnloadCalibrationFile=NULL;
GET_ATTENUATOR GetAttenuator=NULL;
SET_ATTENUATOR SetAttenuator=NULL;
GET_RF_AMPLIFIER GetRFAmplifier=NULL;
SET_RF_AMPLIFIER SetRFAmplifier=NULL;
GET_INTERNAL_RSSI GetInternalRSSI=NULL;
GET_RAW_SIGNAL_STRENGTH GetRawSignalStrength=NULL;
GET_SIGNAL_STRENGTH_DBM GetSignalStrengthdBm=NULL;
GET_REF_CLOCK GetRefClock=NULL;
SET_REF_CLOCK SetRefClock=NULL;
STOP_SCANNING StopScanning=NULL;
START_SCANNING StartScanning=NULL;
GET_FRONT_PANEL_LED GetFrontPanelLED=NULL;
SET_FRONT_PANEL_LED SetFrontPanelLED=NULL;
IS_DEVICE_CONNECTED IsDeviceConnected=NULL;
GET_AUDIO_GAIN GetAudioGain=NULL;
SET_AUDIO_GAIN SetAudioGain=NULL;
GET_FMAF_SQUELCH_LEVEL GetFMAFSquelchLevel=NULL;
SET_FMAF_SQUELCH_LEVEL SetFMAFSquelchLevel=NULL;
GET_ISB_AUDIO_CHANNEL GetISBAudioChannel=NULL;
SET_ISB_AUDIO_CHANNEL SetISBAudioChannel=NULL;
GET_CW_TONE GetCWTone=NULL;
SET_CW_TONE SetCWTone=NULL;
GET_STATISTICS GetStatistics=NULL;
GET_API_VERSION GetAPIVersion=NULL;

void *hWRG315API=NULL;

#define GET_PROC(t,f)               \
    f=(t)dlsym(hWRG315API,"" #f);   \
    if(f==NULL)                     \
    {                               \
                                    \
        fprintf(stderr,"Unable to load valid G315 API.\n"); \
        fprintf(stderr,"Unable to find " #f " procedure.\n");\
        dlclose(hWRG315API);        \
        hWRG315API=NULL;            \
        return 0;                   \
    }


//LoadG315API function loads API and returns 1 if the api is loaded successfully, 0 if function fails.
int LoadG315API(void)
{
    if(hWRG315API)
    {
        return 1;
    }
    else
    {
        hWRG315API=dlopen("wrg315api.so",RTLD_LAZY);

        if(hWRG315API==NULL)
        {
            fprintf(stderr,"Unable to load wrg315api.so shared library  (%s).\n",dlerror());
            return 0;
        }
        else
        {
            GET_PROC(GET_DEVICE_LIST,GetDeviceList)
            GET_PROC(DESTROY_DEVICE_LIST,DestroyDeviceList)
            GET_PROC(OPEN_DEVICE,OpenDevice)
            GET_PROC(CLOSE_DEVICE,CloseDevice)
            GET_PROC(GET_DEVICE_INFO,GetDeviceInfo)
            GET_PROC(GET_POWER,GetPower)
            GET_PROC(SET_POWER,SetPower)
            GET_PROC(GET_FREQUENCY,GetFrequency)
            GET_PROC(SET_FREQUENCY,SetFrequency)
            GET_PROC(GET_VOLUME,GetVolume)
            GET_PROC(SET_VOLUME,SetVolume)
            GET_PROC(GET_MODE,GetMode)
            GET_PROC(SET_MODE,SetMode)
            GET_PROC(SET_AUDIO_CALLBACK,SetAudioCallback)
            GET_PROC(SET_IF_CALLBACK,SetIFCallback)
            GET_PROC(SET_IF_SPECTRUM_CALLBACK,SetIFSpectrumCallback)
            GET_PROC(GET_IF_SHIFT,GetIFShift)
            GET_PROC(SET_IF_SHIFT,SetIFShift)
            GET_PROC(GET_IF_BANDWIDTH,GetIFBandwidth)
            GET_PROC(SET_IF_BANDWIDTH,SetIFBandwidth)
            GET_PROC(GET_AGC,GetAGC)
            GET_PROC(SET_AGC,SetAGC)
            GET_PROC(GET_IF_GAIN,GetIFGain)
            GET_PROC(SET_IF_GAIN,SetIFGain)
            GET_PROC(ENABLE_AUDIO_FILTER,EnableAudioFilter)
            GET_PROC(GET_AUDIO_FILTER,GetAudioFilter)
            GET_PROC(SET_AUDIO_FILTER,SetAudioFilter)
            GET_PROC(GET_SOFT_AGC,GetSoftAGC)
            GET_PROC(SET_SOFT_AGC,SetSoftAGC)
            GET_PROC(GET_NOTCH_FILTER,GetNotchFilter)
            GET_PROC(SET_NOTCH_FILTER,SetNotchFilter)
            GET_PROC(ENABLE_NOTCH_FILTER,EnableNotchFilter)
            GET_PROC(GET_NOISE_BLANKER,GetNoiseBlanker)
            GET_PROC(SET_NOISE_BLANKER,SetNoiseBlanker)
            GET_PROC(LOAD_CALIBRATION_FILE,LoadCalibrationFile)
            GET_PROC(UNLOAD_CALIBRATION_FILE,UnloadCalibrationFile)
            GET_PROC(GET_ATTENUATOR,GetAttenuator)
            GET_PROC(SET_ATTENUATOR,SetAttenuator)
            GET_PROC(GET_RF_AMPLIFIER,GetRFAmplifier)
            GET_PROC(SET_RF_AMPLIFIER,SetRFAmplifier)
            GET_PROC(GET_INTERNAL_RSSI,GetInternalRSSI)
            GET_PROC(GET_RAW_SIGNAL_STRENGTH,GetRawSignalStrength)
            GET_PROC(GET_SIGNAL_STRENGTH_DBM,GetSignalStrengthdBm)
            GET_PROC(GET_REF_CLOCK,GetRefClock)
            GET_PROC(SET_REF_CLOCK,SetRefClock)
            GET_PROC(STOP_SCANNING,StopScanning)
            GET_PROC(START_SCANNING,StartScanning)
            GET_PROC(GET_FRONT_PANEL_LED,GetFrontPanelLED)
            GET_PROC(SET_FRONT_PANEL_LED,SetFrontPanelLED)
            GET_PROC(IS_DEVICE_CONNECTED,IsDeviceConnected)
            GET_PROC(GET_AUDIO_GAIN,GetAudioGain)
            GET_PROC(SET_AUDIO_GAIN,SetAudioGain)
            GET_PROC(GET_FMAF_SQUELCH_LEVEL,GetFMAFSquelchLevel)
            GET_PROC(SET_FMAF_SQUELCH_LEVEL,SetFMAFSquelchLevel)
            GET_PROC(GET_ISB_AUDIO_CHANNEL,GetISBAudioChannel)
            GET_PROC(SET_ISB_AUDIO_CHANNEL,SetISBAudioChannel)
            GET_PROC(GET_CW_TONE,GetCWTone)
            GET_PROC(SET_CW_TONE,SetCWTone)
            GET_PROC(GET_STATISTICS,GetStatistics)
            GET_PROC(GET_API_VERSION, GetAPIVersion)

            return 1;
        }
    }
}

//UnloadG315API function unloads the api
void UnloadG315API(void)
{
    if(hWRG315API)
    {
        dlclose(hWRG315API);
        hWRG315API=0;
    }
}