2013-11-18 18:53:15 +00:00
|
|
|
/*
|
|
|
|
* Hamlib WiNRADiO backend - WR-G313
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#include "winradio.h"
|
|
|
|
|
|
|
|
#define G313_FUNC RIG_FUNC_NONE
|
|
|
|
#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR)
|
|
|
|
|
|
|
|
#define G313_MODES (RIG_MODE_NONE)
|
|
|
|
|
2020-12-27 18:57:01 +00:00
|
|
|
#if defined (_WIN32) || !defined(OTHER_POSIX)
|
2019-12-04 15:02:03 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINBASE_H
|
|
|
|
#include <winbase.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Winradio G3 capabilities.
|
|
|
|
*
|
|
|
|
* TODO: rig_probe, rig_scan
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define WAVEOUT_SOUNDCARDID 0x150901
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams g313_cfg_params[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WAVEOUT_SOUNDCARDID, "wodeviceid", "WaveOut Device ID", "Sound card device ID for playing IF signal from receiver",
|
2013-11-18 18:53:15 +00:00
|
|
|
"-1", RIG_CONF_NUMERIC, { .n = { -3, 32, 1 } }
|
|
|
|
},
|
|
|
|
{ RIG_CONF_END, NULL, }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define WRG313DLL "wrg3130api.dll"
|
|
|
|
|
|
|
|
#define G313_FUNC RIG_FUNC_NONE
|
|
|
|
#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR)
|
|
|
|
|
|
|
|
#define G313_MODES (RIG_MODE_NONE)
|
|
|
|
|
|
|
|
static int g313_init(RIG *rig);
|
|
|
|
static int g313_cleanup(RIG *rig);
|
|
|
|
static int g313_open(RIG *rig);
|
|
|
|
static int g313_close(RIG *rig);
|
|
|
|
static int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
|
|
|
|
static int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
|
|
|
|
static int g313_set_powerstat(RIG *rig, powerstat_t status);
|
|
|
|
static int g313_get_powerstat(RIG *rig, powerstat_t *status);
|
|
|
|
static int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val);
|
|
|
|
static int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
|
2019-11-30 16:19:08 +00:00
|
|
|
static const char *g313_get_info(RIG *rig);
|
2013-11-18 18:53:15 +00:00
|
|
|
int g313_set_conf(RIG *rig, token_t token, const char *val);
|
|
|
|
int g313_get_conf(RIG *rig, token_t token, char *val);
|
|
|
|
|
|
|
|
/* #pragma pack(1) // set byte packing */
|
2019-11-30 16:19:08 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int bLength;
|
|
|
|
char szSerNum[9];
|
|
|
|
char szProdName[9];
|
|
|
|
DWORD dwMinFreq;
|
|
|
|
DWORD dwMaxFreq;
|
|
|
|
BYTE bNumBands;
|
|
|
|
DWORD dwBandFreq[16];
|
|
|
|
DWORD dwLOfreq;
|
|
|
|
BYTE bNumVcos;
|
|
|
|
DWORD dwVcoFreq[8];
|
|
|
|
WORD wVcoDiv[8];
|
|
|
|
BYTE bVcoBits[8];
|
|
|
|
DWORD dwRefClk1;
|
|
|
|
DWORD dwRefClk2;
|
|
|
|
BYTE IF1DAC[8];
|
2013-11-18 18:53:15 +00:00
|
|
|
} __attribute__((packed)) RADIO_INFO;
|
|
|
|
/* #pragma pack() // set back the default packing */
|
|
|
|
|
|
|
|
/* Some type definitions needed for dll access */
|
|
|
|
typedef int (__stdcall *FNCOpenRadioDevice)(int iDeviceNum);
|
|
|
|
typedef BOOL (__stdcall *FNCCloseRadioDevice)(int hRadio);
|
|
|
|
typedef BOOL (__stdcall *FNCG3SetFrequency)(int hRadio, DWORD dwFreq);
|
|
|
|
typedef DWORD (__stdcall *FNCG3GetFrequency)(int hRadio);
|
|
|
|
typedef BOOL (__stdcall *FNCSetPower)(int hRadio, BOOL rPower);
|
|
|
|
typedef BOOL (__stdcall *FNCGetPower)(int hRadio);
|
|
|
|
typedef BOOL (__stdcall *FNCSetAtten)(int hRadio, BOOL rAtten);
|
|
|
|
typedef BOOL (__stdcall *FNCGetAtten)(int hRadio);
|
|
|
|
typedef BOOL (__stdcall *FNCSetAGC)(int hRadio, int rAGC);
|
|
|
|
typedef int (__stdcall *FNCGetAGC)(int hRadio);
|
|
|
|
typedef BOOL (__stdcall *FNCSetIFGain)(int hRadio, int rIFGain);
|
|
|
|
typedef int (__stdcall *FNCGetIFGain)(int hRadio);
|
|
|
|
typedef int (__stdcall *FNCGetSignalStrengthdBm)(int hRadio);
|
|
|
|
typedef int (__stdcall *FNCGetRawSignalStrength)(int hRadio);
|
2019-11-30 16:19:08 +00:00
|
|
|
typedef BOOL (__stdcall *FNCG3GetInfo)(int hRadio, RADIO_INFO *info);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
typedef MMRESULT(__stdcall *TwaveOutGetDevCaps)(UINT_PTR uDeviceID,
|
|
|
|
LPWAVEOUTCAPS pwoc, UINT cbwoc);
|
|
|
|
typedef UINT(__stdcall *TwaveOutGetNumDevs)(void);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
typedef HANDLE(__stdcall *TStartWaveOut)(LONG hRadio, LONG WaveOutDeviceIndex);
|
2013-11-18 18:53:15 +00:00
|
|
|
typedef void (__stdcall *TStopWaveOut)(HANDLE hWaveOut);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
struct g313_priv_data
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
HMODULE dll;
|
|
|
|
int hRadio;
|
|
|
|
|
|
|
|
FNCOpenRadioDevice OpenRadioDevice;
|
|
|
|
FNCCloseRadioDevice CloseRadioDevice;
|
|
|
|
FNCG3SetFrequency G3SetFrequency;
|
|
|
|
FNCG3GetFrequency G3GetFrequency;
|
|
|
|
FNCSetPower SetPower;
|
|
|
|
FNCGetPower GetPower;
|
|
|
|
FNCSetAtten SetAtten;
|
|
|
|
FNCGetAtten GetAtten;
|
|
|
|
FNCSetAGC SetAGC;
|
|
|
|
FNCGetAGC GetAGC;
|
|
|
|
FNCSetIFGain SetIFGain;
|
|
|
|
FNCGetIFGain GetIFGain;
|
|
|
|
FNCGetSignalStrengthdBm GetSignalStrengthdBm;
|
|
|
|
FNCGetRawSignalStrength GetRawSignalStrength;
|
|
|
|
FNCG3GetInfo G3GetInfo;
|
|
|
|
|
|
|
|
|
|
|
|
HMODULE WinMM;
|
2019-11-30 16:19:08 +00:00
|
|
|
TwaveOutGetDevCaps waveOutGetDevCaps;
|
2013-11-18 18:53:15 +00:00
|
|
|
TwaveOutGetNumDevs waveOutGetNumDevs;
|
|
|
|
|
|
|
|
HMODULE hWRG313WO;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
int WaveOutDeviceID;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
HANDLE hWaveOut;
|
2013-11-18 18:53:15 +00:00
|
|
|
TStartWaveOut StartWaveOut;
|
|
|
|
TStopWaveOut StopWaveOut;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
int Opened;
|
2013-11-18 18:53:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct rig_caps g313_caps =
|
|
|
|
{
|
2020-03-05 14:44:18 +00:00
|
|
|
RIG_MODEL(RIG_MODEL_G313),
|
2013-11-18 18:53:15 +00:00
|
|
|
.model_name = "WR-G313",
|
|
|
|
.mfg_name = "Winradio",
|
2020-03-30 04:03:21 +00:00
|
|
|
.version = "20191204.0",
|
2019-11-30 16:19:08 +00:00
|
|
|
.copyright = "LGPL", /* This wrapper, not the G313 DLL */
|
2021-09-15 18:44:42 +00:00
|
|
|
.status = RIG_STATUS_STAB,
|
2013-11-18 18:53:15 +00:00
|
|
|
.rig_type = RIG_TYPE_PCRECEIVER,
|
|
|
|
.port_type = RIG_PORT_NONE,
|
2019-11-30 16:19:08 +00:00
|
|
|
.targetable_vfo = 0,
|
2013-11-18 18:53:15 +00:00
|
|
|
.ptt_type = RIG_PTT_NONE,
|
|
|
|
.dcd_type = RIG_DCD_NONE,
|
|
|
|
.has_get_func = G313_FUNC,
|
|
|
|
.has_set_func = G313_FUNC,
|
|
|
|
.has_get_level = G313_LEVEL,
|
|
|
|
.has_set_level = RIG_LEVEL_SET(G313_LEVEL),
|
2019-11-30 16:19:08 +00:00
|
|
|
.has_get_parm = RIG_PARM_NONE,
|
|
|
|
.has_set_parm = RIG_PARM_NONE,
|
|
|
|
.ctcss_list = NULL,
|
|
|
|
.dcs_list = NULL,
|
|
|
|
.chan_list = { RIG_CHAN_END },
|
2013-11-18 18:53:15 +00:00
|
|
|
.transceive = RIG_TRN_OFF,
|
2019-11-30 16:19:08 +00:00
|
|
|
.max_ifshift = kHz(2),
|
|
|
|
.attenuator = { 20, RIG_DBLST_END, }, /* TBC */
|
2013-11-18 18:53:15 +00:00
|
|
|
.rx_range_list1 = { {
|
2019-11-30 16:19:08 +00:00
|
|
|
.startf = kHz(9), .endf = MHz(30), .modes = G313_MODES,
|
|
|
|
.low_power = -1, .high_power = -1, .vfo = RIG_VFO_A
|
2013-11-18 18:53:15 +00:00
|
|
|
},
|
|
|
|
RIG_FRNG_END,
|
|
|
|
},
|
|
|
|
.tx_range_list1 = { RIG_FRNG_END, },
|
|
|
|
.rx_range_list2 = { {
|
2019-11-30 16:19:08 +00:00
|
|
|
.startf = kHz(9), .endf = MHz(30), .modes = G313_MODES,
|
|
|
|
.low_power = -1, .high_power = -1, .vfo = RIG_VFO_A
|
2013-11-18 18:53:15 +00:00
|
|
|
},
|
|
|
|
RIG_FRNG_END,
|
|
|
|
},
|
|
|
|
.tx_range_list2 = { RIG_FRNG_END, },
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
.tuning_steps = { {G313_MODES, 1},
|
2013-11-18 18:53:15 +00:00
|
|
|
RIG_TS_END,
|
|
|
|
},
|
|
|
|
|
|
|
|
.filters = { {G313_MODES, kHz(12)},
|
|
|
|
RIG_FLT_END,
|
|
|
|
},
|
|
|
|
|
|
|
|
.cfgparams = g313_cfg_params,
|
|
|
|
.set_conf = g313_set_conf,
|
|
|
|
.get_conf = g313_get_conf,
|
|
|
|
|
|
|
|
.rig_init = g313_init,
|
|
|
|
.rig_cleanup = g313_cleanup,
|
|
|
|
.rig_open = g313_open,
|
|
|
|
.rig_close = g313_close,
|
|
|
|
|
|
|
|
.set_freq = g313_set_freq,
|
|
|
|
.get_freq = g313_get_freq,
|
|
|
|
|
|
|
|
.set_powerstat = g313_set_powerstat,
|
|
|
|
.get_powerstat = g313_get_powerstat,
|
|
|
|
.set_level = g313_set_level,
|
|
|
|
.get_level = g313_get_level,
|
|
|
|
|
|
|
|
.get_info = g313_get_info,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int g313_init(RIG *rig)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv;
|
|
|
|
|
2020-02-23 17:26:09 +00:00
|
|
|
rig->state.priv = (struct g313_priv_data *)malloc(sizeof(
|
|
|
|
struct g313_priv_data));
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2020-01-13 18:16:31 +00:00
|
|
|
if (!rig->state.priv)
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
/* whoops! memory shortage! */
|
|
|
|
return -RIG_ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-01-13 18:16:31 +00:00
|
|
|
priv = rig->state.priv;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->WaveOutDeviceID = -1;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->Opened = 0;
|
|
|
|
priv->hWaveOut = NULL;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->WinMM = LoadLibrary("WinMM.dll");
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->WinMM == NULL)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
free(priv);
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->hWRG313WO = LoadLibrary("WRG313WO.dll");
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->hWRG313WO == NULL)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unable to LoadLibrary WRG313WO.dll\n",
|
2019-11-30 16:16:28 +00:00
|
|
|
__func__);
|
2013-11-18 18:53:15 +00:00
|
|
|
FreeLibrary(priv->WinMM);
|
|
|
|
free(priv);
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->StartWaveOut = (TStartWaveOut)GetProcAddress(priv->hWRG313WO,
|
|
|
|
"StartWaveOut");
|
|
|
|
priv->StopWaveOut = (TStopWaveOut)GetProcAddress(priv->hWRG313WO,
|
|
|
|
"StopWaveOut");
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv->StartWaveOut || !priv->StopWaveOut)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unable to load valid WRG313WO.dll library\n",
|
2019-11-30 16:16:28 +00:00
|
|
|
__func__);
|
2013-11-18 18:53:15 +00:00
|
|
|
FreeLibrary(priv->hWRG313WO);
|
|
|
|
FreeLibrary(priv->WinMM);
|
|
|
|
free(priv);
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Try to load required dll */
|
|
|
|
priv->dll = LoadLibrary(WRG313DLL);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv->dll)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unable to LoadLibrary %s\n",
|
2019-11-30 16:16:28 +00:00
|
|
|
__func__, WRG313DLL);
|
2013-11-18 18:53:15 +00:00
|
|
|
FreeLibrary(priv->hWRG313WO);
|
|
|
|
FreeLibrary(priv->WinMM);
|
|
|
|
free(priv);
|
2019-11-30 16:19:08 +00:00
|
|
|
return -RIG_EIO; /* huh! */
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get process addresses from dll for function access */
|
|
|
|
priv->OpenRadioDevice =
|
|
|
|
(FNCOpenRadioDevice) GetProcAddress(priv->dll, "OpenRadioDevice");
|
|
|
|
priv->CloseRadioDevice =
|
|
|
|
(FNCCloseRadioDevice) GetProcAddress(priv->dll, "CloseRadioDevice");
|
|
|
|
priv->G3SetFrequency =
|
|
|
|
(FNCG3SetFrequency) GetProcAddress(priv->dll, "SetFrequency");
|
|
|
|
priv->G3GetFrequency =
|
|
|
|
(FNCG3GetFrequency) GetProcAddress(priv->dll, "GetFrequency");
|
|
|
|
priv->SetPower = (FNCSetPower) GetProcAddress(priv->dll, "SetPower");
|
|
|
|
priv->GetPower = (FNCGetPower) GetProcAddress(priv->dll, "GetPower");
|
|
|
|
priv->SetAtten = (FNCSetAtten) GetProcAddress(priv->dll, "SetAtten");
|
|
|
|
priv->GetAtten = (FNCGetAtten) GetProcAddress(priv->dll, "GetAtten");
|
|
|
|
priv->SetAGC = (FNCSetAGC) GetProcAddress(priv->dll, "SetAGC");
|
|
|
|
priv->GetAGC = (FNCGetAGC) GetProcAddress(priv->dll, "GetAGC");
|
|
|
|
priv->SetIFGain = (FNCSetIFGain) GetProcAddress(priv->dll, "SetIFGain");
|
|
|
|
priv->GetIFGain = (FNCGetIFGain) GetProcAddress(priv->dll, "GetIFGain");
|
|
|
|
priv->GetSignalStrengthdBm =
|
|
|
|
(FNCGetSignalStrengthdBm) GetProcAddress(priv->dll, "GetSignalStrengthdBm");
|
|
|
|
priv->GetRawSignalStrength =
|
|
|
|
(FNCGetRawSignalStrength) GetProcAddress(priv->dll, "GetRawSignalStrength");
|
|
|
|
priv->G3GetInfo = (FNCG3GetInfo) GetProcAddress(priv->dll, "G3GetInfo");
|
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv->OpenRadioDevice || !priv->CloseRadioDevice || !priv->G3SetFrequency
|
|
|
|
||
|
|
|
|
!priv->G3GetFrequency || !priv->SetPower || !priv->GetPower || !priv->SetAtten
|
|
|
|
||
|
|
|
|
!priv->GetAtten || !priv->SetAGC || !priv->GetAGC || !priv->SetIFGain
|
|
|
|
|| !priv->GetIFGain ||
|
2013-11-18 18:53:15 +00:00
|
|
|
!priv->GetSignalStrengthdBm || !priv->GetRawSignalStrength)
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unable to load valid %s library\n",
|
2019-11-30 16:16:28 +00:00
|
|
|
__func__, WRG313DLL);
|
2013-11-18 18:53:15 +00:00
|
|
|
FreeLibrary(priv->dll);
|
|
|
|
FreeLibrary(priv->hWRG313WO);
|
|
|
|
FreeLibrary(priv->WinMM);
|
|
|
|
free(priv);
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->waveOutGetDevCaps = (TwaveOutGetDevCaps)GetProcAddress(priv->WinMM,
|
|
|
|
"waveOutGetDevCapsA");
|
|
|
|
priv->waveOutGetNumDevs = (TwaveOutGetNumDevs)GetProcAddress(priv->WinMM,
|
|
|
|
"waveOutGetNumDevs");
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_findVSC(struct g313_priv_data *priv)
|
|
|
|
{
|
|
|
|
int OutIndex;
|
|
|
|
WAVEOUTCAPS Caps;
|
|
|
|
int Count;
|
|
|
|
int i;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
OutIndex = -1;
|
|
|
|
Count = priv->waveOutGetNumDevs();
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
for (i = 0; i < Count; i++)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->waveOutGetDevCaps(i, &Caps, sizeof(Caps)) == MMSYSERR_NOERROR)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
if (strncmp(Caps.szPname, "WiNRADiO Virtual Sound Card", 27) == 0)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
OutIndex = i;
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OutIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_open(RIG *rig)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int device_num;
|
|
|
|
int Count;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
device_num = atoi(rig->state.rigport.pathname);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
Count = priv->waveOutGetNumDevs();
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (Count == 0)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->WaveOutDeviceID == -2)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
id = g313_findVSC(priv);
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
id = priv->WaveOutDeviceID;
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Open Winradio receiver handle */
|
|
|
|
priv->hRadio = priv->OpenRadioDevice(device_num);
|
|
|
|
|
|
|
|
if (priv->hRadio == 0)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
return -RIG_EIO; /* huh! */
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the receiver is switched on */
|
|
|
|
priv->SetPower(priv->hRadio, TRUE);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (id > -3)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->hWaveOut = priv->StartWaveOut(priv->hRadio, id);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->hWaveOut == NULL)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
priv->CloseRadioDevice(priv->hRadio);
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->hWaveOut = NULL;
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->Opened = 1;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_close(RIG *rig)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv->Opened)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->Opened = 0;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->hWaveOut)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
priv->StopWaveOut(priv->hWaveOut);
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
priv->CloseRadioDevice(priv->hRadio);
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_cleanup(RIG *rig)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv;
|
|
|
|
|
|
|
|
if (!rig)
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EINVAL;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv = (struct g313_priv_data *)rig->state.priv;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
/* Clean up the dll access */
|
|
|
|
FreeLibrary(priv->dll);
|
|
|
|
FreeLibrary(priv->WinMM);
|
|
|
|
FreeLibrary(priv->hWRG313WO);
|
|
|
|
|
2021-01-09 21:19:19 +00:00
|
|
|
free(rig->state.priv);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
rig->state.priv = NULL;
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int ret;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = priv->G3SetFrequency(priv->hRadio, (DWORD)(freq));
|
|
|
|
ret = ret == TRUE ? RIG_OK : -RIG_EIO;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
|
|
|
|
*freq = (freq_t) priv->G3GetFrequency(priv->hRadio);
|
|
|
|
|
|
|
|
return *freq != 0 ? RIG_OK : -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_set_powerstat(RIG *rig, powerstat_t status)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int ret;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = priv->SetPower(priv->hRadio, status == RIG_POWER_ON ? TRUE : FALSE);
|
|
|
|
ret = ret == TRUE ? RIG_OK : -RIG_EIO;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_get_powerstat(RIG *rig, powerstat_t *status)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = priv->GetPower(priv->hRadio);
|
2019-11-30 16:19:08 +00:00
|
|
|
*status = ret == TRUE ? RIG_POWER_ON : RIG_POWER_OFF;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int ret, agc;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (level)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_LEVEL_ATT:
|
|
|
|
ret = priv->SetAtten(priv->hRadio, val.i != 0 ? TRUE : FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_AGC:
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (val.i)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_AGC_OFF:
|
|
|
|
agc = 0;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_AGC_SLOW:
|
|
|
|
agc = 1;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_AGC_MEDIUM:
|
|
|
|
agc = 2;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_AGC_FAST:
|
|
|
|
agc = 3;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
ret = priv->SetAGC(priv->hRadio, agc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_RF:
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = priv->SetIFGain(priv->hRadio, (int)(val.f * 100));
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = ret == TRUE ? RIG_OK : -RIG_EIO;
|
2013-11-18 18:53:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = RIG_OK;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (level)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_LEVEL_ATT:
|
2019-11-30 16:19:08 +00:00
|
|
|
val->i = priv->GetAtten(priv->hRadio) ? rig->caps->attenuator[0] : 0;
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_AGC:
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (priv->GetAGC(priv->hRadio))
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
case 0:
|
|
|
|
val->i = RIG_AGC_OFF;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case 1:
|
|
|
|
val->i = RIG_AGC_SLOW;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case 2:
|
|
|
|
val->i = RIG_AGC_MEDIUM;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case 3:
|
|
|
|
val->i = RIG_AGC_FAST;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case -1:
|
|
|
|
ret = -RIG_EIO;
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_STRENGTH:
|
2019-11-30 16:19:08 +00:00
|
|
|
val->i = priv->GetSignalStrengthdBm(priv->hRadio) / 10 + 73;
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_RAWSTR:
|
|
|
|
val->i = priv->GetRawSignalStrength(priv->hRadio);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static const char *g313_get_info(RIG *rig)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
static RADIO_INFO info;
|
|
|
|
|
|
|
|
info.bLength = sizeof(RADIO_INFO);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->G3GetInfo(priv->hRadio, &info) == FALSE)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return NULL;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
return info.szSerNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int g313_set_conf(RIG *rig, token_t token, const char *val)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
int id;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (token)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
case WAVEOUT_SOUNDCARDID:
|
|
|
|
if (val[0] == '0' && val[1] == 'x')
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
id = strtol(val, (char **)NULL, 16);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
else
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
id = atoi(val);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id < -3 || id > 32)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->WaveOutDeviceID = id;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->Opened)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
if (id == -2)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
id = g313_findVSC(priv);
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->hWaveOut)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
priv->StopWaveOut(priv->hWaveOut);
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (id > -3)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->hWaveOut = priv->StartWaveOut(priv->hRadio, id);
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->hWaveOut = NULL;
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_get_conf(RIG *rig, token_t token, char *val)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (token)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
case WAVEOUT_SOUNDCARDID:
|
2019-11-30 16:19:08 +00:00
|
|
|
sprintf(val, "%d", priv->WaveOutDeviceID);
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
2019-12-04 15:02:03 +00:00
|
|
|
|
|
|
|
#endif /* _WIN32 */
|