Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for VFO mode in Rigctrl. Gpredict will now try to enable … #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 153 additions & 64 deletions src/gtk-rig-ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static gboolean check_aos_los(GtkRigCtrl * ctrl);
static gboolean set_freq_simplex(GtkRigCtrl * ctrl, gint sock, gdouble freq);
static gboolean get_freq_simplex(GtkRigCtrl * ctrl, gint sock, gdouble * freq);
static gboolean set_freq_toggle(GtkRigCtrl * ctrl, gint sock, gdouble freq);
static gboolean set_toggle(GtkRigCtrl * ctrl, gint sock);
static gboolean unset_toggle(GtkRigCtrl * ctrl, gint sock);
static gboolean get_freq_toggle(GtkRigCtrl * ctrl, gint sock, gdouble * freq);
static gboolean get_ptt(GtkRigCtrl * ctrl, gint sock);
Expand Down Expand Up @@ -178,6 +177,7 @@ static void gtk_rig_ctrl_init(GtkRigCtrl * ctrl,
ctrl->lastrxf = 0.0;
ctrl->lasttxf = 0.0;
ctrl->last_toggle_tx = -1;
ctrl->vfo_opt_supported = FALSE;
}

GType gtk_rig_ctrl_get_type()
Expand Down Expand Up @@ -1489,37 +1489,94 @@ static inline gboolean check_get_response(gchar * buffback, gboolean retcode,
return retcode;
}

/* Setup VFOs for split operation (simplex or duplex) */
static gboolean setup_split(GtkRigCtrl * ctrl)
/*
* Return the string for the supplied VFO.
*
* Returns a VFO string (VFOA, VFOB, Main, Sub) for the specified VFO enum if VFO mode is enabled.
* If VFO mode is not enabled, checked via the isVfoSupported argument, an empty string is returned.
*/
static gchar* vfo_str(vfo_t vfo, gboolean isVfoSupported) {
// If --VFO mode is not enabled, no need to specify a VFO. Return an empty string.
if (!isVfoSupported)
return "";

// If --VFO mode is enabled, return the VFO string for the provided vfo enum.
switch (vfo) {
case VFO_A:
return "VFOA";
case VFO_B:
return "VFOB";
case VFO_MAIN:
return "Main";
case VFO_SUB:
return "Sub";
default:
return "currVFO";
}
}

/*
* Check if the radio has the --vfo option enabled.
*
* Returns TRUE if the --vfo option is enabled, FALSE otherwise.
*/
static gboolean check_vfo_option(GtkRigCtrl * ctrl, gint sock)
{
gchar *buff;
gchar buffback[256];
gchar buffback[128];
gboolean retcode;
gboolean retval = FALSE;

switch (ctrl->conf->vfoUp)
{
case VFO_A:
buff = g_strdup("S 1 VFOA\x0a");
break;
// Send command to check if --vfo mode is enabled.
buff = g_strdup_printf("\\chk_vfo\x0a");
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
retcode = check_get_response(buffback, retcode, __func__);

case VFO_B:
buff = g_strdup("S 1 VFOB\x0a");
break;
// Check if '1' was sent back (indicating --vfo mode is enabled.)
if (retcode && (buffback[0]=='1'))
retval = TRUE;

case VFO_MAIN:
buff = g_strdup("S 1 Main\x0a");
break;
g_free(buff);
return retval;
}

case VFO_SUB:
buff = g_strdup("S 1 Sub\x0a");
break;
/*
* Try to enable the --vfo option for a radio if it is supported.
*
* Returns TRUE if the --vfo option has been enabled, FALSE otherwise.
*/
static gboolean enable_vfo_option(GtkRigCtrl * ctrl, gint sock)
{
gchar *buff;
gchar buffback[128];
gboolean retval = FALSE;

default:
sat_log_log(SAT_LOG_LEVEL_ERROR,
_("%s called but TX VFO is %d."), __func__,
ctrl->conf->vfoUp);
return FALSE;
}
buff = g_strdup_printf("\\set_vfo_opt 1\x0a");
send_rigctld_command(ctrl, sock, buff, buffback, 128);

// Check if --vfo mode was successfully enabled.
retval = check_vfo_option(ctrl, sock);

g_free(buff);
return retval;
}

