2007-11-11 23:03:38 +00:00
/*
2011-06-14 23:09:33 +02:00
* rigctl_parse . c - ( C ) Stephane Fillod 2000 - 2011
2013-02-05 12:54:05 -06:00
* ( C ) Nate Bargmann 2003 , 2006 , 2008 , 2010 , 2011 , 2012 , 2013
2011-08-21 20:51:06 -05:00
* ( C ) Terry Embry 2008 - 2009
2026-01-27 15:23:20 -05:00
* ( C ) The Hamlib Group 2002 , 2006 , 2007 , 2008 , 2009 , 2010 , 2011 , 2026
2007-11-11 23:03:38 +00:00
*
2010-02-04 00:53:56 +00:00
* This program tests / controls a radio using Hamlib .
2010-01-24 23:24:20 +00:00
* It takes commands in interactive mode as well as
2007-11-11 23:03:38 +00:00
* from command line options .
*
*
2011-08-21 20:51:06 -05:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
2010-01-24 23:24:20 +00:00
*
2011-08-21 20:51:06 -05:00
* This program 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 General Public License for more details .
2010-01-24 23:24:20 +00:00
*
2011-08-21 20:51:06 -05:00
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
2010-01-24 23:24:20 +00:00
*
2007-11-11 23:03:38 +00:00
*/
2026-01-27 15:23:20 -05:00
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2007-11-11 23:03:38 +00:00
2025-07-20 17:37:24 +02:00
# include "hamlib/config.h"
2007-11-11 23:03:38 +00:00
2023-02-14 20:02:02 +01:00
# include <stdint.h>
2007-11-11 23:03:38 +00:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
2023-02-14 20:02:02 +01:00
# include <strings.h>
2007-11-11 23:03:38 +00:00
# include <unistd.h>
# include <ctype.h>
# include <errno.h>
2025-07-20 17:37:24 +02:00
# include "rig_tests.h"
2007-11-11 23:03:38 +00:00
2021-08-29 00:03:27 -05:00
// If true adds some debug statements to see flow of rigctl parsing
int debugflow = 0 ;
2013-02-18 12:23:34 -06:00
# ifdef HAVE_LIBREADLINE
# if defined(HAVE_READLINE_READLINE_H)
# include <readline / readline.h>
# elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */
# include <readline.h>
# else /* !defined(HAVE_READLINE_H) */
2019-11-30 10:19:08 -06:00
extern char * readline ( ) ;
2013-02-18 12:23:34 -06:00
# endif /* HAVE_READLINE_H */
# else
/* no readline */
# endif /* HAVE_LIBREADLINE */
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
# if defined(HAVE_READLINE_HISTORY_H)
# include <readline / history.h>
# elif defined(HAVE_HISTORY_H)
# include <history.h>
# else /* !defined(HAVE_HISTORY_H) */
2017-08-09 13:09:55 -05:00
extern void add_history ( ) ;
extern int write_history ( ) ;
extern int read_history ( ) ;
2013-02-18 20:42:42 -06:00
# endif /* defined(HAVE_READLINE_HISTORY_H) */
2017-08-09 13:09:55 -05:00
/* no history */
2013-02-18 20:42:42 -06:00
# endif /* HAVE_READLINE_HISTORY */
2007-11-11 23:03:38 +00:00
2025-07-20 17:37:24 +02:00
# include "hamlib/rig.h"
2026-02-11 15:36:35 -05:00
# include "hamlib/port.h"
# include "hamlib/rig_state.h"
2007-11-11 23:03:38 +00:00
# include "misc.h"
# include "iofunc.h"
2023-02-14 20:02:02 +01:00
# include "riglist.h"
2007-11-11 23:03:38 +00:00
# include "sprintflst.h"
# include "rigctl_parse.h"
2012-02-13 15:22:02 -06:00
/* Hash table implementation See: http://uthash.sourceforge.net/ */
# include "uthash.h"
2014-04-30 03:05:34 +01:00
# define STR1(S) #S
# define STR(S) STR1(S)
2007-11-11 23:03:38 +00:00
# define MAXNAMSIZ 32
2017-08-09 13:09:55 -05:00
# define MAXNBOPT 100 /* max number of different options */
2020-10-25 06:43:48 -05:00
# define MAXARGSZ 511
2007-11-11 23:03:38 +00:00
# define ARG_IN1 0x01
# define ARG_OUT1 0x02
# define ARG_IN2 0x04
# define ARG_OUT2 0x08
# define ARG_IN3 0x10
# define ARG_OUT3 0x20
# define ARG_IN4 0x40
# define ARG_OUT4 0x80
2022-05-14 17:36:28 -05:00
# define ARG_OUT5 0x100
2007-11-11 23:03:38 +00:00
# define ARG_IN_LINE 0x4000
# define ARG_NOVFO 0x8000
# define ARG_IN (ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4)
2022-05-14 17:36:28 -05:00
# define ARG_OUT (ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4|ARG_OUT5)
2007-11-11 23:03:38 +00:00
2020-06-23 11:21:22 -05:00
static int chk_vfo_executed ;
2024-03-14 22:43:10 -05:00
char rigctld_password [ 65 ] ;
2022-02-24 17:13:18 -06:00
int is_rigctld ;
2022-06-06 22:54:10 -05:00
extern int lock_mode ; // used by rigctld
2023-05-26 18:03:20 +03:00
extern powerstat_t rig_powerstat ;
2026-06-03 14:48:05 -04:00
pthread_key_t thread_data_key ;
2022-02-24 17:13:18 -06:00
2020-06-23 11:21:22 -05:00
2013-02-18 12:23:34 -06:00
/* variables for readline support */
# ifdef HAVE_LIBREADLINE
static char * input_line = ( char * ) NULL ;
static char * result = ( char * ) NULL ;
2017-08-09 13:09:55 -05:00
static char * parsed_input [ sizeof ( char * ) * 5 ] ;
2013-02-18 12:23:34 -06:00
static const int have_rl = 1 ;
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
static char * rp_hist_buf = ( char * ) NULL ;
# endif
2013-02-18 12:23:34 -06:00
# else /* no readline */
static const int have_rl = 0 ;
# endif
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
struct test_table
{
2017-08-09 13:09:55 -05:00
unsigned char cmd ;
const char * name ;
int ( * rig_routine ) ( RIG * ,
FILE * ,
FILE * ,
int ,
2019-08-25 08:58:19 +01:00
int ,
2020-05-27 12:21:41 -05:00
int * ,
2019-08-25 08:58:19 +01:00
char ,
int ,
char ,
2017-08-09 13:09:55 -05:00
const struct test_table * ,
vfo_t ,
const char * ,
Fix errors found by glibc 2.43
glibc implements some new parts of the C23 standard:
(Taken from https://download.opensuse.org/tumbleweed/iso/Changes.20260430.txt)
* For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type
and
* The aforementioned change in ISO C23 of the declaration of bsearch,
memchr, strchr, strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr,
wcsstr, and wmemchr as const-preserving macros can lead to compilation
issues in code not set up for it
This lead to some warnings about assigning returns from strchr(const, target)
to non-const pointers, and then discovering that Hamlib was modifying
those const parameters.
This commit aligns the const-ness of the offending parameters. Only affects
internal functions in ampctl_parse.c, rigctl_parse.c and rotctl_parse.c,
so API/ABI should not change.
2026-05-03 14:55:05 -04:00
char * ,
2017-08-09 13:09:55 -05:00
const char * ) ;
int flags ;
const char * arg1 ;
Fix errors found by glibc 2.43
glibc implements some new parts of the C23 standard:
(Taken from https://download.opensuse.org/tumbleweed/iso/Changes.20260430.txt)
* For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type
and
* The aforementioned change in ISO C23 of the declaration of bsearch,
memchr, strchr, strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr,
wcsstr, and wmemchr as const-preserving macros can lead to compilation
issues in code not set up for it
This lead to some warnings about assigning returns from strchr(const, target)
to non-const pointers, and then discovering that Hamlib was modifying
those const parameters.
This commit aligns the const-ness of the offending parameters. Only affects
internal functions in ampctl_parse.c, rigctl_parse.c and rotctl_parse.c,
so API/ABI should not change.
2026-05-03 14:55:05 -04:00
char * arg2 ;
2017-08-09 13:09:55 -05:00
const char * arg3 ;
const char * arg4 ;
2021-04-27 10:32:12 -05:00
const char * arg5 ;
2022-05-14 17:36:28 -05:00
const char * arg6 ;
2007-11-11 23:03:38 +00:00
} ;
2023-05-13 16:11:46 -05:00
# define CHKSCN1ARG(a) if ((a) != 1) { rig_debug(RIG_DEBUG_ERR,"%s: chkarg err\n", __func__);RETURNFUNC2(-RIG_EINVAL);} else do {} while(0)
2010-04-05 10:15:36 +00:00
2014-05-02 19:09:35 +01:00
# define ACTION(f) rigctl_##f
2017-08-09 13:09:55 -05:00
# define declare_proto_rig(f) static int (ACTION(f))(RIG *rig, \
FILE * fout , \
FILE * fin , \
int interactive , \
2019-08-25 08:58:19 +01:00
int prompt , \
2020-05-27 12:21:41 -05:00
int * vfo_opt , \
2019-08-25 08:58:19 +01:00
char send_cmd_term , \
int ext_resp , \
char resp_sep , \
2017-08-09 13:09:55 -05:00
const struct test_table * cmd , \
vfo_t vfo , \
const char * arg1 , \
Fix errors found by glibc 2.43
glibc implements some new parts of the C23 standard:
(Taken from https://download.opensuse.org/tumbleweed/iso/Changes.20260430.txt)
* For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type
and
* The aforementioned change in ISO C23 of the declaration of bsearch,
memchr, strchr, strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr,
wcsstr, and wmemchr as const-preserving macros can lead to compilation
issues in code not set up for it
This lead to some warnings about assigning returns from strchr(const, target)
to non-const pointers, and then discovering that Hamlib was modifying
those const parameters.
This commit aligns the const-ness of the offending parameters. Only affects
internal functions in ampctl_parse.c, rigctl_parse.c and rotctl_parse.c,
so API/ABI should not change.
2026-05-03 14:55:05 -04:00
char * arg2 , \
2017-08-09 13:09:55 -05:00
const char * arg3 )
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_freq ) ;
declare_proto_rig ( get_freq ) ;
declare_proto_rig ( set_rit ) ;
declare_proto_rig ( get_rit ) ;
declare_proto_rig ( set_xit ) ;
declare_proto_rig ( get_xit ) ;
declare_proto_rig ( set_mode ) ;
declare_proto_rig ( get_mode ) ;
2021-05-03 09:24:02 -05:00
declare_proto_rig ( get_modes ) ;
2021-05-03 15:35:56 -05:00
declare_proto_rig ( get_mode_bandwidths ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_vfo ) ;
declare_proto_rig ( get_vfo ) ;
2021-04-27 11:51:43 -05:00
declare_proto_rig ( get_rig_info ) ;
2021-02-07 12:45:59 -06:00
declare_proto_rig ( get_vfo_info ) ;
2021-02-10 17:30:46 -06:00
declare_proto_rig ( get_vfo_list ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_ptt ) ;
declare_proto_rig ( get_ptt ) ;
declare_proto_rig ( get_ptt ) ;
2008-09-21 19:24:47 +00:00
declare_proto_rig ( get_dcd ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_rptr_shift ) ;
declare_proto_rig ( get_rptr_shift ) ;
declare_proto_rig ( set_rptr_offs ) ;
declare_proto_rig ( get_rptr_offs ) ;
declare_proto_rig ( set_ctcss_tone ) ;
declare_proto_rig ( get_ctcss_tone ) ;
declare_proto_rig ( set_dcs_code ) ;
declare_proto_rig ( get_dcs_code ) ;
2008-09-21 19:24:47 +00:00
declare_proto_rig ( set_ctcss_sql ) ;
declare_proto_rig ( get_ctcss_sql ) ;
declare_proto_rig ( set_dcs_sql ) ;
declare_proto_rig ( get_dcs_sql ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_split_freq ) ;
declare_proto_rig ( get_split_freq ) ;
declare_proto_rig ( set_split_mode ) ;
declare_proto_rig ( get_split_mode ) ;
2014-04-28 22:25:06 +01:00
declare_proto_rig ( set_split_freq_mode ) ;
declare_proto_rig ( get_split_freq_mode ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_split_vfo ) ;
declare_proto_rig ( get_split_vfo ) ;
declare_proto_rig ( set_ts ) ;
declare_proto_rig ( get_ts ) ;
declare_proto_rig ( power2mW ) ;
2010-02-06 15:05:17 +00:00
declare_proto_rig ( mW2power ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_level ) ;
declare_proto_rig ( get_level ) ;
declare_proto_rig ( set_func ) ;
declare_proto_rig ( get_func ) ;
declare_proto_rig ( set_parm ) ;
declare_proto_rig ( get_parm ) ;
declare_proto_rig ( set_bank ) ;
declare_proto_rig ( set_mem ) ;
declare_proto_rig ( get_mem ) ;
declare_proto_rig ( vfo_op ) ;
declare_proto_rig ( scan ) ;
declare_proto_rig ( set_channel ) ;
declare_proto_rig ( get_channel ) ;
declare_proto_rig ( set_trn ) ;
declare_proto_rig ( get_trn ) ;
declare_proto_rig ( get_info ) ;
declare_proto_rig ( dump_caps ) ;
2008-05-23 14:30:12 +00:00
declare_proto_rig ( dump_conf ) ;
2008-09-21 19:24:47 +00:00
declare_proto_rig ( dump_state ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_ant ) ;
declare_proto_rig ( get_ant ) ;
declare_proto_rig ( reset ) ;
declare_proto_rig ( send_morse ) ;
2020-10-16 08:41:57 -05:00
declare_proto_rig ( stop_morse ) ;
2020-10-18 14:22:42 -05:00
declare_proto_rig ( wait_morse ) ;
2020-02-06 01:00:34 +01:00
declare_proto_rig ( send_voice_mem ) ;
2023-08-18 16:49:35 -05:00
declare_proto_rig ( stop_voice_mem ) ;
2007-11-11 23:03:38 +00:00
declare_proto_rig ( send_cmd ) ;
declare_proto_rig ( set_powerstat ) ;
declare_proto_rig ( get_powerstat ) ;
2008-09-21 19:24:47 +00:00
declare_proto_rig ( send_dtmf ) ;
declare_proto_rig ( recv_dtmf ) ;
2010-02-04 00:53:56 +00:00
declare_proto_rig ( chk_vfo ) ;
2020-05-27 12:21:41 -05:00
declare_proto_rig ( set_vfo_opt ) ;
2020-02-24 09:34:02 -06:00
declare_proto_rig ( set_twiddle ) ;
declare_proto_rig ( get_twiddle ) ;
2020-10-23 11:34:42 -05:00
declare_proto_rig ( set_uplink ) ;
2020-04-30 16:52:11 -05:00
declare_proto_rig ( set_cache ) ;
declare_proto_rig ( get_cache ) ;
2011-06-14 23:09:33 +02:00
declare_proto_rig ( halt ) ;
2014-05-02 18:41:50 +01:00
declare_proto_rig ( pause ) ;
2026-06-03 13:07:07 -04:00
# if RIGCTLD_PASSWORDS
2021-10-16 09:20:24 -05:00
declare_proto_rig ( password ) ;
2022-04-15 13:21:35 -05:00
//declare_proto_rig(set_password);
2026-06-03 13:07:07 -04:00
# endif
2021-12-01 11:50:33 -06:00
declare_proto_rig ( set_clock ) ;
declare_proto_rig ( get_clock ) ;
2022-05-21 12:33:00 -05:00
declare_proto_rig ( set_separator ) ;
declare_proto_rig ( get_separator ) ;
2022-05-29 12:00:03 -05:00
declare_proto_rig ( set_lock_mode ) ;
declare_proto_rig ( get_lock_mode ) ;
2022-11-24 23:27:07 -06:00
declare_proto_rig ( send_raw ) ;
2022-12-23 23:39:20 -06:00
declare_proto_rig ( client_version ) ;
2023-07-11 11:13:04 -05:00
declare_proto_rig ( hamlib_version ) ;
2023-07-04 17:31:07 -05:00
declare_proto_rig ( test ) ;
2023-07-22 10:32:25 -05:00
declare_proto_rig ( cm108_get_bit ) ;
declare_proto_rig ( cm108_set_bit ) ;
2023-11-05 17:03:21 -06:00
declare_proto_rig ( set_conf ) ;
declare_proto_rig ( get_conf ) ;
2007-11-11 23:03:38 +00:00
/*
* convention : upper case cmd is set , lowercase is get
*
* NB : ' q ' ' Q ' ' ? ' are reserved by interactive mode interface
*/
2017-10-06 18:58:42 -05:00
static struct test_table test_list [ ] =
{
2020-05-13 17:44:17 -05:00
#if 0 // implement set_freq VFO later if it can be detected
2021-05-01 15:51:52 -05:00
{ ' F ' , " set_freq " , ACTION ( set_freq ) , ARG_IN1 | ARG_OUT1 , " Frequency " } ,
2020-05-27 23:44:18 -05:00
{ ' f ' , " get_freq " , ACTION ( get_freq ) , ARG_OUT , " Frequency " , " VFO " } ,
2020-05-13 17:44:17 -05:00
# else
{ ' F ' , " set_freq " , ACTION ( set_freq ) , ARG_IN1 , " Frequency " } ,
# endif
2020-05-27 23:44:18 -05:00
{ ' f ' , " get_freq " , ACTION ( get_freq ) , ARG_OUT , " Frequency " } ,
2017-08-09 13:09:55 -05:00
{ ' M ' , " set_mode " , ACTION ( set_mode ) , ARG_IN , " Mode " , " Passband " } ,
2017-10-06 18:58:42 -05:00
{ ' m ' , " get_mode " , ACTION ( get_mode ) , ARG_OUT , " Mode " , " Passband " } ,
2017-08-09 13:09:55 -05:00
{ ' I ' , " set_split_freq " , ACTION ( set_split_freq ) , ARG_IN , " TX Frequency " } ,
2017-10-06 18:58:42 -05:00
{ ' i ' , " get_split_freq " , ACTION ( get_split_freq ) , ARG_OUT , " TX Frequency " } ,
2017-08-09 13:09:55 -05:00
{ ' X ' , " set_split_mode " , ACTION ( set_split_mode ) , ARG_IN , " TX Mode " , " TX Passband " } ,
2017-10-06 18:58:42 -05:00
{ ' x ' , " get_split_mode " , ACTION ( get_split_mode ) , ARG_OUT , " TX Mode " , " TX Passband " } ,
2017-08-09 13:09:55 -05:00
{ ' K ' , " set_split_freq_mode " , ACTION ( set_split_freq_mode ) , ARG_IN , " TX Frequency " , " TX Mode " , " TX Passband " } ,
{ ' k ' , " get_split_freq_mode " , ACTION ( get_split_freq_mode ) , ARG_OUT , " TX Frequency " , " TX Mode " , " TX Passband " } ,
{ ' S ' , " set_split_vfo " , ACTION ( set_split_vfo ) , ARG_IN , " Split " , " TX VFO " } ,
2017-10-06 18:58:42 -05:00
{ ' s ' , " get_split_vfo " , ACTION ( get_split_vfo ) , ARG_OUT , " Split " , " TX VFO " } ,
2017-08-09 13:09:55 -05:00
{ ' N ' , " set_ts " , ACTION ( set_ts ) , ARG_IN , " Tuning Step " } ,
2017-10-06 18:58:42 -05:00
{ ' n ' , " get_ts " , ACTION ( get_ts ) , ARG_OUT , " Tuning Step " } ,
2017-08-09 13:09:55 -05:00
{ ' L ' , " set_level " , ACTION ( set_level ) , ARG_IN , " Level " , " Level Value " } ,
{ ' l ' , " get_level " , ACTION ( get_level ) , ARG_IN1 | ARG_OUT2 , " Level " , " Level Value " } ,
{ ' U ' , " set_func " , ACTION ( set_func ) , ARG_IN , " Func " , " Func Status " } ,
{ ' u ' , " get_func " , ACTION ( get_func ) , ARG_IN1 | ARG_OUT2 , " Func " , " Func Status " } ,
{ ' P ' , " set_parm " , ACTION ( set_parm ) , ARG_IN | ARG_NOVFO , " Parm " , " Parm Value " } ,
{ ' p ' , " get_parm " , ACTION ( get_parm ) , ARG_IN1 | ARG_OUT2 | ARG_NOVFO , " Parm " , " Parm Value " } ,
{ ' G ' , " vfo_op " , ACTION ( vfo_op ) , ARG_IN , " Mem/VFO Op " } ,
{ ' g ' , " scan " , ACTION ( scan ) , ARG_IN , " Scan Fct " , " Scan Channel " } ,
{ ' A ' , " set_trn " , ACTION ( set_trn ) , ARG_IN | ARG_NOVFO , " Transceive " } ,
{ ' a ' , " get_trn " , ACTION ( get_trn ) , ARG_OUT | ARG_NOVFO , " Transceive " } ,
2025-10-05 11:31:58 +02:00
{ ' R ' , " set_rptr_shift " , ACTION ( set_rptr_shift ) , ARG_IN , " Repeater Shift " } ,
{ ' r ' , " get_rptr_shift " , ACTION ( get_rptr_shift ) , ARG_OUT , " Repeater Shift " } ,
{ ' O ' , " set_rptr_offs " , ACTION ( set_rptr_offs ) , ARG_IN , " Repeater Offset " } ,
{ ' o ' , " get_rptr_offs " , ACTION ( get_rptr_offs ) , ARG_OUT , " Repeater Offset " } ,
2017-08-09 13:09:55 -05:00
{ ' C ' , " set_ctcss_tone " , ACTION ( set_ctcss_tone ) , ARG_IN , " CTCSS Tone " } ,
2017-10-06 18:58:42 -05:00
{ ' c ' , " get_ctcss_tone " , ACTION ( get_ctcss_tone ) , ARG_OUT , " CTCSS Tone " } ,
2017-08-09 13:09:55 -05:00
{ ' D ' , " set_dcs_code " , ACTION ( set_dcs_code ) , ARG_IN , " DCS Code " } ,
2017-10-06 18:58:42 -05:00
{ ' d ' , " get_dcs_code " , ACTION ( get_dcs_code ) , ARG_OUT , " DCS Code " } ,
2025-10-05 11:31:58 +02:00
{ 0x90 , " set_ctcss_sql " , ACTION ( set_ctcss_sql ) , ARG_IN , " CTCSS Squelch " } ,
{ 0x91 , " get_ctcss_sql " , ACTION ( get_ctcss_sql ) , ARG_OUT , " CTCSS Squelch " } ,
{ 0x92 , " set_dcs_sql " , ACTION ( set_dcs_sql ) , ARG_IN , " DCS Squelch " } ,
{ 0x93 , " get_dcs_sql " , ACTION ( get_dcs_sql ) , ARG_OUT , " DCS Squelch " } ,
2020-05-27 12:21:41 -05:00
//
2020-05-15 14:17:59 -05:00
//{ 'V', "set_vfo", ACTION(set_vfo), ARG_IN | ARG_NOVFO | ARG_OUT, "VFO" },
{ ' V ' , " set_vfo " , ACTION ( set_vfo ) , ARG_IN | ARG_NOVFO , " VFO " } ,
2020-05-27 12:21:41 -05:00
{ ' v ' , " get_vfo " , ACTION ( get_vfo ) , ARG_NOVFO | ARG_OUT , " VFO " } ,
2017-08-09 13:09:55 -05:00
{ ' T ' , " set_ptt " , ACTION ( set_ptt ) , ARG_IN , " PTT " } ,
2017-10-06 18:58:42 -05:00
{ ' t ' , " get_ptt " , ACTION ( get_ptt ) , ARG_OUT , " PTT " } ,
2017-08-09 13:09:55 -05:00
{ ' E ' , " set_mem " , ACTION ( set_mem ) , ARG_IN , " Memory# " } ,
2017-10-06 18:58:42 -05:00
{ ' e ' , " get_mem " , ACTION ( get_mem ) , ARG_OUT , " Memory# " } ,
2020-05-06 08:06:14 -05:00
{ ' H ' , " set_channel " , ACTION ( set_channel ) , ARG_IN | ARG_NOVFO , " Channel " } ,
{ ' h ' , " get_channel " , ACTION ( get_channel ) , ARG_IN | ARG_NOVFO , " Channel " , " Read Only " } ,
2017-08-09 13:09:55 -05:00
{ ' B ' , " set_bank " , ACTION ( set_bank ) , ARG_IN , " Bank " } ,
{ ' _ ' , " get_info " , ACTION ( get_info ) , ARG_OUT | ARG_NOVFO , " Info " } ,
{ ' J ' , " set_rit " , ACTION ( set_rit ) , ARG_IN , " RIT " } ,
2017-10-06 18:58:42 -05:00
{ ' j ' , " get_rit " , ACTION ( get_rit ) , ARG_OUT , " RIT " } ,
2017-08-09 13:09:55 -05:00
{ ' Z ' , " set_xit " , ACTION ( set_xit ) , ARG_IN , " XIT " } ,
2017-10-06 18:58:42 -05:00
{ ' z ' , " get_xit " , ACTION ( get_xit ) , ARG_OUT , " XIT " } ,
2023-10-10 10:44:39 -05:00
{ ' Y ' , " set_ant " , ACTION ( set_ant ) , ARG_IN , " Antenna " , " Option " } ,
{ ' y ' , " get_ant " , ACTION ( get_ant ) , ARG_IN1 | ARG_OUT2 , " AntCurr " , " Option " , " AntTx " , " AntRx " } ,
2017-08-09 13:09:55 -05:00
{ 0x87 , " set_powerstat " , ACTION ( set_powerstat ) , ARG_IN | ARG_NOVFO , " Power Status " } ,
{ 0x88 , " get_powerstat " , ACTION ( get_powerstat ) , ARG_OUT | ARG_NOVFO , " Power Status " } ,
2023-10-07 14:10:50 -05:00
{ 0x89 , " send_dtmf " , ACTION ( send_dtmf ) , ARG_IN | ARG_NOVFO , " Digits " } ,
{ 0x8a , " recv_dtmf " , ACTION ( recv_dtmf ) , ARG_OUT | ARG_NOVFO , " Digits " } ,
2025-10-05 11:31:58 +02:00
{ ' w ' , " send_cmd " , ACTION ( send_cmd ) , ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO , " Command " , " Reply " } ,
{ ' W ' , " send_cmd_rx " , ACTION ( send_cmd ) , ARG_IN | ARG_OUT2 | ARG_NOVFO , " Command " , " Reply " } ,
2025-10-04 21:50:20 +02:00
{ ' * ' , " reset " , ACTION ( reset ) , ARG_IN | ARG_NOVFO , " Reset " } ,
2021-09-10 05:46:13 -05:00
{ ' b ' , " send_morse " , ACTION ( send_morse ) , ARG_IN | ARG_NOVFO | ARG_IN_LINE , " Morse " } ,
2023-08-21 15:16:32 -05:00
{ 0xbb , " stop_morse " , ACTION ( stop_morse ) , ARG_NOVFO } ,
{ 0xbc , " wait_morse " , ACTION ( wait_morse ) , ARG_NOVFO } ,
{ 0x94 , " send_voice_mem " , ACTION ( send_voice_mem ) , ARG_NOVFO | ARG_IN , " Voice Mem# " } ,
{ 0xab , " stop_voice_mem " , ACTION ( stop_voice_mem ) , ARG_NOVFO } ,
2023-10-07 14:10:50 -05:00
{ 0x8b , " get_dcd " , ACTION ( get_dcd ) , ARG_OUT | ARG_NOVFO , " DCD " } ,
2025-10-05 11:31:10 +02:00
{ 0x97 , " uplink " , ACTION ( set_uplink ) , ARG_IN | ARG_NOVFO , " 1=Sub,2=Main " } ,
2020-10-23 11:34:42 -05:00
{ 0x8d , " set_twiddle " , ACTION ( set_twiddle ) , ARG_IN | ARG_NOVFO , " Timeout (secs) " } ,
{ 0x8e , " get_twiddle " , ACTION ( get_twiddle ) , ARG_OUT | ARG_NOVFO , " Timeout (secs) " } ,
2020-04-30 16:52:11 -05:00
{ 0x95 , " set_cache " , ACTION ( set_cache ) , ARG_IN | ARG_NOVFO , " Timeout (msecs) " } ,
{ 0x96 , " get_cache " , ACTION ( get_cache ) , ARG_OUT | ARG_NOVFO , " Timeout (msecs) " } ,
2017-08-09 13:09:55 -05:00
{ ' 2 ' , " power2mW " , ACTION ( power2mW ) , ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO , " Power [0.0..1.0] " , " Frequency " , " Mode " , " Power mW " } ,
2025-10-05 11:31:58 +02:00
{ ' 4 ' , " mW2power " , ACTION ( mW2power ) , ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO , " Power mW " , " Freq " , " Mode " , " Power [0.0..1.0] " } ,
2017-08-09 13:09:55 -05:00
{ ' 1 ' , " dump_caps " , ACTION ( dump_caps ) , ARG_NOVFO } ,
{ ' 3 ' , " dump_conf " , ACTION ( dump_conf ) , ARG_NOVFO } ,
{ 0x8f , " dump_state " , ACTION ( dump_state ) , ARG_OUT | ARG_NOVFO } ,
2019-09-09 22:45:55 -05:00
{ 0xf0 , " chk_vfo " , ACTION ( chk_vfo ) , ARG_NOVFO , " ChkVFO " } , /* rigctld only--check for VFO mode */
2020-05-27 12:23:08 -05:00
{ 0xf2 , " set_vfo_opt " , ACTION ( set_vfo_opt ) , ARG_NOVFO | ARG_IN , " Status " } , /* turn vfo option on/off */
2023-10-15 22:53:27 -05:00
{ 0xf3 , " get_vfo_info " , ACTION ( get_vfo_info ) , ARG_IN1 | ARG_NOVFO | ARG_OUT5 , " VFO " , " Freq " , " Mode " , " Width " , " Split " , " SatMode " } , /* get several vfo parameters at once */
2021-04-27 11:51:43 -05:00
{ 0xf5 , " get_rig_info " , ACTION ( get_rig_info ) , ARG_NOVFO | ARG_OUT , " RigInfo " } , /* get several vfo parameters at once */
2021-05-03 15:35:56 -05:00
{ 0xf4 , " get_vfo_list " , ACTION ( get_vfo_list ) , ARG_OUT | ARG_NOVFO , " VFOs " } ,
{ 0xf6 , " get_modes " , ACTION ( get_modes ) , ARG_OUT | ARG_NOVFO , " Modes " } ,
2021-12-01 22:52:55 -06:00
// { 0xf9, "get_clock", ACTION(get_clock), ARG_IN | ARG_NOVFO, "local/utc" },
{ 0xf9 , " get_clock " , ACTION ( get_clock ) , ARG_NOVFO } ,
2024-08-30 16:36:10 -05:00
{ 0xf8 , " set_clock " , ACTION ( set_clock ) , ARG_IN | ARG_NOVFO , " local or utc or YYYY-MM-DDTHH:MM:SS.sss+ZZ or YYYY-MM-DDTHH:MM+ZZ " } ,
2017-08-09 13:09:55 -05:00
{ 0xf1 , " halt " , ACTION ( halt ) , ARG_NOVFO } , /* rigctld only--halt the daemon */
2023-10-07 14:10:50 -05:00
{ 0x8c , " pause " , ACTION ( pause ) , ARG_IN | ARG_NOVFO , " Seconds " } ,
2026-06-03 13:07:07 -04:00
# if RIGCTLD_PASSWORDS
2022-02-24 17:13:18 -06:00
{ 0x98 , " password " , ACTION ( password ) , ARG_IN | ARG_NOVFO , " Password " } ,
2022-04-15 13:21:35 -05:00
// { 0x99, "set_password", ACTION(set_password), ARG_IN | ARG_NOVFO, "Password" },
2026-06-03 13:07:07 -04:00
# endif
2022-05-21 12:33:00 -05:00
{ 0xa0 , " set_separator " , ACTION ( set_separator ) , ARG_IN | ARG_NOVFO , " Separator " } ,
2022-05-29 12:00:03 -05:00
{ 0xa1 , " get_separator " , ACTION ( get_separator ) , ARG_NOVFO , " Separator " } ,
2022-05-29 12:06:44 -05:00
{ 0xa2 , " set_lock_mode " , ACTION ( set_lock_mode ) , ARG_IN | ARG_NOVFO , " Locked " } ,
{ 0xa3 , " get_lock_mode " , ACTION ( get_lock_mode ) , ARG_NOVFO , " Locked " } ,
2025-10-04 21:50:20 +02:00
{ 0xf7 , " get_mode_bandwidths " , ACTION ( get_mode_bandwidths ) , ARG_IN | ARG_NOVFO , " Mode " } ,
2022-11-26 16:13:41 -06:00
{ 0xa4 , " send_raw " , ACTION ( send_raw ) , ARG_NOVFO | ARG_IN1 | ARG_IN2 | ARG_OUT3 , " Terminator " , " Command " , " Send raw answer " } ,
2022-12-23 23:39:20 -06:00
{ 0xa5 , " client_version " , ACTION ( client_version ) , ARG_NOVFO | ARG_IN1 , " Version " , " Client version " } ,
2023-07-11 11:13:04 -05:00
{ 0xa8 , " hamlib_version " , ACTION ( hamlib_version ) , ARG_NOVFO } ,
2023-12-16 11:37:58 -06:00
{ 0xaa , " set_gpio " , ACTION ( cm108_set_bit ) , ARG_NOVFO | ARG_IN , " GPIO# " , " 0/1 " } ,
2025-10-05 09:02:00 +02:00
{ 0xa9 , " get_gpio " , ACTION ( cm108_get_bit ) , ARG_NOVFO | ARG_IN1 | ARG_OUT1 , " GPIO# " , " 0/1 " } ,
2023-12-16 11:37:58 -06:00
{ 0xac , " set_conf " , ACTION ( set_conf ) , ARG_NOVFO | ARG_IN , " Token " , " Token Value " } ,
2023-11-05 17:03:21 -06:00
{ 0xad , " get_conf " , ACTION ( get_conf ) , ARG_NOVFO | ARG_IN1 | ARG_OUT2 , " Token " , " Value " } ,
2025-10-04 21:50:20 +02:00
{ 0xa7 , " test " , ACTION ( test ) , ARG_NOVFO | ARG_IN , " routine " } ,
2017-08-09 13:09:55 -05:00
{ 0x00 , " " , NULL } ,
2007-11-11 23:03:38 +00:00
} ;
2017-08-09 13:09:55 -05:00
2019-11-30 10:19:08 -06:00
static struct test_table * find_cmd_entry ( int cmd )
2007-11-11 23:03:38 +00:00
{
2017-08-09 13:09:55 -05:00
int i ;
2019-12-06 12:13:38 -06:00
for ( i = 0 ; test_list [ i ] . cmd ! = 0x00 ; i + + )
2017-10-06 18:58:42 -05:00
{
if ( test_list [ i ] . cmd = = cmd )
{
2017-08-09 13:09:55 -05:00
break ;
}
}
2007-11-11 23:03:38 +00:00
2020-01-14 23:36:01 -06:00
if ( test_list [ i ] . cmd = = 0x00 )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
return NULL ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
return & test_list [ i ] ;
2007-11-11 23:03:38 +00:00
}
2012-02-13 15:22:02 -06:00
2017-08-09 13:09:55 -05:00
2012-02-13 15:22:02 -06:00
/* Structure for hash table provided by uthash.h
*
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 09:02:12 +02:00
* Structure and hash functions patterned after / copied from example . c
2012-02-13 15:22:02 -06:00
* distributed with the uthash package . See : http : //uthash.sourceforge.net/
*/
2017-10-06 18:58:42 -05:00
struct mod_lst
{
2017-08-09 13:09:55 -05:00
int id ; /* caps->rig_model This is the hash key */
char mfg_name [ 32 ] ; /* caps->mfg_name */
char model_name [ 32 ] ; /* caps->model_name */
char version [ 32 ] ; /* caps->version */
char status [ 32 ] ; /* caps->status */
2020-03-05 23:48:14 -06:00
char macro_name [ 32 ] ; /* caps->status */
2017-08-09 13:09:55 -05:00
UT_hash_handle hh ; /* makes this structure hashable */
2012-02-13 15:22:02 -06:00
} ;
2017-08-09 13:09:55 -05:00
2012-02-13 15:22:02 -06:00
/* Hash declaration. Must be initialized to NULL */
struct mod_lst * models = NULL ;
2017-08-09 13:09:55 -05:00
2012-02-13 15:22:02 -06:00
/* Add model information to the hash */
2017-08-09 13:09:55 -05:00
void hash_add_model ( int id ,
const char * mfg_name ,
const char * model_name ,
const char * version ,
2020-03-05 23:48:14 -06:00
const char * status ,
const char * macro_name )
2012-02-13 15:22:02 -06:00
{
2017-08-09 13:09:55 -05:00
struct mod_lst * s ;
2012-02-13 15:22:02 -06:00
2022-07-27 17:16:17 -05:00
s = ( struct mod_lst * ) calloc ( 1 , sizeof ( struct mod_lst ) ) ;
2012-02-13 15:22:02 -06:00
2017-08-09 13:09:55 -05:00
s - > id = id ;
2022-01-11 00:00:44 -06:00
SNPRINTF ( s - > mfg_name , sizeof ( s - > mfg_name ) , " %s " , mfg_name ) ;
SNPRINTF ( s - > model_name , sizeof ( s - > model_name ) , " %s " , model_name ) ;
SNPRINTF ( s - > version , sizeof ( s - > version ) , " %s " , version ) ;
SNPRINTF ( s - > status , sizeof ( s - > status ) , " %s " , status ) ;
SNPRINTF ( s - > macro_name , sizeof ( s - > macro_name ) , " %s " , macro_name ) ;
2012-02-13 15:22:02 -06:00
2017-08-09 13:09:55 -05:00
HASH_ADD_INT ( models , id , s ) ; /* id: name of key field */
2012-02-13 15:22:02 -06:00
}
2017-08-09 13:09:55 -05:00
2012-02-13 15:22:02 -06:00
/* Hash sorting functions */
int hash_model_id_sort ( struct mod_lst * a , struct mod_lst * b )
{
2019-12-06 12:13:38 -06:00
return ( a - > id > b - > id ) ;
2012-02-13 15:22:02 -06:00
}
2017-08-09 13:09:55 -05:00
2012-02-13 15:22:02 -06:00
void hash_sort_by_model_id ( )
{
2020-01-14 23:36:01 -06:00
if ( models ! = NULL )
{
HASH_SORT ( models , hash_model_id_sort ) ;
}
2020-02-23 11:26:09 -06:00
else
{
rig_debug ( RIG_DEBUG_ERR , " %s: models empty? \n " , __func__ ) ;
2020-01-14 23:36:01 -06:00
}
2012-02-13 15:22:02 -06:00
}
2017-08-09 13:09:55 -05:00
2012-02-13 15:22:02 -06:00
/* Delete hash */
2017-08-09 13:09:55 -05:00
void hash_delete_all ( )
{
struct mod_lst * current_model , * tmp ;
2012-02-13 15:22:02 -06:00
2017-10-06 18:58:42 -05:00
HASH_ITER ( hh , models , current_model , tmp )
{
2017-08-09 13:09:55 -05:00
HASH_DEL ( models , current_model ) ; /* delete it (models advances to next) */
free ( current_model ) ; /* free it */
}
2012-02-13 15:22:02 -06:00
}
2024-05-22 11:44:54 -05:00
// modifies s to remove quotes
2025-06-19 11:34:35 -04:00
static void strip_quotes ( char * s )
2024-11-06 08:07:34 -06:00
{
2025-06-19 11:34:35 -04:00
char * s2 ;
2024-05-22 11:44:54 -05:00
char * p ;
2024-11-06 08:07:34 -06:00
if ( s [ 0 ] ! = ' \" ' ) { return ; } // no quotes
2024-05-22 11:44:54 -05:00
s2 = strdup ( & s [ 1 ] ) ;
2024-11-06 08:07:34 -06:00
p = strrchr ( s2 , ' " ' ) ;
if ( p ) { * p = 0 ; }
strcpy ( s , s2 ) ;
2025-06-19 11:34:35 -04:00
free ( s2 ) ;
2024-05-22 11:44:54 -05:00
}
2013-02-18 12:23:34 -06:00
# ifdef HAVE_LIBREADLINE
/* Frees allocated memory and sets pointers to NULL before calling readline
* and then parses the input into space separated tokens .
*/
static void rp_getline ( const char * s )
{
2017-08-09 13:09:55 -05:00
/* free allocated memory and set pointers to NULL */
2017-10-06 18:58:42 -05:00
if ( input_line )
{
2017-08-09 13:09:55 -05:00
free ( input_line ) ;
input_line = ( char * ) NULL ;
}
2013-02-18 12:23:34 -06:00
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
result = ( char * ) NULL ;
}
2013-02-18 12:23:34 -06:00
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; i < 5 ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
parsed_input [ i ] = NULL ;
}
2013-02-18 12:23:34 -06:00
2017-08-09 13:09:55 -05:00
/* Action! Returns typed line with newline stripped. */
input_line = readline ( s ) ;
2013-02-18 12:23:34 -06:00
}
# endif
2007-11-11 23:03:38 +00:00
/*
* TODO : use Lex ?
*/
static char parse_arg ( const char * arg )
{
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; test_list [ i ] . cmd ! = 0x00 ; i + + )
2017-10-06 18:58:42 -05:00
{
if ( ! strncmp ( arg , test_list [ i ] . name , MAXNAMSIZ ) )
{
2017-08-09 13:09:55 -05:00
return test_list [ i ] . cmd ;
}
}
return 0 ;
2007-11-11 23:03:38 +00:00
}
2010-01-24 23:24:20 +00:00
/*
2007-11-11 23:03:38 +00:00
* This scanf works even in presence of signals ( timer , SIGIO , . . )
*/
static int scanfc ( FILE * fin , const char * format , void * p )
{
2017-10-06 18:58:42 -05:00
do
{
2020-01-03 12:18:27 -06:00
int ret ;
2019-12-20 11:22:09 -06:00
* ( char * ) p = 0 ;
2020-02-23 11:26:09 -06:00
2026-07-27 17:14:00 -05:00
errno = 0 ;
2023-10-02 10:48:26 -05:00
2017-08-09 13:09:55 -05:00
ret = fscanf ( fin , format , p ) ;
2026-07-27 17:14:00 -05:00
if ( ret = = EOF & & ferror ( fin ) & & errno = = EINTR )
2017-10-06 18:58:42 -05:00
{
2026-07-27 17:14:00 -05:00
clearerr ( fin ) ;
continue ;
2017-08-09 13:09:55 -05:00
}
2020-04-22 11:47:56 -05:00
if ( ret < 1 ) { rig_debug ( RIG_DEBUG_TRACE , " %s: ret=%d \n " , __func__ , ret ) ; }
2026-07-27 17:14:00 -05:00
if ( ferror ( fin ) )
{
rig_debug ( RIG_DEBUG_ERR , " %s: errno=%d, %s \n " , __func__ , errno ,
strerror ( errno ) ) ;
}
2020-04-22 11:47:56 -05:00
2017-08-09 13:09:55 -05:00
return ret ;
2017-10-06 18:58:42 -05:00
}
while ( 1 ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2014-04-30 03:05:34 +01:00
/*
* function to get the next word from the command line or from stdin
* until stdin exhausted . stdin is read if the special token ' - ' is
* found on the command line .
*
* returns EOF when words exhausted
* returns < 0 is error number
* returns > = 0 when successful
*/
2017-08-09 13:09:55 -05:00
static int next_word ( char * buffer , int argc , char * argv [ ] , int newline )
{
int ret ;
char c ;
static int reading_stdin ;
2017-10-06 18:58:42 -05:00
if ( ! reading_stdin )
{
if ( optind > = argc )
{
2017-08-09 13:09:55 -05:00
return EOF ;
2017-10-06 18:58:42 -05:00
}
else if ( newline & & ' - ' = = argv [ optind ] [ 0 ] & & 1 = = strlen ( argv [ optind ] ) )
{
2017-08-09 13:09:55 -05:00
+ + optind ;
reading_stdin = 1 ;
2014-04-30 03:05:34 +01:00
}
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( reading_stdin )
{
do
{
do
{
2017-08-09 13:09:55 -05:00
ret = scanf ( " %c% " STR ( MAXARGSZ ) " [^ \t \n #] " , & c , & buffer [ 1 ] ) ;
2017-10-06 18:58:42 -05:00
}
while ( EINTR = = ret ) ;
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( ret > 0 & & ' # ' = = c )
{
do
{
2017-08-09 13:09:55 -05:00
ret = scanf ( " %*[^ \n ] " ) ;
2017-10-06 18:58:42 -05:00
}
while ( EINTR = = ret ) ; /* consume comments */
2017-08-09 13:09:55 -05:00
ret = 0 ;
}
2017-10-06 18:58:42 -05:00
}
while ( ! ret ) ;
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( EOF = = ret )
{
2017-08-09 13:09:55 -05:00
reading_stdin = 0 ;
2017-10-06 18:58:42 -05:00
}
else if ( ret < 0 )
{
2017-08-09 13:09:55 -05:00
rig_debug ( RIG_DEBUG_ERR , " scanf: %s \n " , strerror ( errno ) ) ;
reading_stdin = 0 ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
buffer [ 0 ] = c ;
buffer [ 1 = = ret ? 1 : MAXARGSZ ] = ' \0 ' ;
2017-10-06 18:58:42 -05:00
if ( newline )
{
2017-08-09 13:09:55 -05:00
putchar ( ' \n ' ) ;
}
fputs ( buffer , stdout ) ;
putchar ( ' ' ) ;
2014-04-30 03:05:34 +01:00
}
}
2017-10-06 18:58:42 -05:00
if ( ! reading_stdin )
{
if ( optind < argc )
{
2017-08-09 13:09:55 -05:00
strncpy ( buffer , argv [ optind + + ] , MAXARGSZ ) ;
buffer [ MAXARGSZ ] = ' \0 ' ;
ret = 1 ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
ret = EOF ;
2014-04-30 03:05:34 +01:00
}
}
2017-08-09 13:09:55 -05:00
return ret ;
2014-04-30 03:05:34 +01:00
}
2017-08-09 13:09:55 -05:00
2020-01-14 23:36:01 -06:00
# define fprintf_flush(f, a...) \
( { fprintf ( ( f ) , a ) ; \
fflush ( ( f ) ) ; \
\
2017-08-09 13:09:55 -05:00
} )
2010-05-05 20:11:55 +00:00
2026-06-03 14:48:05 -04:00
void rigctl_parse_init ( /* int threaded */ )
{
int retval ;
retval = pthread_key_create ( & thread_data_key , NULL ) ;
if ( retval ! = 0 )
{
rig_debug ( RIG_DEBUG_ERR , " %s: Thread data key not created \n " , __func__ ) ;
}
return ;
}
2019-11-30 10:19:08 -06:00
int rigctl_parse ( RIG * my_rig , FILE * fin , FILE * fout , char * argv [ ] , int argc ,
sync_cb_t sync_cb ,
2020-05-26 12:01:44 -05:00
int interactive , int prompt , int * vfo_opt , char send_cmd_term ,
2022-02-24 17:13:18 -06:00
int * ext_resp_ptr , char * resp_sep_ptr , int use_password )
2007-11-11 23:03:38 +00:00
{
2022-11-28 09:01:28 -06:00
int retcode = - RIG_EINTERNAL ; /* generic return code from functions */
2017-08-09 13:09:55 -05:00
unsigned char cmd ;
struct test_table * cmd_entry = NULL ;
2024-05-31 09:48:30 -04:00
struct rig_state * rs = STATE ( my_rig ) ;
2026-06-03 16:52:49 -04:00
struct handle_data * connection ;
2017-08-09 13:09:55 -05:00
2025-12-10 13:18:49 -05:00
char command [ MAXARGSZ + 1 ] = " " ;
2017-08-09 13:09:55 -05:00
char arg1 [ MAXARGSZ + 1 ] , * p1 = NULL ;
char arg2 [ MAXARGSZ + 1 ] , * p2 = NULL ;
char arg3 [ MAXARGSZ + 1 ] , * p3 = NULL ;
vfo_t vfo = RIG_VFO_CURR ;
2022-12-23 23:39:20 -06:00
char client_version [ 32 ] ;
2026-01-27 15:23:20 -05:00
char name_format [ 8 ] ;
2026-01-28 15:44:36 -05:00
char arg_format [ 8 ] ;
2017-08-09 13:09:55 -05:00
2020-04-25 11:28:38 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: called, interactive=%d \n " , __func__ ,
interactive ) ;
2026-01-27 15:23:20 -05:00
SNPRINTF ( name_format , sizeof ( name_format ) , " %%%ds " , MAXNAMSIZ - 1 ) ;
2026-01-28 15:44:36 -05:00
SNPRINTF ( arg_format , sizeof ( arg_format ) , " %%%ds " , MAXARGSZ - 1 ) ;
2026-01-27 15:23:20 -05:00
2017-08-09 13:09:55 -05:00
/* cmd, internal, rigctld */
2017-10-06 18:58:42 -05:00
if ( ! ( interactive & & prompt & & have_rl ) )
{
2019-12-12 22:29:13 -06:00
2017-10-06 18:58:42 -05:00
if ( interactive )
{
2019-12-19 11:55:14 -06:00
static int last_was_ret = 1 ;
2022-05-10 12:20:54 -05:00
static int last_cmd ;
2019-12-20 11:22:09 -06:00
2017-10-06 18:58:42 -05:00
if ( prompt )
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n Rig command: " ) ;
}
2017-10-06 18:58:42 -05:00
do
{
2020-04-21 10:34:42 -05:00
if ( ( retcode = scanfc ( fin , " %c " , & cmd ) ) < 1 )
2017-10-06 18:58:42 -05:00
{
2023-12-16 11:37:58 -06:00
if ( last_cmd = = 0 )
2023-11-14 10:23:14 -06:00
{
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_WARN ,
" %s: nothing to scan#1? retcode=%d, last_cmd=[empty] \n " ,
__func__ ,
retcode ) ;
2023-11-14 10:23:14 -06:00
}
else
{
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#1? retcode=%d, last_cmd=%c \n " ,
__func__ ,
retcode , last_cmd ) ;
2023-11-14 10:23:14 -06:00
}
2023-12-16 11:37:58 -06:00
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
2020-04-25 11:28:38 -05:00
2021-08-26 06:49:24 -05:00
if ( cmd ! = 0xa & & cmd ! = 0xd )
2020-05-27 12:21:41 -05:00
{
2022-05-11 22:58:46 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: cmd=%c(%02x) handle=%d \n " , __func__ ,
2022-05-11 11:53:20 -05:00
isprint ( cmd ) ? cmd : ' ' , cmd , fileno ( fin ) ) ;
2020-05-26 12:01:44 -05:00
}
2017-08-09 13:09:55 -05:00
/* Extended response protocol requested with leading '+' on command
* string - - rigctld only !
*/
2017-10-06 18:58:42 -05:00
if ( cmd = = ' + ' & & ! prompt )
{
2019-08-25 08:58:19 +01:00
* ext_resp_ptr = 1 ;
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( scanfc ( fin , " %c " , & cmd ) < 1 )
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#2? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
}
else if ( cmd = = ' + ' & & prompt )
{
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
if ( cmd ! = ' \\ '
2019-11-30 10:19:08 -06:00
& & cmd ! = ' _ '
& & cmd ! = ' # '
2020-05-03 17:07:22 -05:00
& & cmd ! = ' ( '
& & cmd ! = ' ) '
2019-11-30 10:19:08 -06:00
& & ispunct ( cmd )
& & ! prompt )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
2019-08-25 08:58:19 +01:00
* ext_resp_ptr = 1 ;
* resp_sep_ptr = cmd ;
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( scanfc ( fin , " %c " , & cmd ) < 1 )
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#3? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
}
else if ( cmd ! = ' \\ '
& & cmd ! = ' ? '
& & cmd ! = ' _ '
& & cmd ! = ' # '
2020-05-01 12:03:54 -05:00
& & cmd ! = ' ( '
& & cmd ! = ' ) '
2017-10-06 18:58:42 -05:00
& & ispunct ( cmd )
& & prompt )
{
2017-08-09 13:09:55 -05:00
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
/* command by name */
2017-10-06 18:58:42 -05:00
if ( cmd = = ' \\ ' )
{
2026-01-27 15:23:20 -05:00
char cmd_name [ MAXNAMSIZ + 1 ] , * pcmd = cmd_name ;
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( scanfc ( fin , " %c " , pcmd ) < 1 )
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#4? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
2026-01-27 15:23:20 -05:00
retcode = fscanf ( fin , name_format , + + pcmd ) ; // Get the rest of the command
2021-02-28 09:46:01 -06:00
2024-12-22 11:14:14 -06:00
if ( retcode = = 0 | | retcode = = EOF ) { rig_debug ( RIG_DEBUG_WARN , " %s: unable to scan %c \n " , __func__ , * ( pcmd - 1 ) ) ; }
2021-02-28 09:46:01 -06:00
while ( * + + pcmd ) ;
2017-08-09 13:09:55 -05:00
* pcmd = ' \0 ' ;
cmd = parse_arg ( ( char * ) cmd_name ) ;
2022-05-13 16:50:13 -05:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s: cmd=%s handle=%d \n " , __func__ , cmd_name ,
fileno ( fin ) ) ;
2017-08-09 13:09:55 -05:00
break ;
}
2021-06-01 07:17:11 -05:00
//rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd==0x%02x\n", __func__, cmd);
2020-07-06 10:15:57 -05:00
2017-10-06 18:58:42 -05:00
if ( cmd = = 0x0a | | cmd = = 0x0d )
{
if ( last_was_ret )
{
if ( prompt )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fprintf_flush ( fout , " \n Rig command: " ) ;
}
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
last_was_ret = 1 ;
}
2017-10-06 18:58:42 -05:00
}
while ( cmd = = 0x0a | | cmd = = 0x0d ) ;
2017-08-09 13:09:55 -05:00
last_was_ret = 0 ;
/* comment line */
2017-10-06 18:58:42 -05:00
if ( cmd = = ' # ' )
{
while ( cmd ! = ' \n ' & & cmd ! = ' \r ' )
{
if ( scanfc ( fin , " %c " , & cmd ) < 1 )
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#6? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
}
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2024-05-31 09:48:30 -04:00
rs - > vfo_opt = * vfo_opt ;
2020-05-01 12:03:54 -05:00
2017-10-06 18:58:42 -05:00
if ( cmd = = ' Q ' | | cmd = = ' q ' )
{
2020-05-03 17:07:22 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: quit returning NETRIGCTL_RET 0 \n " , __func__ ) ;
if ( interactive & & ! prompt ) { fprintf ( fout , " %s0 \n " , NETRIGCTL_RET ) ; }
fflush ( fout ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( cmd = = ' ? ' )
{
2017-08-09 13:09:55 -05:00
usage_rig ( fout ) ;
fflush ( fout ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
/* parse rest of command line */
retcode = next_word ( command , argc , argv , 1 ) ;
2017-10-06 18:58:42 -05:00
if ( EOF = = retcode )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-10-06 18:58:42 -05:00
}
else if ( retcode < 0 )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-10-06 18:58:42 -05:00
}
else if ( ' \0 ' = = command [ 1 ] )
{
2017-08-09 13:09:55 -05:00
cmd = command [ 0 ] ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
cmd = parse_arg ( command ) ;
}
}
2024-12-25 16:36:37 -06:00
if ( strcmp ( command , " skip-init " ) = = 0 )
{
// no-op now since it's automatic in non-interactive mode
return ( RIG_OK ) ;
}
2017-08-09 13:09:55 -05:00
cmd_entry = find_cmd_entry ( cmd ) ;
2017-10-06 18:58:42 -05:00
if ( ! cmd_entry )
{
2024-12-25 16:36:37 -06:00
if ( cmd = = 0 )
{
fprintf ( stderr , " Command '%s' not found! \n " , command ) ;
}
else if ( cmd ! = ' ' )
2020-05-01 12:03:54 -05:00
{
2020-04-27 11:29:03 -05:00
fprintf ( stderr , " Command '%c' not found! \n " , cmd ) ;
}
2020-05-01 12:03:54 -05:00
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2020-05-26 12:01:44 -05:00
if ( ! ( cmd_entry - > flags & ARG_NOVFO ) & & * vfo_opt )
2017-10-06 18:58:42 -05:00
{
if ( interactive )
{
2021-02-08 10:42:24 -06:00
arg1 [ 0 ] = fgetc ( fin ) ;
arg1 [ 1 ] = 0 ;
if ( prompt & & arg1 [ 0 ] = = 0x0a )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " VFO: " ) ;
}
2026-01-28 15:44:36 -05:00
if ( scanfc ( fin , arg_format , arg1 ) < 1 )
2017-10-06 18:58:42 -05:00
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#7? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
vfo = rig_parse_vfo ( arg1 ) ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
retcode = next_word ( arg1 , argc , argv , 0 ) ;
2017-10-06 18:58:42 -05:00
if ( EOF = = retcode )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Invalid arg for command '%s' \n " ,
cmd_entry - > name ) ;
2017-10-06 18:58:42 -05:00
}
else if ( retcode < 0 )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
vfo = rig_parse_vfo ( arg1 ) ;
}
}
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug1 \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
2017-08-09 13:09:55 -05:00
if ( ( cmd_entry - > flags & ARG_IN_LINE )
2019-11-30 10:19:08 -06:00
& & ( cmd_entry - > flags & ARG_IN1 )
& & cmd_entry - > arg1 )
2017-10-06 18:58:42 -05:00
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug2 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( interactive )
{
2017-08-09 13:09:55 -05:00
char * nl ;
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug2a \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( fgets ( arg1 , MAXARGSZ , fin ) = = NULL )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( arg1 [ 0 ] = = 0xa )
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug2b \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
if ( prompt )
{
fprintf_flush ( fout , " %s: " , cmd_entry - > arg1 ) ;
}
2017-10-06 18:58:42 -05:00
if ( fgets ( arg1 , MAXARGSZ , fin ) = = NULL )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
}
nl = strchr ( arg1 , 0xa ) ;
2017-10-06 18:58:42 -05:00
if ( nl )
{
2017-08-09 13:09:55 -05:00
* nl = ' \0 ' ; /* chomp */
}
2023-05-08 07:37:13 -05:00
2023-04-25 22:27:38 -05:00
/* skip a space arg if first arg...happens parsing rigctld commands */
2019-11-30 10:19:08 -06:00
{
2018-03-13 09:05:03 -04:00
p1 = arg1 [ 0 ] = = ' ' ? arg1 + 1 : arg1 ;
}
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
retcode = next_word ( arg1 , argc , argv , 0 ) ;
2017-10-06 18:58:42 -05:00
if ( EOF = = retcode )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Invalid arg for command '%s' \n " ,
cmd_entry - > name ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-10-06 18:58:42 -05:00
}
else if ( retcode < 0 )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
p1 = arg1 ;
}
2017-10-06 18:58:42 -05:00
}
else if ( ( cmd_entry - > flags & ARG_IN1 ) & & cmd_entry - > arg1 )
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug3 \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
2017-10-06 18:58:42 -05:00
if ( interactive )
{
2021-02-08 10:42:24 -06:00
arg1 [ 0 ] = fgetc ( fin ) ;
arg1 [ 1 ] = 0 ;
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug4 arg1=%c \n " , __func__ , arg1 [ 0 ] ) ; }
2017-08-09 13:09:55 -05:00
2021-02-08 10:42:24 -06:00
if ( prompt & & arg1 [ 0 ] = = 0x0a )
2017-10-06 18:58:42 -05:00
{
2020-05-06 08:54:34 -05:00
fprintf_flush ( fout , " %s: " , cmd_entry - > arg1 ) ;
2020-07-06 10:15:57 -05:00
}
2017-08-09 13:09:55 -05:00
2026-01-28 15:44:36 -05:00
if ( scanfc ( fin , arg_format , arg1 ) < 1 )
2019-12-12 22:29:13 -06:00
{
2020-05-06 08:54:34 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#8? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2019-12-12 22:29:13 -06:00
}
2017-08-09 13:09:55 -05:00
p1 = arg1 ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
retcode = next_word ( arg1 , argc , argv , 0 ) ;
2017-10-06 18:58:42 -05:00
if ( EOF = = retcode )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Invalid arg for command '%s' \n " ,
cmd_entry - > name ) ;
2022-02-05 15:27:43 -06:00
return ( 1 ) ;
2017-10-06 18:58:42 -05:00
}
else if ( retcode < 0 )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
p1 = arg1 ;
}
}
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug5 \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
2017-08-09 13:09:55 -05:00
if ( p1
2019-11-30 10:19:08 -06:00
& & p1 [ 0 ] ! = ' ? '
& & ( cmd_entry - > flags & ARG_IN2 )
& & cmd_entry - > arg2 )
2017-10-06 18:58:42 -05:00
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug6 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( interactive )
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug7 \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
2021-08-29 09:59:47 -05:00
arg2 [ 0 ] = fgetc ( fin ) ;
arg2 [ 1 ] = 0 ;
2021-08-28 23:44:35 -05:00
2021-08-29 09:59:47 -05:00
if ( prompt & & arg2 [ 0 ] = = 0x0a )
2017-10-06 18:58:42 -05:00
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug8 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " %s: " , cmd_entry - > arg2 ) ;
}
2020-10-06 23:14:27 -05:00
2026-01-28 15:44:36 -05:00
if ( scanfc ( fin , arg_format , arg2 ) < 1 )
2017-10-06 18:58:42 -05:00
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#9? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
p2 = arg2 ;
2017-10-06 18:58:42 -05:00
}
else
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug9 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
retcode = next_word ( arg2 , argc , argv , 0 ) ;
2017-10-06 18:58:42 -05:00
if ( EOF = = retcode )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Invalid arg for command '%s' \n " ,
cmd_entry - > name ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-10-06 18:58:42 -05:00
}
else if ( retcode < 0 )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
p2 = arg2 ;
}
}
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug10 \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
2017-08-09 13:09:55 -05:00
if ( p1
2019-11-30 10:19:08 -06:00
& & p1 [ 0 ] ! = ' ? '
& & ( cmd_entry - > flags & ARG_IN3 )
& & cmd_entry - > arg3 )
2017-10-06 18:58:42 -05:00
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug11 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( interactive )
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug12 \n " , __func__ ) ; }
2019-12-12 22:29:13 -06:00
2017-10-06 18:58:42 -05:00
if ( prompt )
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug13 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " %s: " , cmd_entry - > arg3 ) ;
}
2026-01-28 15:44:36 -05:00
if ( scanfc ( fin , arg_format , arg3 ) < 1 )
2017-10-06 18:58:42 -05:00
{
2020-04-15 09:57:08 -05:00
rig_debug ( RIG_DEBUG_WARN , " %s: nothing to scan#10? \n " , __func__ ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
p3 = arg3 ;
2017-10-06 18:58:42 -05:00
}
else
{
2021-08-29 00:03:27 -05:00
if ( debugflow ) { rig_debug ( RIG_DEBUG_TRACE , " %s: debug14 \n " , __func__ ) ; }
2017-08-09 13:09:55 -05:00
retcode = next_word ( arg3 , argc , argv , 0 ) ;
2017-10-06 18:58:42 -05:00
if ( EOF = = retcode )
{
fprintf ( stderr ,
" Invalid arg for command '%s' \n " ,
2017-08-09 13:09:55 -05:00
cmd_entry - > name ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-10-06 18:58:42 -05:00
}
else if ( retcode < 0 )
{
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_ERROR ) ;
2017-08-09 13:09:55 -05:00
}
p3 = arg3 ;
}
}
}
2007-11-11 23:03:38 +00:00
2013-02-18 12:23:34 -06:00
# ifdef HAVE_LIBREADLINE
2020-02-23 11:26:09 -06:00
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt & & have_rl )
{
2017-08-09 13:09:55 -05:00
int j , x ;
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
/* Minimum space for 32+1+32+1+128+1+128+1+128+1 = 453 chars, so
* allocate 512 chars cleared to zero for safety .
*/
rp_hist_buf = ( char * ) calloc ( 512 , sizeof ( char ) ) ;
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
rp_getline ( " \n Rig command: " ) ;
/* EOF (Ctl-D) received on empty input line, bail out gracefully. */
2017-10-06 18:58:42 -05:00
if ( ! input_line )
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
/* Q or q to quit */
2017-10-06 18:58:42 -05:00
if ( ! ( strncasecmp ( input_line , " q " , 1 ) ) )
{
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
/* '?' for help */
2017-10-06 18:58:42 -05:00
if ( ! ( strncmp ( input_line , " ? " , 1 ) ) )
{
2017-08-09 13:09:55 -05:00
usage_rig ( fout ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
/* '#' for comment */
2017-10-06 18:58:42 -05:00
if ( ! ( strncmp ( input_line , " # " , 1 ) ) )
{
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
/* Blank line entered */
2017-10-06 18:58:42 -05:00
if ( ! ( strcmp ( input_line , " " ) ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2020-04-04 09:38:50 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: input_line: %s \n " , __func__ , input_line ) ;
2017-08-09 13:09:55 -05:00
/* Split input_line on any number of spaces to get the command token
* Tabs are intercepted by readline for completion and a newline
* causes readline to return the typed text . If more than one
* argument is given , it will be parsed out later .
*/
result = strtok ( input_line , " " ) ;
2021-05-24 10:51:08 -05:00
readline_repeat :
2021-08-26 06:49:24 -05:00
2017-08-09 13:09:55 -05:00
/* parsed_input stores pointers into input_line where the token strings
* start .
*/
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
parsed_input [ 0 ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
/* Oops! Invoke GDB!! */
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
/* At this point parsed_input contains the typed text of the command
* with surrounding space characters removed . If Readline History is
* available , copy the command string into a history buffer .
*/
/* Single character command */
2017-10-06 18:58:42 -05:00
if ( ( strlen ( parsed_input [ 0 ] ) = = 1 ) & & ( * parsed_input [ 0 ] ! = ' \\ ' ) )
{
2017-08-09 13:09:55 -05:00
cmd = * parsed_input [ 0 ] ;
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
/* Store what is typed, not validated, for history. */
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2017-08-09 13:09:55 -05:00
strncpy ( rp_hist_buf , parsed_input [ 0 ] , 1 ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
}
/* Test the command token, parsed_input[0] */
2017-10-06 18:58:42 -05:00
else if ( ( * parsed_input [ 0 ] = = ' \\ ' ) & & ( strlen ( parsed_input [ 0 ] ) > 1 ) )
{
2017-08-09 13:09:55 -05:00
char cmd_name [ MAXNAMSIZ ] ;
/* if there is no terminating '\0' character in the source string,
2025-12-14 01:38:00 +01:00
* strncpy ( ) doesn ' t add one even if the supplied length is less
2017-08-09 13:09:55 -05:00
* than the destination array . Truncate the source string here .
*/
2017-10-06 18:58:42 -05:00
if ( strlen ( parsed_input [ 0 ] + 1 ) > = MAXNAMSIZ )
{
2017-08-09 13:09:55 -05:00
* ( parsed_input [ 0 ] + MAXNAMSIZ ) = ' \0 ' ;
}
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2017-08-09 13:09:55 -05:00
strncpy ( rp_hist_buf , parsed_input [ 0 ] , MAXNAMSIZ ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
/* The starting position of the source string is the first
2019-11-30 10:19:08 -06:00
* character past the initial ' \ ' .
2017-08-09 13:09:55 -05:00
*/
2022-01-11 00:00:44 -06:00
SNPRINTF ( cmd_name , sizeof ( cmd_name ) , " %s " , parsed_input [ 0 ] + 1 ) ;
2017-08-09 13:09:55 -05:00
/* Sanity check as valid multiple character commands consist of
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 09:02:12 +02:00
* alphanumeric characters and the underscore ( ' _ ' ) character .
2017-08-09 13:09:55 -05:00
*/
2017-10-06 18:58:42 -05:00
for ( j = 0 ; cmd_name [ j ] ! = ' \0 ' ; j + + )
{
if ( ! ( isalnum ( ( int ) cmd_name [ j ] ) | | cmd_name [ j ] = = ' _ ' ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr ,
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 09:02:12 +02:00
" Valid multiple character command names contain alphanumeric characters plus '_' \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
}
cmd = parse_arg ( cmd_name ) ;
}
/* Single '\' entered, prompt again */
2017-10-06 18:58:42 -05:00
else if ( ( * parsed_input [ 0 ] = = ' \\ ' ) & & ( strlen ( parsed_input [ 0 ] ) = = 1 ) )
{
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
/* Multiple characters but no leading '\' */
2017-10-06 18:58:42 -05:00
else
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Precede multiple character command names with ' \\ ' \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
cmd_entry = find_cmd_entry ( cmd ) ;
2017-10-06 18:58:42 -05:00
if ( ! cmd_entry )
{
if ( cmd = = ' \0 ' )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Command '%s' not found! \n " , parsed_input [ 0 ] ) ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr , " Command '%c' not found! \n " , cmd ) ;
}
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2020-05-26 12:01:44 -05:00
/* If vfo_opt is enabled (-o|--vfo) check if already given
2017-08-09 13:09:55 -05:00
* or prompt for it .
*/
2020-05-26 12:01:44 -05:00
if ( ! ( cmd_entry - > flags & ARG_NOVFO ) & & * vfo_opt )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
/* Check if VFO was given with command. */
result = strtok ( NULL , " " ) ;
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
x = 1 ;
parsed_input [ x ] = result ;
}
/* Need to prompt if a VFO string was not given. */
2017-10-06 18:58:42 -05:00
else
{
2017-08-09 13:09:55 -05:00
x = 0 ;
rp_getline ( " VFO: " ) ;
2017-10-06 18:58:42 -05:00
if ( ! input_line )
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
/* Blank line entered */
2017-10-06 18:58:42 -05:00
if ( ! ( strcmp ( input_line , " " ) ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
/* Get the first token of input, the rest, if any, will be
* used later .
*/
result = strtok ( input_line , " " ) ;
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
}
/* VFO name tokens are presently quite short. Truncate excessively
* long strings .
*/
2017-10-06 18:58:42 -05:00
if ( strlen ( parsed_input [ x ] ) > = MAXNAMSIZ )
{
2017-08-09 13:09:55 -05:00
* ( parsed_input [ x ] + ( MAXNAMSIZ - 1 ) ) = ' \0 ' ;
}
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2018-04-15 22:54:27 -05:00
strncat ( rp_hist_buf , " " , 2 ) ;
2017-08-09 13:09:55 -05:00
strncat ( rp_hist_buf , parsed_input [ x ] , MAXNAMSIZ ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
/* Sanity check, VFO names are alpha only. */
2017-10-06 18:58:42 -05:00
for ( j = 0 ; j < MAXNAMSIZ & & parsed_input [ x ] [ j ] ! = ' \0 ' ; j + + )
{
if ( ! ( isalpha ( ( int ) parsed_input [ x ] [ j ] ) ) )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] [ j ] = ' \0 ' ;
break ;
}
}
vfo = rig_parse_vfo ( parsed_input [ x ] ) ;
2017-10-06 18:58:42 -05:00
if ( vfo = = RIG_VFO_NONE )
{
2017-08-09 13:09:55 -05:00
fprintf ( stderr ,
" Warning: VFO '%s' unrecognized, using 'currVFO' instead. \n " ,
parsed_input [ x ] ) ;
vfo = RIG_VFO_CURR ;
}
}
/* \send_cmd, \send_morse */
if ( ( cmd_entry - > flags & ARG_IN_LINE )
2019-11-30 10:19:08 -06:00
& & ( cmd_entry - > flags & ARG_IN1 )
& & cmd_entry - > arg1 )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
/* Check for a non-existent delimiter so as to not break up
* remaining line into separate tokens ( spaces OK ) .
*/
result = strtok ( NULL , " \0 " ) ;
2020-05-26 12:01:44 -05:00
if ( * vfo_opt & & result )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
x = 2 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else if ( result )
{
2017-08-09 13:09:55 -05:00
x = 1 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
char pmptstr [ ( strlen ( cmd_entry - > arg1 ) + 3 ) ] ;
2019-12-09 17:12:13 -06:00
x = 0 ;
2017-08-09 13:09:55 -05:00
strcpy ( pmptstr , cmd_entry - > arg1 ) ;
strcat ( pmptstr , " : " ) ;
rp_getline ( pmptstr ) ;
/* Blank line entered */
2019-12-08 23:37:46 -06:00
if ( input_line & & ! ( strcmp ( input_line , " " ) ) )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( input_line )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] = input_line ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
}
/* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */
2017-10-06 18:58:42 -05:00
if ( strlen ( parsed_input [ x ] ) > MAXARGSZ )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] [ MAXARGSZ ] = ' \0 ' ;
}
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2018-04-15 22:54:27 -05:00
strncat ( rp_hist_buf , " " , 2 ) ;
2017-08-09 13:09:55 -05:00
strncat ( rp_hist_buf , parsed_input [ x ] , MAXARGSZ ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
strcpy ( arg1 , parsed_input [ x ] ) ;
p1 = arg1 ;
}
/* Normal argument parsing. */
2017-10-06 18:58:42 -05:00
else if ( ( cmd_entry - > flags & ARG_IN1 ) & & cmd_entry - > arg1 )
{
2017-08-09 13:09:55 -05:00
result = strtok ( NULL , " " ) ;
2020-05-26 12:01:44 -05:00
if ( * vfo_opt & & result )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
x = 2 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else if ( result )
{
2017-08-09 13:09:55 -05:00
x = 1 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
char pmptstr [ ( strlen ( cmd_entry - > arg1 ) + 3 ) ] ;
2019-12-09 17:12:13 -06:00
x = 0 ;
2017-08-09 13:09:55 -05:00
strcpy ( pmptstr , cmd_entry - > arg1 ) ;
strcat ( pmptstr , " : " ) ;
rp_getline ( pmptstr ) ;
2023-04-10 09:15:12 +02:00
if ( ! input_line | | ! ( strcmp ( input_line , " " ) ) )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
result = strtok ( input_line , " " ) ;
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
}
2017-10-06 18:58:42 -05:00
if ( strlen ( parsed_input [ x ] ) > MAXARGSZ )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] [ MAXARGSZ ] = ' \0 ' ;
}
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2018-04-15 22:54:27 -05:00
strncat ( rp_hist_buf , " " , 2 ) ;
2017-08-09 13:09:55 -05:00
strncat ( rp_hist_buf , parsed_input [ x ] , MAXARGSZ ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
strcpy ( arg1 , parsed_input [ x ] ) ;
p1 = arg1 ;
}
if ( p1
2019-11-30 10:19:08 -06:00
& & p1 [ 0 ] ! = ' ? '
& & ( cmd_entry - > flags & ARG_IN2 )
& & cmd_entry - > arg2 )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
result = strtok ( NULL , " " ) ;
2020-05-26 12:01:44 -05:00
if ( * vfo_opt & & result )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
x = 3 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else if ( result )
{
2017-08-09 13:09:55 -05:00
x = 2 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
char pmptstr [ ( strlen ( cmd_entry - > arg2 ) + 3 ) ] ;
2019-12-09 17:12:13 -06:00
x = 0 ;
2017-08-09 13:09:55 -05:00
strcpy ( pmptstr , cmd_entry - > arg2 ) ;
strcat ( pmptstr , " : " ) ;
rp_getline ( pmptstr ) ;
2023-04-10 09:15:12 +02:00
if ( ! input_line | | ! ( strcmp ( input_line , " " ) ) )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
result = strtok ( input_line , " " ) ;
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
}
2017-10-06 18:58:42 -05:00
if ( strlen ( parsed_input [ x ] ) > MAXARGSZ )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] [ MAXARGSZ ] = ' \0 ' ;
}
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2018-04-15 22:54:27 -05:00
strncat ( rp_hist_buf , " " , 2 ) ;
2017-08-09 13:09:55 -05:00
strncat ( rp_hist_buf , parsed_input [ x ] , MAXARGSZ ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
strcpy ( arg2 , parsed_input [ x ] ) ;
p2 = arg2 ;
}
if ( p1
2019-11-30 10:19:08 -06:00
& & p1 [ 0 ] ! = ' ? '
& & ( cmd_entry - > flags & ARG_IN3 )
& & cmd_entry - > arg3 )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
result = strtok ( NULL , " " ) ;
2020-05-26 12:01:44 -05:00
if ( * vfo_opt & & result )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
x = 4 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else if ( result )
{
2017-08-09 13:09:55 -05:00
x = 3 ;
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
char pmptstr [ ( strlen ( cmd_entry - > arg3 ) + 3 ) ] ;
2019-12-09 17:12:13 -06:00
x = 0 ;
2017-08-09 13:09:55 -05:00
strcpy ( pmptstr , cmd_entry - > arg3 ) ;
strcat ( pmptstr , " : " ) ;
rp_getline ( pmptstr ) ;
2017-10-06 18:58:42 -05:00
if ( ! ( strcmp ( input_line , " " ) ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ? for help, q to quit. \n " ) ;
fflush ( fout ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
result = strtok ( input_line , " " ) ;
2017-10-06 18:58:42 -05:00
if ( result )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] = result ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " \n " ) ;
2024-03-15 16:46:14 -05:00
free ( rp_hist_buf ) ;
2022-02-05 15:27:43 -06:00
return ( RIGCTL_PARSE_END ) ;
2017-08-09 13:09:55 -05:00
}
}
2017-10-06 18:58:42 -05:00
if ( strlen ( parsed_input [ x ] ) > MAXARGSZ )
{
2017-08-09 13:09:55 -05:00
parsed_input [ x ] [ MAXARGSZ ] = ' \0 ' ;
}
2013-02-18 12:23:34 -06:00
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2018-04-15 22:54:27 -05:00
strncat ( rp_hist_buf , " " , 2 ) ;
2017-08-09 13:09:55 -05:00
strncat ( rp_hist_buf , parsed_input [ x ] , MAXARGSZ ) ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
strcpy ( arg3 , parsed_input [ x ] ) ;
p3 = arg3 ;
}
2013-02-18 20:42:42 -06:00
# ifdef HAVE_READLINE_HISTORY
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( rp_hist_buf )
{
2017-08-09 13:09:55 -05:00
add_history ( rp_hist_buf ) ;
free ( rp_hist_buf ) ;
rp_hist_buf = ( char * ) NULL ;
}
2013-02-18 20:42:42 -06:00
# endif
2017-08-09 13:09:55 -05:00
}
2020-02-23 11:26:09 -06:00
2020-01-15 17:05:31 -06:00
# endif // HAVE_LIBREADLINE
2013-02-18 12:23:34 -06:00
2020-04-15 09:57:08 -05:00
if ( sync_cb ) { sync_cb ( 1 ) ; } /* lock if necessary */
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( ! prompt )
{
2017-08-09 13:09:55 -05:00
rig_debug ( RIG_DEBUG_TRACE ,
" rigctl(d): %c '%s' '%s' '%s' '%s' \n " ,
cmd ,
rig_strvfo ( vfo ) ,
p1 ? p1 : " " ,
p2 ? p2 : " " ,
p3 ? p3 : " " ) ;
}
2010-01-24 23:24:20 +00:00
2017-08-09 13:09:55 -05:00
/*
* Extended Response protocol : output received command name and arguments
* response . Don ' t send command header on ' \ chk_vfo ' command .
*/
2024-11-06 08:07:34 -06:00
if ( p1 ) { strip_quotes ( p1 ) ; }
2019-08-25 08:58:19 +01:00
if ( interactive & & * ext_resp_ptr & & ! prompt & & cmd ! = 0xf0 )
2017-10-06 18:58:42 -05:00
{
2019-05-22 09:27:01 -05:00
char a1 [ MAXARGSZ + 2 ] ;
char a2 [ MAXARGSZ + 2 ] ;
char a3 [ MAXARGSZ + 2 ] ;
char vfo_str [ MAXARGSZ + 2 ] ;
2017-08-09 13:09:55 -05:00
2020-05-26 12:01:44 -05:00
* vfo_opt = = 0 ? vfo_str [ 0 ] = ' \0 ' : snprintf ( vfo_str ,
2020-05-27 12:21:41 -05:00
sizeof ( vfo_str ) ,
" %s " ,
rig_strvfo ( vfo ) ) ;
2017-08-09 13:09:55 -05:00
2024-03-25 17:50:39 -05:00
// exception for get_vfo_info cmd which fails with log4om otherwise
if ( * vfo_opt & & cmd ! = 0xf3 )
2024-04-02 16:26:27 -05:00
{
p1 = = NULL ? a1 [ 0 ] = ' \0 ' : snprintf ( a1 , sizeof ( a1 ) , " :%s " , p1 ) ;
}
2024-03-25 17:50:39 -05:00
else
2024-04-02 16:26:27 -05:00
{
p1 = = NULL ? a1 [ 0 ] = ' \0 ' : snprintf ( a1 , sizeof ( a1 ) , " %s " , p1 ) ;
}
2024-03-25 17:50:39 -05:00
2017-08-09 13:09:55 -05:00
p2 = = NULL ? a2 [ 0 ] = ' \0 ' : snprintf ( a2 , sizeof ( a2 ) , " %s " , p2 ) ;
p3 = = NULL ? a3 [ 0 ] = ' \0 ' : snprintf ( a3 , sizeof ( a3 ) , " %s " , p3 ) ;
2023-12-16 11:37:58 -06:00
if ( cmd = = ' b ' ) { strtok ( a1 , " \r \n " ) ; }
2023-08-18 12:20:41 -05:00
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
" %s:%s%s%s%s%c " ,
cmd_entry - > name ,
vfo_str ,
a1 ,
a2 ,
a3 ,
2019-08-25 08:58:19 +01:00
* resp_sep_ptr ) ;
2017-08-09 13:09:55 -05:00
}
2010-01-24 23:24:20 +00:00
2020-05-26 12:01:44 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: vfo_opt=%d \n " , __func__ , * vfo_opt ) ;
2021-04-21 23:48:29 -05:00
2024-05-31 09:48:30 -04:00
if ( rs - > comm_state = = 0 )
2021-04-10 14:22:53 -05:00
{
2022-02-05 15:27:43 -06:00
rig_debug ( RIG_DEBUG_WARN , " %s: %p rig not open...trying to reopen \n " , __func__ ,
2024-05-31 09:48:30 -04:00
& rs - > comm_state ) ;
2021-04-10 14:22:53 -05:00
rig_open ( my_rig ) ;
}
2021-04-21 23:48:29 -05:00
2022-02-24 17:13:18 -06:00
// chk_vfo is the one command we'll allow without a password
// since it's in the initial handshake
2022-03-01 11:40:14 -06:00
int preCmd =
2024-11-24 18:44:00 +01:00
0 ; // some command are allowed without password to satisfy rigctld initialization from rigctl -m 2
2022-03-01 11:40:14 -06:00
2022-02-28 13:08:41 -06:00
if ( cmd_entry - > arg1 ! = NULL )
2022-02-24 17:13:18 -06:00
{
2022-03-01 11:40:14 -06:00
if ( strcmp ( cmd_entry - > arg1 , " ChkVFO " ) = = 0 ) { preCmd = 1 ; }
else if ( strcmp ( cmd_entry - > arg1 , " VFO " ) = = 0 ) { preCmd = 1 ; }
else if ( strcmp ( cmd_entry - > arg1 , " Password " ) = = 0 ) { preCmd = 1 ; }
2022-02-28 13:08:41 -06:00
}
2022-03-01 11:40:14 -06:00
2026-06-03 16:52:49 -04:00
connection = pthread_getspecific ( thread_data_key ) ; // Get state of this connection
if ( use_password & & ! ( connection ? connection - > is_passwordOK : 0 ) & & ( cmd_entry - > arg1 ! = NULL ) & & ! preCmd )
2022-02-28 13:08:41 -06:00
{
2022-05-13 11:09:30 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: password has not been provided \n " , __func__ ) ;
2022-04-15 13:21:35 -05:00
fflush ( fin ) ;
2022-04-29 17:17:43 -05:00
retcode = - RIG_ESECURITY ;
2022-02-24 17:13:18 -06:00
}
2022-03-01 11:40:14 -06:00
2022-04-15 13:21:35 -05:00
else
2022-07-27 17:16:17 -05:00
{
2022-08-23 00:10:25 +03:00
// Allow only certain commands when the rig is powered off
2024-05-31 09:48:30 -04:00
if ( rs - > powerstat = = RIG_POWER_OFF & & ( rig_powerstat = = RIG_POWER_OFF
2024-11-06 08:07:34 -06:00
| | rig_powerstat = = RIG_POWER_STANDBY )
2022-08-23 00:10:25 +03:00
& & cmd_entry - > cmd ! = ' 1 ' // dump_caps
& & cmd_entry - > cmd ! = ' 3 ' // dump_conf
& & cmd_entry - > cmd ! = 0x8f // dump_state
2022-07-27 17:16:17 -05:00
& & cmd_entry - > cmd ! = 0xf0 // chk_vfo
2022-12-19 16:58:44 -06:00
& & cmd_entry - > cmd ! = 0x87 // set_powerstat
2023-01-19 17:15:59 -06:00
& & cmd_entry - > cmd ! = 0x88 // get_powerstat
2022-12-23 23:39:20 -06:00
& & cmd_entry - > cmd ! = 0xa5 // client_version
2023-11-20 10:15:45 +02:00
& & cmd_entry - > cmd ! = 0xf2 // set_vfo_opt
2022-12-23 23:39:20 -06:00
& & my_rig - > caps - > rig_model ! =
RIG_MODEL_POWERSDR ) // some rigs can do stuff when powered off
2022-07-15 15:41:23 -05:00
{
2022-07-27 17:16:17 -05:00
rig_debug ( RIG_DEBUG_WARN ,
2022-09-20 08:46:28 -05:00
" %s: command %s not allowed when rig is powered off \n " , __func__ ,
cmd_entry - > name ) ;
2023-05-10 20:53:18 +03:00
retcode = - RIG_EPOWER ;
2022-07-15 15:41:23 -05:00
}
2022-07-27 17:16:17 -05:00
else
{
retcode = ( * cmd_entry - > rig_routine ) ( my_rig ,
fout ,
fin ,
interactive ,
prompt ,
vfo_opt ,
send_cmd_term ,
* ext_resp_ptr ,
* resp_sep_ptr ,
cmd_entry ,
vfo ,
p1 ,
p2 ? p2 : " " ,
p3 ? p3 : " " ) ;
2022-07-15 15:41:23 -05:00
}
2022-12-23 23:39:20 -06:00
// we need to copy client_version to our thread in case there are multiple client versions
2023-03-23 21:25:48 +01:00
// client_version is used to determine any backward compatibility requirements or problems
2026-03-13 05:13:49 -04:00
memcpy ( client_version , rs - > client_version , sizeof ( client_version ) ) ;
2022-04-15 13:21:35 -05:00
}
2007-11-11 23:03:38 +00:00
2020-05-27 12:23:08 -05:00
2021-03-16 23:39:35 +02:00
if ( retcode = = - RIG_EIO )
2020-04-15 09:37:22 -05:00
{
2020-04-20 17:26:57 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: RIG_EIO? \n " , __func__ ) ;
2020-04-22 11:47:56 -05:00
2020-04-15 09:57:08 -05:00
if ( sync_cb ) { sync_cb ( 0 ) ; } /* unlock if necessary */
2020-04-15 09:37:22 -05:00
2022-02-05 15:27:43 -06:00
return ( retcode ) ;
2020-04-15 09:37:22 -05:00
}
2010-02-04 00:53:56 +00:00
2017-10-06 18:58:42 -05:00
if ( retcode ! = RIG_OK )
{
2017-08-09 13:09:55 -05:00
/* only for rigctld */
2017-10-06 18:58:42 -05:00
if ( interactive & & ! prompt )
{
2020-05-03 17:07:22 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: return#1 " NETRIGCTL_RET " %d \n " , __func__ ,
retcode ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , NETRIGCTL_RET " %d \n " , retcode ) ;
2019-08-25 08:58:19 +01:00
* ext_resp_ptr = 0 ;
* resp_sep_ptr = ' \n ' ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2024-12-22 11:26:18 -06:00
//"%s: error = %s\n",
//cmd_entry->name,
" error = %s \n " ,
2017-08-09 13:09:55 -05:00
rigerror ( retcode ) ) ;
}
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
/* only for rigctld */
2017-10-06 18:58:42 -05:00
if ( interactive & & ! prompt )
{
2017-08-09 13:09:55 -05:00
/* netrigctl RIG_OK */
if ( ! ( cmd_entry - > flags & ARG_OUT )
2019-11-30 10:19:08 -06:00
& & ! * ext_resp_ptr & & cmd ! = 0xf0 )
2017-10-06 18:58:42 -05:00
{
2020-05-03 17:07:22 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: return#2 " NETRIGCTL_RET " 0 \n " , __func__ ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , NETRIGCTL_RET " 0 \n " ) ;
}
/* Extended Response protocol */
2019-08-25 08:58:19 +01:00
else if ( * ext_resp_ptr & & cmd ! = 0xf0 )
2017-10-06 18:58:42 -05:00
{
2020-05-03 17:07:22 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: return#3 " NETRIGCTL_RET " 0 \n " , __func__ ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , NETRIGCTL_RET " 0 \n " ) ;
2019-08-25 08:58:19 +01:00
* ext_resp_ptr = 0 ;
* resp_sep_ptr = ' \n ' ;
2017-08-09 13:09:55 -05:00
}
}
}
2022-05-21 13:23:51 -05:00
if ( * resp_sep_ptr ! = ' \n ' ) { fprintf ( fout , " \n " ) ; }
2017-08-09 13:09:55 -05:00
fflush ( fout ) ;
2021-05-24 10:51:08 -05:00
# ifdef HAVE_LIBREADLINE
2021-08-26 06:49:24 -05:00
if ( input_line ! = NULL & & ( result = strtok ( NULL , " " ) ) ) { goto readline_repeat ; }
2021-05-24 10:51:08 -05:00
# endif
2020-04-22 11:47:56 -05:00
2020-04-15 09:57:08 -05:00
if ( sync_cb ) { sync_cb ( 0 ) ; } /* unlock if necessary */
2020-04-15 09:37:22 -05:00
2022-02-05 15:27:43 -06:00
return ( retcode ) ;
2007-11-11 23:03:38 +00:00
}
2023-07-11 11:13:04 -05:00
declare_proto_rig ( hamlib_version )
2007-11-11 23:03:38 +00:00
{
2023-07-11 11:13:04 -05:00
fprintf ( fout , " rigctl(d), %s \n \n " , hamlib_version2 ) ;
fprintf ( fout , " %s \n " , hamlib_copyright ) ;
return RIG_OK ;
2007-11-11 23:03:38 +00:00
}
2022-12-23 23:39:20 -06:00
declare_proto_rig ( client_version )
{
2024-05-31 09:48:30 -04:00
struct rig_state * rs = STATE ( rig ) ;
2024-11-06 08:07:34 -06:00
2022-12-23 23:39:20 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s%c " , arg1 , resp_sep ) ;
2024-05-31 09:48:30 -04:00
strncpy ( rs - > client_version , arg1 , sizeof ( rs - > client_version ) - 1 ) ;
2022-12-23 23:39:20 -06:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s: client_version=%s \n " , __func__ ,
2024-05-31 09:48:30 -04:00
rs - > client_version ) ;
2022-12-23 23:39:20 -06:00
return RIG_OK ;
}
2017-08-09 13:09:55 -05:00
2008-01-05 18:13:12 +00:00
void usage_rig ( FILE * fout )
2007-11-11 23:03:38 +00:00
{
2025-09-22 22:57:08 +02:00
int column = 1 ;
2025-09-22 23:53:33 +02:00
int wrapped = 0 ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " Commands (some may not be available for this rig): \n " ) ;
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; test_list [ i ] . cmd ! = 0 ; i + + )
2017-10-06 18:58:42 -05:00
{
2025-09-22 22:57:08 +02:00
int nbspaces = 20 ; // longest arguments are 32 chars: "TX Frequency,TX Mode,TX Passband"
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2025-09-22 22:57:08 +02:00
" %c: %-19s( " , // longest commands are 19 chars, eg. "set_split_freq_mode"
2017-08-09 13:09:55 -05:00
isprint ( test_list [ i ] . cmd ) ? test_list [ i ] . cmd : ' ? ' ,
test_list [ i ] . name ) ;
2017-10-06 18:58:42 -05:00
if ( test_list [ i ] . arg1 & & ( test_list [ i ] . flags & ARG_IN1 ) )
{
2017-08-09 13:09:55 -05:00
nbspaces - = fprintf ( fout , " %s " , test_list [ i ] . arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( test_list [ i ] . arg2 & & ( test_list [ i ] . flags & ARG_IN2 ) )
{
2017-08-09 13:09:55 -05:00
nbspaces - = fprintf ( fout , " ,%s " , test_list [ i ] . arg2 ) ;
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( test_list [ i ] . arg3 & & ( test_list [ i ] . flags & ARG_IN3 ) )
{
2017-08-09 13:09:55 -05:00
nbspaces - = fprintf ( fout , " ,%s " , test_list [ i ] . arg3 ) ;
}
2007-11-11 23:03:38 +00:00
2025-09-22 23:53:33 +02:00
if ( ( nbspaces < 1 ) | | ( column = = 2 ) | | wrapped )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " ) \n " ) ;
2025-09-22 23:53:33 +02:00
wrapped = ( nbspaces < 1 ) & & ( column = = 1 ) ;
2025-09-22 22:57:08 +02:00
column = 1 ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " )%*s " , nbspaces , " " ) ;
2025-09-22 22:57:08 +02:00
column + + ;
2017-08-09 13:09:55 -05:00
}
}
2013-02-18 12:23:34 -06:00
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
" \n \n In interactive mode prefix long command names with ' \\ ', e.g. ' \\ dump_state' \n \n "
" The special command '-' is used to read further commands from standard input \n "
" Commands and arguments read from standard input must be white space separated, \n "
" comments are allowed, comments start with the # character and continue to the \n "
" end of the line. \n " ) ;
2025-08-15 18:04:30 +02:00
fprintf ( fout , " \n Error codes and messages \n " ) ;
for ( enum rig_errcode_e e = 0 ; e < RIG_EEND ; + + e )
{
fprintf ( fout , " -%d - %s " , e , rigerror2 ( e ) ) ;
}
fprintf ( fout , " \n Report bugs to <hamlib-developer@lists.sourceforge.net>. \n " ) ;
2007-11-11 23:03:38 +00:00
}
int print_conf_list ( const struct confparams * cfp , rig_ptr_t data )
{
2017-08-09 13:09:55 -05:00
RIG * rig = ( RIG * ) data ;
char buf [ 128 ] = " " ;
2025-07-27 11:31:18 -04:00
rig_get_conf2 ( rig , cfp - > token , buf , sizeof ( buf ) ) ;
2017-08-09 13:09:55 -05:00
printf ( " %s: \" %s \" \n " " \t " " Default: %s, Value: %s \n " ,
cfp - > name ,
cfp - > tooltip ,
cfp - > dflt ,
buf ) ;
2017-10-06 18:58:42 -05:00
switch ( cfp - > type )
{
2023-10-11 09:01:15 -05:00
case RIG_CONF_INT :
2023-10-11 23:22:42 -05:00
printf ( " \t Range: %.0f..%.0f, step %.0f \n " ,
2023-10-11 09:01:15 -05:00
cfp - > u . n . min ,
cfp - > u . n . max ,
cfp - > u . n . step ) ;
break ;
2023-12-16 11:37:58 -06:00
2017-08-09 13:09:55 -05:00
case RIG_CONF_NUMERIC :
2023-11-08 17:14:10 -06:00
printf ( " \t Range: %g..%g, step %.1f \n " ,
2017-08-09 13:09:55 -05:00
cfp - > u . n . min ,
cfp - > u . n . max ,
cfp - > u . n . step ) ;
break ;
case RIG_CONF_COMBO :
2017-10-06 18:58:42 -05:00
if ( ! cfp - > u . c . combostr [ 0 ] )
{
2017-08-09 13:09:55 -05:00
break ;
}
printf ( " \t Combo: %s " , cfp - > u . c . combostr [ 0 ] ) ;
2026-06-13 11:33:26 -04:00
for ( int i = 1 ; i < RIG_COMBO_MAX & & cfp - > u . c . combostr [ i ] ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
printf ( " , %s " , cfp - > u . c . combostr [ i ] ) ;
}
printf ( " \n " ) ;
break ;
case RIG_CONF_STRING :
printf ( " \t String. \n " ) ;
break ;
case RIG_CONF_CHECKBUTTON :
printf ( " \t Check button. \n " ) ;
break ;
case RIG_CONF_BUTTON :
printf ( " \t Button. \n " ) ;
break ;
default :
printf ( " \t Unknown conf \n " ) ;
}
return 1 ; /* !=0, we want them all ! */
2007-11-11 23:03:38 +00:00
}
2023-11-05 17:03:21 -06:00
// short list for rigctl/rigctld display
int print_conf_list2 ( const struct confparams * cfp , rig_ptr_t data )
{
RIG * rig = ( RIG * ) data ;
char buf [ 128 ] = " " ;
2025-07-27 11:31:18 -04:00
rig_get_conf2 ( rig , cfp - > token , buf , sizeof ( buf ) ) ;
2023-12-16 11:37:58 -06:00
fprintf ( stdout , " %s: \" %s \" \n " " \t " " Default: %s, Value: %s \n " ,
cfp - > name ,
cfp - > tooltip ,
cfp - > dflt ,
buf ) ;
2023-11-05 17:03:21 -06:00
return 1 ; /* !=0, we want them all ! */
}
2017-08-09 13:09:55 -05:00
2024-12-29 08:42:24 -06:00
static int hash_model_list ( const struct rig_caps * caps , void * data )
2007-11-11 23:03:38 +00:00
{
2017-08-09 13:09:55 -05:00
hash_add_model ( caps - > rig_model ,
caps - > mfg_name ,
caps - > model_name ,
caps - > version ,
2020-03-05 23:48:14 -06:00
caps - > macro_name ,
2017-08-09 13:09:55 -05:00
rig_strstatus ( caps - > status ) ) ;
2012-02-13 15:22:02 -06:00
2017-08-09 13:09:55 -05:00
return 1 ; /* !=0, we want them all ! */
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2025-06-15 13:52:09 -04:00
static void print_model_list ( )
2012-02-13 15:22:02 -06:00
{
2017-08-09 13:09:55 -05:00
struct mod_lst * s ;
2012-02-13 15:22:02 -06:00
2017-10-06 18:58:42 -05:00
for ( s = models ; s ! = NULL ; s = ( struct mod_lst * ) ( s - > hh . next ) )
{
2024-07-14 22:57:40 -05:00
2020-03-05 23:48:14 -06:00
printf ( " %6d %-23s%-24s%-16s%-12s%s \n " ,
2017-08-09 13:09:55 -05:00
s - > id ,
s - > mfg_name ,
s - > model_name ,
s - > version ,
2020-03-05 23:48:14 -06:00
s - > macro_name ,
2017-08-09 13:09:55 -05:00
s - > status ) ;
2024-07-14 22:57:40 -05:00
2024-11-06 08:07:34 -06:00
if ( strcmp ( s - > mfg_name , " Misc " ) = = 0
| | strcmp ( s - > mfg_name , " Other " ) = = 0
| | strcmp ( s - > mfg_name , " Dummy " ) = = 0 )
2024-07-14 22:57:40 -05:00
{
printf ( " Do not use %s as mfg_name \n " , s - > mfg_name ) ;
exit ( 0 ) ;
}
2024-11-06 08:07:34 -06:00
if ( strcmp ( s - > model_name , " Misc " ) = = 0
| | strcmp ( s - > model_name , " Other " ) = = 0 )
2024-07-14 22:57:40 -05:00
{
printf ( " Do not use %s as model_name \n " , s - > model_name ) ;
exit ( 0 ) ;
}
2017-08-09 13:09:55 -05:00
}
2012-02-13 15:22:02 -06:00
}
2017-08-09 13:09:55 -05:00
2007-11-11 23:03:38 +00:00
void list_models ( )
{
2017-08-09 13:09:55 -05:00
int status ;
rig_load_all_backends ( ) ;
2007-11-11 23:03:38 +00:00
2020-03-05 23:48:14 -06:00
printf ( " Rig # Mfg Model Version Status Macro \n " ) ;
2017-08-09 13:09:55 -05:00
status = rig_list_foreach ( hash_model_list , NULL ) ;
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2025-09-02 21:45:44 +02:00
fprintf ( stderr , " rig_list_foreach: error = %s \n " , rigerror2 ( status ) ) ;
2017-08-09 13:09:55 -05:00
exit ( 2 ) ;
}
2012-02-13 15:22:02 -06:00
2017-08-09 13:09:55 -05:00
hash_sort_by_model_id ( ) ;
print_model_list ( ) ;
hash_delete_all ( ) ;
2007-11-11 23:03:38 +00:00
}
/*
2010-01-24 23:24:20 +00:00
* static int ( f ) ( RIG * rig , FILE * fout , int interactive , const struct test_table * cmd ,
2017-08-09 13:09:55 -05:00
* vfo_t vfo , const void * arg1 , const void * arg2 , const void * arg3 )
2007-11-11 23:03:38 +00:00
*/
2008-01-10 03:42:35 +00:00
/* 'F' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_freq )
{
2017-08-09 13:09:55 -05:00
freq_t freq ;
2020-05-11 18:05:11 -05:00
int retval ;
2020-05-13 17:44:17 -05:00
#if 0 // implement set_freq VFO later if it can be detected
2020-05-11 18:05:11 -05:00
char * fmt = " % " PRIll " %c " ;
2020-05-13 17:44:17 -05:00
# endif
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " % " SCNfreq , & freq ) ) ;
2020-05-11 18:05:11 -05:00
retval = rig_set_freq ( rig , vfo , freq ) ;
if ( retval = = RIG_OK )
{
2020-05-13 17:44:17 -05:00
//fprintf(fout, "%s%c", rig_strvfo(vfo), resp_sep);
//fprintf(fout, fmt, (int64_t)freq, resp_sep);
2020-05-11 18:05:11 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( retval ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'f' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_freq )
{
2017-08-09 13:09:55 -05:00
int status ;
freq_t freq ;
2020-06-21 22:31:31 -05:00
// cppcheck-suppress *
2020-03-23 10:13:02 -05:00
char * fmt = " % " PRIll " %c " ;
2017-08-09 13:09:55 -05:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_freq ( rig , vfo , & freq ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ; /* i.e. "Frequency" */
}
2007-11-11 23:03:38 +00:00
2020-03-23 10:13:02 -05:00
fprintf ( fout , fmt , ( int64_t ) freq , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2020-05-20 09:39:43 -05:00
#if 0 // this extra VFO being returned was confusing Log4OM
2020-05-27 12:21:41 -05:00
2020-03-18 17:40:30 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2020-04-22 11:47:56 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ; /* i.e. "Frequency" */
2020-03-18 17:40:30 -05:00
}
2020-05-11 18:05:11 -05:00
fprintf ( fout , " %s%c " , rig_strvfo ( vfo ) , resp_sep ) ;
2020-05-20 09:39:43 -05:00
# endif
2020-03-18 17:40:30 -05:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'J' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_rit )
{
2017-08-09 13:09:55 -05:00
shortfreq_t rit ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %ld " , & rit ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_rit ( rig , vfo , rit ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'j' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_rit )
{
2017-08-09 13:09:55 -05:00
int status ;
shortfreq_t rit ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_rit ( rig , vfo , & rit ) ;
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %ld%c " , rit , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'Z' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_xit )
{
2017-08-09 13:09:55 -05:00
shortfreq_t xit ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %ld " , & xit ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_xit ( rig , vfo , xit ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'z' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_xit )
{
2017-08-09 13:09:55 -05:00
int status ;
shortfreq_t xit ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_xit ( rig , vfo , & xit ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %ld%c " , xit , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'M' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_mode )
{
2017-08-09 13:09:55 -05:00
rmode_t mode ;
pbwidth_t width ;
2024-05-31 09:48:30 -04:00
struct rig_state * rs = STATE ( rig ) ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2024-05-31 09:48:30 -04:00
if ( rs - > lock_mode | | lock_mode ) { RETURNFUNC2 ( RIG_OK ) ; }
2022-06-06 22:54:10 -05:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_mode ( s , sizeof ( s ) , rs - > mode_list ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2010-04-05 10:01:09 +00:00
2017-08-09 13:09:55 -05:00
mode = rig_parse_mode ( arg1 ) ;
CHKSCN1ARG ( sscanf ( arg2 , " %ld " , & width ) ) ;
2022-05-29 12:06:44 -05:00
2024-05-31 09:48:30 -04:00
if ( rs - > lock_mode ) { RETURNFUNC2 ( RIG_OK ) ; }
2022-05-29 12:06:44 -05:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_mode ( rig , vfo , mode , width ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'm' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_mode )
{
2017-08-09 13:09:55 -05:00
int status ;
rmode_t mode ;
pbwidth_t width ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_mode ( rig , vfo , & mode , & width ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s%c " , rig_strrmode ( mode ) , resp_sep ) ;
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
fprintf ( fout , " %ld%c " , width , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'V' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_vfo )
{
2020-05-11 18:05:11 -05:00
int retval ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_vfo ( s , sizeof ( s ) , STATE ( rig ) - > vfo_list ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2015-02-19 23:52:13 +01:00
2020-05-11 18:05:11 -05:00
vfo = rig_parse_vfo ( arg1 ) ;
2022-07-27 17:16:17 -05:00
if ( vfo = = RIG_VFO_NONE )
2022-07-08 16:21:34 -05:00
{
int c ;
2022-07-27 17:16:17 -05:00
while ( ( c = fgetc ( fin ) ) ! = ' \n ' & & c ! = ' \r ' & & c > 0 ) ;
2022-07-08 16:21:34 -05:00
return - RIG_EINVAL ;
}
2022-07-27 17:16:17 -05:00
2020-05-11 18:05:11 -05:00
retval = rig_set_vfo ( rig , vfo ) ;
2020-05-15 14:17:59 -05:00
#if 0 // see if we can make this dynamic
2020-05-27 12:21:41 -05:00
2020-05-11 18:05:11 -05:00
if ( retval = = RIG_OK )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
// fprintf(fout, "%s: ", cmd->arg1);
}
fprintf ( fout , " %s%c " , rig_strvfo ( vfo ) , resp_sep ) ;
}
2020-05-27 12:21:41 -05:00
2020-05-15 14:17:59 -05:00
# endif
2020-05-11 18:05:11 -05:00
2021-02-10 17:30:46 -06:00
if ( retval ! = RIG_OK )
{
2021-02-28 09:46:01 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: set_vfo(%s) failed, requested %s \n " , __func__ ,
rig_strvfo ( vfo ) , arg1 ) ;
2021-02-10 17:30:46 -06:00
}
2021-02-28 09:46:01 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( retval ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'v' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_vfo )
{
2017-08-09 13:09:55 -05:00
int status ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_vfo ( rig , & vfo ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s%c " , rig_strvfo ( vfo ) , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2021-04-27 11:51:43 -05:00
declare_proto_rig ( get_rig_info )
{
char buf [ 1024 ] ; // big enough to last numerous years hopefully
int ret ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-04-27 11:51:43 -05:00
ret = rig_get_rig_info ( rig , buf , sizeof ( buf ) ) ;
2021-04-29 17:23:37 -05:00
2023-05-13 16:11:46 -05:00
if ( ret ! = RIG_OK ) { RETURNFUNC2 ( ret ) ; }
2021-04-29 17:23:37 -05:00
fprintf ( fout , " %s \n " , buf ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2021-04-27 11:51:43 -05:00
}
2021-02-07 12:45:59 -06:00
/* '\get_vfo_info' */
declare_proto_rig ( get_vfo_info )
{
int retval ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-12-05 09:46:00 -06:00
ELAPSED1 ;
2021-02-28 09:46:01 -06:00
2021-02-07 12:45:59 -06:00
if ( ! strcmp ( arg1 , " ? " ) )
{
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_vfo ( s , sizeof ( s ) , STATE ( rig ) - > vfo_list ) ;
2021-02-07 12:45:59 -06:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2021-02-07 12:45:59 -06:00
}
vfo = rig_parse_vfo ( arg1 ) ;
2021-02-28 09:46:01 -06:00
freq_t freq = 0 ;
rmode_t mode = RIG_MODE_NONE ;
2021-02-07 12:45:59 -06:00
pbwidth_t width = 0 ;
2021-03-01 14:56:21 -06:00
split_t split ;
2021-04-27 10:32:12 -05:00
int satmode = 0 ;
retval = rig_get_vfo_info ( rig , vfo , & freq , & mode , & width , & split , & satmode ) ;
2021-02-07 12:45:59 -06:00
2021-03-20 11:21:11 -05:00
if ( retval ! = RIG_OK )
{
rig_debug ( RIG_DEBUG_ERR , " %s: vfo=%s \n " , __func__ , rig_strvfo ( vfo ) ) ;
}
2021-02-28 09:46:01 -06:00
2021-03-26 14:26:56 -05:00
const char * modestr = rig_strrmode ( mode ) ;
if ( strlen ( modestr ) = = 0 ) { modestr = " None " ; }
2021-02-07 12:45:59 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2022-05-22 22:35:21 -05:00
fprintf ( fout , " %s: %.0f%c " , cmd - > arg2 , freq , resp_sep ) ;
fprintf ( fout , " %s: %s%c " , cmd - > arg3 , modestr , resp_sep ) ;
fprintf ( fout , " %s: %d%c " , cmd - > arg4 , ( int ) width , resp_sep ) ;
fprintf ( fout , " %s: %d%c " , cmd - > arg5 , ( int ) split , resp_sep ) ;
fprintf ( fout , " %s: %d%c " , cmd - > arg6 , ( int ) satmode , resp_sep ) ;
2021-02-07 12:45:59 -06:00
}
else
{
2022-05-29 12:06:44 -05:00
fprintf ( fout , " %.0f%c%s%c%d%c%d%c%d \n " , freq , resp_sep , modestr , resp_sep ,
( int ) width , resp_sep , ( int ) split , resp_sep ,
2022-05-22 09:00:38 -05:00
( int ) satmode ) ;
2021-02-07 12:45:59 -06:00
}
2021-02-28 09:46:01 -06:00
2021-12-05 09:46:00 -06:00
ELAPSED2 ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( retval ) ;
2021-02-07 12:45:59 -06:00
}
2021-02-10 17:30:46 -06:00
/* '\get_vfo_list' */
declare_proto_rig ( get_vfo_list )
{
static char prntbuf [ 256 ] ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2024-05-31 09:48:30 -04:00
rig_sprintf_vfo ( prntbuf , sizeof ( prntbuf ) , STATE ( rig ) - > vfo_list ) ;
2021-02-10 17:30:46 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2021-05-12 22:44:33 -05:00
fprintf ( fout , " %s%c \n " , prntbuf [ 0 ] ? prntbuf : " None " , ext_resp ) ;
2021-02-10 17:30:46 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2021-02-10 17:30:46 -06:00
}
2023-07-04 17:31:07 -05:00
/* '\test' */
declare_proto_rig ( test )
{
ENTERFUNC2 ;
2023-12-16 11:37:58 -06:00
2023-07-04 17:31:07 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
fprintf ( fout , " cw \n " ) ;
RETURNFUNC2 ( RIG_OK ) ;
}
2023-12-16 11:37:58 -06:00
if ( strcmp ( arg1 , " cw " ) = = 0 ) { rig_test_cw ( rig ) ; }
2023-07-04 17:31:07 -05:00
RETURNFUNC2 ( RIG_OK ) ;
}
2021-05-03 09:24:02 -05:00
/* '\get_modes' */
declare_proto_rig ( get_modes )
{
static char prntbuf [ 1024 ] ;
2021-05-03 11:26:41 -05:00
char freqbuf [ 32 ] ;
2021-05-03 09:24:02 -05:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-05-03 09:24:02 -05:00
2024-05-31 09:48:30 -04:00
rig_strrmodes ( STATE ( rig ) - > mode_list , prntbuf , sizeof ( prntbuf ) ) ;
2021-05-03 09:24:02 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s%c " , prntbuf [ 0 ] ? prntbuf : " None " , ext_resp ) ;
2021-05-03 11:26:41 -05:00
fprintf ( fout , " \n Bandwidths: " ) ;
2026-06-13 11:33:26 -04:00
for ( int i = 1 ; i < RIG_MODE_TESTS_MAX ; i < < = 1 )
2021-05-03 11:26:41 -05:00
{
pbwidth_t pbnorm = rig_passband_normal ( rig , i ) ;
if ( pbnorm = = 0 )
{
continue ;
}
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , pbnorm ) ;
fprintf ( fout , " \n \t %s \t Normal: %s, \t " , rig_strrmode ( i ) , freqbuf ) ;
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , rig_passband_narrow ( rig , i ) ) ;
fprintf ( fout , " Narrow: %s, \t " , freqbuf ) ;
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , rig_passband_wide ( rig , i ) ) ;
fprintf ( fout , " Wide: %s " , freqbuf ) ;
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2021-05-03 09:24:02 -05:00
}
2021-05-03 15:35:56 -05:00
declare_proto_rig ( get_mode_bandwidths )
{
char freqbuf [ 32 ] ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-05-03 15:35:56 -05:00
rmode_t mode = rig_parse_mode ( arg1 ) ;
2026-06-13 11:33:26 -04:00
for ( int i = 1 ; i < RIG_MODE_TESTS_MAX ; i < < = 1 )
2021-05-03 15:35:56 -05:00
{
if ( i ! = mode ) { continue ; }
if ( mode = = RIG_MODE_CWR ) { mode = RIG_MODE_CW ; }
if ( mode = = RIG_MODE_RTTYR ) { mode = RIG_MODE_RTTY ; }
pbwidth_t pbnorm = rig_passband_normal ( rig , i ) ;
if ( pbnorm = = 0 )
{
continue ;
}
// sprintf_freq(freqbuf, sizeof(freqbuf), pbnorm);
2022-01-11 00:00:44 -06:00
SNPRINTF ( freqbuf , sizeof ( freqbuf ) , " %ldHz " , pbnorm ) ;
2021-05-03 15:35:56 -05:00
fprintf ( fout , " Mode=%s \n " , rig_strrmode ( i ) ) ;
fprintf ( fout , " Normal=%s \n " , freqbuf ) ;
2022-01-11 00:00:44 -06:00
SNPRINTF ( freqbuf , sizeof ( freqbuf ) , " %ldHz " , rig_passband_narrow ( rig , i ) ) ;
2021-05-03 15:35:56 -05:00
fprintf ( fout , " Narrow=%s \n " , freqbuf ) ;
2022-01-11 00:00:44 -06:00
SNPRINTF ( freqbuf , sizeof ( freqbuf ) , " %ldHz " , rig_passband_wide ( rig , i ) ) ;
2021-05-03 15:35:56 -05:00
fprintf ( fout , " Wide=%s " , freqbuf ) ;
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2021-05-03 15:35:56 -05:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'T' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_ptt )
{
2017-08-09 13:09:55 -05:00
int scr ;
ptt_t ptt ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & scr ) ) ;
ptt = scr ;
2022-05-15 11:53:38 -05:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s: set_ptt ptt=%d \n " , __func__ , ptt ) ;
2017-08-09 13:09:55 -05:00
/*
* We allow RIG_PTT_ON_MIC and RIG_PTT_ON_DATA arriving from netrigctl .
* However , if the rig does not have two separate CAT commands , or if
* the rig is actually switched by a hardware signal ( DTR etc . ) , then
* we map this to RIG_PTT_ON .
* Currently , this is not really necessary here because it is taken
* case of in rig_set_ptt , but you never know . . . .
*/
2017-10-06 18:58:42 -05:00
switch ( ptt )
{
2017-08-09 13:09:55 -05:00
case RIG_PTT_ON_MIC :
case RIG_PTT_ON_DATA :
2022-05-15 11:53:38 -05:00
// No longer map this -- is confusing rigctld and MICDATA rigs
// https://github.com/Hamlib/Hamlib/issues/998
#if 0
2022-05-21 13:23:51 -05:00
2017-08-09 13:09:55 -05:00
// map to a legal value
2022-05-15 11:53:38 -05:00
if ( rig - > caps - > ptt_type ! = RIG_PTT_RIG_MICDATA )
2017-10-06 18:58:42 -05:00
{
2022-05-21 13:23:51 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: pttport.type.ptt=%d \n " , __func__ ,
2024-03-01 05:32:08 -05:00
PTTPORT ( rig ) - > type . ptt ) ;
2017-08-09 13:09:55 -05:00
ptt = RIG_PTT_ON ;
}
2022-05-21 13:23:51 -05:00
2022-05-15 11:53:38 -05:00
# endif
2017-08-09 13:09:55 -05:00
break ;
case RIG_PTT_ON :
case RIG_PTT_OFF :
// nothing to do
break ;
default :
// this case is not handled in hamlib, but we guard against
// illegal parameters here. The hamlib behaviour is to switch
// on PTT whenever ptt != RIG_PTT_OFF.
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
2017-08-09 13:09:55 -05:00
}
2022-05-15 11:53:38 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: ptt=%d \n " , __func__ , ptt ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ptt ( rig , vfo , ptt ) ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2008-01-10 03:42:35 +00:00
/* 't' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_ptt )
{
2017-08-09 13:09:55 -05:00
int status ;
2020-05-13 07:22:46 -05:00
ptt_t ptt = 0 ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_ptt ( rig , vfo , & ptt ) ;
2008-01-10 03:42:35 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
/* TODO MICDATA */
fprintf ( fout , " %d%c " , ptt , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2010-01-24 23:24:20 +00:00
/* '0x8b' */
2008-09-21 19:24:47 +00:00
declare_proto_rig ( get_dcd )
{
2017-08-09 13:09:55 -05:00
int status ;
dcd_t dcd ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_dcd ( rig , vfo , & dcd ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2008-09-21 19:24:47 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d%c " , dcd , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'R' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_rptr_shift )
{
2017-08-09 13:09:55 -05:00
rptr_shift_t rptr_shift ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
rptr_shift = rig_parse_rptr_shift ( arg1 ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_rptr_shift ( rig , vfo , rptr_shift ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'r' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_rptr_shift )
{
2017-08-09 13:09:55 -05:00
int status ;
rptr_shift_t rptr_shift ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_rptr_shift ( rig , vfo , & rptr_shift ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s%c " , rig_strptrshift ( rptr_shift ) , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'O' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_rptr_offs )
{
2017-08-09 13:09:55 -05:00
unsigned long rptr_offs ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %lu " , & rptr_offs ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_rptr_offs ( rig , vfo , rptr_offs ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'o' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_rptr_offs )
{
2017-08-09 13:09:55 -05:00
int status ;
shortfreq_t rptr_offs ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_rptr_offs ( rig , vfo , & rptr_offs ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2008-01-10 03:42:35 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %ld%c " , rptr_offs , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'C' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_ctcss_tone )
{
2017-08-09 13:09:55 -05:00
tone_t tone ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %u " , & tone ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ctcss_tone ( rig , vfo , tone ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'c' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_ctcss_tone )
{
2017-08-09 13:09:55 -05:00
int status ;
tone_t tone ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_ctcss_tone ( rig , vfo , & tone ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d%c " , tone , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'D' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_dcs_code )
{
2017-08-09 13:09:55 -05:00
tone_t code ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %u " , & code ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_dcs_code ( rig , vfo , code ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'd' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_dcs_code )
{
2017-08-09 13:09:55 -05:00
int status ;
tone_t code ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_dcs_code ( rig , vfo , & code ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d%c " , code , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2010-01-24 23:24:20 +00:00
/* '0x90' */
2008-09-21 19:24:47 +00:00
declare_proto_rig ( set_ctcss_sql )
{
2017-08-09 13:09:55 -05:00
tone_t tone ;
2008-09-21 19:24:47 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %u " , & tone ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ctcss_sql ( rig , vfo , tone ) ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2010-01-24 23:24:20 +00:00
/* '0x91' */
2008-09-21 19:24:47 +00:00
declare_proto_rig ( get_ctcss_sql )
{
2017-08-09 13:09:55 -05:00
int status ;
tone_t tone ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_ctcss_sql ( rig , vfo , & tone ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2008-09-21 19:24:47 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %d%c " , tone , resp_sep ) ;
2008-09-21 19:24:47 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2010-01-24 23:24:20 +00:00
/* '0x92' */
2008-09-21 19:24:47 +00:00
declare_proto_rig ( set_dcs_sql )
{
2017-08-09 13:09:55 -05:00
tone_t code ;
2008-09-21 19:24:47 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %u " , & code ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_dcs_sql ( rig , vfo , code ) ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2010-01-24 23:24:20 +00:00
/* '0x93' */
2008-09-21 19:24:47 +00:00
declare_proto_rig ( get_dcs_sql )
{
2017-08-09 13:09:55 -05:00
int status ;
tone_t code ;
2008-09-21 19:24:47 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_dcs_sql ( rig , vfo , & code ) ;
2008-01-10 03:42:35 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %d%c " , code , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'I' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_split_freq )
{
2017-08-09 13:09:55 -05:00
freq_t txfreq ;
vfo_t txvfo = RIG_VFO_TX ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " % " SCNfreq , & txfreq ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_split_freq ( rig , txvfo , txfreq ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'i' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_split_freq )
{
2017-08-09 13:09:55 -05:00
int status ;
freq_t txfreq ;
vfo_t txvfo = RIG_VFO_TX ;
2010-01-24 23:24:20 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_split_freq ( rig , txvfo , & txfreq ) ;
2008-01-10 03:42:35 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " % " PRIll " %c " , ( int64_t ) txfreq , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'X' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_split_mode )
{
2017-08-09 13:09:55 -05:00
rmode_t mode ;
int width ;
vfo_t txvfo = RIG_VFO_TX ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_mode ( s , sizeof ( s ) , STATE ( rig ) - > mode_list ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2010-04-05 10:01:09 +00:00
2021-10-16 09:45:24 -05:00
// mode could be RIG_MODE_NONE here
2021-11-28 12:41:10 -06:00
// we treat it as non-fatal
2021-10-16 09:45:24 -05:00
// rig_parse_mode will spit out error msg
2017-08-09 13:09:55 -05:00
mode = rig_parse_mode ( arg1 ) ;
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & width ) ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_split_mode ( rig , txvfo , mode , ( pbwidth_t ) width ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'x' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_split_mode )
{
2017-08-09 13:09:55 -05:00
int status ;
rmode_t mode ;
pbwidth_t width ;
vfo_t txvfo = RIG_VFO_TX ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_split_mode ( rig , txvfo , & mode , & width ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s%c " , rig_strrmode ( mode ) , resp_sep ) ;
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %ld%c " , width , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2014-04-28 22:25:06 +01:00
/* 'K' */
declare_proto_rig ( set_split_freq_mode )
{
2017-08-09 13:09:55 -05:00
freq_t freq ;
rmode_t mode ;
int width ;
vfo_t txvfo = RIG_VFO_TX ;
2014-04-28 22:25:06 +01:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_mode ( s , sizeof ( s ) , STATE ( rig ) - > mode_list ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2014-04-28 22:25:06 +01:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " % " SCNfreq , & freq ) ) ;
mode = rig_parse_mode ( arg2 ) ;
CHKSCN1ARG ( sscanf ( arg3 , " %d " , & width ) ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_split_freq_mode ( rig , txvfo , freq , mode , ( pbwidth_t ) width ) ) ;
2014-04-28 22:25:06 +01:00
}
2017-08-09 13:09:55 -05:00
2014-04-28 22:25:06 +01:00
/* 'k' */
declare_proto_rig ( get_split_freq_mode )
{
2017-08-09 13:09:55 -05:00
int status ;
freq_t freq ;
rmode_t mode ;
pbwidth_t width ;
vfo_t txvfo = RIG_VFO_TX ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_split_freq_mode ( rig , txvfo , & freq , & mode , & width ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2014-04-28 22:25:06 +01:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " % " PRIll " %c " , ( int64_t ) freq , resp_sep ) ;
2014-04-28 22:25:06 +01:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
fprintf ( fout , " %s%c " , rig_strrmode ( mode ) , resp_sep ) ;
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg3 ) ;
}
fprintf ( fout , " %ld%c " , width , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2014-04-28 22:25:06 +01:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'S' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_split_vfo )
{
2017-08-09 13:09:55 -05:00
int split ;
vfo_t tx_vfo ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & split ) ) ;
2015-02-19 23:52:13 +01:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg2 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_vfo ( s , sizeof ( s ) , STATE ( rig ) - > vfo_list ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
tx_vfo = rig_parse_vfo ( arg2 ) ;
2017-10-06 18:58:42 -05:00
if ( tx_vfo = = RIG_VFO_NONE )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
2017-08-09 13:09:55 -05:00
}
2022-02-24 17:13:18 -06:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s(%d): rx_vfo = %s, tx_vfo = %s \n " , __func__ ,
__LINE__ , rig_strvfo ( vfo ) , rig_strvfo ( tx_vfo ) ) ;
2015-02-19 23:52:13 +01:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_split_vfo ( rig , vfo , ( split_t ) split , tx_vfo ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 's' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_split_vfo )
{
2017-08-09 13:09:55 -05:00
int status ;
split_t split ;
vfo_t tx_vfo ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_split_vfo ( rig , vfo , & split , & tx_vfo ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %d%c " , split , resp_sep ) ;
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2008-01-10 03:42:35 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s%c " , rig_strvfo ( tx_vfo ) , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'N' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_ts )
{
2017-08-09 13:09:55 -05:00
unsigned long ts ;
2024-10-07 12:19:03 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2024-10-07 12:19:03 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
rig_sprintf_tuning_steps ( s , sizeof ( s ) , rig - > caps - > tuning_steps ) ;
fprintf ( fout , " %s \n " , s ) ;
RETURNFUNC2 ( RIG_OK ) ;
}
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %lu " , & ts ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ts ( rig , vfo , ts ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'n' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_ts )
{
2017-08-09 13:09:55 -05:00
int status ;
shortfreq_t ts ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_ts ( rig , vfo , & ts ) ;
2008-01-10 03:42:35 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %ld%c " , ts , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* '2' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( power2mW )
{
2017-08-09 13:09:55 -05:00
int status ;
float power ;
freq_t freq ;
rmode_t mode ;
unsigned int mwp ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %f " , & power ) ) ;
CHKSCN1ARG ( sscanf ( arg2 , " % " SCNfreq , & freq ) ) ;
mode = rig_parse_mode ( arg3 ) ;
2010-02-06 15:05:17 +00:00
2017-08-09 13:09:55 -05:00
status = rig_power2mW ( rig , & mwp , power , freq , mode ) ;
2010-02-06 15:05:17 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2010-02-06 15:05:17 +00:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg4 ) ;
}
fprintf ( fout , " %i%c " , mwp , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2010-02-06 15:05:17 +00:00
}
2017-08-09 13:09:55 -05:00
2010-02-06 15:05:17 +00:00
/* '4' */
declare_proto_rig ( mW2power )
{
2017-08-09 13:09:55 -05:00
int status ;
float power ;
freq_t freq ;
rmode_t mode ;
unsigned int mwp ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2019-12-12 22:29:13 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %u " , & mwp ) ) ;
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " % " SCNfreq , & freq ) ) ;
mode = rig_parse_mode ( arg3 ) ;
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
status = rig_mW2power ( rig , & power , mwp , freq , mode ) ;
2010-02-06 15:05:17 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg4 ) ;
}
2008-01-12 00:36:58 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %f%c " , power , resp_sep ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2007-11-11 23:03:38 +00:00
/*
* RIG_CONF_ extparm ' s type :
* NUMERIC : val . f
* COMBO : val . i , starting from 0
* STRING : val . s
* CHECKBUTTON : val . i 0 / 1
2008-01-10 03:42:35 +00:00
*
* ' L '
2007-11-11 23:03:38 +00:00
*/
declare_proto_rig ( set_level )
{
2017-08-09 13:09:55 -05:00
setting_t level ;
value_t val ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_level ( s , sizeof ( s ) , STATE ( rig ) - > has_set_level ) ;
2017-08-09 13:09:55 -05:00
fputs ( s , fout ) ;
2017-10-06 18:58:42 -05:00
if ( rig - > caps - > set_ext_level )
{
2021-03-03 08:03:18 -06:00
sprintf_level_ext ( s , sizeof ( s ) , rig - > caps - > extlevels ) ;
2017-08-09 13:09:55 -05:00
fputs ( s , fout ) ;
}
fputc ( ' \n ' , fout ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
level = rig_parse_level ( arg1 ) ;
2025-08-12 17:24:52 +02:00
if ( ! strcmp ( arg2 , " ? " ) )
2023-08-20 16:03:25 -05:00
{
2025-08-12 17:24:52 +02:00
if ( level = = RIG_LEVEL_METER )
{
fprintf ( fout , " COMP ALC SWR ID/IC VDD DB PO TEMP%c " , resp_sep ) ;
} else {
const gran_t * gran = STATE ( rig ) - > level_gran ;
int idx = rig_setting2idx ( level ) ;
if ( RIG_LEVEL_IS_FLOAT ( level ) )
{
fprintf ( fout , " (%f..%f/%f)%c " , gran [ idx ] . min . f ,
gran [ idx ] . max . f , gran [ idx ] . step . f , resp_sep ) ;
}
else
{
fprintf ( fout , " (%d..%d/%d)%c " , gran [ idx ] . min . i ,
gran [ idx ] . max . i , gran [ idx ] . step . i , resp_sep ) ;
}
}
2023-08-20 16:03:25 -05:00
RETURNFUNC2 ( RIG_OK ) ;
}
2021-02-11 15:52:29 -06:00
// some Java apps send comma in international setups so substitute period
2021-02-28 09:46:01 -06:00
char * p = strchr ( arg2 , ' , ' ) ;
if ( p ) { * p = ' . ' ; }
2021-02-11 15:52:29 -06:00
2017-10-06 18:58:42 -05:00
if ( ! rig_has_set_level ( rig , level ) )
{
2017-08-09 13:09:55 -05:00
const struct confparams * cfp ;
cfp = rig_ext_lookup ( rig , arg1 ) ;
2017-10-06 18:58:42 -05:00
if ( ! cfp )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ENAVAIL ) ; /* no such parameter */
2017-08-09 13:09:55 -05:00
}
2023-08-20 16:03:25 -05:00
2017-10-06 18:58:42 -05:00
switch ( cfp - > type )
{
2017-08-09 13:09:55 -05:00
case RIG_CONF_BUTTON :
/* arg is ignored */
val . i = 0 ; // avoid passing uninitialized data
break ;
case RIG_CONF_CHECKBUTTON :
case RIG_CONF_COMBO :
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & val . i ) ) ;
break ;
2023-10-11 23:22:42 -05:00
case RIG_CONF_INT :
CHKSCN1ARG ( sscanf ( arg2 , " %f " , & val . f ) ) ;
break ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_NUMERIC :
2023-11-08 17:14:10 -06:00
CHKSCN1ARG ( sscanf ( arg2 , " %g " , & val . f ) ) ;
2017-08-09 13:09:55 -05:00
break ;
case RIG_CONF_STRING :
val . cs = arg2 ;
break ;
default :
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ECONF ) ;
2017-08-09 13:09:55 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ext_level ( rig , vfo , cfp - > token , val ) ) ;
2017-08-09 13:09:55 -05:00
}
2023-08-20 16:03:25 -05:00
int dummy ;
2023-12-16 11:37:58 -06:00
2024-12-22 11:14:14 -06:00
if ( level = = RIG_LEVEL_METER & & sscanf ( arg2 , " %d " , & dummy ) < = 0 )
2023-12-16 11:37:58 -06:00
{
if ( strcmp ( arg2 , " COMP " ) = = 0 ) { arg2 = " 2 " ; }
else if ( strcmp ( arg2 , " ALC " ) = = 0 ) { arg2 = " 4 " ; }
else if ( strcmp ( arg2 , " SWR " ) = = 0 ) { arg2 = " 1 " ; }
else if ( strcmp ( arg2 , " ID " ) = = 0 | | strcmp ( arg2 , " IC " ) = = 0 ) { arg2 = " 8 " ; }
else if ( strcmp ( arg2 , " VDD " ) = = 0 ) { arg2 = " 64 " ; }
else if ( strcmp ( arg2 , " DB " ) = = 0 ) { arg2 = " 16 " ; }
else if ( strcmp ( arg2 , " PO " ) = = 0 ) { arg2 = " 32 " ; }
else if ( strcmp ( arg2 , " TEMP " ) = = 0 ) { arg2 = " 128 " ; }
2023-08-20 16:03:25 -05:00
else
{
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_ERR ,
" %s: unknown meter=%s, only know COMP,ALC,SWR,ID/IC,VDD,DB,PO,TEMP \n " , __func__ ,
arg2 ) ;
2023-08-20 16:03:25 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
}
}
2023-12-16 11:37:58 -06:00
2017-10-06 18:58:42 -05:00
if ( RIG_LEVEL_IS_FLOAT ( level ) )
{
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " %f " , & val . f ) ) ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & val . i ) ) ;
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_level ( rig , vfo , level , val ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'l' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_level )
{
2017-08-09 13:09:55 -05:00
int status ;
setting_t level ;
value_t val ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_level ( s , sizeof ( s ) , STATE ( rig ) - > has_get_level ) ;
2017-08-09 13:09:55 -05:00
fputs ( s , fout ) ;
2017-10-06 18:58:42 -05:00
if ( rig - > caps - > get_ext_level )
{
2021-03-03 08:03:18 -06:00
sprintf_level_ext ( s , sizeof ( s ) , rig - > caps - > extlevels ) ;
2022-05-22 22:35:21 -05:00
fprintf ( fout , " %s%c " , s , resp_sep ) ;
2017-08-09 13:09:55 -05:00
}
2023-11-14 07:42:38 -06:00
fputc ( ' \n ' , fout ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2023-12-16 11:37:58 -06:00
2017-08-09 13:09:55 -05:00
level = rig_parse_level ( arg1 ) ;
2017-10-06 18:58:42 -05:00
if ( ! rig_has_get_level ( rig , level ) )
{
2017-08-09 13:09:55 -05:00
const struct confparams * cfp ;
cfp = rig_ext_lookup ( rig , arg1 ) ;
2017-10-06 18:58:42 -05:00
if ( ! cfp )
{
2021-03-08 09:54:24 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: level not found=%s \n " , __func__ , arg1 ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ; /* no such parameter */
2017-08-09 13:09:55 -05:00
}
status = rig_get_ext_level ( rig , vfo , cfp - > token , & val ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2017-10-06 18:58:42 -05:00
switch ( cfp - > type )
{
2017-08-09 13:09:55 -05:00
case RIG_CONF_BUTTON :
/* there's no sense in retrieving value of stateless button */
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_CHECKBUTTON :
case RIG_CONF_COMBO :
2023-10-08 16:51:39 -05:00
fprintf ( fout , " %d%c " , val . i , resp_sep ) ;
2017-08-09 13:09:55 -05:00
break ;
case RIG_CONF_NUMERIC :
2023-11-08 17:14:10 -06:00
fprintf ( fout , " %g%c " , val . f , resp_sep ) ;
2017-08-09 13:09:55 -05:00
break ;
2023-10-08 17:18:16 -05:00
case RIG_CONF_INT :
2023-10-11 23:22:42 -05:00
fprintf ( fout , " %.0f%c " , val . f , resp_sep ) ;
2023-10-08 17:18:16 -05:00
break ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_STRING :
2023-10-08 16:51:39 -05:00
fprintf ( fout , " %s%c " , val . s , resp_sep ) ;
2017-08-09 13:09:55 -05:00
break ;
default :
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ECONF ) ;
2017-08-09 13:09:55 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
status = rig_get_level ( rig , vfo , level , & val ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2023-12-16 11:37:58 -06:00
if ( level = = RIG_LEVEL_METER & & interactive & & prompt )
{
// we will show text answers as they make morse sense for rigtl
switch ( val . i )
2023-08-20 16:03:25 -05:00
{
2023-12-16 11:37:58 -06:00
case RIG_METER_COMP : fprintf ( fout , " %d=%s%c " , val . i , " COMP " , resp_sep ) ; break ;
case RIG_METER_ALC : fprintf ( fout , " %d=%s%c " , val . i , " ALC " , resp_sep ) ; break ;
case RIG_METER_SWR : fprintf ( fout , " %d=%s%c " , val . i , " SWR " , resp_sep ) ; break ;
case RIG_METER_IC : fprintf ( fout , " %d=%s%c " , val . i , " IC " , resp_sep ) ; break ;
case RIG_METER_VDD : fprintf ( fout , " %d=%s%c " , val . i , " VDD " , resp_sep ) ; break ;
case RIG_METER_DB : fprintf ( fout , " %d=%s%c " , val . i , " DB " , resp_sep ) ; break ;
case RIG_METER_PO : fprintf ( fout , " %d=%s%c " , val . i , " PO " , resp_sep ) ; break ;
case RIG_METER_TEMP : fprintf ( fout , " %d=%s%c " , val . i , " TEMP " , resp_sep ) ; break ;
default :
rig_debug ( RIG_DEBUG_ERR ,
" %s: unknown meter=%d, only know COMP,ALC,SWR,ID/IC,VDD,DB,PO,TEMP \n " , __func__ ,
val . i ) ;
RETURNFUNC2 ( - RIG_EINVAL ) ;
2023-08-20 16:03:25 -05:00
}
2024-06-21 10:09:15 -04:00
RETURNFUNC2 ( RIG_OK ) ;
2023-12-16 11:37:58 -06:00
}
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( RIG_LEVEL_IS_FLOAT ( level ) )
{
2023-11-08 17:14:10 -06:00
fprintf ( fout , " %g%c " , val . f , resp_sep ) ;
2017-10-06 18:58:42 -05:00
}
else
{
2022-05-22 23:01:14 -05:00
fprintf ( fout , " %d%c " , val . i , resp_sep ) ;
2017-08-09 13:09:55 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'U' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_func )
{
2017-08-09 13:09:55 -05:00
setting_t func ;
int func_stat ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_func ( s , sizeof ( s ) , STATE ( rig ) - > has_set_func ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
func = rig_parse_func ( arg1 ) ;
2008-05-23 14:30:12 +00:00
2020-02-11 09:48:13 +00:00
if ( ! rig_has_set_func ( rig , func ) )
2017-10-06 18:58:42 -05:00
{
2020-02-11 09:48:13 +00:00
const struct confparams * cfp ;
cfp = rig_ext_lookup ( rig , arg1 ) ;
if ( ! cfp )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ENAVAIL ) ; /* no such parameter */
2020-02-11 09:48:13 +00:00
}
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & func_stat ) ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ext_func ( rig , vfo , cfp - > token , func_stat ) ) ;
2017-08-09 13:09:55 -05:00
}
2010-12-01 21:41:55 +00:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & func_stat ) ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_func ( rig , vfo , func , func_stat ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'u' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_func )
{
2017-08-09 13:09:55 -05:00
int status ;
setting_t func ;
int func_stat ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_func ( s , sizeof ( s ) , STATE ( rig ) - > has_get_func ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
func = rig_parse_func ( arg1 ) ;
2008-05-23 14:30:12 +00:00
2020-02-11 09:48:13 +00:00
if ( ! rig_has_get_func ( rig , func ) )
2017-10-06 18:58:42 -05:00
{
2020-02-11 09:48:13 +00:00
const struct confparams * cfp ;
cfp = rig_ext_lookup ( rig , arg1 ) ;
if ( ! cfp )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ; /* no such parameter */
2020-02-11 09:48:13 +00:00
}
status = rig_get_ext_func ( rig , vfo , cfp - > token , & func_stat ) ;
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2020-02-11 09:48:13 +00:00
}
if ( interactive & & prompt )
{
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %d%c " , func_stat , resp_sep ) ;
2020-02-11 09:48:13 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
status = rig_get_func ( rig , vfo , func , & func_stat ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2010-12-01 21:41:55 +00:00
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt )
{
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
2017-08-09 13:09:55 -05:00
}
2023-12-16 11:37:58 -06:00
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %d%c " , func_stat , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'P' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_parm )
{
2017-08-09 13:09:55 -05:00
setting_t parm ;
value_t val ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_parm ( s , sizeof ( s ) , STATE ( rig ) - > has_set_parm ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2023-12-16 11:37:58 -06:00
2025-08-13 17:27:06 +02:00
parm = rig_parse_parm ( arg1 ) ;
2025-08-13 22:02:59 +02:00
if ( ( parm = = RIG_PARM_BANDSELECT | | parm = = RIG_PARM_KEYERTYPE ) & & ! strcmp ( arg2 , " ? " ) )
2023-08-11 10:40:42 -05:00
{
char s [ SPRINTF_MAX_SIZE ] ;
2025-08-13 22:02:59 +02:00
rig_sprintf_parm_gran ( s , sizeof ( s ) - 1 , parm , rig - > caps - > parm_gran ) ;
2023-12-16 11:37:58 -06:00
char * p = strchr ( s , ' ) ' ) ;
if ( p ) { * p = 0 ; }
p = strchr ( s , ' ( ' ) ;
2023-08-11 10:40:42 -05:00
if ( p )
{
char * comma ;
2023-12-16 11:37:58 -06:00
while ( ( comma = strchr ( p , ' , ' ) ) ) { * comma = ' ' ; }
fprintf ( fout , " %s \n " , p + 1 ) ;
2023-08-11 10:40:42 -05:00
RETURNFUNC2 ( RIG_OK ) ;
}
2023-12-16 11:37:58 -06:00
else { RETURNFUNC2 ( - RIG_EINTERNAL ) ; }
2023-08-11 10:40:42 -05:00
}
2017-08-09 13:09:55 -05:00
2025-08-13 17:27:06 +02:00
if ( parm = = RIG_PARM_KEYERTYPE & & strcmp ( arg2 , " ? " ) ! = 0 )
2023-08-17 22:49:20 -05:00
{
2023-12-16 11:37:58 -06:00
if ( strcmp ( arg2 , " STRAIGHT " ) = = 0 ) { arg2 = " 0 " ; }
else if ( strcmp ( arg2 , " BUG " ) = = 0 ) { arg2 = " 1 " ; }
else if ( strcmp ( arg2 , " PADDLE " ) = = 0 ) { arg2 = " 2 " ; }
2025-08-13 14:20:14 +02:00
else { RETURNFUNC2 ( - RIG_EINVAL ) }
2023-08-17 22:49:20 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ! rig_has_set_parm ( rig , parm ) )
{
2017-08-09 13:09:55 -05:00
const struct confparams * cfp ;
cfp = rig_ext_lookup ( rig , arg1 ) ;
2017-10-06 18:58:42 -05:00
if ( ! cfp )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ; /* no such parameter */
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
switch ( cfp - > type )
{
2017-08-09 13:09:55 -05:00
case RIG_CONF_BUTTON :
/* arg is ignored */
val . i = 0 ; // avoid passing uninitialized data
break ;
case RIG_CONF_CHECKBUTTON :
case RIG_CONF_COMBO :
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & val . i ) ) ;
break ;
2023-10-11 23:22:42 -05:00
case RIG_CONF_INT :
CHKSCN1ARG ( sscanf ( arg2 , " %f " , & val . f ) ) ;
break ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_NUMERIC :
2023-11-08 17:14:10 -06:00
CHKSCN1ARG ( sscanf ( arg2 , " %g " , & val . f ) ) ;
2017-08-09 13:09:55 -05:00
break ;
case RIG_CONF_STRING :
2024-10-21 22:31:42 -05:00
#if 0
2023-08-19 08:43:06 -05:00
if ( parm = = RIG_PARM_KEYERTYPE )
2023-12-16 11:37:58 -06:00
{
val . i = atoi ( arg2 ) ;
}
2023-08-19 08:43:06 -05:00
else
2024-10-21 22:31:42 -05:00
# endif
2023-12-16 11:37:58 -06:00
{
val . cs = arg2 ;
}
2017-08-09 13:09:55 -05:00
break ;
2020-01-04 05:59:44 +00:00
case RIG_CONF_BINARY :
2020-01-06 19:54:09 +00:00
val . b . d = ( unsigned char * ) arg2 ;
2020-01-04 05:59:44 +00:00
break ;
2017-08-09 13:09:55 -05:00
default :
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ECONF ) ;
2017-08-09 13:09:55 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ext_parm ( rig , cfp - > token , val ) ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( RIG_PARM_IS_FLOAT ( parm ) )
{
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " %f " , & val . f ) ) ;
2017-10-06 18:58:42 -05:00
}
2023-08-11 10:40:42 -05:00
else if ( RIG_PARM_IS_STRING ( parm ) )
{
Fix segfault with set_parm KEYERTYPE
Steps to reproduce:
tests/rigctl -m 1 \
set_parm KEYERTYPE BUG
Fixes:
Thread 1 "rigctl" received signal SIGSEGV, Segmentation fault.
__strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-sse2.S:142
warning: 142 ../sysdeps/x86_64/multiarch/strlen-sse2.S: File o directory non esistente
(gdb) bt
#0 __strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-sse2.S:142
#1 0x00007ffac346e300 in __printf_buffer (buf=buf@entry=0x7ffc3bcf40d0, format=0x7ffac38aef17 "%s", ap=0x7ffc3bcf4190, mode_flags=0) at ./stdio-common/vfprintf-process-arg.c:435
#2 0x00007ffac3491daf in __vsnprintf_internal (string=<optimized out>, maxlen=<optimized out>, format=<optimized out>, args=args@entry=0x7ffc3bcf4190, mode_flags=mode_flags@entry=0) at ./libio/vsnprintf.c:96
#3 0x00007ffac3469642 in __GI___snprintf (s=s@entry=0x7ffc3bcf4290 "", maxlen=maxlen@entry=32, format=format@entry=0x7ffac38aef17 "%s") at ./stdio-common/snprintf.c:31
#4 0x00007ffac370b7b9 in dummy_set_parm (rig=0x558fe1991b20, parm=2048, val=...) at dummy.c:1704
#5 0x0000558fb536afbe in rigctl_set_parm (rig=0x558fe1991b20, fout=0x7ffac35f25c0 <_IO_2_1_stdout_>, fin=<optimized out>, interactive=<optimized out>, prompt=<optimized out>, vfo_opt=<optimized out>, send_cmd_term=13 '\r', ext_resp=0,
resp_sep=10 '\n', cmd=0x558fb5388000 <test_list+1440>, vfo=536870912, arg1=0x7ffc3bcf4e10 "KEYERTYPE", arg2=0x558fb537fdb1 "1", arg3=0x558fb537ece8 "") at rigctl_parse.c:3829
#6 0x0000558fb53727d6 in rigctl_parse (my_rig=<optimized out>, fin=<optimized out>, fout=<optimized out>, argv=argv@entry=0x7ffc3bcf6fd8, argc=argc@entry=3, sync_cb=sync_cb@entry=0x0, interactive=<optimized out>, prompt=<optimized out>,
vfo_opt=<optimized out>, send_cmd_term=<optimized out>, ext_resp_ptr=<optimized out>, resp_sep_ptr=<optimized out>, use_password=<optimized out>) at rigctl_parse.c:1847
#7 0x0000558fb535cadc in main (argc=<optimized out>, argv=0x7ffc3bcf6fd8) at rigctl.c:801
2025-08-13 14:25:54 +02:00
#if 0
2023-08-19 08:43:06 -05:00
if ( parm = = RIG_PARM_KEYERTYPE )
2023-12-16 11:37:58 -06:00
{
val . i = atoi ( arg2 ) ;
}
2023-08-19 08:43:06 -05:00
else
Fix segfault with set_parm KEYERTYPE
Steps to reproduce:
tests/rigctl -m 1 \
set_parm KEYERTYPE BUG
Fixes:
Thread 1 "rigctl" received signal SIGSEGV, Segmentation fault.
__strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-sse2.S:142
warning: 142 ../sysdeps/x86_64/multiarch/strlen-sse2.S: File o directory non esistente
(gdb) bt
#0 __strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-sse2.S:142
#1 0x00007ffac346e300 in __printf_buffer (buf=buf@entry=0x7ffc3bcf40d0, format=0x7ffac38aef17 "%s", ap=0x7ffc3bcf4190, mode_flags=0) at ./stdio-common/vfprintf-process-arg.c:435
#2 0x00007ffac3491daf in __vsnprintf_internal (string=<optimized out>, maxlen=<optimized out>, format=<optimized out>, args=args@entry=0x7ffc3bcf4190, mode_flags=mode_flags@entry=0) at ./libio/vsnprintf.c:96
#3 0x00007ffac3469642 in __GI___snprintf (s=s@entry=0x7ffc3bcf4290 "", maxlen=maxlen@entry=32, format=format@entry=0x7ffac38aef17 "%s") at ./stdio-common/snprintf.c:31
#4 0x00007ffac370b7b9 in dummy_set_parm (rig=0x558fe1991b20, parm=2048, val=...) at dummy.c:1704
#5 0x0000558fb536afbe in rigctl_set_parm (rig=0x558fe1991b20, fout=0x7ffac35f25c0 <_IO_2_1_stdout_>, fin=<optimized out>, interactive=<optimized out>, prompt=<optimized out>, vfo_opt=<optimized out>, send_cmd_term=13 '\r', ext_resp=0,
resp_sep=10 '\n', cmd=0x558fb5388000 <test_list+1440>, vfo=536870912, arg1=0x7ffc3bcf4e10 "KEYERTYPE", arg2=0x558fb537fdb1 "1", arg3=0x558fb537ece8 "") at rigctl_parse.c:3829
#6 0x0000558fb53727d6 in rigctl_parse (my_rig=<optimized out>, fin=<optimized out>, fout=<optimized out>, argv=argv@entry=0x7ffc3bcf6fd8, argc=argc@entry=3, sync_cb=sync_cb@entry=0x0, interactive=<optimized out>, prompt=<optimized out>,
vfo_opt=<optimized out>, send_cmd_term=<optimized out>, ext_resp_ptr=<optimized out>, resp_sep_ptr=<optimized out>, use_password=<optimized out>) at rigctl_parse.c:1847
#7 0x0000558fb535cadc in main (argc=<optimized out>, argv=0x7ffc3bcf6fd8) at rigctl.c:801
2025-08-13 14:25:54 +02:00
# endif
2023-12-16 11:37:58 -06:00
{
val . cs = arg2 ;
}
2023-08-11 10:40:42 -05:00
}
2017-10-06 18:58:42 -05:00
else
{
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & val . i ) ) ;
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_parm ( rig , parm , val ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'p' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_parm )
{
2017-08-09 13:09:55 -05:00
int status ;
setting_t parm ;
value_t val ;
2020-01-04 05:59:44 +00:00
char buffer [ RIG_BIN_MAX ] ;
2017-08-09 13:09:55 -05:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_parm ( s , sizeof ( s ) , STATE ( rig ) - > has_get_parm ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
parm = rig_parse_parm ( arg1 ) ;
2017-10-06 18:58:42 -05:00
if ( ! rig_has_get_parm ( rig , parm ) )
{
2017-08-09 13:09:55 -05:00
const struct confparams * cfp ;
cfp = rig_ext_lookup ( rig , arg1 ) ;
2017-10-06 18:58:42 -05:00
if ( ! cfp )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ; /* no such parameter */
2017-08-09 13:09:55 -05:00
}
2020-01-04 05:59:44 +00:00
switch ( cfp - > type )
{
case RIG_CONF_STRING :
memset ( buffer , ' 0 ' , sizeof ( buffer ) ) ;
2020-02-23 11:26:09 -06:00
buffer [ sizeof ( buffer ) - 1 ] = 0 ;
2020-01-04 05:59:44 +00:00
val . s = buffer ;
break ;
2020-02-23 11:26:09 -06:00
2020-01-04 05:59:44 +00:00
case RIG_CONF_BINARY :
memset ( buffer , 0 , sizeof ( buffer ) ) ;
val . b . d = ( unsigned char * ) buffer ;
val . b . l = RIG_BIN_MAX ;
break ;
2020-02-23 11:26:09 -06:00
2020-01-04 05:59:44 +00:00
default :
break ;
}
2017-08-09 13:09:55 -05:00
status = rig_get_ext_parm ( rig , cfp - > token , & val ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2017-10-06 18:58:42 -05:00
switch ( cfp - > type )
{
2017-08-09 13:09:55 -05:00
case RIG_CONF_BUTTON :
/* there's not sense in retrieving value of stateless button */
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_CHECKBUTTON :
case RIG_CONF_COMBO :
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %d%c " , val . i , resp_sep ) ;
2017-08-09 13:09:55 -05:00
break ;
2023-10-11 23:22:42 -05:00
case RIG_CONF_INT :
fprintf ( fout , " %.0f%c " , val . f , resp_sep ) ;
break ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_NUMERIC :
2023-11-08 17:14:10 -06:00
fprintf ( fout , " %g%c " , val . f , resp_sep ) ;
2017-08-09 13:09:55 -05:00
break ;
case RIG_CONF_STRING :
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %s%c " , val . s , resp_sep ) ;
2017-08-09 13:09:55 -05:00
break ;
2020-01-04 05:59:44 +00:00
case RIG_CONF_BINARY :
dump_hex ( ( unsigned char * ) buffer , val . b . l ) ;
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %c " , resp_sep ) ;
2020-01-04 05:59:44 +00:00
break ;
2017-08-09 13:09:55 -05:00
default :
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ECONF ) ;
2017-08-09 13:09:55 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
status = rig_get_parm ( rig , parm , & val ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2023-08-18 00:04:59 -05:00
if ( parm = = RIG_PARM_KEYERTYPE )
{
2025-08-13 16:21:57 +02:00
const char * cs ;
2023-12-16 11:37:58 -06:00
Fix segfault when using the dummy driver
Steps to reproduce:
tests/rigctl -m 1 \
get_parm KEYERTYPE
Fixes:
Thread 1 "rigctl" received signal SIGSEGV, Segmentation fault.
0x0000556aff4f890d in rigctl_get_parm (rig=<optimized out>, fout=0x7f87517f25c0 <_IO_2_1_stdout_>, fin=<optimized out>, interactive=1, prompt=1, vfo_opt=<optimized out>, send_cmd_term=13 '\r', ext_resp=0, resp_sep=10 '\n',
cmd=0x556aff516050 <test_list+1520>, vfo=536870912, arg1=0x7ffc5985b5c0 "KEYERTYPE", arg2=0x556aff50cce8 "", arg3=0x556aff50cce8 "") at rigctl_parse.c:3947
3947 if (strcmp(val.s, "0") == 0) {s = "STRAIGHT";}
(gdb) bt
#0 0x0000556aff4f890d in rigctl_get_parm (rig=<optimized out>, fout=0x7f87517f25c0 <_IO_2_1_stdout_>, fin=<optimized out>, interactive=1, prompt=1, vfo_opt=<optimized out>, send_cmd_term=13 '\r', ext_resp=0, resp_sep=10 '\n',
cmd=0x556aff516050 <test_list+1520>, vfo=536870912, arg1=0x7ffc5985b5c0 "KEYERTYPE", arg2=0x556aff50cce8 "", arg3=0x556aff50cce8 "") at rigctl_parse.c:3947
#1 0x0000556aff5007f6 in rigctl_parse (my_rig=<optimized out>, fin=<optimized out>, fout=<optimized out>, argv=argv@entry=0x7ffc5985d788, argc=argc@entry=3, sync_cb=sync_cb@entry=0x0, interactive=<optimized out>, prompt=<optimized out>,
vfo_opt=<optimized out>, send_cmd_term=<optimized out>, ext_resp_ptr=<optimized out>, resp_sep_ptr=<optimized out>, use_password=<optimized out>) at rigctl_parse.c:1847
#2 0x0000556aff4eaadc in main (argc=<optimized out>, argv=0x7ffc5985d788) at rigctl.c:801
2025-08-13 16:43:32 +02:00
if ( val . cs = = NULL ) { cs = " (null) " ; }
else if ( strcmp ( val . cs , " 0 " ) = = 0 ) { cs = " STRAIGHT " ; }
2025-08-13 16:21:57 +02:00
else if ( strcmp ( val . cs , " 1 " ) = = 0 ) { cs = " BUG " ; }
else if ( strcmp ( val . cs , " 2 " ) = = 0 ) { cs = " PADDLE " ; }
else { cs = " UNKNOWN " ; }
2023-12-16 11:37:58 -06:00
2025-08-13 16:21:57 +02:00
fprintf ( fout , " %s%c " , cs , resp_sep ) ;
2023-08-18 00:04:59 -05:00
}
else if ( RIG_PARM_IS_FLOAT ( parm ) )
2017-10-06 18:58:42 -05:00
{
2023-08-14 12:35:28 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: float \n " , __func__ ) ;
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %f%c " , val . f , resp_sep ) ;
2017-10-06 18:58:42 -05:00
}
2023-08-14 12:35:28 -05:00
else if ( RIG_PARM_IS_STRING ( parm ) )
2023-08-11 10:40:42 -05:00
{
2023-08-14 12:35:28 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: string \n " , __func__ ) ;
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %s%c " , val . s , resp_sep ) ;
2023-08-11 10:40:42 -05:00
}
2017-10-06 18:58:42 -05:00
else
{
2023-08-14 12:35:28 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: int \n " , __func__ ) ;
Standardize extended response in rigctld for level, func, and parm
,l VFOA AGC
get_level: VFOA,AGC,0,RPRT 0
,u VFOA RIT
get_func: VFOA,RIT,0,RPRT 0
,p ANN
get_parm: currVFO,ANN,0,RPRT 0
Error example
,p NB
get_parm: currVFO,NB,RPRT -1
https://github.com/Hamlib/Hamlib/issues/1361
2023-08-13 23:23:23 -05:00
fprintf ( fout , " %d%c " , val . i , resp_sep ) ;
2017-08-09 13:09:55 -05:00
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'B' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_bank )
{
2017-08-09 13:09:55 -05:00
int bank ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & bank ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_bank ( rig , vfo , bank ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'E' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_mem )
{
2017-08-09 13:09:55 -05:00
int ch ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & ch ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_mem ( rig , vfo , ch ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'e' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_mem )
{
2017-08-09 13:09:55 -05:00
int status ;
int ch ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_mem ( rig , vfo , & ch ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d%c " , ch , resp_sep ) ;
2008-01-12 00:36:58 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'G' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( vfo_op )
{
2017-08-09 13:09:55 -05:00
vfo_op_t op ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2024-05-31 09:48:30 -04:00
rig_sprintf_vfop ( s , sizeof ( s ) , STATE ( rig ) - > vfo_ops ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
op = rig_parse_vfo_op ( arg1 ) ;
2008-05-23 14:30:12 +00:00
2017-10-06 18:58:42 -05:00
if ( RIG_OP_NONE = = op )
{
2021-11-28 12:41:10 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: rig_parse_vfo failed with '%s' \n " , __func__ ,
arg1 ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
2017-08-09 13:09:55 -05:00
}
2010-12-01 21:41:55 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_vfo_op ( rig , vfo , op ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'g' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( scan )
{
2017-08-09 13:09:55 -05:00
scan_t op ;
int ch ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-10-06 18:58:42 -05:00
if ( ! strcmp ( arg1 , " ? " ) )
{
2017-08-09 13:09:55 -05:00
char s [ SPRINTF_MAX_SIZE ] ;
2021-03-03 08:03:18 -06:00
rig_sprintf_scan ( s , sizeof ( s ) , rig - > caps - > scan_ops ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s \n " , s ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2017-08-09 13:09:55 -05:00
}
2008-05-23 14:30:12 +00:00
2017-08-09 13:09:55 -05:00
op = rig_parse_scan ( arg1 ) ;
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & ch ) ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_scan ( rig , vfo , op , ch ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'H' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_channel )
{
2017-08-09 13:09:55 -05:00
const channel_cap_t * mem_caps = NULL ;
const chan_t * chan_list ;
channel_t chan ;
int status ;
2026-01-28 15:44:36 -05:00
char s [ HAMLIB_MAXCHANDESC ] ;
2017-08-09 13:09:55 -05:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
memset ( & chan , 0 , sizeof ( channel_t ) ) ;
2017-10-06 18:58:42 -05:00
if ( isdigit ( ( int ) arg1 [ 0 ] ) )
{
2017-08-09 13:09:55 -05:00
chan . vfo = RIG_VFO_MEM ;
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & chan . channel_num ) ) ;
/*
* find mem_caps in caps , we ' ll need it later
*/
chan_list = rig_lookup_mem_caps ( rig , chan . channel_num ) ;
2017-10-06 18:58:42 -05:00
if ( chan_list )
{
2017-08-09 13:09:55 -05:00
mem_caps = & chan_list - > mem_caps ;
}
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
chan . vfo = rig_parse_vfo ( arg1 ) ;
chan . channel_num = 0 ;
/* TODO: mem_caps for VFO! */
/* either from mem, or reverse computed from caps */
}
2017-10-06 18:58:42 -05:00
if ( ! mem_caps )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_ECONF ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > bank_num )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf_flush ( fout , " Bank Num: " ) ;
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . bank_num ) ) ;
}
2010-05-28 19:47:35 +00:00
#if 0
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( mem_caps - > vfo )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " vfo (VFOA,MEM,etc...): " ) ;
2017-08-09 13:09:55 -05:00
}
2026-01-28 15:44:36 -05:00
CHKSCN1ARG ( scanfc ( fin , " %10s " , s ) ) ;
2017-08-09 13:09:55 -05:00
chan . vfo = rig_parse_vfo ( s ) ;
}
2010-05-28 19:47:35 +00:00
# endif
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( mem_caps - > ant )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " ant: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . ant ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > freq )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " Frequency: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " % " SCNfreq , & chan . freq ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > mode )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " mode (FM,LSB,etc...): " ) ;
2017-08-09 13:09:55 -05:00
}
2026-01-28 15:44:36 -05:00
CHKSCN1ARG ( scanfc ( fin , " %10s " , s ) ) ;
2017-08-09 13:09:55 -05:00
chan . mode = rig_parse_mode ( s ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > width )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " width: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %ld " , & chan . width ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > tx_freq )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " tx freq: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " % " SCNfreq , & chan . tx_freq ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > tx_mode )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " tx mode (FM,LSB,etc...): " ) ;
2017-08-09 13:09:55 -05:00
}
2026-01-28 15:44:36 -05:00
CHKSCN1ARG ( scanfc ( fin , " %10s " , s ) ) ;
2017-08-09 13:09:55 -05:00
chan . tx_mode = rig_parse_mode ( s ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > tx_width )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " tx width: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %ld " , & chan . tx_width ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > split )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " split (0,1): " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & status ) ) ;
chan . split = status ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > tx_vfo )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " tx vfo (VFOA,MEM,etc...): " ) ;
2017-08-09 13:09:55 -05:00
}
2026-01-28 15:44:36 -05:00
CHKSCN1ARG ( scanfc ( fin , " %10s " , s ) ) ;
2017-08-09 13:09:55 -05:00
chan . tx_vfo = rig_parse_vfo ( s ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > rptr_shift )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " rptr shift (+-0): " ) ;
2017-08-09 13:09:55 -05:00
}
2026-01-28 15:44:36 -05:00
CHKSCN1ARG ( scanfc ( fin , " %12s " , s ) ) ;
2017-08-09 13:09:55 -05:00
chan . rptr_shift = rig_parse_rptr_shift ( s ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > rptr_offs )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " rptr offset: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %ld " , & chan . rptr_offs ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > tuning_step )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " tuning step: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %ld " , & chan . tuning_step ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > rit )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " rit (Hz,0=off): " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %ld " , & chan . rit ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > xit )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " xit (Hz,0=off): " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %ld " , & chan . xit ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > funcs )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " funcs: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %lx " , & chan . funcs ) ) ;
}
2007-11-11 23:03:38 +00:00
#if 0
2017-08-09 13:09:55 -05:00
/* for all levels (except READONLY), ask */
2017-10-06 18:58:42 -05:00
if ( mem_caps - > levels )
{
2017-08-09 13:09:55 -05:00
sscanf ( arg1 , " %d " , & chan . levels ) ;
}
2007-11-11 23:03:38 +00:00
# endif
2017-08-09 13:09:55 -05:00
2017-10-06 18:58:42 -05:00
if ( mem_caps - > ctcss_tone )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " ctcss tone freq in tenth of Hz (0=off): " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . ctcss_tone ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > ctcss_sql )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " ctcss sql freq in tenth of Hz (0=off): " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . ctcss_sql ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > dcs_code )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " dcs code: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . dcs_code ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > dcs_sql )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " dcs sql: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . dcs_sql ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > scan_group )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " scan group: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . scan_group ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > flags )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " flags: " ) ;
2017-08-09 13:09:55 -05:00
}
CHKSCN1ARG ( scanfc ( fin , " %d " , & chan . flags ) ) ;
}
2017-10-06 18:58:42 -05:00
if ( mem_caps - > channel_desc )
{
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2010-05-28 19:47:35 +00:00
fprintf_flush ( fout , " channel desc: " ) ;
2017-08-09 13:09:55 -05:00
}
2026-07-27 17:14:00 -05:00
CHKSCN1ARG ( scanfc ( fin , " %29s " , s ) ) ;
2017-08-09 13:09:55 -05:00
strcpy ( chan . channel_desc , s ) ;
}
2007-11-11 23:03:38 +00:00
#if 0
2017-08-09 13:09:55 -05:00
/* TODO: same as levels, allocate/free the array */
2017-10-06 18:58:42 -05:00
if ( mem_caps - > ext_levels )
{
2017-08-09 13:09:55 -05:00
sscanf ( arg1 , " %d " , & chan . ext_levels [ i ] . val . i ) ;
}
2007-11-11 23:03:38 +00:00
# endif
2020-11-29 23:32:14 -06:00
status = rig_set_channel ( rig , vfo , & chan ) ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'h' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_channel )
{
2017-08-09 13:09:55 -05:00
int status ;
2020-05-06 08:06:14 -05:00
int read_only = 0 ;
2017-08-09 13:09:55 -05:00
channel_t chan ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
memset ( & chan , 0 , sizeof ( channel_t ) ) ;
2010-01-24 23:24:20 +00:00
2017-10-06 18:58:42 -05:00
if ( isdigit ( ( int ) arg1 [ 0 ] ) )
{
2017-08-09 13:09:55 -05:00
chan . vfo = RIG_VFO_MEM ;
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & chan . channel_num ) ) ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
chan . vfo = rig_parse_vfo ( arg1 ) ;
chan . channel_num = 0 ;
}
2007-11-11 23:03:38 +00:00
2020-05-06 08:06:14 -05:00
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & read_only ) ) ;
2020-11-29 23:32:14 -06:00
status = rig_get_channel ( rig , RIG_VFO_NONE , & chan , read_only ) ;
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2010-05-28 19:47:35 +00:00
2017-08-09 13:09:55 -05:00
status = dump_chan ( fout , rig , & chan ) ;
2010-05-28 19:47:35 +00:00
2017-10-06 18:58:42 -05:00
if ( chan . ext_levels )
{
2017-08-09 13:09:55 -05:00
free ( chan . ext_levels ) ;
}
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'A' */
2021-11-28 20:52:29 +02:00
/**
* \ deprecated Function deprecated . Use the new async data functionality instead .
*/
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_trn )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
RETURNFUNC2 ( - RIG_EDEPRECATED ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'a' */
2021-11-28 20:52:29 +02:00
/**
* \ deprecated Function deprecated . Use the new async data functionality instead .
*/
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_trn )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
RETURNFUNC2 ( - RIG_EDEPRECATED ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* '_' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_info )
{
2017-08-09 13:09:55 -05:00
const char * s ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
s = rig_get_info ( rig ) ;
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s%c " , s ? s : " None " , resp_sep ) ;
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2010-05-28 19:47:35 +00:00
int dump_chan ( FILE * fout , RIG * rig , channel_t * chan )
2007-11-11 23:03:38 +00:00
{
2017-08-09 13:09:55 -05:00
int idx , firstloop = 1 ;
char freqbuf [ 16 ] ;
char widthbuf [ 16 ] ;
char prntbuf [ 256 ] ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
" Channel: %d, Name: '%s' \n " ,
chan - > channel_num ,
chan - > channel_desc ) ;
fprintf ( fout ,
" VFO: %s, Antenna: %d, Split: %s \n " ,
rig_strvfo ( chan - > vfo ) ,
chan - > ant ,
chan - > split = = RIG_SPLIT_ON ? " ON " : " OFF " ) ;
2021-03-03 08:03:18 -06:00
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , chan - > freq ) ;
sprintf_freq ( widthbuf , sizeof ( widthbuf ) , chan - > width ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
" Freq: %s \t Mode: %s \t Width: %s \n " ,
freqbuf ,
rig_strrmode ( chan - > mode ) ,
widthbuf ) ;
2021-03-03 08:03:18 -06:00
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , chan - > tx_freq ) ;
sprintf_freq ( widthbuf , sizeof ( widthbuf ) , chan - > tx_width ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
" txFreq: %s \t txMode: %s \t txWidth: %s \n " ,
freqbuf ,
rig_strrmode ( chan - > tx_mode ) ,
widthbuf ) ;
2021-03-03 08:03:18 -06:00
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , chan - > rptr_offs ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
" Shift: %s, Offset: %s%s, " ,
rig_strptrshift ( chan - > rptr_shift ) ,
chan - > rptr_offs > 0 ? " + " : " " ,
freqbuf ) ;
2021-03-03 08:03:18 -06:00
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , chan - > tuning_step ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " Step: %s, " , freqbuf ) ;
2021-03-03 08:03:18 -06:00
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , chan - > rit ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " RIT: %s%s, " , chan - > rit > 0 ? " + " : " " , freqbuf ) ;
2021-03-03 08:03:18 -06:00
sprintf_freq ( freqbuf , sizeof ( freqbuf ) , chan - > xit ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " XIT: %s%s \n " , chan - > xit > 0 ? " + " : " " , freqbuf ) ;
2020-01-14 23:36:01 -06:00
fprintf ( fout , " CTCSS: %u.%uHz, " , chan - > ctcss_tone / 10 , chan - > ctcss_tone % 10 ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2020-01-14 23:36:01 -06:00
" CTCSSsql: %u.%uHz, " ,
2017-08-09 13:09:55 -05:00
chan - > ctcss_sql / 10 ,
chan - > ctcss_sql % 10 ) ;
2020-01-14 23:36:01 -06:00
fprintf ( fout , " DCS: %u.%u, " , chan - > dcs_code / 10 , chan - > dcs_code % 10 ) ;
fprintf ( fout , " DCSsql: %u.%u \n " , chan - > dcs_sql / 10 , chan - > dcs_sql % 10 ) ;
2017-08-09 13:09:55 -05:00
2021-03-03 08:03:18 -06:00
rig_sprintf_func ( prntbuf , sizeof ( prntbuf ) , chan - > funcs ) ;
2017-08-09 13:09:55 -05:00
fprintf ( fout , " Functions: %s \n " , prntbuf ) ;
fprintf ( fout , " Levels: " ) ;
2017-10-06 18:58:42 -05:00
for ( idx = 0 ; idx < RIG_SETTING_MAX ; idx + + )
{
2017-08-09 13:09:55 -05:00
setting_t level = rig_idx2setting ( idx ) ;
const char * level_s ;
if ( ! RIG_LEVEL_SET ( level )
2019-11-30 10:19:08 -06:00
| | ( ! rig_has_set_level ( rig , level )
& & ! rig_has_get_level ( rig , level ) ) )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
continue ;
}
level_s = rig_strlevel ( level ) ;
2017-10-06 18:58:42 -05:00
if ( ! level_s | | level_s [ 0 ] = = ' \0 ' )
{
2017-08-09 13:09:55 -05:00
continue ; /* duh! */
}
2017-10-06 18:58:42 -05:00
if ( firstloop )
{
2017-08-09 13:09:55 -05:00
firstloop = 0 ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " , \t " ) ;
}
2017-10-06 18:58:42 -05:00
if ( RIG_LEVEL_IS_FLOAT ( level ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: %g%% " , level_s , 100 * chan - > levels [ idx ] . f ) ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: %d " , level_s , chan - > levels [ idx ] . i ) ;
}
}
/* ext_levels */
for ( idx = 0 ; chan - > ext_levels
2019-11-30 10:19:08 -06:00
& & ! RIG_IS_EXT_END ( chan - > ext_levels [ idx ] ) ; idx + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
const struct confparams * cfp ;
char lstr [ 32 ] ;
cfp = rig_ext_lookup_tok ( rig , chan - > ext_levels [ idx ] . token ) ;
2017-10-06 18:58:42 -05:00
if ( ! cfp )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINVAL ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
switch ( cfp - > type )
{
2017-08-09 13:09:55 -05:00
case RIG_CONF_STRING :
strcpy ( lstr , chan - > ext_levels [ idx ] . val . s ) ;
break ;
case RIG_CONF_COMBO :
2022-01-11 00:00:44 -06:00
SNPRINTF ( lstr , sizeof ( lstr ) , " %d " , chan - > ext_levels [ idx ] . val . i ) ;
2017-08-09 13:09:55 -05:00
break ;
2023-10-11 23:22:42 -05:00
case RIG_CONF_INT :
SNPRINTF ( lstr , sizeof ( lstr ) , " %.0f " , chan - > ext_levels [ idx ] . val . f ) ;
break ;
2017-08-09 13:09:55 -05:00
case RIG_CONF_NUMERIC :
2023-11-08 17:14:10 -06:00
SNPRINTF ( lstr , sizeof ( lstr ) , " %g " , chan - > ext_levels [ idx ] . val . f ) ;
2017-08-09 13:09:55 -05:00
break ;
case RIG_CONF_CHECKBUTTON :
2022-01-11 00:00:44 -06:00
SNPRINTF ( lstr , sizeof ( lstr ) , " %s " , chan - > ext_levels [ idx ] . val . i ? " ON " : " OFF " ) ;
2017-08-09 13:09:55 -05:00
break ;
case RIG_CONF_BUTTON :
continue ;
default :
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( - RIG_EINTERNAL ) ;
2017-08-09 13:09:55 -05:00
}
fprintf ( fout , " , \t %s: %s " , cfp - > name , lstr ) ;
}
fprintf ( fout , " \n " ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* '1' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( dump_caps )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2023-06-03 16:50:30 -05:00
# if 1
2023-12-16 11:37:58 -06:00
2023-06-03 16:50:30 -05:00
if ( rig - > caps - > rig_model = = RIG_MODEL_NETRIGCTL )
{
char cmd [ 32 ] ;
SNPRINTF ( cmd , sizeof ( cmd ) , " \\ dump_caps \n " ) ;
dumpstate ( rig , fout ) ;
}
else
# endif
{
dumpcaps ( rig , fout ) ;
}
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2008-09-21 19:24:47 +00:00
/* For rigctld internal use */
declare_proto_rig ( dump_state )
{
2017-08-09 13:09:55 -05:00
int i ;
2024-05-31 09:48:30 -04:00
struct rig_state * rs = STATE ( rig ) ;
2022-11-23 23:29:18 -06:00
char buf [ 1024 ] ;
2008-09-21 19:24:47 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
/*
* - Protocol version
*/
2020-04-04 09:38:50 -05:00
# define RIGCTLD_PROT_VER 1
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d \n " , RIGCTLD_PROT_VER ) ;
fprintf ( fout , " %d \n " , rig - > caps - > rig_model ) ;
2020-07-24 12:57:33 -05:00
#if 0 // deprecated -- not one rig uses this
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d \n " , rs - > itu_region ) ;
2020-10-11 18:03:50 +02:00
# else // need to print something to maintain backward compatibility
2020-07-24 12:57:33 -05:00
fprintf ( fout , " %d \n " , 0 ) ;
# endif
2017-08-09 13:09:55 -05:00
2021-03-15 17:51:22 -05:00
for ( i = 0 ; i < HAMLIB_FRQRANGESIZ
& & ! RIG_IS_FRNG_END ( rs - > rx_range_list [ i ] ) ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2018-12-21 16:46:48 -05:00
" % " FREQFMT " % " FREQFMT " 0x% " PRXll " %d %d 0x%x 0x%x \n " ,
2019-08-17 23:20:48 -05:00
rs - > rx_range_list [ i ] . startf ,
rs - > rx_range_list [ i ] . endf ,
2018-12-22 23:56:30 -05:00
rs - > rx_range_list [ i ] . modes ,
2017-08-09 13:09:55 -05:00
rs - > rx_range_list [ i ] . low_power ,
rs - > rx_range_list [ i ] . high_power ,
rs - > rx_range_list [ i ] . vfo ,
rs - > rx_range_list [ i ] . ant ) ;
}
fprintf ( fout , " 0 0 0 0 0 0 0 \n " ) ;
2021-03-15 17:51:22 -05:00
for ( i = 0 ; i < HAMLIB_FRQRANGESIZ
& & ! RIG_IS_FRNG_END ( rs - > tx_range_list [ i ] ) ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2018-12-21 16:46:48 -05:00
" % " FREQFMT " % " FREQFMT " 0x% " PRXll " %d %d 0x%x 0x%x \n " ,
2019-08-17 23:20:48 -05:00
rs - > tx_range_list [ i ] . startf ,
rs - > tx_range_list [ i ] . endf ,
2018-12-22 23:56:30 -05:00
rs - > tx_range_list [ i ] . modes ,
2017-08-09 13:09:55 -05:00
rs - > tx_range_list [ i ] . low_power ,
rs - > tx_range_list [ i ] . high_power ,
rs - > tx_range_list [ i ] . vfo ,
rs - > tx_range_list [ i ] . ant ) ;
}
fprintf ( fout , " 0 0 0 0 0 0 0 \n " ) ;
2021-03-06 14:59:57 -06:00
for ( i = 0 ; i < HAMLIB_TSLSTSIZ & & ! RIG_IS_TS_END ( rs - > tuning_steps [ i ] ) ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2018-12-21 16:46:48 -05:00
" 0x% " PRXll " %ld \n " ,
2018-12-22 23:56:30 -05:00
rs - > tuning_steps [ i ] . modes ,
2017-08-09 13:09:55 -05:00
rs - > tuning_steps [ i ] . ts ) ;
}
fprintf ( fout , " 0 0 \n " ) ;
2021-03-06 14:59:57 -06:00
for ( i = 0 ; i < HAMLIB_FLTLSTSIZ & & ! RIG_IS_FLT_END ( rs - > filters [ i ] ) ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout ,
2018-12-21 16:46:48 -05:00
" 0x% " PRXll " %ld \n " ,
2018-12-22 23:56:30 -05:00
rs - > filters [ i ] . modes ,
2017-08-09 13:09:55 -05:00
rs - > filters [ i ] . width ) ;
}
fprintf ( fout , " 0 0 \n " ) ;
2008-09-21 19:24:47 +00:00
#if 0
2021-03-06 14:59:57 -06:00
chan_t chan_list [ HAMLIB_CHANLSTSIZ ] ; /*!< Channel list, zero ended */
2008-09-21 19:24:47 +00:00
# endif
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %ld \n " , rs - > max_rit ) ;
fprintf ( fout , " %ld \n " , rs - > max_xit ) ;
fprintf ( fout , " %ld \n " , rs - > max_ifshift ) ;
fprintf ( fout , " %d \n " , rs - > announces ) ;
2021-03-06 14:59:57 -06:00
for ( i = 0 ; i < HAMLIB_MAXDBLSTSIZ & & rs - > preamp [ i ] ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d " , rs - > preamp [ i ] ) ;
}
fprintf ( fout , " \n " ) ;
2021-03-06 14:59:57 -06:00
for ( i = 0 ; i < HAMLIB_MAXDBLSTSIZ & & rs - > attenuator [ i ] ; i + + )
2017-10-06 18:58:42 -05:00
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %d " , rs - > attenuator [ i ] ) ;
}
fprintf ( fout , " \n " ) ;
2018-12-22 23:56:30 -05:00
fprintf ( fout , " 0x% " PRXll " \n " , rs - > has_get_func ) ;
fprintf ( fout , " 0x% " PRXll " \n " , rs - > has_set_func ) ;
fprintf ( fout , " 0x% " PRXll " \n " , rs - > has_get_level ) ;
fprintf ( fout , " 0x% " PRXll " \n " , rs - > has_set_level ) ;
fprintf ( fout , " 0x% " PRXll " \n " , rs - > has_get_parm ) ;
fprintf ( fout , " 0x% " PRXll " \n " , rs - > has_set_parm ) ;
2008-09-21 19:24:47 +00:00
2020-04-04 09:38:50 -05:00
// protocol 1 fields are "setting=value"
// protocol 1 allows fields can be listed/processed in any order
// protocol 1 fields can be multi-line -- just write the thing to allow for it
2020-04-04 15:49:26 -05:00
// backward compatible as new values will just generate warnings
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: chk_vfo_executed=%d \n " , __func__ ,
chk_vfo_executed ) ;
2024-11-24 18:44:00 +01:00
if ( chk_vfo_executed ) // for 3.3 compatibility
2020-06-23 11:12:15 -05:00
{
2020-07-01 08:52:44 -05:00
fprintf ( fout , " vfo_ops=0x%x \n " , rig - > caps - > vfo_ops ) ;
2021-08-26 06:49:24 -05:00
fprintf ( fout , " ptt_type=0x%x \n " ,
2024-03-01 05:32:08 -05:00
PTTPORT ( rig ) - > type . ptt ) ;
2020-10-06 21:50:37 +01:00
fprintf ( fout , " targetable_vfo=0x%x \n " , rig - > caps - > targetable_vfo ) ;
2021-01-09 10:13:17 -06:00
fprintf ( fout , " has_set_vfo=%d \n " , rig - > caps - > set_vfo ! = NULL ) ;
fprintf ( fout , " has_get_vfo=%d \n " , rig - > caps - > get_vfo ! = NULL ) ;
fprintf ( fout , " has_set_freq=%d \n " , rig - > caps - > set_freq ! = NULL ) ;
fprintf ( fout , " has_get_freq=%d \n " , rig - > caps - > get_freq ! = NULL ) ;
2021-04-28 17:39:08 -05:00
fprintf ( fout , " has_set_conf=%d \n " , rig - > caps - > set_conf ! = NULL ) ;
fprintf ( fout , " has_get_conf=%d \n " , rig - > caps - > get_conf ! = NULL ) ;
2021-04-29 17:25:54 -05:00
#if 0
2021-04-29 17:16:51 -05:00
fprintf ( fout , " has_set_parm=%d \n " , rig - > caps - > set_parm ! = NULL ) ;
fprintf ( fout , " has_get_parm=%d \n " , rig - > caps - > get_parm ! = NULL ) ;
fprintf ( fout , " parm_gran=0x%x \n " , rig - > caps - > parm_gran ) ;
2021-04-29 17:25:54 -05:00
# endif
2021-04-28 17:39:08 -05:00
// for the future
// fprintf(fout, "has_set_trn=%d\n", rig->caps->set_trn != NULL);
// fprintf(fout, "has_get_trn=%d\n", rig->caps->get_trn != NULL);
fprintf ( fout , " has_power2mW=%d \n " , rig - > caps - > power2mW ! = NULL ) ;
fprintf ( fout , " has_mW2power=%d \n " , rig - > caps - > mW2power ! = NULL ) ;
2023-12-29 15:59:34 -06:00
fprintf ( fout , " has_get_ant=%d \n " , rig - > caps - > get_ant ! = NULL ) ;
fprintf ( fout , " has_set_ant=%d \n " , rig - > caps - > set_ant ! = NULL ) ;
2021-04-09 15:35:30 -05:00
fprintf ( fout , " timeout=%d \n " , rig - > caps - > timeout ) ;
2021-12-11 22:54:54 -06:00
fprintf ( fout , " rig_model=%d \n " , rig - > caps - > rig_model ) ;
fprintf ( fout , " rigctld_version=%s \n " , hamlib_version2 ) ;
2022-11-23 23:29:18 -06:00
rig_sprintf_agc_levels ( rig , buf , sizeof ( buf ) ) ;
2024-04-02 16:26:27 -05:00
if ( strlen ( buf ) > 0 ) { fprintf ( fout , " agc_levels=%s \n " , buf ) ; }
2021-04-29 17:23:37 -05:00
2021-04-30 15:42:03 -05:00
if ( rig - > caps - > ctcss_list )
2021-04-29 10:49:29 -05:00
{
2021-04-30 15:42:03 -05:00
fprintf ( fout , " ctcss_list= " ) ;
2021-04-29 17:23:37 -05:00
2021-04-30 15:42:03 -05:00
for ( i = 0 ; i < CTCSS_LIST_SIZE & & rig - > caps - > ctcss_list [ i ] ! = 0 ; i + + )
{
fprintf ( fout ,
" %u.%1u " ,
rig - > caps - > ctcss_list [ i ] / 10 , rig - > caps - > ctcss_list [ i ] % 10 ) ;
}
2021-04-29 17:23:37 -05:00
2021-04-30 15:42:03 -05:00
fprintf ( fout , " \n " ) ;
2021-04-29 10:49:29 -05:00
}
2021-04-29 17:23:37 -05:00
2021-04-30 15:42:03 -05:00
if ( rig - > caps - > dcs_list )
{
fprintf ( fout , " dcs_list= " ) ;
for ( i = 0 ; i < DCS_LIST_SIZE & & rig - > caps - > dcs_list [ i ] ! = 0 ; i + + )
{
fprintf ( fout ,
" %u " ,
rig - > caps - > dcs_list [ i ] ) ;
}
fprintf ( fout , " \n " ) ;
}
2021-04-29 10:49:29 -05:00
2023-06-03 16:50:30 -05:00
fprintf ( fout , " level_gran= " ) ;
for ( i = 0 ; i < RIG_SETTING_MAX ; + + i )
{
2025-08-17 18:13:43 +02:00
setting_t level = rig_idx2setting ( i ) ;
if ( RIG_LEVEL_IS_FLOAT ( level ) )
2023-06-03 16:50:30 -05:00
{
2024-05-31 09:48:30 -04:00
fprintf ( fout , " %d=%g,%g,%g; " , i , rs - > level_gran [ i ] . min . f ,
rs - > level_gran [ i ] . max . f , rs - > level_gran [ i ] . step . f ) ;
2023-06-03 16:50:30 -05:00
}
else
{
2024-05-31 09:48:30 -04:00
fprintf ( fout , " %d=%d,%d,%d; " , i , rs - > level_gran [ i ] . min . i ,
rs - > level_gran [ i ] . max . i , rs - > level_gran [ i ] . step . i ) ;
2023-06-03 16:50:30 -05:00
}
}
fprintf ( fout , " \n parm_gran= " ) ;
for ( i = 0 ; i < RIG_SETTING_MAX ; + + i )
{
2025-08-17 18:13:43 +02:00
setting_t parm = rig_idx2setting ( i ) ;
if ( RIG_PARM_IS_FLOAT ( parm ) )
2023-06-03 16:50:30 -05:00
{
2024-05-31 09:48:30 -04:00
fprintf ( fout , " %d=%g,%g,%g; " , i , rs - > parm_gran [ i ] . min . f ,
rs - > parm_gran [ i ] . max . f , rs - > parm_gran [ i ] . step . f ) ;
2023-06-03 16:50:30 -05:00
}
2025-08-17 18:13:43 +02:00
else if ( RIG_PARM_IS_STRING ( parm ) )
{
fprintf ( fout , " %d=%s; " , i , rs - > parm_gran [ i ] . step . cs ) ;
}
2023-06-03 16:50:30 -05:00
else
{
2024-05-31 09:48:30 -04:00
fprintf ( fout , " %d=%d,%d,%d; " , i , rs - > level_gran [ i ] . min . i ,
rs - > level_gran [ i ] . max . i , rs - > level_gran [ i ] . step . i ) ;
2023-06-03 16:50:30 -05:00
}
}
2023-12-16 11:37:58 -06:00
2023-06-03 16:50:30 -05:00
fprintf ( fout , " \n " ) ;
2023-12-16 11:37:58 -06:00
2024-05-31 09:48:30 -04:00
rs - > rig_model = rig - > caps - > rig_model ;
fprintf ( fout , " rig_model=%d \n " , rs - > rig_model ) ;
2023-07-20 10:01:30 -05:00
fprintf ( fout , " hamlib_version=%s \n " , hamlib_version2 ) ;
2020-07-01 08:52:44 -05:00
fprintf ( fout , " done \n " ) ;
2020-06-23 11:12:15 -05:00
}
2020-04-04 09:38:50 -05:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-05-23 14:30:12 +00:00
/* '3' */
declare_proto_rig ( dump_conf )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
dumpconf ( rig , fout ) ;
2008-05-23 14:30:12 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2008-05-23 14:30:12 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'Y' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_ant )
{
2017-08-09 13:09:55 -05:00
ant_t ant ;
2020-01-21 17:53:12 -06:00
value_t option ; // some rigs have a another option for the antenna
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & ant ) ) ;
2020-01-21 17:53:12 -06:00
CHKSCN1ARG ( sscanf ( arg2 , " %d " , & option . i ) ) ; // assuming they are integer values
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_ant ( rig , vfo , rig_idx2setting ( ant - 1 ) , option ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'y' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_ant )
{
2017-08-09 13:09:55 -05:00
int status ;
2020-02-18 23:10:14 -06:00
ant_t ant , ant_curr , ant_tx , ant_rx ;
2020-01-21 17:53:12 -06:00
value_t option ;
2022-05-25 11:55:14 -05:00
char antbuf [ 64 ] ;
2017-08-09 13:09:55 -05:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-02-04 07:40:24 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & ant ) ) ;
2020-02-02 08:38:10 -06:00
2020-02-10 12:17:30 -06:00
if ( ant = = 0 ) // then we want the current antenna info
{
2020-02-23 11:26:09 -06:00
status = rig_get_ant ( rig , vfo , RIG_ANT_CURR , & option , & ant_curr , & ant_tx ,
& ant_rx ) ;
2020-02-10 12:17:30 -06:00
}
else
{
2020-02-23 11:26:09 -06:00
status = rig_get_ant ( rig , vfo , rig_idx2setting ( ant - 1 ) , & option , & ant_curr ,
& ant_tx , & ant_rx ) ;
2020-02-10 12:17:30 -06:00
}
2007-11-11 23:03:38 +00:00
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2020-02-23 11:26:09 -06:00
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2021-03-15 17:51:22 -05:00
rig_sprintf_ant ( antbuf , sizeof ( antbuf ) , ant_curr ) ;
2020-02-18 23:10:14 -06:00
fprintf ( fout , " %s%c " , antbuf , resp_sep ) ;
//fprintf(fout, "%d%c", rig_setting2idx(ant_curr)+1, resp_sep);
2017-08-09 13:09:55 -05:00
2020-01-21 17:53:12 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
fprintf ( fout , " %d%c " , option . i , resp_sep ) ;
2020-02-18 23:10:14 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg3 ) ;
}
2021-03-03 08:03:18 -06:00
rig_sprintf_ant ( antbuf , sizeof ( antbuf ) , ant_tx ) ;
2020-02-18 23:10:14 -06:00
fprintf ( fout , " %s%c " , antbuf , resp_sep ) ;
//fprintf(fout, "%d%c", rig_setting2idx(ant_tx)+1, resp_sep);
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg4 ) ;
}
2021-03-03 08:03:18 -06:00
rig_sprintf_ant ( antbuf , sizeof ( antbuf ) , ant_rx ) ;
2020-02-18 23:10:14 -06:00
fprintf ( fout , " %s%c " , antbuf , resp_sep ) ;
//fprintf(fout, "%d%c", rig_setting2idx(ant_rx)+1, resp_sep);
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* '*' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( reset )
{
2017-08-09 13:09:55 -05:00
int reset ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & reset ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_reset ( rig , ( reset_t ) reset ) ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* 'b' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( send_morse )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_send_morse ( rig , vfo , arg1 ) ) ;
2007-11-11 23:03:38 +00:00
}
2020-10-16 08:41:57 -05:00
/* 0xvv */
declare_proto_rig ( stop_morse )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_stop_morse ( rig , vfo ) ) ;
2020-10-16 08:41:57 -05:00
}
2020-10-18 14:22:42 -05:00
declare_proto_rig ( wait_morse )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_wait_morse ( rig , vfo ) ) ;
2020-10-18 14:22:42 -05:00
}
2020-02-06 01:00:34 +01:00
/* '8' */
declare_proto_rig ( send_voice_mem )
{
int ch ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-02-06 01:00:34 +01:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & ch ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_send_voice_mem ( rig , vfo , ch ) ) ;
2020-02-06 01:00:34 +01:00
}
2017-08-09 13:09:55 -05:00
2023-08-18 16:49:35 -05:00
declare_proto_rig ( stop_voice_mem )
{
ENTERFUNC2 ;
RETURNFUNC2 ( rig_stop_voice_mem ( rig , vfo ) ) ;
}
2008-09-21 19:24:47 +00:00
declare_proto_rig ( send_dtmf )
2021-03-15 17:51:22 -05:00
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_send_dtmf ( rig , vfo , arg1 ) ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2008-09-21 19:24:47 +00:00
declare_proto_rig ( recv_dtmf )
{
2017-08-09 13:09:55 -05:00
int status ;
int len ;
char digits [ MAXARGSZ ] ;
2008-09-21 19:24:47 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
len = MAXARGSZ - 1 ;
status = rig_recv_dtmf ( rig , vfo , digits , & len ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2008-09-21 19:24:47 +00:00
2017-10-06 18:58:42 -05:00
if ( interactive & & prompt )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %s \n " , digits ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2008-09-21 19:24:47 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* '0x87' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( set_powerstat )
{
2017-08-09 13:09:55 -05:00
int stat ;
2022-05-09 07:11:01 -05:00
int retval ;
2007-11-11 23:03:38 +00:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & stat ) ) ;
2021-03-08 09:54:24 -06:00
2022-05-09 07:11:01 -05:00
retval = rig_set_powerstat ( rig , ( powerstat_t ) stat ) ;
2023-05-30 16:10:52 -05:00
2023-05-21 23:01:03 +03:00
if ( retval = = RIG_OK )
{
rig_powerstat = stat ; // update our global so others can see powerstat
}
2023-05-30 16:10:52 -05:00
2022-05-09 07:11:01 -05:00
fflush ( fin ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( retval ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2008-01-10 03:42:35 +00:00
/* '0x88' */
2007-11-11 23:03:38 +00:00
declare_proto_rig ( get_powerstat )
{
2017-08-09 13:09:55 -05:00
int status ;
powerstat_t stat ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
status = rig_get_powerstat ( rig , & stat ) ;
2017-10-06 18:58:42 -05:00
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2017-08-09 13:09:55 -05:00
}
2017-10-06 18:58:42 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2017-08-09 13:09:55 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
2007-11-11 23:03:38 +00:00
2023-06-29 16:20:00 +02:00
fprintf ( fout , " %d%c " , stat , resp_sep ) ;
2023-05-21 23:01:03 +03:00
rig_powerstat = stat ; // update our global so others can see powerstat
2008-01-10 03:42:35 +00:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2007-11-11 23:03:38 +00:00
}
2020-10-02 17:23:48 -05:00
static int hasbinary ( char * s , int len )
2019-12-12 22:29:13 -06:00
{
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; i < len ; + + i )
2019-12-12 22:29:13 -06:00
{
2022-02-05 15:27:43 -06:00
if ( ! isascii ( s [ i ] ) ) { return ( 1 ) ; }
2019-12-12 22:29:13 -06:00
}
return 0 ;
}
2017-08-09 13:09:55 -05:00
2026-07-27 17:14:00 -05:00
static int hex_digit_value ( char digit )
{
if ( digit > = ' 0 ' & & digit < = ' 9 ' )
{
return digit - ' 0 ' ;
}
digit = tolower ( ( unsigned char ) digit ) ;
if ( digit > = ' a ' & & digit < = ' f ' )
{
return digit - ' a ' + 10 ;
}
return - 1 ;
}
static int has_binary_command_prefix ( const char * command )
{
while ( isspace ( ( unsigned char ) * command ) )
{
command + + ;
}
if ( ( command [ 0 ] = = ' x ' | | command [ 0 ] = = ' X ' )
& & isxdigit ( ( unsigned char ) command [ 1 ] ) )
{
return 1 ;
}
return command [ 0 ] = = ' \\ ' & & command [ 1 ] = = ' 0 '
& & ( command [ 2 ] = = ' x ' | | command [ 2 ] = = ' X ' ) ;
}
static int decode_binary_command ( const char * command , char * decoded ,
size_t decoded_size , int * decoded_length )
{
const char * p = command ;
size_t length = 0 ;
while ( 1 )
{
int bytes_in_group = 0 ;
while ( isspace ( ( unsigned char ) * p ) )
{
p + + ;
}
if ( * p = = ' \0 ' )
{
break ;
}
if ( * p = = ' \\ ' & & p [ 1 ] = = ' 0 ' & & ( p [ 2 ] = = ' x ' | | p [ 2 ] = = ' X ' ) )
{
p + = 3 ;
}
else if ( * p = = ' x ' | | * p = = ' X ' )
{
p + + ;
}
else
{
return - RIG_EINVAL ;
}
while ( isxdigit ( ( unsigned char ) * p ) )
{
int high = hex_digit_value ( p [ 0 ] ) ;
int low = hex_digit_value ( p [ 1 ] ) ;
if ( low < 0 | | length + 1 > = decoded_size )
{
return - RIG_EINVAL ;
}
decoded [ length + + ] = ( char ) ( ( high < < 4 ) | low ) ;
bytes_in_group + + ;
p + = 2 ;
}
if ( bytes_in_group = = 0 )
{
return - RIG_EINVAL ;
}
if ( * p ! = ' \0 ' & & ! isspace ( ( unsigned char ) * p ) & & * p ! = ' \\ '
& & * p ! = ' x ' & & * p ! = ' X ' )
{
return - RIG_EINVAL ;
}
}
if ( length = = 0 )
{
return - RIG_EINVAL ;
}
decoded [ length ] = ' \0 ' ;
* decoded_length = ( int ) length ;
return RIG_OK ;
}
2007-11-11 23:03:38 +00:00
/*
2017-08-09 13:09:55 -05:00
* Special debugging purpose send command display reply until there ' s a
* timeout .
2008-01-10 03:42:35 +00:00
*
2019-12-09 23:37:14 -06:00
* ' w ' and ' W '
2007-11-11 23:03:38 +00:00
*/
2024-04-02 16:26:27 -05:00
extern int flrig_cat_string2 ( RIG * rig , const char * arg , char * value ,
int value_size ) ;
2022-04-25 12:42:27 -05:00
extern int flrig_cat_string ( RIG * rig , const char * arg ) ;
2024-04-02 16:26:27 -05:00
static void toLowerCase ( char * s )
{
if ( s = = NULL ) { return ; } // Check if the pointer is NULL
while ( * s ) // Iterate until we hit the null terminator of the string
{
* s = tolower ( ( unsigned char ) * s ) ; // Convert each character to lowercase
s + + ; // Move to the next character
}
}
2007-11-11 23:03:38 +00:00
declare_proto_rig ( send_cmd )
{
2017-08-09 13:09:55 -05:00
int retval ;
2024-03-01 05:32:08 -05:00
hamlib_port_t * rp = RIGPORT ( rig ) ;
2017-08-09 13:09:55 -05:00
int backend_num , cmd_len ;
2020-10-25 06:43:48 -05:00
# define BUFSZ 512
2024-04-02 16:26:27 -05:00
char bufcmd [ BUFSZ * 5 ] ; // allow for 5 chars for each binary
2019-12-12 22:29:13 -06:00
unsigned char buf [ BUFSZ ] ;
2017-08-09 13:09:55 -05:00
char eom_buf [ 4 ] = { 0xa , 0xd , 0 , 0 } ;
2019-12-06 07:58:19 -06:00
int binary = 0 ;
2019-12-09 23:37:14 -06:00
int rxbytes = BUFSZ ;
2024-04-02 16:26:27 -05:00
int cmdcount = 1 ;
2023-05-10 20:53:18 +03:00
int simulate = rig - > caps - > rig_model = = RIG_MODEL_DUMMY | |
rig - > caps - > rig_model = = RIG_MODEL_NONE | |
2024-03-01 05:32:08 -05:00
rp - > rig = = RIG_PORT_NONE ;
2019-12-06 07:58:19 -06:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2017-08-09 13:09:55 -05:00
2026-07-27 17:14:00 -05:00
if ( arg1 = = NULL | | arg1 [ 0 ] = = ' \0 ' )
{
RETURNFUNC2 ( - RIG_EINVAL ) ;
}
2017-08-09 13:09:55 -05:00
/*
* binary protocols enter values as \ 0 xZZ \ 0 xYY . .
*/
backend_num = RIG_BACKEND_NUM ( rig - > caps - > rig_model ) ;
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: backend_num=%d \n " , __func__ , backend_num ) ;
2022-04-25 12:54:06 -05:00
if ( rig - > caps - > rig_model = = RIG_MODEL_FLRIG )
2022-04-25 12:42:27 -05:00
{
// call flrig raw send function cat_string or cat_priority_string
2024-11-06 08:07:34 -06:00
flrig_cat_string2 ( rig , arg1 , ( char * ) buf , sizeof ( buf ) ) ;
2024-04-04 07:53:06 -05:00
fwrite ( cmd - > arg2 , 1 , strlen ( cmd - > arg2 ) , fout ) ; /* i.e. "Frequency" */
fprintf ( fout , " : %s \n " , buf ) ;
2024-06-21 10:09:15 -04:00
RETURNFUNC2 ( RIG_OK ) ;
2022-04-25 12:42:27 -05:00
}
2025-05-19 23:01:26 +02:00
// need to move the eom_buf to rig-specific backends
2019-12-12 22:29:13 -06:00
// we'll let KENWOOD backends use the ; char in the rigctl commands
2020-05-12 08:33:36 -05:00
if ( backend_num = = RIG_KENWOOD | | backend_num = = RIG_YAESU )
2019-12-12 22:29:13 -06:00
{
rig_debug ( RIG_DEBUG_TRACE , " %s: KENWOOD \n " , __func__ ) ;
2022-02-24 17:13:18 -06:00
// eom_buf[0] = 0;
2019-12-12 22:29:13 -06:00
send_cmd_term = 0 ;
}
rig_debug ( RIG_DEBUG_TRACE , " %s: arg1=%s \n " , __func__ , arg1 ) ;
2017-08-09 13:09:55 -05:00
if ( send_cmd_term = = - 1
2019-11-30 10:19:08 -06:00
| | backend_num = = RIG_ICOM
| | backend_num = = RIG_KACHINA
2019-12-12 22:29:13 -06:00
| | backend_num = = RIG_MICROTUNE
2026-07-27 17:14:00 -05:00
| | ( has_binary_command_prefix ( arg1 )
2024-04-02 16:26:27 -05:00
& & ( rig - > caps - > rig_model ! = RIG_MODEL_NETRIGCTL ) )
2019-12-12 22:29:13 -06:00
)
2017-10-06 18:58:42 -05:00
{
2026-07-27 17:14:00 -05:00
int decode_status ;
2017-08-09 13:09:55 -05:00
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: send_cmd_term==-1, arg1=%s \n " , __func__ , arg1 ) ;
2026-07-27 17:14:00 -05:00
decode_status = decode_binary_command ( arg1 , bufcmd , BUFSZ , & cmd_len ) ;
if ( decode_status ! = RIG_OK )
2019-12-12 22:29:13 -06:00
{
2024-04-02 16:26:27 -05:00
rig_debug ( RIG_DEBUG_ERR ,
2026-07-27 17:14:00 -05:00
" %s: expecting binary hex bytes such as x00 xff, \\ 0x00 \\ 0xff, x00ff, or x00xff \n " ,
2024-04-02 16:26:27 -05:00
__func__ ) ;
2026-07-27 17:14:00 -05:00
RETURNFUNC2 ( decode_status ) ;
2017-08-09 13:09:55 -05:00
}
/* must save length to allow 0x00 to be sent as part of a command */
/* no End Of Message chars */
eom_buf [ 0 ] = ' \0 ' ;
2017-10-06 18:58:42 -05:00
}
2019-12-06 07:58:19 -06:00
else if ( rig - > caps - > rig_model = = RIG_MODEL_NETRIGCTL )
{
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: we're netrigctl#2 \n " , __func__ ) ;
2022-01-11 00:00:44 -06:00
//SNPRINTF(bufcmd, sizeof(bufcmd), "%s %s\n", cmd->cmd, arg1);
2019-12-12 22:29:13 -06:00
if ( cmd - > cmd = = ' w ' )
{
2022-01-11 00:00:44 -06:00
SNPRINTF ( bufcmd , sizeof ( bufcmd ) , " %c %s \n " , cmd - > cmd , arg1 ) ;
2019-12-12 22:29:13 -06:00
}
else
{
int nbytes = 0 ;
2023-05-30 15:57:33 -05:00
int n = sscanf ( arg2 , " %d " , & nbytes ) ;
2023-05-30 16:10:52 -05:00
2023-05-30 15:57:33 -05:00
if ( n = = 1 ) { SNPRINTF ( bufcmd , sizeof ( bufcmd ) , " %c %s %d \n " , cmd - > cmd , arg1 , nbytes ) ; }
else { SNPRINTF ( bufcmd , sizeof ( bufcmd ) , " %c %s %s \n " , cmd - > cmd , arg1 , arg2 ) ; }
2019-12-12 22:29:13 -06:00
}
2019-12-06 07:58:19 -06:00
cmd_len = strlen ( bufcmd ) ;
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s: cmd=%s, len=%d \n " , __func__ , bufcmd , cmd_len ) ;
2019-12-06 07:58:19 -06:00
}
2017-10-06 18:58:42 -05:00
else
{
2019-12-12 22:29:13 -06:00
char tmpbuf [ 64 ] ;
2017-08-09 13:09:55 -05:00
/* text protocol */
2019-12-20 11:22:09 -06:00
strncpy ( bufcmd , arg1 , BUFSZ - 1 ) ;
2019-12-12 22:29:13 -06:00
strtok ( bufcmd , " \0 xa \0 xd " ) ;
2017-08-09 13:09:55 -05:00
bufcmd [ BUFSZ - 2 ] = ' \0 ' ;
cmd_len = strlen ( bufcmd ) ;
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: bufcmd=%s \n " , __func__ , bufcmd ) ;
2017-08-09 13:09:55 -05:00
/* Automatic termination char */
2017-10-06 18:58:42 -05:00
if ( send_cmd_term ! = 0 )
{
2017-08-09 13:09:55 -05:00
bufcmd [ cmd_len + + ] = send_cmd_term ;
}
eom_buf [ 2 ] = send_cmd_term ;
2019-12-12 22:29:13 -06:00
2022-01-11 00:00:44 -06:00
SNPRINTF ( tmpbuf , sizeof ( tmpbuf ) , " 0x%02x 0x%02x 0x%02x " , eom_buf [ 0 ] , eom_buf [ 1 ] ,
2019-12-12 22:29:13 -06:00
eom_buf [ 2 ] ) ;
rig_debug ( RIG_DEBUG_TRACE , " %s: text protocol, send_cmd_term=%s \n " , __func__ ,
tmpbuf ) ;
2017-08-09 13:09:55 -05:00
}
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: rigport=%d, bufcmd=%s, cmd_len=%d \n " , __func__ ,
2024-03-01 05:32:08 -05:00
rp - > fd , hasbinary ( bufcmd , cmd_len ) ? " BINARY " : bufcmd , cmd_len ) ;
2017-08-09 13:09:55 -05:00
2023-05-13 00:04:37 +03:00
set_transaction_active ( rig ) ;
2023-05-10 20:53:18 +03:00
if ( simulate )
2017-10-06 18:58:42 -05:00
{
2023-05-10 20:53:18 +03:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s: simulating response for model %s \n " ,
2023-05-30 16:10:52 -05:00
__func__ , rig - > caps - > model_name ) ;
2023-05-10 20:53:18 +03:00
}
else
{
2024-03-01 05:32:08 -05:00
rig_flush ( rp ) ;
2023-05-10 20:53:18 +03:00
// we don't want the 'w' command to wait too long
2024-03-01 05:32:08 -05:00
int save_retry = rp - > retry ;
rp - > retry = 0 ;
retval = write_block ( rp , ( unsigned char * ) bufcmd , cmd_len ) ;
rp - > retry = save_retry ;
2023-05-10 20:53:18 +03:00
if ( retval ! = RIG_OK )
{
2024-03-01 05:32:08 -05:00
rig_flush_force ( rp , 1 ) ;
2023-05-13 00:04:37 +03:00
set_transaction_inactive ( rig ) ;
2023-05-14 12:08:15 +03:00
RETURNFUNC2 ( retval ) ;
2023-05-10 20:53:18 +03:00
}
2017-08-09 13:09:55 -05:00
}
2019-12-06 07:58:19 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
2017-10-06 18:58:42 -05:00
{
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: debug Cmd \n " , __func__ ) ;
fwrite ( cmd - > arg2 , 1 , strlen ( cmd - > arg2 ) , fout ) ; /* i.e. "Frequency" */
2020-10-02 17:23:48 -05:00
fwrite ( " : " , 1 , 2 , fout ) ; /* i.e. "Frequency" */
2017-08-09 13:09:55 -05:00
}
2023-05-10 20:53:18 +03:00
retval = 0 ;
2023-05-30 16:10:52 -05:00
2024-04-02 16:26:27 -05:00
if ( strstr ( arg1 , " ; " ) | | arg2 [ 0 ] = = ' ; ' )
2017-10-06 18:58:42 -05:00
{
Fix errors found by glibc 2.43
glibc implements some new parts of the C23 standard:
(Taken from https://download.opensuse.org/tumbleweed/iso/Changes.20260430.txt)
* For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type
and
* The aforementioned change in ISO C23 of the declaration of bsearch,
memchr, strchr, strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr,
wcsstr, and wmemchr as const-preserving macros can lead to compilation
issues in code not set up for it
This lead to some warnings about assigning returns from strchr(const, target)
to non-const pointers, and then discovering that Hamlib was modifying
those const parameters.
This commit aligns the const-ness of the offending parameters. Only affects
internal functions in ampctl_parse.c, rigctl_parse.c and rotctl_parse.c,
so API/ABI should not change.
2026-05-03 14:55:05 -04:00
const char * p = strchr ( arg1 , ' ; ' ) ;
2019-12-12 22:29:13 -06:00
2024-04-02 16:26:27 -05:00
while ( p )
2019-12-12 22:29:13 -06:00
{
2024-04-02 16:26:27 -05:00
cmdcount + + ;
p = strchr ( p + 1 , ' ; ' ) ;
}
// Kenwood, Yaeus, and similar
eom_buf [ 0 ] = ' ; ' ;
eom_buf [ 1 ] = 0 ;
}
else if ( strstr ( arg1 , " xfd " ) | | strstr ( arg2 , " xfd " ) )
{
char * s = strdup ( arg1 ) ;
toLowerCase ( s ) ;
// ICOM answer terminator
eom_buf [ 0 ] = 0xfd ;
eom_buf [ 1 ] = 0 ;
char * p = strstr ( s , " xfd " ) ;
while ( p )
{
cmdcount + + ;
p = strstr ( p + 1 , " xfd " ) ;
2019-12-12 22:29:13 -06:00
}
2022-11-16 15:30:36 -06:00
2024-04-02 16:26:27 -05:00
free ( s ) ;
}
do
{
2023-07-17 09:33:18 -05:00
int hexval ;
2024-04-02 16:26:27 -05:00
rxbytes = BUFSZ ; // leave room for CR
2023-12-16 11:37:58 -06:00
2024-04-02 16:26:27 -05:00
if ( arg2 ) // see if we have bytes or a hexval for terminating the 'W' command
2023-12-16 11:37:58 -06:00
{
2024-04-02 16:26:27 -05:00
sscanf ( arg2 , " %d " , & rxbytes ) ;
if ( sscanf ( arg2 , " \\ 0x%2x " , & hexval ) = = 1 )
{
eom_buf [ 0 ] = hexval ;
}
2023-07-17 09:33:18 -05:00
}
2023-12-16 11:37:58 -06:00
2024-04-02 16:26:27 -05:00
if ( rxbytes > 0 & & rxbytes ! = BUFSZ )
{
+ + rxbytes ; // need length + 1 for end of string
eom_buf [ 0 ] = 0 ;
}
2019-12-12 22:29:13 -06:00
2023-05-10 20:53:18 +03:00
if ( simulate )
{
if ( retval = = 0 )
{
// Simulate a response by copying the command
memcpy ( buf , bufcmd , cmd_len ) ;
retval = cmd_len ;
}
else
{
retval = 0 ;
}
}
else
2017-10-06 18:58:42 -05:00
{
2023-05-10 20:53:18 +03:00
/* Assumes CR or LF is end of line char for all ASCII protocols. */
2024-03-01 05:32:08 -05:00
retval = read_string ( rp , buf , rxbytes , eom_buf ,
2023-05-10 20:53:18 +03:00
strlen ( eom_buf ) , 0 , 1 ) ;
2019-12-12 22:29:13 -06:00
2023-05-10 20:53:18 +03:00
if ( retval < 0 )
{
rig_debug ( RIG_DEBUG_ERR , " %s: read_string error %s \n " , __func__ ,
rigerror ( retval ) ) ;
break ;
}
2017-08-09 13:09:55 -05:00
}
2023-05-10 20:53:18 +03:00
2017-10-06 18:58:42 -05:00
if ( retval < BUFSZ )
{
2017-08-09 13:09:55 -05:00
buf [ retval ] = ' \0 ' ;
2017-10-06 18:58:42 -05:00
}
else
{
2017-08-09 13:09:55 -05:00
buf [ BUFSZ - 1 ] = ' \0 ' ;
}
2020-10-02 17:23:48 -05:00
//if (rig->caps->rig_model != RIG_MODEL_NETRIGCTL)
2019-12-06 07:58:19 -06:00
{
// see if we have binary being returned
2020-10-02 17:23:48 -05:00
binary = hasbinary ( ( char * ) buf , retval ) ;
2019-12-06 07:58:19 -06:00
}
2017-08-09 13:09:55 -05:00
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 09:02:12 +02:00
if ( binary ) // convert our buf to a hex representation
2019-12-06 07:58:19 -06:00
{
2019-12-12 22:29:13 -06:00
char hex [ 8 ] ;
2019-12-17 08:08:39 -06:00
int hexbufbytes = retval * 6 ;
char * hexbuf = calloc ( hexbufbytes , 1 ) ;
rig_debug ( RIG_DEBUG_VERBOSE , " %s: sending binary, hexbuf size=%d \n " , __func__ ,
hexbufbytes ) ;
2019-12-12 22:29:13 -06:00
hexbuf [ 0 ] = 0 ;
2019-12-06 07:58:19 -06:00
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; i < retval ; + + i )
2019-12-06 07:58:19 -06:00
{
2022-01-11 00:00:44 -06:00
SNPRINTF ( hex , sizeof ( hex ) , " \\ 0x%02X " , ( unsigned char ) buf [ i ] ) ;
2019-12-17 08:08:39 -06:00
if ( ( strlen ( hexbuf ) + strlen ( hex ) + 1 ) > = hexbufbytes )
{
hexbufbytes * = 2 ;
rig_debug ( RIG_DEBUG_TRACE , " %s: doubling hexbuf size to %d \n " , __func__ ,
hexbufbytes ) ;
hexbuf = realloc ( hexbuf , hexbufbytes ) ;
}
2019-12-20 11:22:09 -06:00
strncat ( hexbuf , hex , hexbufbytes - 1 ) ;
2019-12-06 07:58:19 -06:00
}
2024-03-01 05:32:08 -05:00
rig_flush_force ( rp , 1 ) ;
2023-05-13 00:04:37 +03:00
set_transaction_inactive ( rig ) ;
2019-12-12 22:29:13 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: binary=%s, retval=%d \n " , __func__ , hexbuf ,
retval ) ;
fprintf ( fout , " %s %d \n " , hexbuf , retval ) ;
free ( hexbuf ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2019-12-06 07:58:19 -06:00
}
else
{
2019-12-06 08:34:31 -06:00
// we should be in printable ASCII here
2024-04-02 16:26:27 -05:00
fprintf ( fout , " %s%c " , buf , cmdcount = = 1 ? ' \n ' : ' \0 ' ) ;
2019-12-06 07:58:19 -06:00
}
2017-10-06 18:58:42 -05:00
}
2024-04-02 16:26:27 -05:00
while ( ( retval > 0 & & rxbytes = = BUFSZ & & eom_buf [ 0 ] ! = ' ; '
2024-09-08 11:52:06 -05:00
& & ( unsigned char ) eom_buf [ 0 ] ! = 0xfd ) | | - - cmdcount > 1 ) ;
2017-08-09 13:09:55 -05:00
2024-03-01 05:32:08 -05:00
rig_flush_force ( rp , 1 ) ;
2023-05-13 00:04:37 +03:00
set_transaction_inactive ( rig ) ;
2023-05-10 20:53:18 +03:00
// we use fwrite in case of any nulls in binary return
2019-12-06 07:58:19 -06:00
if ( binary ) { fwrite ( buf , 1 , retval , fout ) ; }
if ( binary )
{
fwrite ( " \n " , 1 , 1 , fout ) ;
}
2017-10-06 18:58:42 -05:00
if ( retval > 0 | | retval = = - RIG_ETIMEOUT )
{
2017-08-09 13:09:55 -05:00
retval = RIG_OK ;
}
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( retval ) ;
2007-11-11 23:03:38 +00:00
}
2017-08-09 13:09:55 -05:00
2011-06-14 23:09:33 +02:00
/* '0xf0'--test if rigctld called with -o|--vfo option */
2010-02-04 00:53:56 +00:00
declare_proto_rig ( chk_vfo )
{
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: ********************************** \n " , __func__ ) ;
2019-08-23 22:53:25 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg1 ) ; /* i.e. "Frequency" */
}
2024-05-31 09:48:30 -04:00
fprintf ( fout , " %d \n " , STATE ( rig ) - > vfo_opt ) ;
2010-02-04 00:53:56 +00:00
2020-06-23 11:12:15 -05:00
chk_vfo_executed = 1 ; // this allows us to control dump_state version
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2010-02-04 00:53:56 +00:00
}
2020-05-27 12:21:41 -05:00
/* '(' -- turn vfo option on */
declare_proto_rig ( set_vfo_opt )
{
int opt = 0 ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-05-27 12:21:41 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & opt ) ) ;
2024-05-31 09:48:30 -04:00
* vfo_opt = STATE ( rig ) - > vfo_opt = opt ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_vfo_opt ( rig , opt ) ) ;
2020-05-27 12:21:41 -05:00
}
2017-08-09 13:09:55 -05:00
2011-06-14 23:09:33 +02:00
/* '0xf1'--halt rigctld daemon */
declare_proto_rig ( halt )
{
/* a bit rough, TODO: clean daemon shutdown */
exit ( 0 ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2011-06-14 23:09:33 +02:00
}
2014-05-02 18:41:50 +01:00
2017-08-09 13:09:55 -05:00
2014-05-02 18:41:50 +01:00
/* '0x8c'--pause processing */
declare_proto_rig ( pause )
{
2017-08-09 13:09:55 -05:00
unsigned seconds ;
2021-03-08 09:54:24 -06:00
2017-08-09 13:09:55 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %u " , & seconds ) ) ;
sleep ( seconds ) ;
2021-03-08 09:54:24 -06:00
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2014-05-02 18:41:50 +01:00
}
2020-02-24 09:34:02 -06:00
2026-06-03 13:07:07 -04:00
# if RIGCTLD_PASSWORDS
2026-06-03 16:52:49 -04:00
// Compare our known secret with remote submission
// Returns 1 if match, 0 if not
2026-06-03 13:07:07 -04:00
static int rigctld_password_check ( RIG * rig , const char * md5 )
2022-02-24 17:13:18 -06:00
{
2026-06-03 16:52:49 -04:00
int retval ;
2026-06-13 11:33:26 -04:00
int len , hits = 0 ;
2026-06-04 11:33:09 -04:00
char padded [ HAMLIB_SECRET_LENGTH + 1 ] ;
2022-02-24 17:13:18 -06:00
//fprintf(fout, "password %s\n", password);
2024-12-21 15:19:06 -06:00
//rig_debug(RIG_DEBUG_TRACE, "%s: %s == %s\n", __func__, md5, rigctld_password);
2022-03-01 11:40:14 -06:00
2022-04-15 22:44:53 -05:00
char * mymd5 = rig_make_md5 ( rigctld_password ) ;
2022-04-15 13:21:35 -05:00
2026-06-03 16:52:49 -04:00
len = strlen ( mymd5 ) ;
2026-06-04 11:33:09 -04:00
strncpy ( padded , md5 , HAMLIB_SECRET_LENGTH ) ;
padded [ HAMLIB_SECRET_LENGTH ] = ' \0 ' ; // Make sure it's a terminated string
/* Brute force, constant time comparison */
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; i < = len ; i + + )
2022-03-01 11:40:14 -06:00
{
2026-06-04 11:33:09 -04:00
hits + = ( int ) ( padded [ i ] = = mymd5 [ i ] ) ;
2022-02-24 17:13:18 -06:00
}
2026-06-03 16:52:49 -04:00
retval = ( hits = = len + 1 ) ; // Entire string + terminator
free ( mymd5 ) ;
2022-03-01 11:40:14 -06:00
return ( retval ) ;
2022-02-24 17:13:18 -06:00
}
2021-10-16 09:20:24 -05:00
/* 0x98 */
declare_proto_rig ( password )
{
2022-02-24 17:50:57 -06:00
int retval = - RIG_EPROTO ;
2022-04-15 13:21:35 -05:00
const char * key = arg1 ;
2026-06-03 16:52:49 -04:00
struct handle_data * connection ;
2021-11-28 12:41:10 -06:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2022-03-01 11:40:14 -06:00
2022-02-24 17:13:18 -06:00
if ( is_rigctld )
{
2022-04-15 13:21:35 -05:00
retval = rigctld_password_check ( rig , key ) ;
2026-06-04 11:33:09 -04:00
connection = pthread_getspecific ( thread_data_key ) ;
2026-06-03 16:52:49 -04:00
if ( connection )
{
connection - > is_passwordOK = retval ;
retval = retval = = 1 ? RIG_OK : - RIG_EPROTO ;
}
else
{
retval = - RIG_EPROTO ;
}
2022-03-01 11:39:11 -06:00
}
else
{
2022-04-15 13:21:35 -05:00
retval = rig_password ( rig , key ) ;
2022-03-01 11:40:14 -06:00
//retval = RIG_OK;
2022-03-01 11:39:11 -06:00
}
2022-02-24 17:13:18 -06:00
if ( retval = = RIG_OK )
2021-11-28 12:41:10 -06:00
{
rig_debug ( RIG_DEBUG_ERR , " %s: #1 password OK \n " , __func__ ) ;
2022-04-15 13:21:35 -05:00
//fprintf(fout, "Logged in\n");
2022-02-24 17:13:18 -06:00
}
else
{
2024-12-22 11:30:04 -06:00
//rig_debug(RIG_DEBUG_ERR, "%s: password error, '%s'!='%s'\n", __func__,
// key, rigctld_password);
rig_debug ( RIG_DEBUG_ERR , " %s: password error \n " , __func__ ) ;
2022-02-24 17:13:18 -06:00
}
2021-11-28 12:41:10 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( retval ) ;
2021-10-16 09:20:24 -05:00
}
2026-06-03 13:07:07 -04:00
# endif
2021-10-16 09:20:24 -05:00
2022-04-15 13:21:35 -05:00
#if 0 // don't think we need this yet
2021-10-16 09:20:24 -05:00
/* 0x99 */
declare_proto_rig ( set_password )
{
const char * passwd = arg1 ;
2022-02-24 17:13:18 -06:00
strncpy ( rigctld_password , passwd , sizeof ( passwd ) - 1 ) ;
rig_debug ( RIG_DEBUG_ERR , " %s: set_password %s \n " , __func__ , rigctld_password ) ;
2022-02-05 15:27:43 -06:00
return ( RIG_OK ) ;
2021-10-16 09:20:24 -05:00
}
2022-04-15 13:21:35 -05:00
# endif
2021-10-16 09:20:24 -05:00
2020-02-24 09:34:02 -06:00
/* '0x8d' */
declare_proto_rig ( set_twiddle )
{
int seconds ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-02-24 09:34:02 -06:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & seconds ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_twiddle ( rig , seconds ) ) ;
2020-02-24 09:34:02 -06:00
}
2020-10-23 11:34:42 -05:00
/* '0x97' */
declare_proto_rig ( set_uplink )
{
int val ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-10-23 11:34:42 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & val ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_uplink ( rig , val ) ) ;
2020-10-23 11:34:42 -05:00
}
2020-02-24 09:34:02 -06:00
/* '0x8e' */
declare_proto_rig ( get_twiddle )
{
int status ;
int seconds ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-02-24 09:34:02 -06:00
status = rig_get_twiddle ( rig , & seconds ) ;
if ( status ! = RIG_OK )
{
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2020-02-24 09:34:02 -06:00
}
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %d \n " , seconds ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( status ) ;
2020-02-24 09:34:02 -06:00
}
2020-04-30 16:52:11 -05:00
/* '0x95' */
declare_proto_rig ( set_cache )
{
int ms ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-04-30 16:52:11 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & ms ) ) ;
2021-03-08 09:54:24 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_cache_timeout_ms ( rig , HAMLIB_CACHE_ALL , ms ) ) ;
2020-04-30 16:52:11 -05:00
}
/* '0x96' */
declare_proto_rig ( get_cache )
{
int ms ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-03-08 09:54:24 -06:00
2020-07-02 10:23:41 -05:00
ms = rig_get_cache_timeout_ms ( rig , HAMLIB_CACHE_ALL ) ;
2020-04-30 16:52:11 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
}
fprintf ( fout , " %d \n " , ms ) ;
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( RIG_OK ) ;
2020-04-30 16:52:11 -05:00
}
2021-12-01 11:50:33 -06:00
/* '0xf8' */
declare_proto_rig ( set_clock )
{
2022-10-25 23:26:16 -05:00
int year , mon , day , hour = - 1 , min = - 1 , sec = 0 ;
2022-11-16 15:30:36 -06:00
double msec = - 1 ;
int utc_offset = 0 ;
2021-12-01 11:50:33 -06:00
int n ;
2021-12-06 10:23:18 -06:00
char timebuf [ 64 ] ;
2021-12-01 11:50:33 -06:00
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-12-01 11:50:33 -06:00
2021-12-06 10:23:18 -06:00
if ( arg1 & & strcasecmp ( arg1 , " local " ) = = 0 )
{
date_strget ( timebuf , sizeof ( timebuf ) , 1 ) ;
rig_debug ( RIG_DEBUG_VERBOSE , " %s: local time set = %s \n " , __func__ , timebuf ) ;
n = sscanf ( timebuf , " %04d-%02d-%02dT%02d:%02d:%02d%lf%d " , & year , & mon , & day ,
& hour ,
& min , & sec , & msec , & utc_offset ) ;
}
else if ( arg1 & & strcasecmp ( arg1 , " utc " ) = = 0 )
{
date_strget ( timebuf , sizeof ( timebuf ) , 0 ) ;
rig_debug ( RIG_DEBUG_VERBOSE , " %s: utc time set = %s \n " , __func__ , timebuf ) ;
n = sscanf ( timebuf , " %04d-%02d-%02dT%02d:%02d:%02d%lf%d " , & year , & mon , & day ,
& hour ,
& min , & sec , & msec , & utc_offset ) ;
}
2024-07-19 22:39:12 -05:00
else if ( arg1 & & ( arg1 [ 16 ] = = ' + ' | | arg1 [ 16 ] = = ' - ' ) )
2022-11-16 15:30:36 -06:00
{
// YYYY-MM-DDTHH:MM+ZZ
2022-10-25 23:26:16 -05:00
n = sscanf ( arg1 , " %04d-%02d-%02dT%02d:%02d%d " , & year , & mon , & day , & hour ,
& min , & utc_offset ) ;
}
2024-07-19 22:39:12 -05:00
else if ( arg1 & & ( arg1 [ 19 ] = = ' + ' | | arg1 [ 19 ] = = ' - ' ) )
2022-11-16 15:30:36 -06:00
{
// YYYY-MM-DDTHH:MM:SS+ZZ
2022-10-25 23:26:16 -05:00
n = sscanf ( arg1 , " %04d-%02d-%02dT%02d:%02d:%02d%d " , & year , & mon , & day , & hour ,
& min , & sec , & utc_offset ) ;
}
2024-07-19 22:39:12 -05:00
else if ( arg1 & & ( arg1 [ 23 ] = = ' + ' | | arg1 [ 23 ] = = ' - ' ) )
2022-11-16 15:30:36 -06:00
{
// YYYY-MM-DDTHH:MM:SS.SSS+ZZ
2021-12-06 10:23:18 -06:00
n = sscanf ( arg1 , " %04d-%02d-%02dT%02d:%02d:%02d%lf%d " , & year , & mon , & day , & hour ,
& min , & sec , & msec , & utc_offset ) ;
}
2022-10-25 23:26:16 -05:00
else
{
rig_debug ( RIG_DEBUG_ERR , " %s: '%s' not valid time format \n " , __func__ , arg1 ) ;
RETURNFUNC2 ( - RIG_EINVAL ) ;
}
2021-12-06 10:23:18 -06:00
2021-12-01 11:50:33 -06:00
rig_debug ( RIG_DEBUG_VERBOSE ,
" %s: n=%d, %04d-%02d-%02dT%02d:%02d:%02d.%0.3f%s%02d \n " ,
__func__ , n , year , mon , day , hour , min , sec , msec , utc_offset > = 0 ? " + " : " - " ,
( unsigned ) abs ( utc_offset ) ) ;
2024-09-10 03:33:43 -04:00
if ( abs ( utc_offset ) < 24 ) { utc_offset * = 100 ; } // allow for minutes offset too
2021-12-05 09:46:00 -06:00
2022-10-25 23:26:16 -05:00
rig_debug ( RIG_DEBUG_VERBOSE , " %s: utc_offset=%d \n " , __func__ , utc_offset ) ;
2021-12-05 09:46:00 -06:00
2023-05-13 16:11:46 -05:00
RETURNFUNC2 ( rig_set_clock ( rig , year , mon , day , hour , min , sec , msec ,
2023-05-30 16:10:52 -05:00
utc_offset ) ) ;
2021-12-01 11:50:33 -06:00
}
/* '0xf9' */
declare_proto_rig ( get_clock )
{
2021-12-01 22:52:55 -06:00
//char option[64];
int year , month , day , hour , min , sec , utc_offset , aoffset ;
2021-12-01 11:50:33 -06:00
int retval ;
double msec ;
2023-05-13 16:11:46 -05:00
ENTERFUNC2 ;
2021-12-01 11:50:33 -06:00
2021-12-01 22:52:55 -06:00
//CHKSCN1ARG(sscanf(arg1, "%63s", option));
2021-12-01 11:50:33 -06:00
retval = rig_get_clock ( rig , & year , & month , & day , & hour , & min , & sec , & msec ,
& utc_offset ) ;
2021-12-01 22:52:55 -06:00
aoffset = abs ( utc_offset ) ;
fprintf ( fout , " %04d-%02d-%02dT%02d:%02d:%06.3f%s%02d:%02d \n " , year , month , day ,
hour , min , sec + msec / 1000 , utc_offset > = 0 ? " + " : " - " ,
2021-12-05 09:46:00 -06:00
aoffset / 100 , aoffset % 100 ) ;
2021-12-01 11:50:33 -06:00
return retval ;
}
2022-05-21 12:33:00 -05:00
char rig_resp_sep = ' \n ' ;
/* '0xa0' */
declare_proto_rig ( set_separator )
{
CHKSCN1ARG ( sscanf ( arg1 , " %c " , & rig_resp_sep ) ) ;
2022-05-21 13:23:51 -05:00
rig_debug ( RIG_DEBUG_ERR , " %s: arg1=%s, resp_sep=0x%x, %p \n " , __func__ , arg1 ,
( unsigned int ) rig_resp_sep , & rig_resp_sep ) ;
2022-05-21 12:33:00 -05:00
return RIG_OK ;
}
/* '0xa1' */
declare_proto_rig ( get_separator )
{
char buf [ 32 ] ;
2022-05-21 13:23:51 -05:00
2022-05-29 12:06:03 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
2022-05-21 13:23:51 -05:00
{
2022-05-29 12:06:44 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
2022-05-21 13:23:51 -05:00
}
2022-05-29 12:06:44 -05:00
2022-05-29 12:06:03 -05:00
sprintf ( buf , " 0x%x " , rig_resp_sep ) ;
2022-05-21 13:23:51 -05:00
fprintf ( fout , " %s \n " , buf ) ;
2022-05-21 12:33:00 -05:00
return RIG_OK ;
}
2022-05-29 12:00:03 -05:00
/* '0xa2' */
declare_proto_rig ( set_lock_mode )
{
int lock ;
2022-06-06 22:54:10 -05:00
int retval ;
rig_debug ( RIG_DEBUG_TRACE , " %s: \n " , __func__ ) ;
2022-05-29 12:00:03 -05:00
CHKSCN1ARG ( sscanf ( arg1 , " %d " , & lock ) ) ;
2022-06-06 22:54:10 -05:00
if ( is_rigctld )
{
rig_debug ( RIG_DEBUG_ERR , " %s: rigctld lock \n " , __func__ ) ;
lock_mode = lock ;
retval = RIG_OK ;
}
else
{
rig_debug ( RIG_DEBUG_ERR , " %s: rig lock \n " , __func__ ) ;
retval = rig_set_lock_mode ( rig , lock ) ;
}
return retval ;
2022-05-29 12:00:03 -05:00
}
2022-06-02 15:55:56 -05:00
2022-05-29 12:00:03 -05:00
/* '0xa3' */
declare_proto_rig ( get_lock_mode )
{
2022-06-02 15:55:56 -05:00
int retval ;
int lock ;
2022-06-06 22:54:10 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: \n " , __func__ ) ;
2022-05-29 12:00:03 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2022-05-29 12:06:44 -05:00
fprintf ( fout , " %s: " , cmd - > arg1 ) ;
2022-05-29 12:00:03 -05:00
}
2022-06-06 22:54:10 -05:00
if ( is_rigctld )
{
rig_debug ( RIG_DEBUG_ERR , " %s: rigctld lock \n " , __func__ ) ;
lock = lock_mode ;
retval = RIG_OK ;
}
else
{
rig_debug ( RIG_DEBUG_ERR , " %s: rig lock \n " , __func__ ) ;
retval = rig_get_lock_mode ( rig , & lock ) ;
}
2022-06-02 15:55:56 -05:00
if ( retval ! = RIG_OK )
{
return retval ;
}
fprintf ( fout , " %d \n " , lock ) ;
2022-05-29 12:00:03 -05:00
return RIG_OK ;
}
2022-11-24 23:27:07 -06:00
static int parse_hex ( const char * s , unsigned char * buf , int len )
{
2022-11-28 09:01:28 -06:00
int i = 0 ;
2022-11-24 23:27:07 -06:00
buf [ 0 ] = 0 ;
char * s2 = strdup ( s ) ;
2024-12-01 11:23:13 -06:00
char * p = strtok ( s2 , " ;: " ) ;
2022-11-25 17:39:35 -06:00
while ( p )
2022-11-24 23:27:07 -06:00
{
unsigned int val ;
2024-12-01 11:23:13 -06:00
int n ;
if ( ( n = sscanf ( p , " 0x%2x " , & val ) ) ! = 1 )
{
n = sscanf ( p , " x%2x " , & val ) ;
}
if ( n = = 0 )
{
rig_debug ( RIG_DEBUG_ERR , " %s: unable to parse 0x??; or x??; from '%s' \n " ,
__func__ , s ) ;
}
2022-11-24 23:27:07 -06:00
buf [ i + + ] = val ;
2024-12-01 11:23:13 -06:00
p = strtok ( NULL , " ;: " ) ;
2022-11-24 23:27:07 -06:00
}
2022-11-25 17:39:35 -06:00
2022-11-24 23:27:07 -06:00
free ( s2 ) ;
return i ;
}
2022-12-01 16:20:23 -06:00
2024-11-24 18:44:00 +01:00
// sends whatever is in s -- no additions or changes done
2022-12-01 16:20:23 -06:00
extern int netrigctl_send_raw ( RIG * rig , char * s ) ;
2022-11-24 23:27:07 -06:00
/* 0xa4 */
declare_proto_rig ( send_raw )
{
2023-05-12 10:01:32 +03:00
int result ;
2022-11-25 17:39:35 -06:00
int reply_len ;
2023-05-12 10:01:32 +03:00
unsigned char termbyte [ 1 ] ;
unsigned char * term = NULL ;
unsigned char buf [ 200 ] ;
unsigned char send [ 200 ] ;
2022-11-26 15:19:23 -06:00
unsigned char * sendp = ( unsigned char * ) arg2 ;
int arg2_len = strlen ( arg2 ) ;
2023-05-12 10:01:32 +03:00
int is_binary = 0 ;
2022-11-26 15:19:23 -06:00
int buf_len = sizeof ( buf ) ;
int val = 0 ;
2022-12-01 16:20:23 -06:00
if ( rig - > caps - > rig_model = = RIG_MODEL_NETRIGCTL )
{
char netbuf [ 1024 ] ;
int retval ;
snprintf ( netbuf , sizeof ( netbuf ) - 1 , " \\ sendraw %s %s \n " , arg2 , arg3 ) ;
rig_debug ( RIG_DEBUG_ERR , " %s: calling netrigctl \n " , __func__ ) ;
retval = RIG_OK ;
return retval ;
}
2023-05-12 10:01:32 +03:00
if ( strcmp ( arg1 , " ; " ) = = 0 ) { termbyte [ 0 ] = ' ; ' ; term = termbyte ; }
else if ( strcasecmp ( arg1 , " CR " ) = = 0 ) { termbyte [ 0 ] = 0x0d ; term = termbyte ; }
else if ( strcasecmp ( arg1 , " LF " ) = = 0 ) { termbyte [ 0 ] = 0x0a ; term = termbyte ; }
else if ( strcasecmp ( arg1 , " ICOM " ) = = 0 ) { termbyte [ 0 ] = 0xfd ; term = termbyte ; }
else if ( sscanf ( arg1 , " 0x%x " , & val ) = = 1 ) { termbyte [ 0 ] = val ; term = termbyte ; }
else if ( sscanf ( arg1 , " %d " , & val ) = = 1 )
{
2026-06-06 10:02:26 -04:00
if ( val < buf_len - 1 & & val > = 0 )
2023-05-12 10:01:32 +03:00
{
// Reserve one byte more to allow padding with null
buf_len = val + 1 ;
}
else
{
rig_debug ( RIG_DEBUG_ERR ,
" %s: response length %d is larger than maximum of %d bytes " ,
__func__ , val , buf_len ) ;
return - RIG_EINVAL ;
}
}
2022-11-26 16:13:41 -06:00
else
{
rig_debug ( RIG_DEBUG_ERR ,
2023-05-12 10:01:32 +03:00
" %s: unknown arg1 val=%s, expected ';', 'CR', 'LF', 'ICOM', 0xFF (hex byte) or "
" # of bytes where 0 means no reply and -1 means unknown " ,
2022-11-26 16:13:41 -06:00
__func__ , arg1 ) ;
2022-11-26 15:19:23 -06:00
return - RIG_EINVAL ;
}
2022-11-26 16:13:41 -06:00
2024-12-01 11:23:13 -06:00
if ( strncmp ( arg2 , " 0x " , 2 ) = = 0 | | arg2 [ 0 ] = = ' x ' )
2022-11-25 17:39:35 -06:00
{
2022-11-26 15:19:23 -06:00
arg2_len = parse_hex ( arg2 , send , sizeof ( send ) ) ;
2022-11-24 23:27:07 -06:00
sendp = send ;
2023-05-12 10:01:32 +03:00
is_binary = 1 ;
2022-11-24 23:27:07 -06:00
}
2022-11-25 17:39:35 -06:00
2022-11-24 23:27:07 -06:00
rig_debug ( RIG_DEBUG_TRACE , " %s: \n " , __func__ ) ;
2023-05-12 10:01:32 +03:00
2023-05-30 16:10:52 -05:00
result = rig_send_raw ( rig , ( unsigned char * ) sendp , arg2_len , buf , buf_len ,
term ) ;
2023-05-12 10:01:32 +03:00
if ( result < 0 )
{
return result ;
}
reply_len = result ;
2026-06-06 10:02:26 -04:00
if ( ! is_binary ) { buf [ buf_len - 1 ] = 0 ; } // null terminate in case it's a string
2022-11-25 17:39:35 -06:00
2022-11-24 23:27:07 -06:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
2022-11-26 15:19:23 -06:00
fprintf ( fout , " %s: " , cmd - > arg3 ) ;
2022-11-24 23:27:07 -06:00
}
2022-11-25 17:39:35 -06:00
if ( reply_len = = 0 )
{
fprintf ( fout , " No answer \n " ) ;
}
2023-05-12 10:01:32 +03:00
else if ( is_binary )
2022-11-25 17:39:35 -06:00
{
2026-06-13 11:33:26 -04:00
for ( int i = 0 ; i < reply_len ; + + i )
2022-11-25 17:39:35 -06:00
{
fprintf ( fout , " 0x%02x " , buf [ i ] ) ;
}
fprintf ( fout , " \n " ) ;
}
else
{
fprintf ( fout , " %s \n " , buf ) ;
}
return RIG_OK ;
2022-11-24 23:27:07 -06:00
}
2023-07-22 10:32:25 -05:00
declare_proto_rig ( cm108_get_bit )
{
rig_debug ( RIG_DEBUG_TRACE , " %s: \n " , __func__ ) ;
int gpio = - 1 ;
int bit = - 1 ;
// try GPIO format first
2023-12-16 11:37:58 -06:00
int n = sscanf ( arg1 , " GPIO%d " , & gpio ) ;
2024-12-22 11:14:14 -06:00
if ( n = = 0 | | n = = EOF )
2023-12-16 11:37:58 -06:00
{
n = sscanf ( arg1 , " %d " , & gpio ) ;
}
if ( n ! = 1 ) { return - RIG_EINVAL ; }
2024-03-01 05:32:08 -05:00
int retval = rig_cm108_get_bit ( PTTPORT ( rig ) , gpio , & bit ) ;
2023-12-16 11:37:58 -06:00
2023-07-22 10:32:25 -05:00
if ( retval ! = RIG_OK )
{
rig_debug ( RIG_DEBUG_ERR , " %s: %s \n " , __func__ , strerror ( retval ) ) ;
return retval ;
}
2023-12-16 11:37:58 -06:00
2023-07-22 10:32:25 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: gpio=%d \n " , __func__ , gpio ) ;
2023-12-16 11:37:58 -06:00
2023-07-22 10:32:25 -05:00
if ( ( interactive & & prompt ) | | ( interactive & & ! prompt & & ext_resp ) )
{
fprintf ( fout , " %s: " , cmd - > arg2 ) ;
}
2023-12-16 11:37:58 -06:00
2023-07-22 10:32:25 -05:00
fprintf ( fout , " %d (simulated) \n " , 1 ) ;
return RIG_OK ;
}
declare_proto_rig ( cm108_set_bit )
{
rig_debug ( RIG_DEBUG_TRACE , " %s: \n " , __func__ ) ;
2023-12-16 11:37:58 -06:00
int gpio , bit = - 1 ;
2023-07-22 10:32:25 -05:00
// try GPIO format first
2023-12-16 11:37:58 -06:00
int n = sscanf ( arg1 , " GPIO%d " , & gpio ) ;
2024-12-22 10:38:07 -06:00
if ( n = = 0 | | n = = EOF )
2023-12-16 11:37:58 -06:00
{
n = sscanf ( arg1 , " %d " , & gpio ) ;
}
if ( n ! = 1 ) { return - RIG_EINVAL ; }
2023-07-22 10:32:25 -05:00
n = sscanf ( arg2 , " %d " , & bit ) ;
2023-12-16 11:37:58 -06:00
if ( n ! = 1 ) { return - RIG_EINVAL ; }
2023-07-22 10:32:25 -05:00
rig_debug ( RIG_DEBUG_TRACE , " %s: set gpio=%d, bit=%d \n " , __func__ , gpio , bit ) ;
2024-03-01 05:32:08 -05:00
int retval = rig_cm108_set_bit ( PTTPORT ( rig ) , gpio , bit ) ;
2023-12-16 11:37:58 -06:00
2023-07-22 10:32:25 -05:00
if ( retval ! = RIG_OK )
{
rig_debug ( RIG_DEBUG_ERR , " %s: %s \n " , __func__ , strerror ( retval ) ) ;
}
2023-12-16 11:37:58 -06:00
2023-07-22 10:32:25 -05:00
return retval ;
}
2023-11-05 17:03:21 -06:00
declare_proto_rig ( get_conf )
{
int ret ;
rig_debug ( RIG_DEBUG_ERR , " %s: \n " , __func__ ) ;
2023-12-16 11:37:58 -06:00
2023-11-05 17:03:21 -06:00
if ( arg1 = = NULL | | arg1 [ 0 ] = = ' ? ' )
{
2025-08-31 16:38:39 +02:00
dumpconf_list ( rig , fout ) ;
2023-11-05 17:03:21 -06:00
debugmsgsave [ 0 ] = 0 ;
debugmsgsave2 [ 0 ] = 0 ;
return RIG_OK ;
}
2023-12-16 11:37:58 -06:00
2024-01-21 23:11:55 -06:00
hamlib_token_t mytoken = rig_token_lookup ( rig , arg1 ) ;
2023-12-16 11:37:58 -06:00
2023-11-05 17:03:21 -06:00
if ( mytoken = = 0 )
{
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: unknown token '%s' for this rig \n " , __func__ ,
arg1 ) ;
2023-11-05 17:03:21 -06:00
ret = - RIG_EINVAL ;
}
else
{
char value [ 4096 ] ; // no max value known -- should we limit it?
2025-07-27 11:31:18 -04:00
ret = rig_get_conf2 ( rig , mytoken , value , sizeof ( value ) ) ;
2023-12-16 11:37:58 -06:00
2023-11-05 17:03:21 -06:00
if ( ret ! = RIG_OK )
{
return ret ;
}
2023-12-16 11:37:58 -06:00
2023-11-05 17:03:21 -06:00
fprintf ( fout , " %s=%s \n " , arg1 , value ) ;
}
return ( ret ) ;
}
declare_proto_rig ( set_conf )
{
int ret ;
rig_debug ( RIG_DEBUG_TRACE , " %s: called \n " , __func__ ) ;
if ( arg1 [ 0 ] = = ' ? ' )
{
dumpconf_list ( rig , fout ) ;
debugmsgsave [ 0 ] = 0 ;
debugmsgsave2 [ 0 ] = 0 ;
return RIG_OK ;
}
2023-12-16 11:37:58 -06:00
2024-01-21 23:11:55 -06:00
hamlib_token_t mytoken = rig_token_lookup ( rig , arg1 ) ;
2023-12-16 11:37:58 -06:00
2023-11-05 17:03:21 -06:00
if ( mytoken = = 0 )
{
2023-12-16 11:37:58 -06:00
rig_debug ( RIG_DEBUG_ERR , " %s: unknown token '%s' for this rig \n " , __func__ ,
arg1 ) ;
2023-11-05 17:03:21 -06:00
ret = - RIG_EINVAL ;
}
else
{
Remove double call to rig_token_lookup() and rot_token_lookup()
The needed value is already in the variable.
Test case /to check that the changes don't break the code):
tests/rigctl --set-conf=rig_pathname=test,write_delay=1,timeout=2 --show-conf Q | grep --no-group-separator -A1 -E "(rig_pathname|^write_delay|^timeout):"
tests/rotctl --set-conf=rot_pathname=test,write_delay=1,timeout=2 --show-conf Q | grep --no-group-separator -A1 -E "(rot_pathname|^write_delay|^timeout):"
The output before and after this patch is:
rig_pathname: "Path name to the device file of the rig"
Default: /dev/rig, Value: test
write_delay: "Delay in ms between each byte sent out"
Default: 0, Value: 1
timeout: "Timeout in ms"
Default: 0, Value: 2
Command 'Q' not found!
rot_pathname: "Path name to the device file of the rotator"
Default: /dev/rotator, Value: test
write_delay: "Delay in ms between each byte sent out"
Default: 0, Value: 1
timeout: "Timeout in ms"
Default: 0, Value: 2
2025-08-20 23:04:41 +02:00
ret = rig_set_conf ( rig , mytoken , arg2 ) ;
2023-11-05 17:03:21 -06:00
}
return ( ret ) ;
}