From 841acdf011bfdc50be3cb1934d130317195d8164 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sat, 14 Apr 2018 10:46:13 -0500 Subject: [PATCH 1/2] Improve network connect error message --- src/network.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/network.c b/src/network.c index e573dc9c9..53d44c1cb 100644 --- a/src/network.c +++ b/src/network.c @@ -241,8 +241,9 @@ int network_open(hamlib_port_t *rp, int default_port) { break; } - - handle_error(RIG_DEBUG_WARN, "connect (trying next interface)"); + char msg[150]; + snprintf(msg,sizeof(msg),"connect to %s failed, (trying next interface)",rp->pathname); + handle_error(RIG_DEBUG_WARN, msg); #ifdef __MINGW32__ closesocket(fd); From 6c369109e64d35ba7196e765474566856fd8bd8c Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sat, 14 Apr 2018 17:20:28 -0500 Subject: [PATCH 2/2] Add debug time stamps via -Z and --debug-time-stamps --- doc/utility_programs.texi | 18 ++++++++++++++++++ include/hamlib/rig.h | 3 +++ src/debug.c | 35 ++++++++++++++++++++++++++++++++++- tests/rigctl.1 | 4 ++++ tests/rigctl.c | 8 +++++++- tests/rigctld.1 | 3 +++ tests/rigctld.c | 8 +++++--- tests/rotctl.1 | 3 +++ tests/rotctl.c | 8 +++++++- tests/rotctld.1 | 3 +++ tests/rotctld.c | 8 +++++++- 11 files changed, 94 insertions(+), 7 deletions(-) diff --git a/doc/utility_programs.texi b/doc/utility_programs.texi index 28d6320dd..e3716ccb1 100644 --- a/doc/utility_programs.texi +++ b/doc/utility_programs.texi @@ -411,6 +411,10 @@ will use the verbose facility to print critical values useful for testing and will often ask for this output in response to a request for help. +@item -Z +@itemx --debug-time-stamps +Enable time stamps on debug output. + @item -h @itemx --help Show summary of these options and exit. @@ -421,6 +425,7 @@ Show summary of these options and exit. @item -V @itemx --version Show version of @command{rigctl} and exit. + @end table @quotation Note @@ -1414,6 +1419,10 @@ will use the verbose facility to print critical values useful for testing and will often ask for this output in response to a request for help. +@item -Z +@itemx --debug-time-stamps +Enable time stamps on debug output. + @item -h @itemx --help Show summary of these options and exit. @@ -1913,6 +1922,10 @@ will use the verbose facility to print critical values useful for testing and will often ask for this output in response to a request for help. +@item -Z +@itemx --debug_time_stamps +Enable time stamps on debug output. + @item -h @itemx --help Show summary of these options and exit. @@ -1923,6 +1936,7 @@ Show summary of these options and exit. @item -V @itemx --version Show version of @command{rigctl} and exit. + @end table @quotation Note @@ -2948,6 +2962,10 @@ will use the verbose facility to print critical values useful for testing and will often ask for this output in response to a request for help. +@item -Z +@itemx --debug-time-stamps +Enable time stamps on debug output. + @item -h @itemx --help Show summary of these options and exit. diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index b94af30ce..941242a96 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2180,6 +2180,9 @@ rig_setting2idx HAMLIB_PARAMS((setting_t s)); extern HAMLIB_EXPORT(void) rig_set_debug HAMLIB_PARAMS((enum rig_debug_level_e debug_level)); +extern HAMLIB_EXPORT(void) +rig_set_debug_time_stamp HAMLIB_PARAMS((int flag)); + #define rig_set_debug_level(level) rig_set_debug(level) extern HAMLIB_EXPORT(int) diff --git a/src/debug.c b/src/debug.c index 1ddfc910d..1ac4bfe5e 100644 --- a/src/debug.c +++ b/src/debug.c @@ -42,6 +42,7 @@ #include /* Error number definitions */ #include #include +#include #ifdef ANDROID # include @@ -54,6 +55,7 @@ static int rig_debug_level = RIG_DEBUG_TRACE; +static int rig_debug_time_stamp = 0; static FILE *rig_debug_stream; static vprintf_cb_t rig_vprintf_cb; static rig_ptr_t rig_vprintf_arg; @@ -128,6 +130,30 @@ int HAMLIB_API rig_need_debug(enum rig_debug_level_e debug_level) return (debug_level <= rig_debug_level); } +/** + * \param debug_time_stamp + * \brief Enbable/disable time stamp on debug output + */ +void HAMLIB_API rig_set_debug_time_stamp(int flag) +{ + rig_debug_time_stamp = flag; +} + + +char *date_strget(char *buf,int buflen) +{ + time_t mytime; + struct tm *mytm; + struct timeval tv; + mytime=time(NULL); + mytm = gmtime(&mytime); + gettimeofday(&tv,NULL); + strftime(buf,buflen,"%Y-%m-%d:%H:%M:%S.",mytm); + char tmp[16]; + sprintf(tmp,"%06ld",tv.tv_usec); + strcat(buf,tmp); + return buf; +} /** * \param debug_level @@ -157,7 +183,10 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, { rig_debug_stream = stderr; } - + if (rig_debug_time_stamp) { + char buf[256]; + fprintf(rig_debug_stream,"%s: ",date_strget(buf,sizeof(buf))); + } vfprintf(rig_debug_stream, fmt, ap); fflush(rig_debug_stream); } @@ -190,6 +219,10 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, a = ANDROID_LOG_VERBOSE; break; + case RIG_DEBUG_TIME: + a = ANDROID_LOG_VERBOSE; + break; + default: a = ANDROID_LOG_DEBUG; break; diff --git a/tests/rigctl.1 b/tests/rigctl.1 index df3a0bb2c..08872c7d1 100644 --- a/tests/rigctl.1 +++ b/tests/rigctl.1 @@ -151,11 +151,15 @@ is not set, the value of HOME is used. .B \-v, --verbose Set verbose mode, cumulative (see DIAGNOSTICS below). .TP +.B \-Z, --debug-time-stamps +Enable time stamps for the debug messages +.TP .B \-h, --help Show summary of these options and exit. .TP .B \-V, --version Show version of \fBrigctl\fP and exit. +.sp .PP \fBN.B.\fP Some options may not be implemented by a given backend and will return an error. This is most likely to occur with the \fI\-\-set-conf\fP diff --git a/tests/rigctl.c b/tests/rigctl.c index 82458eabf..2c5d1a36d 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -87,7 +87,7 @@ void usage(void); * NB: do NOT use -W since it's reserved by POSIX. * TODO: add an option to read from a file */ -#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhV" +#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhVZ" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -105,6 +105,7 @@ static struct option long_options[] = {"dump-caps", 0, 0, 'u'}, {"vfo", 0, 0, 'o'}, {"no-restore-ai", 0, 0, 'n'}, + {"debug-time-stamps",0, 0, 'Z'}, #ifdef HAVE_READLINE_HISTORY {"read-history", 0, 0, 'i'}, {"save-history", 0, 0, 'I'}, @@ -399,6 +400,10 @@ int main(int argc, char *argv[]) dump_caps_opt++; break; + case 'Z': + rig_set_debug_time_stamp(1); + break; + default: usage(); /* unknown option? */ exit(1); @@ -636,6 +641,7 @@ void usage(void) " -I, --save-history save current interactive session history\n" #endif " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" + " -Z, --debug-time-stamps enable time stamps for debug messages\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n\n" ); diff --git a/tests/rigctld.1 b/tests/rigctld.1 index fd19355de..7b032766c 100644 --- a/tests/rigctld.1 +++ b/tests/rigctld.1 @@ -137,6 +137,9 @@ below. .B \-v, --verbose Set verbose mode, cumulative (see \fIDIAGNOSTICS\fP below). .TP +.B \-Z, --debug-time-stamps +Enable time stamps for the debug messages +.TP .B \-h, --help Show a summary of these options and exit. .TP diff --git a/tests/rigctld.c b/tests/rigctld.c index e029a0df3..448da51ae 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -85,7 +85,7 @@ * NB: do NOT use -W since it's reserved by POSIX. * TODO: add an option to read from a file */ -#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhV" +#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhVZ" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -106,6 +106,7 @@ static struct option long_options[] = {"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, + {"debug-time-stamps",0, 0, 'Z'}, {0, 0, 0, 0} }; @@ -929,7 +930,7 @@ void * handle_socket(void *arg) { retcode = 1; } - if (retcode == 1) + if (retcode == 1) { retcode = rig_open(my_rig); } @@ -1020,8 +1021,9 @@ void usage(void) " -u, --dump-caps dump capabilities and exit\n" " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" + " -Z, --debug-time-stamps enable time stamps for debug messages\n" " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n", + " -V, --version output version information and exit\n\n", portno); usage_rig(stdout); diff --git a/tests/rotctl.1 b/tests/rotctl.1 index 3a5689afc..b52acf49b 100644 --- a/tests/rotctl.1 +++ b/tests/rotctl.1 @@ -110,6 +110,9 @@ is not set, the value of HOME is used. .B \-v, --verbose Set verbose mode, cumulative (see DIAGNOSTICS below). .TP +.B \-Z, --debug-time-stamps +Enable time stamps for the debug messages +.TP .B \-h, --help Show summary of these options and exit. .TP diff --git a/tests/rotctl.c b/tests/rotctl.c index 16e412fef..e77ba85fb 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -82,7 +82,7 @@ void usage(); * NB: do NOT use -W since it's reserved by POSIX. * TODO: add an option to read from a file */ -#define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu" +#define SHORT_OPTIONS "+m:r:s:C:t:LvhVluZ" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -93,6 +93,7 @@ static struct option long_options[] = {"set-conf", 1, 0, 'C'}, {"show-conf", 0, 0, 'L'}, {"dump-caps", 0, 0, 'u'}, + {"debug-time-stamps",0,0, 'Z'}, #ifdef HAVE_READLINE_HISTORY {"read-history", 0, 0, 'i'}, {"save-history", 0, 0, 'I'}, @@ -258,6 +259,10 @@ int main(int argc, char *argv[]) dump_caps_opt++; break; + case 'Z': + rig_set_debug_time_stamp(1); + break; + default: usage(); /* unknown option? */ exit(1); @@ -460,6 +465,7 @@ void usage() " -I, --save-history save current interactive session history\n" #endif " -v, --verbose set verbose mode, cumulative\n" + " -Z, --debug-time-stamps enable time stamps for debug messages\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n\n" ); diff --git a/tests/rotctld.1 b/tests/rotctld.1 index 3383758e6..6204814e5 100644 --- a/tests/rotctld.1 +++ b/tests/rotctld.1 @@ -109,6 +109,9 @@ Dump capabilities for the rotator defined with -m above and exit. .B \-v, --verbose Set verbose mode, cumulative (see DIAGNOSTICS below). .TP +.B \-Z, --debug-time-stamps +Enable time stamps for the debug messages +.TP .B \-h, --help Show a summary of these options and exit. .TP diff --git a/tests/rotctld.c b/tests/rotctld.c index 763f76d90..660a7d450 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -84,7 +84,7 @@ void usage(); * NB: do NOT use -W since it's reserved by POSIX. * TODO: add an option to read from a file */ -#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl" +#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVlZ" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -96,6 +96,7 @@ static struct option long_options[] = {"set-conf", 1, 0, 'C'}, {"show-conf", 0, 0, 'L'}, {"dump-caps", 0, 0, 'u'}, + {"debug-time-stamps",0, 0, 'Z'}, {"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, @@ -279,6 +280,10 @@ int main(int argc, char *argv[]) dump_caps_opt++; break; + case 'Z': + rig_set_debug_time_stamp(1); + break; + default: usage(); /* unknown option? */ exit(1); @@ -692,6 +697,7 @@ void usage() " -l, --list list all model numbers and exit\n" " -u, --dump-caps dump capabilities and exit\n" " -v, --verbose set verbose mode, cumulative\n" + " -Z, --debug-time-stamps enable time stamps for debug messages\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n\n", portno);