/* Setup VFOs for split operation (simplex or duplex) */
static gboolean setup_split(GtkRigCtrl * ctrl)
{
gchar *buff;
gchar buffback[256];
gboolean retcode;

/* send command to enable split mode
* Example: S VFOA 1 VFOB\x0a
* S: Rigctrl set split VFO
* VFOA: Downlink vfo. Omitted if --VFO mode is not enabled in Rigctrl
* 1: Enable split (0 would disable split.)
* VFOB: Uplink vfo.
* /x0a: End of command
*/
buff = g_strdup_printf("S %s 1 %s\x0a", vfo_str(ctrl->conf->vfoDown, ctrl->vfo_opt_supported), vfo_str(ctrl->conf->vfoUp, TRUE));

retcode = send_rigctld_command(ctrl, ctrl->sock, buff, buffback, 128);
g_free(buff);
Expand Down Expand Up @@ -2252,8 +2309,13 @@ static gboolean get_ptt(GtkRigCtrl * ctrl, gint sock)

if (ctrl->conf->ptt == PTT_TYPE_CAT)
{
/* send command get_ptt (t) */
buff = g_strdup_printf("t\x0a");
/* send command to enable or disable the PTT
* Example: t VFOA 1 \x0a
* t: Rigctrl get PTT command
* VFOA: VFO to get PTT of. In this case the uplink VFO. Omitted if --VFO mode is not enabled in Rigctrl
* /x0a: End of command
*/
buff = g_strdup_printf("t %s\x0a", vfo_str(ctrl->conf->vfoUp, ctrl->vfo_opt_supported));
}
else
{
Expand Down Expand Up @@ -2281,11 +2343,15 @@ static gboolean set_ptt(GtkRigCtrl * ctrl, gint sock, gboolean ptt)
gchar buffback[128];
gboolean retcode;

/* send command */
if (ptt == TRUE)
buff = g_strdup_printf("T 1\x0aq\x0a");
else
buff = g_strdup_printf("T 0\x0aq\x0a");
/* send command to enable or disable the PTT
* Example: T VFOA 1 \x0a
* T: Rigctrl set PTT command
* VFOA: VFO to set PTT on. In this case the uplink VFO. Omitted if --VFO mode is not enabled in Rigctrl
* 1: 1 or 0, corresponding to enable PTT and disable PTT respectively
* /x0a: End of command
*/
gchar pttChar = (ptt) ? '1' : '0';
buff = g_strdup_printf("T %s %c\x0a", vfo_str(ctrl->conf->vfoUp, ctrl->vfo_opt_supported), pttChar);

retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
g_free(buff);
Expand Down Expand Up @@ -2363,7 +2429,14 @@ static gboolean set_freq_simplex(GtkRigCtrl * ctrl, gint sock, gdouble freq)
gchar buffback[128];
gboolean retcode;

buff = g_strdup_printf("F %10.0f\x0a", freq);
/* send command to set downlink frequency
* Example: F VFOA 10000000 \x0a
* F: Rigctrl set frequency command
* VFOA: VFO to set the frequency of. In this case the downlink VFO. Omitted if --VFO mode is not enabled in Rigctrl
* 10000000: Frequency in Hz
* /x0a: End of command
*/
buff = g_strdup_printf("F %s %10.0f\x0a", vfo_str(ctrl->conf->vfoDown, ctrl->vfo_opt_supported), freq);
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
g_free(buff);

Expand All @@ -2376,33 +2449,24 @@ static gboolean set_freq_simplex(GtkRigCtrl * ctrl, gint sock, gdouble freq)
*
* Returns TRUE if the operation was successful, FALSE otherwise
*/
static gboolean set_freq_toggle(GtkRigCtrl * ctrl, gint sock, gdouble freq)
{
gchar *buff;
gchar buffback[128];
gboolean retcode;

/* send command */
buff = g_strdup_printf("I %10.0f\x0a", freq);
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
g_free(buff);

return (check_set_response(buffback, retcode, __func__));

}

/*
* Turn on the radios toggle mode
*
* Returns TRUE if the operation was successful
*/
static gboolean set_toggle(GtkRigCtrl * ctrl, gint sock)
{
gchar *buff;
gchar buffback[128];
gboolean retcode;

buff = g_strdup_printf("S 1 %d\x0a", ctrl->conf->vfoDown);
static gboolean set_freq_toggle(GtkRigCtrl * ctrl, gint sock, gdouble freq) {
gchar * buff;
gchar buffback[128];
gboolean retcode;

/* send command to set uplink frequency
* Example: F VFOA 10000000 \x0a
* F: Rigctrl set frequency command. If --VFO mode is not enabled, the "I" command is used instead.
* The "I" command has to be used to set the TX frequency when not in --VFO mode.
* VFOA: VFO to set the frequency of. In this case the uplink VFO. Not used with "I" command.
* 10000000: Frequency in Hz
* /x0a: End of command
*/
if (ctrl->vfo_opt_supported) {
buff = g_strdup_printf("F %s %10.0f\x0a", vfo_str(ctrl->conf->vfoUp, TRUE), freq);
} else {
buff = g_strdup_printf("I %10.0f\x0a", freq);
}
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
g_free(buff);

Expand All @@ -2421,7 +2485,15 @@ static gboolean unset_toggle(GtkRigCtrl * ctrl, gint sock)
gboolean retcode;

/* send command */
buff = g_strdup_printf("S 0 %d\x0a", ctrl->conf->vfoDown);
/* send command to disable split mode
* Example: S VFOA 1 VFOB\x0a
* S: Rigctrl set split VFO
* VFOA: Downlink vfo. Omitted if --VFO mode is not enabled in Rigctrl
* 0: Disable split (1 would enable split.)
* VFOB: Uplink vfo.
* /x0a: End of command
*/
buff = g_strdup_printf("S %s 0 %s\x0a", vfo_str(ctrl->conf->vfoDown, ctrl->vfo_opt_supported), vfo_str(ctrl->conf->vfoUp, TRUE));
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
g_free(buff);

Expand All @@ -2440,7 +2512,13 @@ static gboolean get_freq_simplex(GtkRigCtrl * ctrl, gint sock, gdouble * freq)
gboolean retcode;
gboolean retval = TRUE;

buff = g_strdup_printf("f\x0a");
/* send command to get downlink frequency
* Example: f VFOA \x0a
* f: Rigctrl get frequency command
* VFOA: VFO to get the frequency of. In this case the downlink VFO. Omitted if --VFO mode is not enabled in Rigctrl
* /x0a: End of command
*/
buff = g_strdup_printf("f %s\x0a", vfo_str(ctrl->conf->vfoDown, ctrl->vfo_opt_supported));
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
retcode = check_get_response(buffback, retcode, __func__);
if (retcode)
Expand Down Expand Up @@ -2480,8 +2558,18 @@ static gboolean get_freq_toggle(GtkRigCtrl * ctrl, gint sock, gdouble * freq)
return FALSE;
}

/* send command */
buff = g_strdup_printf("i\x0a");
/* send command to set uplink frequency
* Example: f VFOA \x0a
* f: Rigctrl set frequency command. If --VFO mode is not enabled, the "i" command is used instead.
* The "I" command has to be used to get the TX frequency when not in --VFO mode.
* VFOA: VFO to get the frequency of. In this case the uplink VFO. Not used with "i" command.
* /x0a: End of command
*/
if (ctrl->vfo_opt_supported) {
buff = g_strdup_printf("f %s\x0a", vfo_str(ctrl->conf->vfoUp, TRUE));
} else {
buff = g_strdup_printf("i\x0a");
}
retcode = send_rigctld_command(ctrl, sock, buff, buffback, 128);
retcode = check_get_response(buffback, retcode, __func__);
if (retcode)
Expand Down Expand Up @@ -2739,6 +2827,7 @@ static void rigctrl_open(GtkRigCtrl * data)
}
else
{
ctrl->vfo_opt_supported = enable_vfo_option(ctrl, ctrl->sock);
switch (ctrl->conf->type)
{

Expand All @@ -2762,7 +2851,7 @@ static void rigctrl_open(GtkRigCtrl * data)

case RIG_TYPE_TOGGLE_AUTO:
case RIG_TYPE_TOGGLE_MAN:
set_toggle(ctrl, ctrl->sock);
setup_split(ctrl);
ctrl->last_toggle_tx = -1;
exec_toggle_cycle(ctrl);
break;
Expand Down
1 change: 1 addition & 0 deletions src/gtk-rig-ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct _gtk_rig_ctrl {
GSList *trsplist; /*!< List of available transponders */
trsp_t *trsp; /*!< Pointer to the current transponder configuration */
gboolean trsplock; /*!< Flag indicating whether uplink and downlink are lockled */
gboolean vfo_opt_supported; /*!< Does the rig support and have the --vfo enabled in Hamlib*/

GSList *sats; /*!< List of sats in parent module */
sat_t *target; /*!< Target satellite */
Expand Down
12 changes: 7 additions & 5 deletions src/radio-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ gboolean radio_conf_read(radio_conf_t * conf)
return FALSE;
}

/* VFO up and down, only if radio is full-duplex */
if (conf->type == RIG_TYPE_DUPLEX)
{
/* VFO up and down, only if radio is full-duplex, auto, manual */
if ((conf->type == RIG_TYPE_DUPLEX) ||
(conf->type == RIG_TYPE_TOGGLE_AUTO) ||
(conf->type == RIG_TYPE_TOGGLE_MAN)) {
/* downlink */
if (g_key_file_has_key(cfg, GROUP, KEY_VFO_DOWN, NULL))
{
Expand Down Expand Up @@ -280,8 +281,9 @@ void radio_conf_save(radio_conf_t * conf)
else
g_key_file_set_integer(cfg, GROUP, KEY_CYCLE, conf->cycle);

if (conf->type == RIG_TYPE_DUPLEX)
{
if ((conf->type == RIG_TYPE_DUPLEX) ||
(conf->type == RIG_TYPE_TOGGLE_AUTO) ||
(conf->type == RIG_TYPE_TOGGLE_MAN)) {
g_key_file_set_integer(cfg, GROUP, KEY_VFO_UP, conf->vfoUp);
g_key_file_set_integer(cfg, GROUP, KEY_VFO_DOWN, conf->vfoDown);
}
Expand Down
Loading