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 <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_DLFCN_H
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
|
|
|
|
#include "winradio.h"
|
|
|
|
#include "linradio/wrg313api.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)
|
|
|
|
|
|
|
|
#define TOK_SHM_AUDIO 0x150901
|
|
|
|
#define TOK_SHM_IF 0x150902
|
|
|
|
#define TOK_SHM_SPECTRUM 0x150903
|
|
|
|
|
|
|
|
#define FIFO_PATHNAME_SIZE 64
|
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams g313_cfg_params[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TOK_SHM_AUDIO, "audio_path", "audio path name",
|
2013-11-18 18:53:15 +00:00
|
|
|
"POSIX shared memory path name to the audio ringbuffer",
|
|
|
|
"", RIG_CONF_STRING,
|
|
|
|
},
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
|
|
|
TOK_SHM_IF, "if_path", "I/F path name",
|
2013-11-18 18:53:15 +00:00
|
|
|
"POSIX shared memory path name to the I/F ringbuffer",
|
|
|
|
"", RIG_CONF_STRING,
|
|
|
|
},
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
|
|
|
TOK_SHM_SPECTRUM, "spectrum_path", "spectrum path name",
|
2013-11-18 18:53:15 +00:00
|
|
|
"POSIX shared memory path name to the spectrum ringbuffer",
|
|
|
|
"", RIG_CONF_STRING,
|
|
|
|
},
|
|
|
|
{ RIG_CONF_END, NULL, }
|
|
|
|
};
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
struct g313_fifo_data
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
int fd;
|
|
|
|
char path[FIFO_PATHNAME_SIZE];
|
|
|
|
};
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
struct g313_priv_data
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
void *hWRAPI;
|
|
|
|
int hRadio;
|
|
|
|
int Opened;
|
|
|
|
struct g313_fifo_data if_buf;
|
|
|
|
struct g313_fifo_data audio_buf;
|
|
|
|
struct g313_fifo_data spectrum_buf;
|
|
|
|
};
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static void g313_audio_callback(short *buffer, int count, void *arg);
|
|
|
|
static void g313_if_callback(short *buffer, int count, void *arg);
|
|
|
|
static void g313_spectrum_callback(float *buffer, int count, void *arg);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
void *g313_init_api(void)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
void *hWRAPI = dlopen("wrg313api.so", RTLD_LAZY);
|
|
|
|
|
|
|
|
if (hWRAPI == 0)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,
|
|
|
|
"%s: Unable to load G313 shared library wrg313api.so\n", __func__);
|
2013-11-18 18:53:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (InitAPI(hWRAPI) == 0)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unable to initialise G313 api\n", __func__);
|
2013-11-18 18:53:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
return hWRAPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_init(RIG *rig)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv;
|
|
|
|
|
2022-07-27 22:16:17 +00:00
|
|
|
priv = (struct g313_priv_data *)calloc(1, sizeof(struct g313_priv_data));
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
/* whoops! memory shortage! */
|
|
|
|
return -RIG_ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-12-24 18:55:01 +00:00
|
|
|
memset(priv, 0, sizeof(struct g313_priv_data));
|
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
priv->hWRAPI = g313_init_api();
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (priv->hWRAPI)
|
|
|
|
{
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Initialised G313 API\n", __func__);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
/* otherwise try again when open rig */
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig->state.priv = (void *)priv;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_open(RIG *rig)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
RADIO_DESC *List;
|
|
|
|
int Count;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
void *audio_callback = g313_audio_callback;
|
|
|
|
void *if_callback = g313_if_callback;
|
|
|
|
void *spectrum_callback = g313_spectrum_callback;
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->hWRAPI == 0) /* might not be done yet, must be done now! */
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
priv->hWRAPI = g313_init_api();
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (priv->hWRAPI)
|
|
|
|
{
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Initialised G313 API\n", __func__);
|
2019-11-30 16:04:31 +00:00
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
else
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO; /* can't go any further */
|
2019-11-30 16:04:31 +00:00
|
|
|
}
|
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
|
|
|
return RIG_OK;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
ret = GetDeviceList(&List, &Count);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret < 0 || Count == 0)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
/* Open Winradio receiver handle (default to first device?) */
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: found %d rigs 0 is %s\n", __func__, Count,
|
|
|
|
List[0].Path);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2022-01-25 23:41:26 +00:00
|
|
|
if (rig->state.rigport.pathname[0])
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2022-01-25 23:41:26 +00:00
|
|
|
priv->hRadio = OpenDevice(rig->state.rigport.pathname);
|
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
|
|
|
priv->hRadio = OpenDevice(List[0].Path);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
DestroyDeviceList(List);
|
|
|
|
|
|
|
|
|
|
|
|
if (priv->hRadio < 0)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
return -RIG_EIO; /* huh! */
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2020-07-17 13:36:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Opened G313\n", __func__);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
/* Make sure the receiver is switched on */
|
|
|
|
SetPower(priv->hRadio, 1);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->audio_buf.fd = open(priv->audio_buf.path, O_WRONLY | O_NONBLOCK);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: audio path %s fifo: %d\n", __func__,
|
|
|
|
priv->audio_buf.path, priv->audio_buf.fd);
|
|
|
|
|
|
|
|
if (priv->audio_buf.fd == -1)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
audio_callback = NULL;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->if_buf.fd = open(priv->if_buf.path, O_WRONLY | O_NONBLOCK);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: if path %s fifo: %d\n", __func__,
|
|
|
|
priv->if_buf.path, priv->if_buf.fd);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->if_buf.fd == -1)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
if_callback = NULL;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->spectrum_buf.fd = open(priv->spectrum_buf.path, O_WRONLY | O_NONBLOCK);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: spectrum path %s fifo: %d\n", __func__,
|
|
|
|
priv->spectrum_buf.path, priv->spectrum_buf.fd);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->spectrum_buf.fd == -1)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
spectrum_callback = NULL;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = StartStreaming(priv->hRadio, audio_callback, if_callback,
|
|
|
|
spectrum_callback, priv);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,
|
|
|
|
"%s: told G313 to start streaming audio: %d, if: %d, spec: %d\n",
|
2019-11-30 16:16:28 +00:00
|
|
|
__func__,
|
2019-11-30 16:19:08 +00:00
|
|
|
audio_callback ? 1 : 0, if_callback ? 1 : 0, spectrum_callback ? 1 : 0);
|
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
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: stop streaming\n", __func__);
|
|
|
|
StopStreaming(priv->hRadio);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
req.tv_sec=0;
|
|
|
|
req.tv_nsec=500000000L;
|
|
|
|
nanosleep(&req, NULL);
|
2013-11-18 18:53:15 +00:00
|
|
|
*/
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Closing G313\n", __func__);
|
2013-11-18 18:53:15 +00:00
|
|
|
CloseDevice(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
|
|
|
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: close fifos\n", __func__);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (priv->audio_buf.fd >= 0)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
close(priv->audio_buf.fd);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->if_buf.fd >= 0)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
close(priv->if_buf.fd);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->spectrum_buf.fd)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
close(priv->spectrum_buf.fd);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Uninitialising G313 API\n", __func__);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (priv->hWRAPI)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
dlclose(priv->hWRAPI);
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
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:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: %u\n", __func__, (unsigned int)freq);
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = SetFrequency(priv->hRadio, (unsigned int)(freq));
|
|
|
|
ret = ret == 0 ? 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;
|
|
|
|
|
|
|
|
unsigned int f;
|
|
|
|
int ret = GetFrequency(priv->hRadio, &f);
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d f: %u\n", __func__, ret, f);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
*freq = (freq_t)f;
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_set_powerstat(RIG *rig, powerstat_t status)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
int p = status == RIG_POWER_ON ? 1 : 0;
|
2013-11-18 18:53:15 +00:00
|
|
|
int ret = SetPower(priv->hRadio, p);
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d state: %d\n", __func__, ret, p);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return ret == 0 ? RIG_OK : -RIG_EIO;
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int g313_get_powerstat(RIG *rig, powerstat_t *status)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
|
|
|
|
int p;
|
|
|
|
int ret = GetPower(priv->hRadio, &p);
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d state: %d\n", __func__, ret, p);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
|
|
|
*status = p ? RIG_POWER_ON : RIG_POWER_OFF;
|
|
|
|
|
|
|
|
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 = SetAttenuator(priv->hRadio, val.i != 0 ? 1 : 0);
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Attenuator: %d\n", __func__, ret,
|
|
|
|
val.i);
|
2013-11-18 18:53:15 +00:00
|
|
|
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 = SetAGC(priv->hRadio, agc);
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d AGC: %d\n", __func__, ret, val.i);
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_RF:
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = SetIFGain(priv->hRadio, (int)(val.f * 100));
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Gain: %f\n", __func__, ret, val.f);
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return ret == 0 ? RIG_OK : -RIG_EIO;
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
int value;
|
|
|
|
unsigned int uvalue;
|
|
|
|
double dbl;
|
|
|
|
unsigned char ch;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (level)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
case RIG_LEVEL_ATT:
|
|
|
|
ret = GetAttenuator(priv->hRadio, &value);
|
2020-03-23 12:52:01 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Attenuator: %d\n", __func__, ret,
|
2019-11-30 16:19:08 +00:00
|
|
|
value);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val->i = value ? rig->caps->attenuator[0] : 0;
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_AGC:
|
|
|
|
ret = GetAGC(priv->hRadio, &value);
|
2020-03-23 12:52:01 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d AGC: %d\n", __func__, ret, value);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (value)
|
|
|
|
{
|
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
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_RF:
|
|
|
|
ret = GetIFGain(priv->hRadio, &uvalue);
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Gain: %u\n", __func__, ret, uvalue);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val->f = ((float)uvalue) / 100.0;
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_STRENGTH:
|
|
|
|
ret = GetSignalStrength(priv->hRadio, &dbl);
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d sigstr: %f\n", __func__, ret, dbl);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val->i = ((int)dbl / 1.0) + 73;
|
2013-11-18 18:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_RAWSTR:
|
|
|
|
ret = GetRawSignalStrength(priv->hRadio, &ch);
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Raw Sigstr: %u\n", __func__, ret,
|
|
|
|
(unsigned int)ch);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-18 18:53:15 +00:00
|
|
|
return -RIG_EIO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
val->i = ch;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
info.Size = sizeof(RADIO_INFO);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = GetRadioInfo(priv->hRadio, &info);
|
2013-11-18 18:53:15 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
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
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d sernum: %s\n", __func__, ret,
|
|
|
|
info.SerNum);
|
2013-11-18 18:53:15 +00:00
|
|
|
return info.SerNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
int g313_set_conf(RIG *rig, token_t token, const char *val)
|
|
|
|
{
|
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv;
|
|
|
|
|
|
|
|
size_t len = strlen(val);
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (token)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
|
|
|
case TOK_SHM_AUDIO:
|
2019-11-30 16:19:08 +00:00
|
|
|
if (len > (FIFO_PATHNAME_SIZE - 1))
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_WARN, "%s: set audio_path %s is too long\n", __func__, val);
|
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
|
|
|
memset(priv->audio_buf.path, 0, FIFO_PATHNAME_SIZE);
|
|
|
|
strcpy(priv->audio_buf.path, val);
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: set audio_path %s\n", __func__,
|
|
|
|
priv->audio_buf.path);
|
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
|
|
|
case TOK_SHM_IF:
|
2019-11-30 16:19:08 +00:00
|
|
|
if (len > (FIFO_PATHNAME_SIZE - 1))
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:16:28 +00:00
|
|
|
rig_debug(RIG_DEBUG_WARN, "%s: set if_path %s is too long\n", __func__, val);
|
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
|
|
|
memset(priv->if_buf.path, 0, FIFO_PATHNAME_SIZE);
|
|
|
|
strcpy(priv->if_buf.path, val);
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: set if_path %s\n", __func__,
|
|
|
|
priv->if_buf.path);
|
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
|
|
|
case TOK_SHM_SPECTRUM:
|
2019-11-30 16:19:08 +00:00
|
|
|
if (len > (FIFO_PATHNAME_SIZE - 1))
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_WARN, "%s: set spectrum_path %s is too long\n", __func__,
|
|
|
|
val);
|
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
|
|
|
memset(priv->spectrum_buf.path, 0, FIFO_PATHNAME_SIZE);
|
|
|
|
strcpy(priv->spectrum_buf.path, val);
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: set spectrum_path %s\n", __func__,
|
|
|
|
priv->spectrum_buf.path);
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
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 TOK_SHM_AUDIO:
|
|
|
|
strcpy(val, priv->audio_buf.path);
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case TOK_SHM_IF:
|
|
|
|
strcpy(val, priv->if_buf.path);
|
|
|
|
break;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
case TOK_SHM_SPECTRUM:
|
|
|
|
strcpy(val, priv->spectrum_buf.path);
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2013-11-18 18:53:15 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no need to check return from write - if not all can be written, accept overruns */
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static void g313_audio_callback(short *buffer, int count, void *arg)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)arg;
|
2018-12-23 23:08:32 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-result"
|
2019-11-30 16:19:08 +00:00
|
|
|
write(priv->audio_buf.fd, buffer, count * sizeof(short));
|
2018-12-23 23:08:32 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static void g313_if_callback(short *buffer, int count, void *arg)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)arg;
|
2018-12-23 23:08:32 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-result"
|
2019-11-30 16:19:08 +00:00
|
|
|
write(priv->if_buf.fd, buffer, count * sizeof(short));
|
2018-12-23 23:08:32 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2013-11-18 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static void g313_spectrum_callback(float *buffer, int count, void *arg)
|
2013-11-18 18:53:15 +00:00
|
|
|
{
|
2018-12-23 23:08:32 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-result"
|
2019-11-30 16:19:08 +00:00
|
|
|
struct g313_priv_data *priv = (struct g313_priv_data *)arg;
|
|
|
|
write(priv->spectrum_buf.fd, buffer, count * sizeof(float));
|
2018-12-23 23:08:32 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2013-11-18 18:53:15 +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 = "20191224.0",
|
2019-11-30 16:19:08 +00:00
|
|
|
.copyright = "LGPL", /* This wrapper, not the G313 shared library or driver */
|
2022-04-16 22:35:39 +00:00
|
|
|
.status = RIG_STATUS_BETA,
|
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,
|
2022-02-11 21:04:19 +00:00
|
|
|
.hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
|
2013-11-18 18:53:15 +00:00
|
|
|
};
|