Functions GetDeviceList DestroyDeviceList OpenDevice CloseDevice GetRadioInfo SetPower SetFrequency SetAGC SetGain SetAttenuator SetMode SetIFShift SetIFBandwidth SetSoftAGC SetVolume SetCWTone SetFMAFSquelchLevel SetNotchFilter SetNoiseBlanker SetISBAudioChannel GetPower GetFrequency GetAGC GetGain GetAttenuator GetMode GetIFShift GetIFBandwidth GetSoftAGC GetVolume GetCWTone GetFMAFSquelchLevel GetNotchFilter GetNoiseBlanker GetISBAudioChannel GetRawSignalStrength GetSignalStrength LoadCalibrationFile ResetCalibration StartStreaming StopStreaming IsDeviceConnected GetInterface GetAPIVersion Structures RADIO_INFO RADIO_DESC Examples Loading and initializing API |
GetDeviceList The GetDeviceList returns information about available G313 devices that can be opened. Declaration int GetDeviceList(RADIO_DESC **List,int *Count); Parameters List The pointer to a variable that receives a pointer to RADIO_DESC array containing information about available G313 devices. If it is not available receiver the received value is NULL. When you no longer need the array, call the DestroyDeviceList to delete it. This cannot be NULL. Count The pointer to a variable that receiver number of available G313 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_DESC *List); Parameter List Pointer to array allocated by the GetDeviceList. This can be NULL, in this case the function does nothing. Return value No return value. OpenDevice The OpenDevice opens the G313 device to allow you to control the device using the other API functions. Declaration int OpenDevice(const char *Path); Parameter Path Pointer to a null-terminated string that specifies the path to the device file that represents G313 device. It can be used the path included in the RADIO_DESC returned by the GetDeviceList. The path of the device file of the first G313 device is usually /dev/wrg3130, the next is /dev/wrg3131, etc. Return value If the function succeeds, the return value is a handle to opened G313 device. If the function fails, the return value is less than zero. CloseDevice The function closes the handle of the opened G313 device. Declaration void CloseDevice(int hRadio); Parameter hRadio Handle to opened G313 device returned by the OpenDevice. Return value No return value. GetRadioInfo The function returns information about opened G313 device. Declaration int GetRadioInfo(int hRadio,RADIO_INFO *Info); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Info Pointer to structure that receives information about the device. This 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 int SetPower(int hRadio,int Power); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Power If 1, the radio's power is on, if 0, 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 int GetPower(int hRadio,int *Power); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Power Pointer to a variable that receives the power state, 1 if the power is on,0 is the power is off. 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 int SetFrequency(int hRadio,unsigned int Frequency); Parameters hRadio Handle to opened G313 device returned by the 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 int GetFrequency(int hRadio,unsigned int *Frequency); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Frequency Pointer to a variable that receives current receiver 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 int SetAGC(int hRadio,int AGC); Parameters hRadio Handle to opened G313 device returned by the 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 int GetAGC(int hRadio,int *AGC); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. AGC Pointer to a variable that receives current AGC. 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 int SetIFGain(int hRadio,unsigned int Gain); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Gain IF Gain value to be set. Possible values are from 0 to 100, otherwise the function will fail. 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 int GetIFGain(int hRadio,unsigned int *Gain); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Gain Pointer to a variable that receives current IF gain value 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 int SetAttenuator(int hRadio,int Attenuator); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Attenuator If 1, the RF attenuator is on, otherwise if 0, 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 int GetAttenuator(int hRadio,int *Attenuator); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Attenuator Pointer to a variable that receives RF input attenuator state. If the value is 1 the attenuator is enabled, if the value is 0, 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. SetMode Function for selecting the desired demodulation mode. Declaration int SetMode(int hRadio,int Mode); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Mode The code for the demodulation mode 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 int GetMode(int hRadio,int *Mode); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Mode Pointer to a variable that receives code of the current demodulation mode. See the SetMode for more information. 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 (15kHz for G313), thus the accepted values are in the range -7500...+7500. Declaration int SetIFShift(int hRadio,int IFShift); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. IFShift IF shift value relative to the IF crystal filter center. Possible values are from -7500 to 7500, otherwise the function will fail. Return value If the function succeeds, the return value is zero, otherwise the return value is less than zero. GetIFShift The function returns current IF shift value. Declaration int GetIFShift(int hRadio,int *IFShift); Parameters hRadio Handle to opened G313 device returned by the 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. Values in the 1Hz...15kHz range are accepted. Through this API call the filters that come after the I and Q multipliers are controlled. Declaration int SetIFBandwidth(int hRadio,unsigned int IFBandwidth); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. IFBandwidth The IF bandwidth value in Hz. Possible values are from 1 to 15000, otherwise the function will fail. 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 int GetIFBandwidth(int hRadio,unsigned int *IFBandwidth); Parameters hRadio Handle to opened G313 device returned by the 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 (Automatic Gain Control) 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 int SetSoftAGC(int hRadio,int AGC); Parameters hRadio Handle to opened G313 device returned by the 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 int GetSoftAGC(int hRadio,int *AGC); Parameters hRadio Handle to opened G313 device returned by the 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 audition volume. It can be any value between 0 and 31. Declaration int SetVolume(int hRadio,unsigned int Volume); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Volume The audition volume. Possible values are from 0 to 31, otherwise the function will fail. 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 audition volume. Declaration int GetVolume(int hRadio,unsigned int *Volume); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Volume Pointer to a variable that receives current value of audition 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 int SetCWTone(int hRadio,unsigned int Frequency); Parameter hRadio Handle to opened G313 device returned by the 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 int GetCWTone(int hRadio,unsigned int *Frequency); Parameters hRadio Handle to opened G313 device returned by the 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. By specifying a value of 0 the AF squelch is disabled. Declaration int SetFMAFSquelchLevel(int hRadio,unsigned int Level); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Level The FM AF squelch level. Possible values are from 0 to 99, otherwise the function will fail. 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 int GetFMAFSquelchLevel(int hRadio,unsigned int *Level); Parameters hRadio Handle to opened G313 device returned by the 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. 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 int SetNotchFilter(int hRadio,int Active,int Frequency,unsigned int Bandwidth); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Active If the values is 1, the filter is active, if the values is 0, the filter is not active. 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, otherwise the function fail. Bandwidth The bandwidth of the notch filter in Hz. Possible values are from 1 to 3000, otherwise the function will fail. 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 int GetNotchFilter(int hRadio,int *Active,int *Frequency,unsigned int *Bandwidth); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Active Pointer to a variable that receives current notch filter state, 0 if the filter is disabled, 1 if the filter is enabled. This parameter can be NULL. Frequency Pointer to a variable that receives current central frequency of the filter. This parameter can be NULL. Bandwidth Pointer to a variable that receives current bandwidth of the filter. This parameter can be NULL. 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 int SetNoiseBlanker(int hRadio,int Active,unsigned int Threshold); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Active If the values is 1, the filter is active, if the values is 0, the filter is not active. 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 int GetNoiseBlanker(int hRadio,int *Active,unsigned int *Threshold); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Active Pointer to a variable that receives current noise blanker state. If it is 0 the noise blanker is disabled, if it is 1 the noise blanker is enabled. This parameter can be NULL. Threshold Pointer to a variable that receives current threshold of the noise blanker. This parameter can be NULL. 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 int SetISBAudioChannel(int hRadio,unsigned int Channel); Parameters hRadio Handle to opened G313 device returned by the 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 int GetISBAudioChannel(int hRadio,unsigned int *Channel); Parameters hRadio Handle to opened G313 device returned by the 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. GetRawSignalStrength The GetRawSignalStrength function returns current "raw" signal strength value. Declaration int GetRawSignalStrength(int hRadio,unsigned char *Raw); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Raw Pointer to a variable that receives raw signal strength in interval from 0 to 255. This parameter cannot be NULL. Return value If the function succeeds, the return value is zero, otherwise the return value is less than zero. GetSignalStrength The GetSignalStrength function returns calibrated value [dBm] of current signal strength. It is needed to load calibration file using the LoadCalibrationFile function before first use of GetSignalStrength, otherwise the returned value will be inaccurate. Declaration int GetSignalStrength(int hRadio,double *SignalStrength); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. SignalStrength Pointer to a variable that receives calibrated signal strength value in dBm. This parameter cannot be NULL. 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 required by the GetSignalStrength function. Declaration int LoadCalibrationFile(int hRadio,const char *Path); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Path Pointer to a null-terminated string that specified the path of the file that contains calibration data for G313 receiver. If the file does not contain valid G313 calibration data, the function fails. This parameter cannot be NULL. Return value If the function succeeds, the return value is zero, otherwise the return value is less than zero. ResetCalibration The function unload calibration data previously loaded by the LoadCalibrationFile function. If no calibration data are loaded, the function does nothing. Declaration int ResetCalibration(int hRadio); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Return value If the function succeeds, the return value is zero, otherwise the return value is less than zero. StartStreaming The function starts audio, IF and spectrum streaming via callback functions. Declaration int StartStreaming(int hRadio,AUDIO_CALLBACK AudioCallback,IF_CALLBACK IFCallback,SPECTRUM_CALLBACK SpectrumCallback,void *Context); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. AudioCallback Pointer to an application-defined callback function. For more information, see AUDIO_CALLBACK. This parameter can be NULL. IFCallback Pointer to an application-defined callback function. For more information, see IF_CALLBACK. This parameter can be NULL. SpectrumCallback Pointer to an application-defined callback function. For more information, see SPECTRUM_CALLBACK. This parameter can be NULL. Context Specifies an application-defined value to be passed to the callback functions. Return value If the function succeeds, the return value is zero, otherwise the return value is less than zero. Note All the callback function are called in the context of the threads created inside the API. This means, if the callback functions access shared data, synchronization is needed. Do not call API functions inside the callback functions. StopStreaming The function stops the audio, IF and spectrum streaming previously started by StartStreaming function. Declaration int StopStreaming(int hRadio); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. 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 int IsDeviceConnected(int hRadio); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Return value If the function succeeds, the function returns 1, if the device is connected or 0, if the devices is not connected. If the function fails, the return value is less than zero. GetInterface The function returns information how the device is connected to the computer - PCI or USB. Declaration int GetInterface(int hRadio,int *Interface); Parameters hRadio Handle to opened G313 device returned by the OpenDevice. Interface Pointer to a variable that receives information how the device is connected to the computer. If the value is 0, the device is connected via PCI, if the values is 1, the device is connected via USB. 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 unsigned int GetAPIVersion(void); Parameters No parameters. Return value The function returns the version number of the API. The high order 16 bits specify major number and low order 16 bits specify minor version number. RADIO_INFO Declaration #pragma pack(push,1)Members Size Specifies size of the structure. It must be filled before calling the GetRadioInfo. 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 suported by the receiver. NumBands Number of band filters on RF input of the receiver; also, number of valid entries in BandFreq array. BandFreq Crossover frequencies between band filters. LOFreq Local oscillator offset. NumVcos Number of VCOs on PLL board; also, number of valid entries in VcoFreq, VcoDiv and VcoBits arrays. VcoFreq Highest frequency for each VCO. VcoDiv VCO dividers. VcoBits VCO select bits. RefClk1 Reference Clock 1 frequency [Hz]. RefClk2 Reference Clock 2 frequency [Hz], 0 if not fitted. IF1DAC DACs on IF1 module. AGCstart Raw AGC level at low power (-97dBm). AGCmid Raw AGC value 5dB above AGC start. AGCend Raw AGC value at -30dBm. DropLevel The level where AGC starts *10dBm. RSSItop The level where raw RSSI value is 0x03FF *10dBm. RSSIref Raw RSSI value at -97dBm. RADIO_DESC Declaration #pragma pack(push,1)Members Path Null-terminated string that specifies path to he device file. This can be passed to the OpenDevice as parameter. Interface Specifies how the device is connected to the computer. 0 via PCI, 1 via USB. Info Hardware information structure. AUDIO_CALLBACK The AUDIO_CALLBACK function is an application-defined callback function used with the StartStreming function. It retrieves audio samples read from the G313 receiver. Definition typedef void (*AUDIO_CALLBACK)(short *AudioBuffer,int Count,void *Context); Parameters AudioBuffer Pointer to a buffer with audio samples. Sample format is 16 bit signed and the sample rate is 16kHz. The pointer is valid only in current call of the callback function. Count Specifies number of samples in the buffer. Context Specifies the application-defined value given in StartStreaming function. Return value No return value. Note The callback is called in the thread created inside API. If the callback accesses shared data, the synchronization is required. Do not call API functions inside the callback. IF_CALLBACK The IF_CALLBACK function is an application-defined callback function used with the StartStreming function. It retrieves IF samples read from the G313 receiver. Definition typedef void (*IF_CALLBACK)(short *IFBuffer,int Count,void *Context); Parameters IFBuffer 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. Context Specifies the application-defined value given in StartStreaming function. Return value No return value. Note The callback is called in the thread created inside API. If the callback accesses shared data, the synchronization is required. Do not call API functions inside the callback. SPECTRUM_CALLBACK The SPECTRUM_CALLBACK function is an application-defined callback function used with the StartStreming function. It retrieves IF spectrum calculated from IF signal read from the G313 receiver. Definition typedef void (*SPECTRUM_CALLBACK)(float *Spectrum,int Count,void *Context); Parameters Spectrum Pointer to a buffer containing spectrum data in dB. The buffer always contains whole IF spectrum. Spectrum is 24kHz wide. Count Specifies number of items in the spectrum buffer. This value should be always 1024. This means that the resolution of the spectrum is 23.4375 Hz. Context Specifies the application-defined value given in StartStreaming function. Return value No return value. Note The callback is called in the thread created inside API. If the callback accesses shared data, the synchronization is required. Do not call API functions inside the callback. Loading and initializing G313 API Header file #ifndef __WRG313_API_H__ #define __WRG313_API_H__ #include <linux/types.h> #define WRG3APINAME "wrg313api" #define RADIOMODE_AM 0 #define RADIOMODE_SAM 1 #define RADIOMODE_LSB 2 #define RADIOMODE_USB 3 #define RADIOMODE_DSB 4 #define RADIOMODE_ISB 5 #define RADIOMODE_CW 6 #define RADIOMODE_FMN 7 #define AGC_NONE 0 #define AGC_SLOW 1 #define AGC_MEDIUM 2 #define AGC_FAST 3 #define INTERFACE_PCI 0 #define INTERFACE_USB 1 #pragma pack(push,1) typedef struct { __u32 Size; char SerNum[9]; char Model[9]; __u32 MinFreq; __u32 MaxFreq; __u8 NumBands; __u32 BandFreq[16]; __u32 LOFreq; __u8 NumVcos; __u32 VcoFreq[8]; __u16 VcoDiv[8]; __u8 VcoBits[8]; __u32 RefClk1; __u32 RefClk2; __u8 IF1DAC[8]; __s32 AGCstart; __s32 AGCmid; __s32 AGCend; __s32 DropLevel; __s32 RSSItop; __s32 RSSIref; __s32 RxGain; } RADIO_INFO; typedef struct { char Path[64]; __u8 Interface; RADIO_INFO Info; } RADIO_DESC; #pragma pack(pop) extern "C" { typedef void (*IF_CALLBACK)(__s16 *Buffer,int Count,void *Context); typedef void (*SPECTRUM_CALLBACK)(float *Spectrum,int Count,void *Context); typedef void (*AUDIO_CALLBACK)(__s16 *AudioBuffer,int Count,void *UserData); typedef int (*OPEN_DEVICE)(const char *DeviceName); typedef void (*CLOSE_DEVICE)(int hRadio); typedef int (*SET_POWER)(int hRadio,int Power); typedef int (*GET_POWER)(int hRadio,int *Power); typedef int (*GET_FREQUENCY)(int hRadio,unsigned int *Frequency); typedef int (*SET_FREQUENCY)(int hRadio,unsigned int Frequency); typedef int (*GET_RADIO_INFO)(int hRadio,RADIO_INFO *Info); typedef int (*GET_RSSI)(int hRadio,int *RSSI); typedef int (*GET_AGC)(int hRadio,int *AGC); typedef int (*SET_AGC)(int hRadio,int AGC); typedef int (*SET_IF_GAIN)(int hRadio,unsigned int Gain); typedef int (*GET_IF_GAIN)(int hRadio,unsigned int *Gain); typedef int (*SET_SOFT_AGC)(int hRadio,int AGC); typedef int (*GET_SOFT_AGC)(int hRadio,int *AGC); typedef int (*SET_VOLUME)(int hRadio,unsigned int Volume); typedef int (*GET_VOLUME)(int hRadio,unsigned int *Volume); typedef int (*SET_MODE)(int hRadio,int Mode); typedef int (*GET_MODE)(int hRadio,int *Mode); typedef int (*SET_IF_SHIFT)(int hRadio,int IFShift); typedef int (*GET_IF_SHIFT)(int hRadio,int *IFShift); typedef int (*SET_IF_BANDWIDTH)(int hRadio,unsigned int IFBandwidth); typedef int (*GET_IF_BANDWIDTH)(int hRadio,unsigned int *IFBandwidth); typedef int (*GET_DEVICE_LIST)(RADIO_DESC **List,int *Count); typedef void (*DESTROY_DEVICE_LIST)(RADIO_DESC *List); typedef int (*SET_ATTENUATOR)(int hRadio,int Atennutator); typedef int (*GET_ATTENUATOR)(int hRadio,int *Attenuator); typedef int (*START_STREAMING)(int hRadio,AUDIO_CALLBACK AudioCallback,IF_CALLBACK IFCallback,SPECTRUM_CALLBACK SpectrumCallback,void *Context); typedef int (*STOP_STREAMING)(int hRadio); typedef int (*GET_RAW_SIGNAL_STRENGTH)(int hRadio,unsigned char *Raw); typedef int (*GET_SIGNAL_STRENGTH)(int hRadio,double *SignalStrength); typedef int (*IS_DEVICE_CONNECTED)(int hRadio); typedef int (*GET_INTERFACE)(int hRadio,int *Interface); typedef int (*SET_CW_TONE)(int hRadio,unsigned int Frequency); typedef int (*GET_CW_TONE)(int hRadio,unsigned int *Frequency); typedef int (*SET_FM_AF_SQUELCH_LEVEL)(int hRadio,unsigned int Level); typedef int (*GET_FM_AF_SQUELCH_LEVEL)(int hRadio,unsigned int *Level); typedef int (*SET_NOTCH_FILTER)(int hRadio,int Active,int Frequency,unsigned int Bandwidth); typedef int (*GET_NOTCH_FILTER)(int hRadio,int *Active,int *Frequency,unsigned int *Bandwidth); typedef int (*SET_NOISE_BLANKER)(int hRadio,int Active,unsigned int Threshold); typedef int (*GET_NOISE_BLANKER)(int hRadio,int *Active,unsigned int *Threshold); typedef int (*SET_ISB_AUDIO_CHANNEL)(int hRadio,unsigned int Channel); typedef int (*GET_ISB_AUDIO_CHANNEL)(int hRadio,unsigned int *Channel); typedef int (*LOAD_CALIBRATION_FILE)(int hRadio,const char *Path); typedef int (*RESET_CALIBRATION)(int hRadio); typedef unsigned int (*GET_API_VERSION)(void); }; extern OPEN_DEVICE OpenDevice; extern CLOSE_DEVICE CloseDevice; extern SET_POWER SetPower; extern GET_POWER GetPower; extern SET_FREQUENCY SetFrequency; extern GET_FREQUENCY GetFrequency; extern GET_RADIO_INFO GetRadioInfo; extern GET_RSSI GetRSSI; extern GET_AGC GetAGC; extern SET_AGC SetAGC; extern SET_IF_GAIN SetIFGain; extern GET_IF_GAIN GetIFGain; extern SET_SOFT_AGC SetSoftAGC; extern GET_SOFT_AGC GetSoftAGC; extern SET_VOLUME SetVolume; extern GET_VOLUME GetVolume; extern SET_MODE SetMode; extern GET_MODE GetMode; extern SET_IF_SHIFT SetIFShift; extern GET_IF_SHIFT GetIFShift; extern SET_IF_BANDWIDTH SetIFBandwidth; extern GET_IF_BANDWIDTH GetIFBandwidth; extern GET_DEVICE_LIST GetDeviceList; extern DESTROY_DEVICE_LIST DestroyDeviceList; extern SET_ATTENUATOR SetAttenuator; extern GET_ATTENUATOR GetAttenuator; extern START_STREAMING StartStreaming; extern STOP_STREAMING StopStreaming; extern GET_RAW_SIGNAL_STRENGTH GetRawSignalStrength; extern GET_SIGNAL_STRENGTH GetSignalStrength; extern IS_DEVICE_CONNECTED IsDeviceConnected; extern GET_INTERFACE GetInterface; extern SET_CW_TONE SetCWTone; extern GET_CW_TONE GetCWTone; extern SET_FM_AF_SQUELCH_LEVEL SetFMAFSquelchLevel; extern GET_FM_AF_SQUELCH_LEVEL GetFMAFSquelchLevel; extern SET_NOTCH_FILTER SetNotchFilter; extern GET_NOTCH_FILTER GetNotchFilter; extern SET_NOISE_BLANKER SetNoiseBlanker; extern GET_NOISE_BLANKER GetNoiseBlanker; extern SET_ISB_AUDIO_CHANNEL SetISBAudioChannel; extern GET_ISB_AUDIO_CHANNEL GetISBAudioChannel; extern LOAD_CALIBRATION_FILE LoadCalibrationFile; extern RESET_CALIBRATION ResetCalibration; extern GET_API_VERSION GetAPIVersion; int InitAPI(void); void UninitAPI(void); #endif C file #include <dlfcn.h> #include <stdio.h> #include <errno.h> #include "wrg313api.h" OPEN_DEVICE OpenDevice=0; CLOSE_DEVICE CloseDevice=0; SET_POWER SetPower=0; GET_POWER GetPower=0; SET_FREQUENCY SetFrequency=0; GET_FREQUENCY GetFrequency=0; GET_RADIO_INFO GetRadioInfo=0; GET_RSSI GetRSSI=0; GET_AGC GetAGC=0; SET_AGC SetAGC=0; SET_IF_GAIN SetIFGain=0; GET_IF_GAIN GetIFGain=0; SET_SOFT_AGC SetSoftAGC=0; GET_SOFT_AGC GetSoftAGC=0; SET_VOLUME SetVolume=0; GET_VOLUME GetVolume=0; SET_MODE SetMode=0; GET_MODE GetMode=0; GET_DEVICE_LIST GetDeviceList=0; DESTROY_DEVICE_LIST DestroyDeviceList=0; SET_ATTENUATOR SetAttenuator=0; GET_ATTENUATOR GetAttenuator=0; SET_IF_SHIFT SetIFShift=0; GET_IF_SHIFT GetIFShift=0; SET_IF_BANDWIDTH SetIFBandwidth=0; GET_IF_BANDWIDTH GetIFBandwidth=0; START_STREAMING StartStreaming=0; STOP_STREAMING StopStreaming=0; GET_RAW_SIGNAL_STRENGTH GetRawSignalStrength=0; GET_SIGNAL_STRENGTH GetSignalStrength=0; IS_DEVICE_CONNECTED IsDeviceConnected=0; GET_INTERFACE GetInterface=0; SET_CW_TONE SetCWTone=0; GET_CW_TONE GetCWTone=0; SET_FM_AF_SQUELCH_LEVEL SetFMAFSquelchLevel=0; GET_FM_AF_SQUELCH_LEVEL GetFMAFSquelchLevel=0; SET_NOTCH_FILTER SetNotchFilter=0; GET_NOTCH_FILTER GetNotchFilter=0; SET_NOISE_BLANKER SetNoiseBlanker=0; GET_NOISE_BLANKER GetNoiseBlanker=0; SET_ISB_AUDIO_CHANNEL SetISBAudioChannel=0; GET_ISB_AUDIO_CHANNEL GetISBAudioChannel=0; LOAD_CALIBRATION_FILE LoadCalibrationFile=0; RESET_CALIBRATION ResetCalibration=0; GET_API_VERSION GetAPIVersion=0; void *hWRAPI=0; int InitAPI(void) { if(hWRAPI) { return 1; } else { hWRAPI=dlopen("wrg313api.so",RTLD_LAZY); if(hWRAPI==NULL) { fprintf(stderr,"Unable to load "WRG3APINAME" shared library (%s).\n", dlerror()); return 0; } else { GetAPIVersion=(GET_API_VERSION)dlsym(hWRAPI,"GetAPIVersion"); OpenDevice=(OPEN_DEVICE)dlsym(hWRAPI,"OpenDevice"); CloseDevice=(CLOSE_DEVICE)dlsym(hWRAPI,"CloseDevice"); SetPower=(SET_POWER)dlsym(hWRAPI,"SetPower"); GetPower=(GET_POWER)dlsym(hWRAPI,"GetPower"); SetFrequency=(SET_FREQUENCY)dlsym(hWRAPI,"SetFrequency"); GetFrequency=(GET_FREQUENCY)dlsym(hWRAPI,"GetFrequency"); GetRadioInfo=(GET_RADIO_INFO)dlsym(hWRAPI,"GetRadioInfo"); GetRSSI=(GET_RSSI)dlsym(hWRAPI,"GetRSSI"); GetAGC=(GET_AGC)dlsym(hWRAPI,"GetAGC"); SetAGC=(SET_AGC)dlsym(hWRAPI,"SetAGC"); SetIFGain=(SET_IF_GAIN)dlsym(hWRAPI,"SetIFGain"); GetIFGain=(GET_IF_GAIN)dlsym(hWRAPI,"GetIFGain"); GetDeviceList=(GET_DEVICE_LIST)dlsym(hWRAPI,"GetDeviceList"); DestroyDeviceList=(DESTROY_DEVICE_LIST)dlsym(hWRAPI,"DestroyDeviceList"); SetSoftAGC=(SET_SOFT_AGC)dlsym(hWRAPI,"SetSoftAGC"); GetSoftAGC=(GET_SOFT_AGC)dlsym(hWRAPI,"GetSoftAGC"); GetVolume=(GET_VOLUME)dlsym(hWRAPI,"GetVolume"); SetVolume=(SET_VOLUME)dlsym(hWRAPI,"SetVolume"); SetMode=(SET_MODE)dlsym(hWRAPI,"SetMode"); GetMode=(GET_MODE)dlsym(hWRAPI,"GetMode"); SetIFShift=(SET_IF_SHIFT)dlsym(hWRAPI,"SetIFShift"); GetIFShift=(GET_IF_SHIFT)dlsym(hWRAPI,"GetIFShift"); SetIFBandwidth=(SET_IF_BANDWIDTH)dlsym(hWRAPI,"SetIFBandwidth"); GetIFBandwidth=(GET_IF_BANDWIDTH)dlsym(hWRAPI,"GetIFBandwidth"); StartStreaming=(START_STREAMING)dlsym(hWRAPI,"StartStreaming"); StopStreaming=(STOP_STREAMING)dlsym(hWRAPI,"StopStreaming"); SetAttenuator=(SET_ATTENUATOR)dlsym(hWRAPI,"SetAttenuator"); GetAttenuator=(GET_ATTENUATOR)dlsym(hWRAPI,"GetAttenuator"); IsDeviceConnected=(IS_DEVICE_CONNECTED)dlsym(hWRAPI,"IsDeviceConnected"); GetInterface=(GET_INTERFACE)dlsym(hWRAPI,"GetInterface"); GetRawSignalStrength=(GET_RAW_SIGNAL_STRENGTH)dlsym(hWRAPI,"GetRawSignalStrength"); GetSignalStrength=(GET_SIGNAL_STRENGTH)dlsym(hWRAPI,"GetSignalStrength"); SetCWTone=(SET_CW_TONE)dlsym(hWRAPI,"SetCWTone"); GetCWTone=(GET_CW_TONE)dlsym(hWRAPI,"GetCWTone"); SetFMAFSquelchLevel=(SET_FM_AF_SQUELCH_LEVEL)dlsym(hWRAPI,"SetFMAFSquelchLevel"); GetFMAFSquelchLevel=(GET_FM_AF_SQUELCH_LEVEL)dlsym(hWRAPI,"GetFMAFSquelchLevel"); SetNotchFilter=(SET_NOTCH_FILTER)dlsym(hWRAPI,"SetNotchFilter"); GetNotchFilter=(GET_NOTCH_FILTER)dlsym(hWRAPI,"GetNotchFilter"); SetNoiseBlanker=(SET_NOISE_BLANKER)dlsym(hWRAPI,"SetNoiseBlanker"); GetNoiseBlanker=(GET_NOISE_BLANKER)dlsym(hWRAPI,"GetNoiseBlanker"); SetISBAudioChannel=(SET_ISB_AUDIO_CHANNEL)dlsym(hWRAPI,"SetISBAudioChannel"); GetISBAudioChannel=(GET_ISB_AUDIO_CHANNEL)dlsym(hWRAPI,"GetISBAudioChannel"); LoadCalibrationFile=(LOAD_CALIBRATION_FILE)dlsym(hWRAPI,"LoadCalibrationFile"); ResetCalibration=(RESET_CALIBRATION)dlsym(hWRAPI,"ResetCalibration"); if(!GetAPIVersion || !OpenDevice || !CloseDevice || !SetPower || !GetPower || !GetFrequency || !SetFrequency || !GetRadioInfo || !GetRSSI || !GetAGC || !SetAGC || !GetIFGain || !SetIFGain || !SetSoftAGC || !GetSoftAGC || !SetVolume || !GetVolume || !GetMode || !SetMode || !GetDeviceList || !DestroyDeviceList || !StartStreaming || !StopStreaming || !GetSignalStrength || !SetAttenuator || !GetAttenuator || !LoadCalibrationFile || !ResetCalibration || !SetIFShift || !SetIFBandwidth || !GetIFBandwidth || !GetIFShift || !GetRawSignalStrength || !IsDeviceConnected || !GetInterface || !SetCWTone || !GetCWTone || !SetFMAFSquelchLevel || !GetFMAFSquelchLevel || !SetNotchFilter || !GetNotchFilter || !SetNoiseBlanker || !GetNoiseBlanker || !SetISBAudioChannel || !GetISBAudioChannel) { fprintf(stderr,"Unable to load valid "WRG3APINAME" library.\n"); dlclose(hWRAPI); hWRAPI=0; return 0; } return 1; } } } void UninitAPI(void) { if(hWRAPI) { dlclose(hWRAPI); hWRAPI=0; } } |