diff --git a/.gitignore b/.gitignore index 5af52a7b3..671f89b16 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.o *.lo *.la +*.orig *.swp Makefile Makefile.in diff --git a/README.developer b/README.developer index 3bfa5a18c..1e6deda08 100644 --- a/README.developer +++ b/README.developer @@ -542,17 +542,29 @@ readability. Align closing braces with the opening block's keyword. In function definitions put the opening brace on its own line under the definition's parameter line. -Hamlib source code is no place for an entry into the obsfucated C contest! +A configuration file for the Artistic Style (http://astyle.sourceforge.net/) +utility can be found in the scripts directory. The settings it provides should +conform reasonably close to the Linux style guide referenced above. This file +can be copied to $HOME/.astylerc where it will be used as the default +configuration. If you already have an existing .astylerc, passing + + --options=/path/to/hamlib/scripts/astylerc + +will use this file as the configuration for formatting. Consider using this +utility whenever working on a given C source file in Hamlib. + +Hamlib source code is no place for an entry into the obfuscated C contest! Many of us are hobbyists and write this for fun. Easy to read and understand logic is preferred over a clever solution. If your solution must be written in a clever fashion, please document it well in your comments. -Any header files included from the hamlib/ directory should be enclosed -in <>: +Any header files included from the hamlib/ directory should be enclosed in <>: + #include # Per GNU GCC documentation Other included header files (backend and rig specific headers) should be enclosed in "": + #include "yaesu.h" Contributed code should always keep the source base in a compilable state, @@ -581,6 +593,7 @@ Hamlib should also compile with the following common compilers: Portability issues to watch: + * C99 is probably (in 2016) a reasonable target * little vs. big endian systems (use shifts or adhoc functions) * 64 bit int: avoid them in API * printf/scanf of 64bit int: use PRIll (cast value to int64_t) and SCNll @@ -672,6 +685,9 @@ big, you can send it as a compressed attachment. 8.3.1 Changelog +A ChangeLog file is no longer manually maintained. At some point it may be +automatically generated from the Git commit log for source tarballs. + Simply summarize your changes when the files are committed to Git or, if providing patches to the mailing list, provide a summary so the uploader can include it in the commit message which will show in the commit log (Git diff --git a/adat/adat.c b/adat/adat.c index f953c9f10..dce6181b5 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -63,7 +63,7 @@ * */ #if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -#include "hl_sleep.h" +# include "hl_sleep.h" #endif // --------------------------------------------------------------------------- @@ -76,8 +76,8 @@ // GLOBAL DEFINITIONS // --------------------------------------------------------------------------- -#if !defined( NDEDBUG ) -#define ADAT_DEBUG 1 +#if !defined(NDEDBUG) +# define ADAT_DEBUG 1 #endif #undef ADAT_DEBUG // manual override ... @@ -92,86 +92,84 @@ static int gFnLevel = 0; // ADAT MODES -static adat_mode_list_t the_adat_mode_list = -{ - ADAT_NR_MODES, +static adat_mode_list_t the_adat_mode_list = { + ADAT_NR_MODES, - { - { - ADAT_MODE_STR_CW_R, - ADAT_MODE_RNR_CW_R, - ADAT_MODE_ANR_CW_R - }, + { + { + ADAT_MODE_STR_CW_R, + ADAT_MODE_RNR_CW_R, + ADAT_MODE_ANR_CW_R + }, - { - ADAT_MODE_STR_CW, - ADAT_MODE_RNR_CW, - ADAT_MODE_ANR_CW - }, + { + ADAT_MODE_STR_CW, + ADAT_MODE_RNR_CW, + ADAT_MODE_ANR_CW + }, - { - ADAT_MODE_STR_LSB, - ADAT_MODE_RNR_LSB, - ADAT_MODE_ANR_LSB - }, + { + ADAT_MODE_STR_LSB, + ADAT_MODE_RNR_LSB, + ADAT_MODE_ANR_LSB + }, - { - ADAT_MODE_STR_USB, - ADAT_MODE_RNR_USB, - ADAT_MODE_ANR_USB - }, + { + ADAT_MODE_STR_USB, + ADAT_MODE_RNR_USB, + ADAT_MODE_ANR_USB + }, - { - ADAT_MODE_STR_AM, - ADAT_MODE_RNR_AM, - ADAT_MODE_ANR_AM - }, + { + ADAT_MODE_STR_AM, + ADAT_MODE_RNR_AM, + ADAT_MODE_ANR_AM + }, - { - ADAT_MODE_STR_AM_SL, - ADAT_MODE_RNR_AM_SL, - ADAT_MODE_ANR_AM_SL - }, + { + ADAT_MODE_STR_AM_SL, + ADAT_MODE_RNR_AM_SL, + ADAT_MODE_ANR_AM_SL + }, - { - ADAT_MODE_STR_AM_SU, - ADAT_MODE_RNR_AM_SU, - ADAT_MODE_ANR_AM_SU - }, + { + ADAT_MODE_STR_AM_SU, + ADAT_MODE_RNR_AM_SU, + ADAT_MODE_ANR_AM_SU + }, - { - ADAT_MODE_STR_FM, - ADAT_MODE_RNR_FM, - ADAT_MODE_ANR_FM - } - } + { + ADAT_MODE_STR_FM, + ADAT_MODE_RNR_FM, + ADAT_MODE_ANR_FM + } + } }; // ADAT VFOS -static adat_vfo_list_t the_adat_vfo_list = -{ - ADAT_NR_VFOS, +static adat_vfo_list_t the_adat_vfo_list = { + ADAT_NR_VFOS, - { - { - ADAT_VFO_STR_A, - ADAT_VFO_RNR_A, - ADAT_VFO_ANR_A - }, + { + { + ADAT_VFO_STR_A, + ADAT_VFO_RNR_A, + ADAT_VFO_ANR_A + }, - { - ADAT_VFO_STR_B, - ADAT_VFO_RNR_B, - ADAT_VFO_ANR_B - }, + { + ADAT_VFO_STR_B, + ADAT_VFO_RNR_B, + ADAT_VFO_ANR_B + }, - { - ADAT_VFO_STR_C, - ADAT_VFO_RNR_C, - ADAT_VFO_ANR_C - } - } + { + ADAT_VFO_STR_C, + ADAT_VFO_RNR_C, + ADAT_VFO_ANR_C + } + } }; // --------------------------------------------------------------------------- @@ -180,407 +178,376 @@ static adat_vfo_list_t the_adat_vfo_list = // -- NIL -- (Marks the end of a cmd list) #if 0 -static adat_cmd_def_t adat_cmd_nil = -{ - ADAT_CMD_DEF_NIL, - ADAT_CMD_KIND_WITHOUT_RESULT, - NULL, +static adat_cmd_def_t adat_cmd_nil = { + ADAT_CMD_DEF_NIL, + ADAT_CMD_KIND_WITHOUT_RESULT, + NULL, - 0, - { - NULL - } + 0, + { + NULL + } }; #endif // -- ADAT SPECIAL: DISPLAY OFF -- -static adat_cmd_def_t adat_cmd_display_off = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITHOUT_RESULT, - NULL, +static adat_cmd_def_t adat_cmd_display_off = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITHOUT_RESULT, + NULL, - 1, - { - ADAT_CMD_DEF_STRING_DISPLAY_OFF - } + 1, + { + ADAT_CMD_DEF_STRING_DISPLAY_OFF + } }; // -- ADAT SPECIAL: DISPLAY ON -- -static adat_cmd_def_t adat_cmd_display_on = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITHOUT_RESULT, - NULL, +static adat_cmd_def_t adat_cmd_display_on = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITHOUT_RESULT, + NULL, - 1, - { - ADAT_CMD_DEF_STRING_DISPLAY_ON - } + 1, + { + ADAT_CMD_DEF_STRING_DISPLAY_ON + } }; // -- ADAT SPECIAL: SELECT VFO -- // -- ADAT SPECIAL: GET SERIAL NR -- -static adat_cmd_def_t adat_cmd_get_serial_nr = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_serial_nr, +static adat_cmd_def_t adat_cmd_get_serial_nr = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_serial_nr, - 1, - { - ADAT_CMD_DEF_STRING_GET_SERIAL_NR - } + 1, + { + ADAT_CMD_DEF_STRING_GET_SERIAL_NR + } }; // -- ADAT SPECIAL: GET FIRMWARE VERSION -- -static adat_cmd_def_t adat_cmd_get_fw_version = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_fw_version, +static adat_cmd_def_t adat_cmd_get_fw_version = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_fw_version, - 1, - { - ADAT_CMD_DEF_STRING_GET_FW_VERSION - } + 1, + { + ADAT_CMD_DEF_STRING_GET_FW_VERSION + } }; // -- ADAT SPECIAL: GET HARDWARE VERSION -- -static adat_cmd_def_t adat_cmd_get_hw_version = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_hw_version, +static adat_cmd_def_t adat_cmd_get_hw_version = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_hw_version, - 1, - { - ADAT_CMD_DEF_STRING_GET_HW_VERSION - } + 1, + { + ADAT_CMD_DEF_STRING_GET_HW_VERSION + } }; // -- ADAT SPECIAL: GET FIRMWARE VERSION -- -static adat_cmd_def_t adat_cmd_get_id_code = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_id_code, +static adat_cmd_def_t adat_cmd_get_id_code = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_id_code, - 1, - { - ADAT_CMD_DEF_STRING_GET_ID_CODE - } + 1, + { + ADAT_CMD_DEF_STRING_GET_ID_CODE + } }; // -- ADAT SPECIAL: GET GUI FIRMWARE VERSION -- -static adat_cmd_def_t adat_cmd_get_gui_fw_version = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_gui_fw_version, +static adat_cmd_def_t adat_cmd_get_gui_fw_version = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_gui_fw_version, - 1, - { - ADAT_CMD_DEF_STRING_GET_GUI_FW_VERSION - } + 1, + { + ADAT_CMD_DEF_STRING_GET_GUI_FW_VERSION + } }; // -- ADAT SPECIAL: GET OPTIONS -- -static adat_cmd_def_t adat_cmd_get_options = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_options, +static adat_cmd_def_t adat_cmd_get_options = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_options, - 1, - { - ADAT_CMD_DEF_STRING_GET_OPTIONS - } + 1, + { + ADAT_CMD_DEF_STRING_GET_OPTIONS + } }; // -- ADAT SPECIAL: GET CALLSIGN -- -static adat_cmd_def_t adat_cmd_get_callsign = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_callsign, +static adat_cmd_def_t adat_cmd_get_callsign = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITH_RESULT, + adat_cmd_fn_get_callsign, - 1, - { - ADAT_CMD_DEF_STRING_GET_CALLSIGN - } + 1, + { + ADAT_CMD_DEF_STRING_GET_CALLSIGN + } }; // -- ADAT SPECIAL: SET CALLSIGN -- -static adat_cmd_def_t adat_cmd_set_callsign = -{ - ADAT_CMD_DEF_ADAT_SPECIAL, - ADAT_CMD_KIND_WITHOUT_RESULT, - adat_cmd_fn_set_callsign, +static adat_cmd_def_t adat_cmd_set_callsign = { + ADAT_CMD_DEF_ADAT_SPECIAL, + ADAT_CMD_KIND_WITHOUT_RESULT, + adat_cmd_fn_set_callsign, - 1, - { - ADAT_CMD_DEF_STRING_SET_CALLSIGN - } + 1, + { + ADAT_CMD_DEF_STRING_SET_CALLSIGN + } }; // -- HAMLIB DEFINED COMMANDS -- // -- GET FREQ -- -static adat_cmd_def_t adat_cmd_get_freq = -{ - ADAT_CMD_DEF_GET_FREQ, - ADAT_CMD_KIND_WITH_RESULT, +static adat_cmd_def_t adat_cmd_get_freq = { + ADAT_CMD_DEF_GET_FREQ, + ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_freq, + adat_cmd_fn_get_freq, - 1, - { - ADAT_CMD_DEF_STRING_GET_FREQ - } + 1, + { + ADAT_CMD_DEF_STRING_GET_FREQ + } }; -static adat_cmd_list_t adat_cmd_list_get_freq = -{ - 2, - { - &adat_cmd_display_off, - &adat_cmd_get_freq - } +static adat_cmd_list_t adat_cmd_list_get_freq = { + 2, + { + &adat_cmd_display_off, + &adat_cmd_get_freq + } }; // -- SET FREQ -- -static adat_cmd_def_t adat_cmd_set_freq = -{ - ADAT_CMD_DEF_SET_FREQ, - ADAT_CMD_KIND_WITHOUT_RESULT, +static adat_cmd_def_t adat_cmd_set_freq = { + ADAT_CMD_DEF_SET_FREQ, + ADAT_CMD_KIND_WITHOUT_RESULT, - adat_cmd_fn_set_freq, + adat_cmd_fn_set_freq, - 1, - { - ADAT_CMD_DEF_STRING_SET_FREQ - } + 1, + { + ADAT_CMD_DEF_STRING_SET_FREQ + } }; -static adat_cmd_list_t adat_cmd_list_set_freq = -{ - 3, - { - &adat_cmd_display_off, - &adat_cmd_set_freq, - &adat_cmd_get_freq, - } +static adat_cmd_list_t adat_cmd_list_set_freq = { + 3, + { + &adat_cmd_display_off, + &adat_cmd_set_freq, + &adat_cmd_get_freq, + } }; // -- GET VFO -- -static adat_cmd_list_t adat_cmd_list_get_vfo = -{ - 2, - { - &adat_cmd_display_off, - &adat_cmd_get_freq, - } +static adat_cmd_list_t adat_cmd_list_get_vfo = { + 2, + { + &adat_cmd_display_off, + &adat_cmd_get_freq, + } }; // -- GET MODE -- -static adat_cmd_def_t adat_cmd_get_mode = -{ - ADAT_CMD_DEF_GET_MODE, - ADAT_CMD_KIND_WITH_RESULT, +static adat_cmd_def_t adat_cmd_get_mode = { + ADAT_CMD_DEF_GET_MODE, + ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_mode, + adat_cmd_fn_get_mode, - 1, - { - ADAT_CMD_DEF_STRING_GET_MODE - } + 1, + { + ADAT_CMD_DEF_STRING_GET_MODE + } }; -static adat_cmd_list_t adat_cmd_list_get_mode = -{ - 2, - { - &adat_cmd_display_off, - &adat_cmd_get_mode - } +static adat_cmd_list_t adat_cmd_list_get_mode = { + 2, + { + &adat_cmd_display_off, + &adat_cmd_get_mode + } }; // -- SET VFO -- -static adat_cmd_def_t adat_cmd_set_vfo = -{ - ADAT_CMD_DEF_SET_VFO, - ADAT_CMD_KIND_WITHOUT_RESULT, +static adat_cmd_def_t adat_cmd_set_vfo = { + ADAT_CMD_DEF_SET_VFO, + ADAT_CMD_KIND_WITHOUT_RESULT, - adat_cmd_fn_set_vfo, + adat_cmd_fn_set_vfo, - 2, - { - ADAT_CMD_DEF_STRING_SWITCH_ON_VFO, - ADAT_CMD_DEF_STRING_SET_VFO_AS_MAIN_VFO - } + 2, + { + ADAT_CMD_DEF_STRING_SWITCH_ON_VFO, + ADAT_CMD_DEF_STRING_SET_VFO_AS_MAIN_VFO + } }; -static adat_cmd_list_t adat_cmd_list_set_vfo = -{ - 2, - { - &adat_cmd_display_off, - &adat_cmd_set_vfo - } +static adat_cmd_list_t adat_cmd_list_set_vfo = { + 2, + { + &adat_cmd_display_off, + &adat_cmd_set_vfo + } }; // -- SET MODE -- -static adat_cmd_def_t adat_cmd_set_mode = -{ - ADAT_CMD_DEF_SET_MODE, - ADAT_CMD_KIND_WITHOUT_RESULT, +static adat_cmd_def_t adat_cmd_set_mode = { + ADAT_CMD_DEF_SET_MODE, + ADAT_CMD_KIND_WITHOUT_RESULT, - adat_cmd_fn_set_mode, + adat_cmd_fn_set_mode, - 1, - { - ADAT_CMD_DEF_STRING_SET_MODE - } + 1, + { + ADAT_CMD_DEF_STRING_SET_MODE + } }; -static adat_cmd_list_t adat_cmd_list_set_mode = -{ - 3, - { - &adat_cmd_display_off, - &adat_cmd_set_vfo, - &adat_cmd_set_mode, - } +static adat_cmd_list_t adat_cmd_list_set_mode = { + 3, + { + &adat_cmd_display_off, + &adat_cmd_set_vfo, + &adat_cmd_set_mode, + } }; // -- SET PTT -- -static adat_cmd_def_t adat_cmd_set_ptt = -{ - ADAT_CMD_DEF_SET_PTT, - ADAT_CMD_KIND_WITHOUT_RESULT, +static adat_cmd_def_t adat_cmd_set_ptt = { + ADAT_CMD_DEF_SET_PTT, + ADAT_CMD_KIND_WITHOUT_RESULT, - adat_cmd_fn_set_ptt, + adat_cmd_fn_set_ptt, - 1, - { - ADAT_CMD_DEF_STRING_SET_PTT - } + 1, + { + ADAT_CMD_DEF_STRING_SET_PTT + } }; -static adat_cmd_list_t adat_cmd_list_set_ptt = -{ - 2, - { - &adat_cmd_set_ptt, - &adat_cmd_display_off - } +static adat_cmd_list_t adat_cmd_list_set_ptt = { + 2, + { + &adat_cmd_set_ptt, + &adat_cmd_display_off + } }; // -- GET PTT -- -static adat_cmd_def_t adat_cmd_get_ptt = -{ - ADAT_CMD_DEF_GET_PTT, - ADAT_CMD_KIND_WITH_RESULT, +static adat_cmd_def_t adat_cmd_get_ptt = { + ADAT_CMD_DEF_GET_PTT, + ADAT_CMD_KIND_WITH_RESULT, - adat_cmd_fn_get_ptt, + adat_cmd_fn_get_ptt, - 1, - { - ADAT_CMD_DEF_STRING_GET_PTT - } + 1, + { + ADAT_CMD_DEF_STRING_GET_PTT + } }; -static adat_cmd_list_t adat_cmd_list_get_ptt = -{ - 2, - { - &adat_cmd_display_off, - &adat_cmd_get_ptt - } +static adat_cmd_list_t adat_cmd_list_get_ptt = { + 2, + { + &adat_cmd_display_off, + &adat_cmd_get_ptt + } }; // -- GET POWER STATUS -- -static adat_cmd_list_t adat_cmd_list_get_powerstatus = -{ - 1, - { - &adat_cmd_get_id_code - } +static adat_cmd_list_t adat_cmd_list_get_powerstatus = { + 1, + { + &adat_cmd_get_id_code + } }; // -- GET INFO -- -static adat_cmd_list_t adat_cmd_list_get_info = -{ - 7, - { - &adat_cmd_get_serial_nr, - &adat_cmd_get_id_code, - &adat_cmd_get_fw_version, - &adat_cmd_get_gui_fw_version, - &adat_cmd_get_hw_version, - &adat_cmd_get_options, - &adat_cmd_get_callsign - } +static adat_cmd_list_t adat_cmd_list_get_info = { + 7, + { + &adat_cmd_get_serial_nr, + &adat_cmd_get_id_code, + &adat_cmd_get_fw_version, + &adat_cmd_get_gui_fw_version, + &adat_cmd_get_hw_version, + &adat_cmd_get_options, + &adat_cmd_get_callsign + } }; // -- OPEN ADAT -- -static adat_cmd_list_t adat_cmd_list_open_adat = -{ - 8, - { - &adat_cmd_display_off, - &adat_cmd_get_serial_nr, - &adat_cmd_get_id_code, - &adat_cmd_get_fw_version, - &adat_cmd_get_gui_fw_version, - &adat_cmd_get_hw_version, - &adat_cmd_get_options, - &adat_cmd_set_callsign - } +static adat_cmd_list_t adat_cmd_list_open_adat = { + 8, + { + &adat_cmd_display_off, + &adat_cmd_get_serial_nr, + &adat_cmd_get_id_code, + &adat_cmd_get_fw_version, + &adat_cmd_get_gui_fw_version, + &adat_cmd_get_hw_version, + &adat_cmd_get_options, + &adat_cmd_set_callsign + } }; // -- CLOSE ADAT -- -static adat_cmd_list_t adat_cmd_list_close_adat = -{ - 1, - { - &adat_cmd_display_on - } +static adat_cmd_list_t adat_cmd_list_close_adat = { + 1, + { + &adat_cmd_display_on + } }; // -- ADAT SPECIAL: RECOVER FROM ERROR -- -static adat_cmd_list_t adat_cmd_list_recover_from_error = -{ - 1, - { - &adat_cmd_display_on - } +static adat_cmd_list_t adat_cmd_list_recover_from_error = { + 1, + { + &adat_cmd_display_on + } }; // --------------------------------------------------------------------------- @@ -593,57 +560,55 @@ static adat_cmd_list_t adat_cmd_list_recover_from_error = // --------------------------------------------------------------------------- // Status: RELEASED -size_t trimwhitespace( char *out, size_t len, const char *str ) +size_t trimwhitespace(char *out, size_t len, const char *str) { - char *end = NULL; - size_t out_size = 0; + char *end = NULL; + size_t out_size = 0; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. In -> \"%s\", %d.\n", - gFnLevel, __func__, __FILE__, __LINE__, str, len ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. In -> \"%s\", %d.\n", + gFnLevel, __func__, __FILE__, __LINE__, str, len); - if(len == 0) - { - gFnLevel--; - return 0; - } + if (len == 0) { + gFnLevel--; + return 0; + } - // Trim leading space - while(isspace((int)*str)) str++; + // Trim leading space + while (isspace((int)*str)) str++; - if(*str == 0) // All spaces? - { - out = NULL; - gFnLevel--; - return 1; - } + if (*str == 0) { // All spaces? + out = NULL; + gFnLevel--; + return 1; + } - // Trim trailing space - end = (char *)(str + strlen(str) - 1); - while(end > str && isspace((int)*end)) - { - *end = '\0'; - end--; - } + // Trim trailing space + end = (char *)(str + strlen(str) - 1); - end++; + while (end > str && isspace((int)*end)) { + *end = '\0'; + end--; + } - // Set output size to minimum of trimmed string length and buffer size minus 1 - //out_size = (end - str) < len-1 ? (end - str) : len - 1; - out_size = strlen( str ); + end++; - // Copy trimmed string and add null terminator - memcpy(out, str, out_size); - out[out_size] = 0; + // Set output size to minimum of trimmed string length and buffer size minus 1 + //out_size = (end - str) < len-1 ? (end - str) : len - 1; + out_size = strlen(str); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Out -> \"%s\", %d.\n", - gFnLevel, __func__, __FILE__, __LINE__, out, out_size ); - gFnLevel--; + // Copy trimmed string and add null terminator + memcpy(out, str, out_size); + out[out_size] = 0; - return out_size; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Out -> \"%s\", %d.\n", + gFnLevel, __func__, __FILE__, __LINE__, out, out_size); + gFnLevel--; + + return out_size; } // --------------------------------------------------------------------------- @@ -651,45 +616,44 @@ size_t trimwhitespace( char *out, size_t len, const char *str ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_print_cmd( adat_cmd_def_ptr pCmd ) +int adat_print_cmd(adat_cmd_def_ptr pCmd) { - int nRC = RIG_OK; + int nRC = RIG_OK; - int nI = 0; + int nI = 0; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %s (%s:%d): ENTRY.\n", - __func__, __FILE__, __LINE__ ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %s (%s:%d): ENTRY.\n", + __func__, __FILE__, __LINE__); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT COMMAND:\n"); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT COMMAND:\n"); - rig_debug( RIG_DEBUG_TRACE, - "*** -> Command ID = %"PRIll"\n", - pCmd->nCmdId ); + rig_debug(RIG_DEBUG_TRACE, + "*** -> Command ID = %"PRIll"\n", + pCmd->nCmdId); - rig_debug( RIG_DEBUG_TRACE, - "*** -> Command kind = %d\n", - pCmd->nCmdKind ); + rig_debug(RIG_DEBUG_TRACE, + "*** -> Command kind = %d\n", + pCmd->nCmdKind); - rig_debug( RIG_DEBUG_TRACE, - "*** -> Command FN Ptr = 0x%08x\n", - pCmd->pfCmdFn ); + rig_debug(RIG_DEBUG_TRACE, + "*** -> Command FN Ptr = 0x%08x\n", + pCmd->pfCmdFn); - while ( nI < pCmd->nNrCmdStrs ) - { - rig_debug( RIG_DEBUG_TRACE, - "*** -> Command String %d = \"%s\"\n", - nI, pCmd->pacCmdStrs[ nI ] ); - nI++; - } + while (nI < pCmd->nNrCmdStrs) { + rig_debug(RIG_DEBUG_TRACE, + "*** -> Command String %d = \"%s\"\n", + nI, pCmd->pacCmdStrs[ nI ]); + nI++; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %s (%s:%d): EXIT. Return Code = %d\n", - __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %s (%s:%d): EXIT. Return Code = %d\n", + __func__, __FILE__, __LINE__, + nRC); - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -701,144 +665,124 @@ int adat_print_cmd( adat_cmd_def_ptr pCmd ) // "1 123.456kHz" => nMode = ADAT_FREQ_PARSE_MODE_WITH_VFO // "800Hz" => nMode = ADAT_FREQ_PARSE_MODE_WITHOUT_VFO -int adat_parse_freq( char *pcStr, - adat_freq_parse_mode_t nMode, - int *nVFO, - freq_t *nFreq ) +int adat_parse_freq(char *pcStr, + adat_freq_parse_mode_t nMode, + int *nVFO, + freq_t *nFreq) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", - gFnLevel, __func__, __FILE__, __LINE__, - pcStr ); + gFnLevel++; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", + gFnLevel, __func__, __FILE__, __LINE__, + pcStr); - if( pcStr != NULL ) - { - int _nVFO = 0; - freq_t _nFreq = 0; + if (pcStr != NULL) { + int _nVFO = 0; + freq_t _nFreq = 0; - char *pcEnd = NULL; + char *pcEnd = NULL; - if( nMode == ADAT_FREQ_PARSE_MODE_WITH_VFO ) - { - // Get VFO from response string + if (nMode == ADAT_FREQ_PARSE_MODE_WITH_VFO) { + // Get VFO from response string - _nVFO = strtol( pcStr, &pcEnd, 10 ); + _nVFO = strtol(pcStr, &pcEnd, 10); - // Save VFO + // Save VFO - *nVFO = _nVFO; - } - else - { - pcEnd = pcStr; - } + *nVFO = _nVFO; + } else { + pcEnd = pcStr; + } - if(( _nVFO != 0 ) || // VFO = 0 -> Current VFO not active. - ( nMode == ADAT_FREQ_PARSE_MODE_WITHOUT_VFO )) - { - char acValueBuf[ ADAT_BUFSZ + 1 ]; - char acUnitBuf[ ADAT_BUFSZ + 1 ]; - int nI = 0; - double dTmpFreq = 0.0; + if ((_nVFO != 0) || // VFO = 0 -> Current VFO not active. + (nMode == ADAT_FREQ_PARSE_MODE_WITHOUT_VFO)) { + char acValueBuf[ ADAT_BUFSZ + 1 ]; + char acUnitBuf[ ADAT_BUFSZ + 1 ]; + int nI = 0; + double dTmpFreq = 0.0; - memset( acValueBuf, 0, ADAT_BUFSZ + 1 ); - memset( acUnitBuf, 0, ADAT_BUFSZ + 1 ); + memset(acValueBuf, 0, ADAT_BUFSZ + 1); + memset(acUnitBuf, 0, ADAT_BUFSZ + 1); - // Get Freq Value from response string + // Get Freq Value from response string - while(( isalpha( (int)*pcEnd ) == 0 ) || - ( *pcEnd == '.' )) - { - acValueBuf[ nI++ ] = *pcEnd; - pcEnd += sizeof( char ); - } + while ((isalpha((int)*pcEnd) == 0) || + (*pcEnd == '.')) { + acValueBuf[ nI++ ] = *pcEnd; + pcEnd += sizeof(char); + } - dTmpFreq = strtod( acValueBuf, (char**) NULL ); + dTmpFreq = strtod(acValueBuf, (char **) NULL); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d acValueBuf = \"%s\", dTmpFreq = %f, *pcEnd = %c\n", - gFnLevel, acValueBuf, dTmpFreq, *pcEnd ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d acValueBuf = \"%s\", dTmpFreq = %f, *pcEnd = %c\n", + gFnLevel, acValueBuf, dTmpFreq, *pcEnd); - // Get Freq Unit from response string + // Get Freq Unit from response string - nI = 0; - while( isalpha( (int)*pcEnd ) != 0 ) - { - acUnitBuf[ nI++ ] = *pcEnd; - pcEnd += sizeof( char ); - } + nI = 0; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d acUnitBuf = \"%s\"\n", - gFnLevel, acUnitBuf ); + while (isalpha((int)*pcEnd) != 0) { + acUnitBuf[ nI++ ] = *pcEnd; + pcEnd += sizeof(char); + } - // Normalize to Hz + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d acUnitBuf = \"%s\"\n", + gFnLevel, acUnitBuf); - if( !strncmp( acUnitBuf, - ADAT_FREQ_UNIT_HZ, - ADAT_FREQ_UNIT_HZ_LEN )) - { - _nFreq = Hz( dTmpFreq ); - } - else - { - if( !strncmp( acUnitBuf, - ADAT_FREQ_UNIT_KHZ, - ADAT_FREQ_UNIT_KHZ_LEN )) - { - _nFreq = kHz( dTmpFreq ); - } - else - { - if( !strncmp( acUnitBuf, - ADAT_FREQ_UNIT_MHZ, - ADAT_FREQ_UNIT_MHZ_LEN )) - { - _nFreq = MHz( dTmpFreq ); - } - else - { - if( !strncmp( acUnitBuf, - ADAT_FREQ_UNIT_GHZ, - ADAT_FREQ_UNIT_GHZ_LEN )) - { - _nFreq = GHz( dTmpFreq ); - } - else - { - _nFreq = 0; - nRC = -RIG_EINVAL; - } - } - } + // Normalize to Hz - } + if (!strncmp(acUnitBuf, + ADAT_FREQ_UNIT_HZ, + ADAT_FREQ_UNIT_HZ_LEN)) { + _nFreq = Hz(dTmpFreq); + } else { + if (!strncmp(acUnitBuf, + ADAT_FREQ_UNIT_KHZ, + ADAT_FREQ_UNIT_KHZ_LEN)) { + _nFreq = kHz(dTmpFreq); + } else { + if (!strncmp(acUnitBuf, + ADAT_FREQ_UNIT_MHZ, + ADAT_FREQ_UNIT_MHZ_LEN)) { + _nFreq = MHz(dTmpFreq); + } else { + if (!strncmp(acUnitBuf, + ADAT_FREQ_UNIT_GHZ, + ADAT_FREQ_UNIT_GHZ_LEN)) { + _nFreq = GHz(dTmpFreq); + } else { + _nFreq = 0; + nRC = -RIG_EINVAL; + } + } + } - // Save Freq + } - *nFreq = _nFreq; - } - } - else - { - // If input string is NULL set Freq and VFO also to NULL + // Save Freq - *nFreq = 0; - *nVFO = 0; - } + *nFreq = _nFreq; + } + } else { + // If input string is NULL set Freq and VFO also to NULL - // Done + *nFreq = 0; + *nVFO = 0; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, nVFO = %d, nFreq = %f\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nVFO, *nFreq ); - gFnLevel--; + // Done - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, nVFO = %d, nFreq = %f\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nVFO, *nFreq); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -846,55 +790,48 @@ int adat_parse_freq( char *pcStr, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_parse_mode( char *pcStr, - rmode_t *nRIGMode, - char *pcADATMode ) +int adat_parse_mode(char *pcStr, + rmode_t *nRIGMode, + char *pcADATMode) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", - gFnLevel, __func__, __FILE__, __LINE__, - pcStr ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", + gFnLevel, __func__, __FILE__, __LINE__, + pcStr); - if( pcStr != NULL ) - { - int nI = 0; - int nFini = 0; + if (pcStr != NULL) { + int nI = 0; + int nFini = 0; - while(( nI < the_adat_mode_list.nNrModes ) && ( nFini == 0 )) - { - if( !strcmp( pcStr, - the_adat_mode_list.adat_modes[ nI ].pcADATModeStr )) - { - *nRIGMode = the_adat_mode_list.adat_modes[ nI ].nRIGMode; - nFini = 1; // Done. - } - else - { - nI++; - } - } - } - else - { - // If input string is NULL ... + while ((nI < the_adat_mode_list.nNrModes) && (nFini == 0)) { + if (!strcmp(pcStr, + the_adat_mode_list.adat_modes[ nI ].pcADATModeStr)) { + *nRIGMode = the_adat_mode_list.adat_modes[ nI ].nRIGMode; + nFini = 1; // Done. + } else { + nI++; + } + } + } else { + // If input string is NULL ... - *nRIGMode = RIG_MODE_NONE; - pcADATMode = NULL; - } + *nRIGMode = RIG_MODE_NONE; + pcADATMode = NULL; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, Mode = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nRIGMode ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, Mode = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nRIGMode); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -902,49 +839,44 @@ int adat_parse_mode( char *pcStr, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_mode_rnr2anr( rmode_t nRIGMode, - int *nADATMode ) +int adat_mode_rnr2anr(rmode_t nRIGMode, + int *nADATMode) { - int nRC = RIG_OK; - int nI = 0; - int nFini = 0; + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGMode = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRIGMode ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGMode = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRIGMode); - while(( nI < the_adat_mode_list.nNrModes ) && ( nFini == 0 )) - { - if( the_adat_mode_list.adat_modes[ nI ].nRIGMode == nRIGMode ) - { - *nADATMode = the_adat_mode_list.adat_modes[ nI ].nADATMode; - nFini = 1; // Done. - } - else - { - nI++; - } - } + while ((nI < the_adat_mode_list.nNrModes) && (nFini == 0)) { + if (the_adat_mode_list.adat_modes[ nI ].nRIGMode == nRIGMode) { + *nADATMode = the_adat_mode_list.adat_modes[ nI ].nADATMode; + nFini = 1; // Done. + } else { + nI++; + } + } - if( nFini == 0 ) - { - // No valid Mode given + if (nFini == 0) { + // No valid Mode given - nRC = -RIG_EINVAL; - } + nRC = -RIG_EINVAL; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, ADAT Mode = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nADATMode ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, ADAT Mode = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nADATMode); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -952,49 +884,44 @@ int adat_mode_rnr2anr( rmode_t nRIGMode, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_mode_anr2rnr( int nADATMode, - rmode_t *nRIGMode ) +int adat_mode_anr2rnr(int nADATMode, + rmode_t *nRIGMode) { - int nRC = RIG_OK; - int nI = 0; - int nFini = 0; + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGMode = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRIGMode ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGMode = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRIGMode); - while(( nI < the_adat_mode_list.nNrModes ) && ( nFini == 0 )) - { - if( the_adat_mode_list.adat_modes[ nI ].nADATMode == nADATMode ) - { - *nRIGMode = the_adat_mode_list.adat_modes[ nI ].nRIGMode; - nFini = 1; // Done. - } - else - { - nI++; - } - } + while ((nI < the_adat_mode_list.nNrModes) && (nFini == 0)) { + if (the_adat_mode_list.adat_modes[ nI ].nADATMode == nADATMode) { + *nRIGMode = the_adat_mode_list.adat_modes[ nI ].nRIGMode; + nFini = 1; // Done. + } else { + nI++; + } + } - if( nFini == 0 ) - { - // No valid Mode given + if (nFini == 0) { + // No valid Mode given - nRC = -RIG_EINVAL; - } + nRC = -RIG_EINVAL; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG Mode = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nRIGMode ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG Mode = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nRIGMode); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1002,61 +929,53 @@ int adat_mode_anr2rnr( int nADATMode, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_parse_vfo( char *pcStr, - vfo_t *nRIGVFONr, - int *nADATVFONr ) +int adat_parse_vfo(char *pcStr, + vfo_t *nRIGVFONr, + int *nADATVFONr) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", - gFnLevel, __func__, __FILE__, __LINE__, - pcStr ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", + gFnLevel, __func__, __FILE__, __LINE__, + pcStr); - if( pcStr != NULL ) - { - int nI = 0; - int nFini = 0; + if (pcStr != NULL) { + int nI = 0; + int nFini = 0; - while(( nI < the_adat_vfo_list.nNrVFOs ) && ( nFini == 0 )) - { - if( !strcmp( pcStr, - the_adat_vfo_list.adat_vfos[ nI ].pcADATVFOStr )) - { - *nRIGVFONr = the_adat_vfo_list.adat_vfos[ nI ].nRIGVFONr; - *nADATVFONr = the_adat_vfo_list.adat_vfos[ nI ].nADATVFONr; - nFini = 1; // Done. - } - else - { - nI++; - } - } + while ((nI < the_adat_vfo_list.nNrVFOs) && (nFini == 0)) { + if (!strcmp(pcStr, + the_adat_vfo_list.adat_vfos[ nI ].pcADATVFOStr)) { + *nRIGVFONr = the_adat_vfo_list.adat_vfos[ nI ].nRIGVFONr; + *nADATVFONr = the_adat_vfo_list.adat_vfos[ nI ].nADATVFONr; + nFini = 1; // Done. + } else { + nI++; + } + } - if( nFini == 0 ) - { - nRC = -RIG_EINVAL; - } - } - else - { - // If input string is NULL ... + if (nFini == 0) { + nRC = -RIG_EINVAL; + } + } else { + // If input string is NULL ... - *nRIGVFONr = RIG_VFO_NONE; - *nADATVFONr = 0; - } + *nRIGVFONr = RIG_VFO_NONE; + *nADATVFONr = 0; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG VFO Nr = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nRIGVFONr ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG VFO Nr = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nRIGVFONr); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1064,49 +983,44 @@ int adat_parse_vfo( char *pcStr, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_vfo_rnr2anr( vfo_t nRIGVFONr, - int *nADATVFONr ) +int adat_vfo_rnr2anr(vfo_t nRIGVFONr, + int *nADATVFONr) { - int nRC = RIG_OK; - int nI = 0; - int nFini = 0; + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGVFONr = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRIGVFONr ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGVFONr = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRIGVFONr); - while(( nI < the_adat_vfo_list.nNrVFOs ) && ( nFini == 0 )) - { - if( the_adat_vfo_list.adat_vfos[ nI ].nRIGVFONr == nRIGVFONr ) - { - *nADATVFONr = the_adat_vfo_list.adat_vfos[ nI ].nADATVFONr; - nFini = 1; // Done. - } - else - { - nI++; - } - } + while ((nI < the_adat_vfo_list.nNrVFOs) && (nFini == 0)) { + if (the_adat_vfo_list.adat_vfos[ nI ].nRIGVFONr == nRIGVFONr) { + *nADATVFONr = the_adat_vfo_list.adat_vfos[ nI ].nADATVFONr; + nFini = 1; // Done. + } else { + nI++; + } + } - if( nFini == 0 ) - { - // No valid Mode given + if (nFini == 0) { + // No valid Mode given - nRC = -RIG_EINVAL; - } + nRC = -RIG_EINVAL; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, ADAT VFO Nr = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nADATVFONr ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, ADAT VFO Nr = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nADATVFONr); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1114,49 +1028,44 @@ int adat_vfo_rnr2anr( vfo_t nRIGVFONr, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_vfo_anr2rnr( int nADATVFONr, - vfo_t *nRIGVFONr ) +int adat_vfo_anr2rnr(int nADATVFONr, + vfo_t *nRIGVFONr) { - int nRC = RIG_OK; - int nI = 0; - int nFini = 0; + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: nADATVFONr = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nADATVFONr ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: nADATVFONr = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nADATVFONr); - while(( nI < the_adat_vfo_list.nNrVFOs ) && ( nFini == 0 )) - { - if( the_adat_vfo_list.adat_vfos[ nI ].nADATVFONr == nADATVFONr ) - { - *nRIGVFONr = the_adat_vfo_list.adat_vfos[ nI ].nRIGVFONr; - nFini = 1; // Done. - } - else - { - nI++; - } - } + while ((nI < the_adat_vfo_list.nNrVFOs) && (nFini == 0)) { + if (the_adat_vfo_list.adat_vfos[ nI ].nADATVFONr == nADATVFONr) { + *nRIGVFONr = the_adat_vfo_list.adat_vfos[ nI ].nRIGVFONr; + nFini = 1; // Done. + } else { + nI++; + } + } - if( nFini == 0 ) - { - // No valid ADAT VFO Nr given + if (nFini == 0) { + // No valid ADAT VFO Nr given - nRC = -RIG_EINVAL; - } + nRC = -RIG_EINVAL; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG VFO Nr = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nRIGVFONr ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG VFO Nr = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nRIGVFONr); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1164,39 +1073,36 @@ int adat_vfo_anr2rnr( int nADATVFONr, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_parse_ptt( char *pcStr, - int *nADATPTTStatus ) +int adat_parse_ptt(char *pcStr, + int *nADATPTTStatus) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", - gFnLevel, __func__, __FILE__, __LINE__, - pcStr ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pcStr = \"%s\"\n", + gFnLevel, __func__, __FILE__, __LINE__, + pcStr); - if(( pcStr != NULL ) && ( strlen( pcStr ) > 0 )) - { - *nADATPTTStatus = strtol( pcStr, NULL, 10 ); - } - else - { - // If input string is NULL ... + if ((pcStr != NULL) && (strlen(pcStr) > 0)) { + *nADATPTTStatus = strtol(pcStr, NULL, 10); + } else { + // If input string is NULL ... - *nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; - nRC = -RIG_EINVAL; - } + *nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; + nRC = -RIG_EINVAL; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1204,43 +1110,42 @@ int adat_parse_ptt( char *pcStr, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_ptt_rnr2anr( ptt_t nRIGPTTStatus, - int *nADATPTTStatus ) +int adat_ptt_rnr2anr(ptt_t nRIGPTTStatus, + int *nADATPTTStatus) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGPTTStatus = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRIGPTTStatus ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: nRIGPTTStatus = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRIGPTTStatus); - switch( nRIGPTTStatus ) - { - case ADAT_PTT_STATUS_RNR_ON: - *nADATPTTStatus = ADAT_PTT_STATUS_ANR_ON; - break; + switch (nRIGPTTStatus) { + case ADAT_PTT_STATUS_RNR_ON: + *nADATPTTStatus = ADAT_PTT_STATUS_ANR_ON; + break; - case ADAT_PTT_STATUS_RNR_OFF: - *nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; - break; + case ADAT_PTT_STATUS_RNR_OFF: + *nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; + break; - default: - nRC = -RIG_EINVAL; - break; - } + default: + nRC = -RIG_EINVAL; + break; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, ADAT PTT Status = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nADATPTTStatus ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, ADAT PTT Status = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nADATPTTStatus); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1248,42 +1153,41 @@ int adat_ptt_rnr2anr( ptt_t nRIGPTTStatus, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_ptt_anr2rnr( int nADATPTTStatus, - ptt_t *nRIGPTTStatus ) +int adat_ptt_anr2rnr(int nADATPTTStatus, + ptt_t *nRIGPTTStatus) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: nADATPTTStatus = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nADATPTTStatus ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: nADATPTTStatus = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nADATPTTStatus); - switch( nADATPTTStatus ) - { - case ADAT_PTT_STATUS_ANR_ON: - *nRIGPTTStatus = ADAT_PTT_STATUS_RNR_ON; - break; + switch (nADATPTTStatus) { + case ADAT_PTT_STATUS_ANR_ON: + *nRIGPTTStatus = ADAT_PTT_STATUS_RNR_ON; + break; - case ADAT_PTT_STATUS_ANR_OFF: - *nRIGPTTStatus = ADAT_PTT_STATUS_RNR_OFF; - break; + case ADAT_PTT_STATUS_ANR_OFF: + *nRIGPTTStatus = ADAT_PTT_STATUS_RNR_OFF; + break; - default: - nRC = -RIG_EINVAL; - break; - } + default: + nRC = -RIG_EINVAL; + break; + } - // Done + // Done - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG PTT Status = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, *nRIGPTTStatus ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d, RIG PTT Status = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, *nRIGPTTStatus); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1291,31 +1195,31 @@ int adat_ptt_anr2rnr( int nADATPTTStatus, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_send( RIG *pRig, - char *pcData ) +int adat_send(RIG *pRig, + char *pcData) { - int nRC = RIG_OK; - struct rig_state *pRigState = &pRig->state; + int nRC = RIG_OK; + struct rig_state *pRigState = &pRig->state; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x, pcData = %s\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig, pcData ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x, pcData = %s\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig, pcData); - serial_flush( &pRigState->rigport ); + serial_flush(&pRigState->rigport); - nRC = write_block( &pRigState->rigport, pcData, strlen( pcData )); + nRC = write_block(&pRigState->rigport, pcData, strlen(pcData)); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1323,34 +1227,33 @@ int adat_send( RIG *pRig, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_receive( RIG *pRig, - char *pcData ) +int adat_receive(RIG *pRig, + char *pcData) { - int nRC = RIG_OK; - struct rig_state *pRigState = &pRig->state; + int nRC = RIG_OK; + struct rig_state *pRigState = &pRig->state; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - nRC = read_string( &pRigState->rigport, pcData, ADAT_RESPSZ, ADAT_EOL, 1 ); + nRC = read_string(&pRigState->rigport, pcData, ADAT_RESPSZ, ADAT_EOL, 1); - if( nRC > 0 ) - { - nRC = RIG_OK; - } + if (nRC > 0) { + nRC = RIG_OK; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1358,42 +1261,39 @@ int adat_receive( RIG *pRig, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_priv_set_cmd( RIG *pRig, char *pcCmd, int nCmdKind ) +int adat_priv_set_cmd(RIG *pRig, char *pcCmd, int nCmdKind) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x, pcCmd = \"%s\"\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig, pcCmd ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x, pcCmd = \"%s\"\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig, pcCmd); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - if( pPriv->pcCmd != NULL ) - free( pPriv->pcCmd ); + if (pPriv->pcCmd != NULL) + free(pPriv->pcCmd); - pPriv->pcCmd = strdup( pcCmd ); - pPriv->nCmdKind = nCmdKind; - } + pPriv->pcCmd = strdup(pcCmd); + pPriv->nCmdKind = nCmdKind; + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1401,45 +1301,42 @@ int adat_priv_set_cmd( RIG *pRig, char *pcCmd, int nCmdKind ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_priv_set_result( RIG *pRig, char *pcResult ) +int adat_priv_set_result(RIG *pRig, char *pcResult) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x, pcResult = \"%s\"\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig, pcResult ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x, pcResult = \"%s\"\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig, pcResult); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - if( pPriv->pcResult != NULL ) - free( pPriv->pcResult ); + if (pPriv->pcResult != NULL) + free(pPriv->pcResult); - pPriv->pcResult = strdup( pcResult ); + pPriv->pcResult = strdup(pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcResult = \"%s\"\n", - gFnLevel, pPriv->pcResult ); - } + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcResult = \"%s\"\n", + gFnLevel, pPriv->pcResult); + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1447,41 +1344,38 @@ int adat_priv_set_result( RIG *pRig, char *pcResult ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_priv_clear_result( RIG *pRig ) +int adat_priv_clear_result(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - if( pPriv->pcResult != NULL ) - free( pPriv->pcResult ); + if (pPriv->pcResult != NULL) + free(pPriv->pcResult); - pPriv->pcResult = NULL; - } + pPriv->pcResult = NULL; + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1489,134 +1383,121 @@ int adat_priv_clear_result( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_get_single_cmd_result( RIG *pRig ) +int adat_get_single_cmd_result(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - struct rig_state *pRigState = &pRig->state; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + struct rig_state *pRigState = &pRig->state; - nRC = adat_send( pRig, pPriv->pcCmd ); + nRC = adat_send(pRig, pPriv->pcCmd); - if(( nRC == RIG_OK ) && - ( pPriv->nCmdKind == ADAT_CMD_KIND_WITH_RESULT )) - { - char acBuf[ ADAT_RESPSZ + 1 ]; - char acBuf2[ ADAT_RESPSZ + 1 ]; - int nBufLength = 0; - char *pcBufEnd = NULL; - char *pcPos = NULL; - char *pcResult = NULL; + if ((nRC == RIG_OK) && + (pPriv->nCmdKind == ADAT_CMD_KIND_WITH_RESULT)) { + char acBuf[ ADAT_RESPSZ + 1 ]; + char acBuf2[ ADAT_RESPSZ + 1 ]; + int nBufLength = 0; + char *pcBufEnd = NULL; + char *pcPos = NULL; + char *pcResult = NULL; - memset( acBuf, 0, ADAT_RESPSZ + 1 ); - memset( acBuf2, 0, ADAT_RESPSZ + 1 ); + memset(acBuf, 0, ADAT_RESPSZ + 1); + memset(acBuf2, 0, ADAT_RESPSZ + 1); - nRC = adat_receive( pRig, acBuf ); + nRC = adat_receive(pRig, acBuf); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d acBuf ........ = 0x%08x\n", - gFnLevel, acBuf ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d acBuf ........ = 0x%08x\n", + gFnLevel, acBuf); - pcPos = acBuf; + pcPos = acBuf; - if(( nRC == RIG_OK ) && ( pcPos != NULL )) - { - int nLength = 0; + if ((nRC == RIG_OK) && (pcPos != NULL)) { + int nLength = 0; - if( *pcPos == '\0' ) // Adjust for 00 byte at beginning ... - pcPos++; // No, please don't ask me why this - // happens ... ;-) + if (*pcPos == '\0') // Adjust for 00 byte at beginning ... + pcPos++; // No, please don't ask me why this - nBufLength = strlen( pcPos ); - pcBufEnd = pcPos + nBufLength - 1; + // happens ... ;-) - pcResult = pcPos; // Save position + nBufLength = strlen(pcPos); + pcBufEnd = pcPos + nBufLength - 1; - if( pcPos < pcBufEnd ) - { - nLength = strlen( pcPos ); + pcResult = pcPos; // Save position - if( nLength > 0 ) - { - char *pcPos2 = strchr( pcPos, (char) 0x0d ); - if( pcPos2 != NULL ) - *pcPos2 = '\0'; // Truncate \0d\0a + if (pcPos < pcBufEnd) { + nLength = strlen(pcPos); - pcPos = strchr( pcPos, ' ' ); + if (nLength > 0) { + char *pcPos2 = strchr(pcPos, (char) 0x0d); - if(( pcPos != NULL ) && ( pcPos < pcBufEnd )) - { - pcPos += sizeof( char ); + if (pcPos2 != NULL) + *pcPos2 = '\0'; // Truncate \0d\0a - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pcPos ........ = 0x%08x\n", - gFnLevel, pcPos ); + pcPos = strchr(pcPos, ' '); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pcBufEnd ..... = 0x%08x\n", - gFnLevel, pcBufEnd ); + if ((pcPos != NULL) && (pcPos < pcBufEnd)) { + pcPos += sizeof(char); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d nBufLength ... = %d\n", - gFnLevel, nBufLength ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pcPos ........ = 0x%08x\n", + gFnLevel, pcPos); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pcPos2 ....... = 0x%08x\n", - gFnLevel, pcPos2 ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pcBufEnd ..... = 0x%08x\n", + gFnLevel, pcBufEnd); - trimwhitespace( acBuf2, strlen( pcPos ), pcPos ); - pcResult = acBuf2; - } - } - else - { - nRC = -RIG_EINVAL; - } - } - else - { - nRC = -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d nBufLength ... = %d\n", + gFnLevel, nBufLength); - if( nRC == RIG_OK ) - { - adat_priv_set_result( pRig, pcResult ); - } - else - { - adat_priv_clear_result( pRig ); - } - } - } + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pcPos2 ....... = 0x%08x\n", + gFnLevel, pcPos2); - serial_flush( &pRigState->rigport ); + trimwhitespace(acBuf2, strlen(pcPos), pcPos); + pcResult = acBuf2; + } + } else { + nRC = -RIG_EINVAL; + } + } else { + nRC = -RIG_EINVAL; + } - pPriv->nRC = nRC; - } + if (nRC == RIG_OK) { + adat_priv_set_result(pRig, pcResult); + } else { + adat_priv_clear_result(pRig); + } + } + } - // Done ! + serial_flush(&pRigState->rigport); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + pPriv->nRC = nRC; + } - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -1624,56 +1505,52 @@ int adat_get_single_cmd_result( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_recover_from_error( RIG *pRig, int nError ) +int adat_cmd_recover_from_error(RIG *pRig, int nError) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - // Recover from communication error + // Recover from communication error - if(( nError == RIG_ETIMEOUT ) || - ( nError == RIG_EPROTO ) || - ( nError == RIG_EIO )) - { - rig_close( pRig ); - sleep( ADAT_SLEEP_AFTER_RIG_CLOSE ); + if ((nError == RIG_ETIMEOUT) || + (nError == RIG_EPROTO) || + (nError == RIG_EIO)) { + rig_close(pRig); + sleep(ADAT_SLEEP_AFTER_RIG_CLOSE); - rig_open( pRig ); - } + rig_open(pRig); + } - // Reset critical Priv values + // Reset critical Priv values - pPriv->nRC = RIG_OK; + pPriv->nRC = RIG_OK; - // Execute recovery commands + // Execute recovery commands - (void) adat_transaction( pRig, &adat_cmd_list_recover_from_error ); - } + (void) adat_transaction(pRig, &adat_cmd_list_recover_from_error); + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -1681,52 +1558,49 @@ int adat_cmd_recover_from_error( RIG *pRig, int nError ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_callsign( RIG *pRig ) +int adat_cmd_fn_get_callsign(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_CALLSIGN, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcCallsign = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_CALLSIGN, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcCallsign = \"%s\"\n", - gFnLevel, pPriv->pcCallsign ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcCallsign = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcCallsign = \"%s\"\n", + gFnLevel, pPriv->pcCallsign); + } + } + } - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -1734,48 +1608,45 @@ int adat_cmd_fn_get_callsign( RIG *pRig ) // --------------------------------------------------------------------------- // Status: IN WORK -int adat_cmd_fn_set_callsign( RIG *pRig ) +int adat_cmd_fn_set_callsign(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - char acBuf[ ADAT_BUFSZ + 1 ]; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + char acBuf[ ADAT_BUFSZ + 1 ]; - memset( acBuf, 0, ADAT_BUFSZ + 1 ); + memset(acBuf, 0, ADAT_BUFSZ + 1); - strcpy( acBuf, ADAT_CMD_DEF_STRING_SET_CALLSIGN ); - strcat( acBuf, "DG1SBG"ADAT_CR ); + strcpy(acBuf, ADAT_CMD_DEF_STRING_SET_CALLSIGN); + strcat(acBuf, "DG1SBG"ADAT_CR); - nRC = adat_priv_set_cmd( pRig, acBuf, - ADAT_CMD_KIND_WITHOUT_RESULT); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - } - } + nRC = adat_priv_set_cmd(pRig, acBuf, + ADAT_CMD_KIND_WITHOUT_RESULT); - // Done ! + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + // Done ! - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - return nRC; + gFnLevel--; + + return nRC; } @@ -1784,51 +1655,48 @@ int adat_cmd_fn_set_callsign( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_serial_nr( RIG *pRig ) +int adat_cmd_fn_get_serial_nr(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_SERIAL_NR, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcSerialNr = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_SERIAL_NR, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcSerialNr = \"%s\"\n", - gFnLevel, pPriv->pcSerialNr ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcSerialNr = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcSerialNr = \"%s\"\n", + gFnLevel, pPriv->pcSerialNr); + } + } + } - return nRC; + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -1836,52 +1704,49 @@ int adat_cmd_fn_get_serial_nr( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_fw_version( RIG *pRig ) +int adat_cmd_fn_get_fw_version(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_FW_VERSION, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcFWVersion = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_FW_VERSION, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcFWVersion = \"%s\"\n", - gFnLevel, pPriv->pcFWVersion ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcFWVersion = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcFWVersion = \"%s\"\n", + gFnLevel, pPriv->pcFWVersion); + } + } + } - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -1889,51 +1754,48 @@ int adat_cmd_fn_get_fw_version( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_hw_version( RIG *pRig ) +int adat_cmd_fn_get_hw_version(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_HW_VERSION, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcHWVersion = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_HW_VERSION, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcHWVersion = \"%s\"\n", - gFnLevel, pPriv->pcHWVersion ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcHWVersion = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcHWVersion = \"%s\"\n", + gFnLevel, pPriv->pcHWVersion); + } + } + } - return nRC; + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -1941,52 +1803,49 @@ int adat_cmd_fn_get_hw_version( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_gui_fw_version( RIG *pRig ) +int adat_cmd_fn_get_gui_fw_version(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_GUI_FW_VERSION, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcGUIFWVersion = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_GUI_FW_VERSION, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcGUIFWVersion = \"%s\"\n", - gFnLevel, pPriv->pcGUIFWVersion ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcGUIFWVersion = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcGUIFWVersion = \"%s\"\n", + gFnLevel, pPriv->pcGUIFWVersion); + } + } + } - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -1994,51 +1853,48 @@ int adat_cmd_fn_get_gui_fw_version( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_id_code( RIG *pRig ) +int adat_cmd_fn_get_id_code(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_ID_CODE, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcIDCode = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_ID_CODE, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcIDCode = \"%s\"\n", - gFnLevel, pPriv->pcIDCode ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcIDCode = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcIDCode = \"%s\"\n", + gFnLevel, pPriv->pcIDCode); + } + } + } - return nRC; + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2046,51 +1902,48 @@ int adat_cmd_fn_get_id_code( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_options( RIG *pRig ) +int adat_cmd_fn_get_options(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_OPTIONS, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - pPriv->pcOptions = strdup( pPriv->pcResult ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_OPTIONS, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->pcOptions = \"%s\"\n", - gFnLevel, pPriv->pcOptions ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + pPriv->pcOptions = strdup(pPriv->pcResult); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcOptions = \"%s\"\n", + gFnLevel, pPriv->pcOptions); + } + } + } - return nRC; + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2098,49 +1951,46 @@ int adat_cmd_fn_get_options( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_mode( RIG *pRig ) +int adat_cmd_fn_get_mode(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_MODE, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - nRC = adat_parse_mode( pPriv->pcResult, - &(pPriv->nRIGMode), - pPriv->acADATMode ); - } - } - } + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_MODE, + ADAT_CMD_KIND_WITH_RESULT); - // Done ! + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + if (nRC == RIG_OK) { + nRC = adat_parse_mode(pPriv->pcResult, + &(pPriv->nRIGMode), + pPriv->acADATMode); + } + } + } - return nRC; + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2148,63 +1998,58 @@ int adat_cmd_fn_get_mode( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_set_mode( RIG *pRig ) +int adat_cmd_fn_set_mode(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - // Translate Mode from RIG Mode Nr to ADAT Mode Nr + // Translate Mode from RIG Mode Nr to ADAT Mode Nr - nRC = adat_mode_rnr2anr( pPriv->nRIGMode, &(pPriv->nADATMode) ); + nRC = adat_mode_rnr2anr(pPriv->nRIGMode, &(pPriv->nADATMode)); - if( nRC == RIG_OK ) - { - // Prepare Command + if (nRC == RIG_OK) { + // Prepare Command - char acBuf[ ADAT_BUFSZ + 1 ]; + char acBuf[ ADAT_BUFSZ + 1 ]; - memset( acBuf, 0, ADAT_BUFSZ + 1 ); + memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf( acBuf, ADAT_BUFSZ, "%s%02d%s", - ADAT_CMD_DEF_STRING_SET_MODE, - (int) pPriv->nADATMode, - ADAT_EOM ); + snprintf(acBuf, ADAT_BUFSZ, "%s%02d%s", + ADAT_CMD_DEF_STRING_SET_MODE, + (int) pPriv->nADATMode, + ADAT_EOM); - nRC = adat_priv_set_cmd( pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT ); + nRC = adat_priv_set_cmd(pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT); - // Execute Command + // Execute Command - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); + } + } + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); - gFnLevel--; + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -2212,59 +2057,56 @@ int adat_cmd_fn_set_mode( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_freq( RIG *pRig ) +int adat_cmd_fn_get_freq(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_FREQ, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - nRC = adat_parse_freq( pPriv->pcResult, - ADAT_FREQ_PARSE_MODE_WITH_VFO, - &(pPriv->nCurrentVFO), - &(pPriv->nFreq) ); + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_FREQ, + ADAT_CMD_KIND_WITH_RESULT); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pPriv->nCurrentVFO = %d, Freq [Hz] = %f\n", - gFnLevel, pPriv->nCurrentVFO, pPriv->nFreq ); - if( nRC == RIG_OK ) - { - nRC = adat_vfo_anr2rnr( pPriv->nCurrentVFO, - &(pPriv->nRIGVFONr) ); - } - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + nRC = adat_parse_freq(pPriv->pcResult, + ADAT_FREQ_PARSE_MODE_WITH_VFO, + &(pPriv->nCurrentVFO), + &(pPriv->nFreq)); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->nCurrentVFO = %d, Freq [Hz] = %f\n", + gFnLevel, pPriv->nCurrentVFO, pPriv->nFreq); - return nRC; + if (nRC == RIG_OK) { + nRC = adat_vfo_anr2rnr(pPriv->nCurrentVFO, + &(pPriv->nRIGVFONr)); + } + } + } + } + + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2272,51 +2114,48 @@ int adat_cmd_fn_get_freq( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_set_freq( RIG *pRig ) +int adat_cmd_fn_set_freq(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - char acBuf[ ADAT_BUFSZ + 1 ]; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + char acBuf[ ADAT_BUFSZ + 1 ]; - // Get frequency of selected VFO + // Get frequency of selected VFO - memset( acBuf, 0, ADAT_BUFSZ + 1 ); + memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf( acBuf, ADAT_BUFSZ, "%s%d%s", - ADAT_CMD_DEF_STRING_SET_FREQ, - (int) pPriv->nFreq, - ADAT_EOM ); + snprintf(acBuf, ADAT_BUFSZ, "%s%d%s", + ADAT_CMD_DEF_STRING_SET_FREQ, + (int) pPriv->nFreq, + ADAT_EOM); - nRC = adat_priv_set_cmd( pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - } - } + nRC = adat_priv_set_cmd(pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT); - // Done ! + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2328,65 +2167,62 @@ int adat_cmd_fn_set_freq( RIG *pRig ) // 1. Switching on that VFO // 2. Setting this VFO as the main VFO -int adat_cmd_fn_set_vfo( RIG *pRig ) +int adat_cmd_fn_set_vfo(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - char acBuf[ ADAT_BUFSZ + 1 ]; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + char acBuf[ ADAT_BUFSZ + 1 ]; - // Switch on VFO + // Switch on VFO - memset( acBuf, 0, ADAT_BUFSZ + 1 ); + memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf( acBuf, ADAT_BUFSZ, ADAT_CMD_DEF_STRING_SWITCH_ON_VFO, - (int) pPriv->nCurrentVFO, - ADAT_EOM ); + snprintf(acBuf, ADAT_BUFSZ, ADAT_CMD_DEF_STRING_SWITCH_ON_VFO, + (int) pPriv->nCurrentVFO, + ADAT_EOM); - nRC = adat_priv_set_cmd( pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - memset( acBuf, 0, ADAT_BUFSZ + 1 ); - snprintf( acBuf, ADAT_BUFSZ, - ADAT_CMD_DEF_STRING_SET_VFO_AS_MAIN_VFO, - (int) pPriv->nCurrentVFO, - ADAT_EOM ); + nRC = adat_priv_set_cmd(pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT); - nRC = adat_priv_set_cmd( pRig, acBuf, - ADAT_CMD_KIND_WITHOUT_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - } - } - } - } + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - // Done ! + if (nRC == RIG_OK) { + memset(acBuf, 0, ADAT_BUFSZ + 1); + snprintf(acBuf, ADAT_BUFSZ, + ADAT_CMD_DEF_STRING_SET_VFO_AS_MAIN_VFO, + (int) pPriv->nCurrentVFO, + ADAT_EOM); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + nRC = adat_priv_set_cmd(pRig, acBuf, + ADAT_CMD_KIND_WITHOUT_RESULT); - return nRC; + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); + } + } + } + } + + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2394,53 +2230,50 @@ int adat_cmd_fn_set_vfo( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_get_ptt( RIG *pRig ) +int adat_cmd_fn_get_ptt(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_priv_set_cmd( pRig, - ADAT_CMD_DEF_STRING_GET_PTT, - ADAT_CMD_KIND_WITH_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - if( nRC == RIG_OK ) - { - nRC = adat_parse_ptt( pPriv->pcResult, - &(pPriv->nADATPTTStatus) ); - if( nRC == RIG_OK ) - { - nRC = adat_ptt_anr2rnr( pPriv->nADATPTTStatus, - &(pPriv->nRIGPTTStatus) ); - } - } - } - } + nRC = adat_priv_set_cmd(pRig, + ADAT_CMD_DEF_STRING_GET_PTT, + ADAT_CMD_KIND_WITH_RESULT); - // Done ! + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + if (nRC == RIG_OK) { + nRC = adat_parse_ptt(pPriv->pcResult, + &(pPriv->nADATPTTStatus)); - return nRC; + if (nRC == RIG_OK) { + nRC = adat_ptt_anr2rnr(pPriv->nADATPTTStatus, + &(pPriv->nRIGPTTStatus)); + } + } + } + } + + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2448,76 +2281,71 @@ int adat_cmd_fn_get_ptt( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cmd_fn_set_ptt( RIG *pRig ) +int adat_cmd_fn_set_ptt(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - char acBuf[ ADAT_BUFSZ + 1 ]; - char *pcPTTStr = NULL; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + char acBuf[ ADAT_BUFSZ + 1 ]; + char *pcPTTStr = NULL; - memset( acBuf, 0, ADAT_BUFSZ + 1 ); + memset(acBuf, 0, ADAT_BUFSZ + 1); - // Switch PTT + // Switch PTT - switch( pPriv->nOpCode ) - { - case ADAT_OPCODE_PTT_SWITCH_ON: + switch (pPriv->nOpCode) { + case ADAT_OPCODE_PTT_SWITCH_ON: - pPriv->nADATPTTStatus = ADAT_PTT_STATUS_ANR_ON; - nRC = adat_ptt_anr2rnr( ADAT_PTT_STATUS_ANR_ON, - &(pPriv->nRIGPTTStatus) ); - pcPTTStr = ADAT_CMD_PTT_STR_ON; - break; + pPriv->nADATPTTStatus = ADAT_PTT_STATUS_ANR_ON; + nRC = adat_ptt_anr2rnr(ADAT_PTT_STATUS_ANR_ON, + &(pPriv->nRIGPTTStatus)); + pcPTTStr = ADAT_CMD_PTT_STR_ON; + break; - case ADAT_OPCODE_PTT_SWITCH_OFF: - pPriv->nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; - nRC = adat_ptt_anr2rnr( ADAT_PTT_STATUS_ANR_OFF, - &(pPriv->nRIGPTTStatus) ); - pcPTTStr = ADAT_CMD_PTT_STR_OFF; - break; + case ADAT_OPCODE_PTT_SWITCH_OFF: + pPriv->nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; + nRC = adat_ptt_anr2rnr(ADAT_PTT_STATUS_ANR_OFF, + &(pPriv->nRIGPTTStatus)); + pcPTTStr = ADAT_CMD_PTT_STR_OFF; + break; - default: - nRC = -RIG_EINVAL; - break; - } + default: + nRC = -RIG_EINVAL; + break; + } - if( nRC == RIG_OK ) - { - snprintf( acBuf, ADAT_BUFSZ, ADAT_CMD_DEF_STRING_SET_PTT, - pcPTTStr, - ADAT_EOM ); + if (nRC == RIG_OK) { + snprintf(acBuf, ADAT_BUFSZ, ADAT_CMD_DEF_STRING_SET_PTT, + pcPTTStr, + ADAT_EOM); - nRC = adat_priv_set_cmd( pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT ); - if( nRC == RIG_OK ) - { - nRC = adat_get_single_cmd_result( pRig ); - } - } - } + nRC = adat_priv_set_cmd(pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT); - // Done ! + if (nRC == RIG_OK) { + nRC = adat_get_single_cmd_result(pRig); + } + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } @@ -2530,128 +2358,116 @@ int adat_cmd_fn_set_ptt( RIG *pRig ) // adat_transaction is a generalized command processor able to execute // commands of type adat_cmd_def_t . -int adat_transaction( RIG *pRig, - adat_cmd_list_ptr pCmdList ) +int adat_transaction(RIG *pRig, + adat_cmd_list_ptr pCmdList) { - int nRC = RIG_OK; - int nFini = 0; // = 1 -> Stop executing commands + int nRC = RIG_OK; + int nFini = 0; // = 1 -> Stop executing commands - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - int nI = 0; - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + int nI = 0; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): Nr of commands = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - pCmdList->nNrCmds ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): Nr of commands = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + pCmdList->nNrCmds); - while(( nRC == RIG_OK ) && ( nFini == 0 ) && ( nI < pCmdList->nNrCmds )) - { - adat_cmd_def_ptr pCmd = NULL; + while ((nRC == RIG_OK) && (nFini == 0) && (nI < pCmdList->nNrCmds)) { + adat_cmd_def_ptr pCmd = NULL; - pCmd = pCmdList->adat_cmds[ nI ]; + pCmd = pCmdList->adat_cmds[ nI ]; - if(( pCmd != NULL ) && ( pCmd->nCmdId != ADAT_CMD_DEF_NIL )) - { + if ((pCmd != NULL) && (pCmd->nCmdId != ADAT_CMD_DEF_NIL)) { - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d About to execute ADAT Command ... \n", - gFnLevel, __func__, __FILE__, __LINE__); - adat_print_cmd( pCmd ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d About to execute ADAT Command ... \n", + gFnLevel, __func__, __FILE__, __LINE__); + adat_print_cmd(pCmd); - // Execute Command + // Execute Command - if( pCmd->pfCmdFn != NULL ) - { - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d Calling function via fn ptr ... \n", - gFnLevel ); - nRC = pCmd->pfCmdFn( pRig ); - } - else - { - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d Sending command string ... \n", - gFnLevel ); + if (pCmd->pfCmdFn != NULL) { + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d Calling function via fn ptr ... \n", + gFnLevel); + nRC = pCmd->pfCmdFn(pRig); + } else { + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d Sending command string ... \n", + gFnLevel); +// TODO: Quell clang warning of conditional always evaluating to true. +// if( pCmd->pacCmdStrs != NULL ) +// { + int nJ = 0; - if( pCmd->pacCmdStrs != NULL ) - { - int nJ = 0; + if (pCmd->nNrCmdStrs > 0) { + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d pacCmdStrs[%d] = %s\n", + gFnLevel, nJ, pCmd->pacCmdStrs[ nJ ]); - if( pCmd->nNrCmdStrs > 0 ) - { - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d pacCmdStrs[%d] = %s\n", - gFnLevel, nJ, pCmd->pacCmdStrs[ nJ ] ); + while ((nJ < pCmd->nNrCmdStrs) && + (nRC == RIG_OK) && + (pCmd->pacCmdStrs[ nJ ] != NULL)) { + nRC = adat_send(pRig, pCmd->pacCmdStrs[ nJ ]); - while(( nJ < pCmd->nNrCmdStrs ) && - ( nRC == RIG_OK ) && - ( pCmd->pacCmdStrs[ nJ ] != NULL )) - { - nRC = adat_send( pRig, pCmd->pacCmdStrs[ nJ ] ); - if( nRC == RIG_OK ) - { - if( pCmd->nCmdKind == ADAT_CMD_KIND_WITH_RESULT ) - { - char acBuf[ ADAT_RESPSZ + 1 ]; + if (nRC == RIG_OK) { + if (pCmd->nCmdKind == ADAT_CMD_KIND_WITH_RESULT) { + char acBuf[ ADAT_RESPSZ + 1 ]; - memset( acBuf, 0, ADAT_RESPSZ + 1 ); + memset(acBuf, 0, ADAT_RESPSZ + 1); - nRC = adat_receive( pRig, acBuf ); - while(( nRC == RIG_OK ) && - ( strncmp( acBuf, ADAT_BOM, strlen( ADAT_BOM )) != 0)) - { - nRC = adat_receive( pRig, acBuf ); - } - pPriv->pcResult = strdup( acBuf ); - } - } + nRC = adat_receive(pRig, acBuf); - nJ++; - } - } - } - } + while ((nRC == RIG_OK) && + (strncmp(acBuf, ADAT_BOM, strlen(ADAT_BOM)) != 0)) { + nRC = adat_receive(pRig, acBuf); + } - if( nRC != RIG_OK ) - { - (void) adat_cmd_recover_from_error( pRig, nRC ); - } + pPriv->pcResult = strdup(acBuf); + } + } - nI++; - } - else - { - nFini = 1; - } + nJ++; + } + } - // sleep between cmds - ADAT needs time to act upoon cmds +// } + } - usleep( ADAT_SLEEP_MICROSECONDS_BETWEEN_CMDS ); - } - } + if (nRC != RIG_OK) { + (void) adat_cmd_recover_from_error(pRig, nRC); + } - // Done ! + nI++; + } else { + nFini = 1; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + // sleep between cmds - ADAT needs time to act upoon cmds - return nRC; + usleep(ADAT_SLEEP_MICROSECONDS_BETWEEN_CMDS); + } + } + + // Done ! + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2659,58 +2475,54 @@ int adat_transaction( RIG *pRig, // --------------------------------------------------------------------------- // Status: RELEASED -adat_priv_data_ptr adat_new_priv_data( RIG *pRig ) +adat_priv_data_ptr adat_new_priv_data(RIG *pRig) { - int nRC = 0; - adat_priv_data_ptr pPriv = NULL; + int nRC = 0; + adat_priv_data_ptr pPriv = NULL; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig != NULL ) - { - // Init Priv Data + if (pRig != NULL) { + // Init Priv Data - pPriv = (adat_priv_data_ptr) calloc( sizeof( adat_priv_data_t ), 1 ); - if ( pPriv != NULL ) - { - char acBuf[ ADAT_BUFSZ + 1 ]; - memset( acBuf, 0, ADAT_BUFSZ + 1 ); + pPriv = (adat_priv_data_ptr) calloc(sizeof(adat_priv_data_t), 1); - // FIXME: pointless code at init time + if (pPriv != NULL) { + char acBuf[ ADAT_BUFSZ + 1 ]; + memset(acBuf, 0, ADAT_BUFSZ + 1); + + // FIXME: pointless code at init time #if 0 - nRC = adat_get_conf( pRig, TOKEN_ADAT_PRODUCT_NAME, acBuf ); - if( nRC == 0) - { - pPriv->pcProductName = strdup( acBuf ); + nRC = adat_get_conf(pRig, TOKEN_ADAT_PRODUCT_NAME, acBuf); + + if (nRC == 0) { + pPriv->pcProductName = strdup(acBuf); + + pRig->state.priv = (void *) pPriv; + } - pRig->state.priv = (void *) pPriv; - } #else - pRig->state.priv = (void *) pPriv; + pRig->state.priv = (void *) pPriv; #endif - } - else - { - nRC = -RIG_ENOMEM; - } - } - else - { - nRC = -RIG_EARG; - } + } else { + nRC = -RIG_ENOMEM; + } + } else { + nRC = -RIG_EARG; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. RC = %d, pPriv = 0x%x\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC, pPriv ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. RC = %d, pPriv = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC, pPriv); + gFnLevel--; - return pPriv; + return pPriv; } // --------------------------------------------------------------------------- @@ -2718,78 +2530,67 @@ adat_priv_data_ptr adat_new_priv_data( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -void adat_del_priv_data( adat_priv_data_t **ppPriv ) +void adat_del_priv_data(adat_priv_data_t **ppPriv) { - int nRC = 0; + int nRC = 0; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: ppPrivData = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - ppPriv ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: ppPrivData = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + ppPriv); - if(( ppPriv != NULL ) && ( *ppPriv != NULL )) - { - // Delete / Free Priv Data + if ((ppPriv != NULL) && (*ppPriv != NULL)) { + // Delete / Free Priv Data - if( (*ppPriv)->pcProductName != NULL ) - { - free( (*ppPriv)->pcProductName ); - } + if ((*ppPriv)->pcProductName != NULL) { + free((*ppPriv)->pcProductName); + } - if( (*ppPriv)->pcSerialNr != NULL ) - { - free( (*ppPriv)->pcSerialNr ); - } + if ((*ppPriv)->pcSerialNr != NULL) { + free((*ppPriv)->pcSerialNr); + } - if( (*ppPriv)->pcHWVersion != NULL ) - { - free( (*ppPriv)->pcHWVersion ); - } + if ((*ppPriv)->pcHWVersion != NULL) { + free((*ppPriv)->pcHWVersion); + } - if( (*ppPriv)->pcFWVersion != NULL ) - { - free( (*ppPriv)->pcFWVersion ); - } + if ((*ppPriv)->pcFWVersion != NULL) { + free((*ppPriv)->pcFWVersion); + } - if( (*ppPriv)->pcGUIFWVersion != NULL ) - { - free( (*ppPriv)->pcGUIFWVersion ); - } + if ((*ppPriv)->pcGUIFWVersion != NULL) { + free((*ppPriv)->pcGUIFWVersion); + } - if( (*ppPriv)->pcOptions != NULL ) - { - free( (*ppPriv)->pcOptions ); - } + if ((*ppPriv)->pcOptions != NULL) { + free((*ppPriv)->pcOptions); + } - if( (*ppPriv)->pcIDCode != NULL ) - { - free( (*ppPriv)->pcIDCode ); - } + if ((*ppPriv)->pcIDCode != NULL) { + free((*ppPriv)->pcIDCode); + } - if( (*ppPriv)->pcCallsign != NULL ) - { - free( (*ppPriv)->pcCallsign ); - } + if ((*ppPriv)->pcCallsign != NULL) { + free((*ppPriv)->pcCallsign); + } - // Free priv struct itself + // Free priv struct itself - free( (*ppPriv) ); - *ppPriv = NULL; - } - else - { - nRC = -RIG_EARG; - } + free((*ppPriv)); + *ppPriv = NULL; + } else { + nRC = -RIG_EARG; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. RC = %d.\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. RC = %d.\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return; + return; }; // --------------------------------------------------------------------------- @@ -2797,45 +2598,42 @@ void adat_del_priv_data( adat_priv_data_t **ppPriv ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_init( RIG *pRig ) +int adat_init(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = NULL; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = NULL; - // Get new Priv Data + // Get new Priv Data - pPriv = adat_new_priv_data( pRig ); - if( pPriv == NULL ) - { - nRC = -RIG_ENOMEM; - } - } + pPriv = adat_new_priv_data(pRig); - // Done ! + if (pPriv == NULL) { + nRC = -RIG_ENOMEM; + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + // Done ! - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -2843,37 +2641,33 @@ int adat_init( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_cleanup( RIG *pRig ) +int adat_cleanup(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - if( pRig->state.priv != NULL ) - { - adat_del_priv_data( (adat_priv_data_t **)&(pRig->state.priv) ); - pRig->state.priv = NULL; - } - } + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + if (pRig->state.priv != NULL) { + adat_del_priv_data((adat_priv_data_t **) & (pRig->state.priv)); + pRig->state.priv = NULL; + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -2881,43 +2675,40 @@ int adat_cleanup( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_open( RIG *pRig ) +int adat_open(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - // grace period for the radio to be there + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + // grace period for the radio to be there - sleep( ADAT_SLEEP_AFTER_RIG_OPEN ); + sleep(ADAT_SLEEP_AFTER_RIG_OPEN); - // Now get basic info from ADAT TRX + // Now get basic info from ADAT TRX - nRC = adat_transaction( pRig, &adat_cmd_list_open_adat ); - } + nRC = adat_transaction(pRig, &adat_cmd_list_open_adat); + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -2925,39 +2716,36 @@ int adat_open( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_close( RIG *pRig ) +int adat_close(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - // Now switch to interactive mode + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + // Now switch to interactive mode - nRC = adat_transaction( pRig, &adat_cmd_list_close_adat ); - } + nRC = adat_transaction(pRig, &adat_cmd_list_close_adat); + } - // Done ! + // Done ! - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -2965,46 +2753,45 @@ int adat_close( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -const char * adat_get_info( RIG *pRig ) +const char *adat_get_info(RIG *pRig) { - int nRC = RIG_OK; - static char acBuf[ 512 ]; + int nRC = RIG_OK; + static char acBuf[ 512 ]; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - memset( acBuf, 0, 512 ); + memset(acBuf, 0, 512); - if( pRig != NULL ) - { - nRC = adat_transaction( pRig, &adat_cmd_list_get_info ); - if( nRC == RIG_OK ) - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig != NULL) { + nRC = adat_transaction(pRig, &adat_cmd_list_get_info); - snprintf( acBuf, 512, - "ADAT ADT-200A, Callsign: %s, S/N: %s, ID Code: %s, Options: %s, FW: %s, GUI FW: %s, HW: %s", - pPriv->pcCallsign, - pPriv->pcSerialNr, - pPriv->pcIDCode, - pPriv->pcOptions, - pPriv->pcFWVersion, - pPriv->pcGUIFWVersion, - pPriv->pcHWVersion ); - } - } + if (nRC == RIG_OK) { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Value ='%s'\n", - gFnLevel, __func__, __FILE__, __LINE__, - acBuf ); - gFnLevel--; + snprintf(acBuf, 512, + "ADAT ADT-200A, Callsign: %s, S/N: %s, ID Code: %s, Options: %s, FW: %s, GUI FW: %s, HW: %s", + pPriv->pcCallsign, + pPriv->pcSerialNr, + pPriv->pcIDCode, + pPriv->pcOptions, + pPriv->pcFWVersion, + pPriv->pcGUIFWVersion, + pPriv->pcHWVersion); + } + } - return acBuf; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Value ='%s'\n", + gFnLevel, __func__, __FILE__, __LINE__, + acBuf); + gFnLevel--; + + return acBuf; } // --------------------------------------------------------------------------- @@ -3012,39 +2799,36 @@ const char * adat_get_info( RIG *pRig ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_set_freq( RIG *pRig, vfo_t vfo, freq_t freq ) +int adat_set_freq(RIG *pRig, vfo_t vfo, freq_t freq) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - pPriv->nFreq = freq; + pPriv->nFreq = freq; - nRC = adat_transaction( pRig, &adat_cmd_list_set_freq ); - } + nRC = adat_transaction(pRig, &adat_cmd_list_set_freq); + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3052,39 +2836,36 @@ int adat_set_freq( RIG *pRig, vfo_t vfo, freq_t freq ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_get_freq( RIG *pRig, vfo_t vfo, freq_t *freq ) +int adat_get_freq(RIG *pRig, vfo_t vfo, freq_t *freq) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_transaction( pRig, &adat_cmd_list_get_freq ); + nRC = adat_transaction(pRig, &adat_cmd_list_get_freq); - *freq = pPriv->nFreq; - } + *freq = pPriv->nFreq; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3092,36 +2873,33 @@ int adat_get_freq( RIG *pRig, vfo_t vfo, freq_t *freq ) // --------------------------------------------------------------------------- // Status: IN WORK -int adat_set_level( RIG *pRig, vfo_t vfo, setting_t level, value_t val ) +int adat_set_level(RIG *pRig, vfo_t vfo, setting_t level, value_t val) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3129,36 +2907,33 @@ int adat_set_level( RIG *pRig, vfo_t vfo, setting_t level, value_t val ) // --------------------------------------------------------------------------- // Status: IN WORK -int adat_get_level( RIG *pRig, vfo_t vfo, setting_t level, value_t *val ) +int adat_get_level(RIG *pRig, vfo_t vfo, setting_t level, value_t *val) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3166,45 +2941,42 @@ int adat_get_level( RIG *pRig, vfo_t vfo, setting_t level, value_t *val ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_set_mode(RIG *pRig, vfo_t vfo, rmode_t mode, pbwidth_t width ) +int adat_set_mode(RIG *pRig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - pPriv->nRIGMode = mode; - nRC = adat_vfo_rnr2anr( vfo, &(pPriv->nCurrentVFO) ); + pPriv->nRIGMode = mode; + nRC = adat_vfo_rnr2anr(vfo, &(pPriv->nCurrentVFO)); - if( width == RIG_PASSBAND_NORMAL ) - width = rig_passband_normal( pRig, mode ); + if (width == RIG_PASSBAND_NORMAL) + width = rig_passband_normal(pRig, mode); - pPriv->nWidth = width; + pPriv->nWidth = width; - nRC = adat_transaction( pRig, &adat_cmd_list_set_mode ); - } + nRC = adat_transaction(pRig, &adat_cmd_list_set_mode); + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3212,40 +2984,37 @@ int adat_set_mode(RIG *pRig, vfo_t vfo, rmode_t mode, pbwidth_t width ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_get_mode( RIG *pRig, vfo_t vfo, rmode_t *mode, pbwidth_t *width ) +int adat_get_mode(RIG *pRig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_transaction( pRig, &adat_cmd_list_get_mode ); - if( nRC == RIG_OK ) - { - *mode = pPriv->nRIGMode; - *width = pPriv->nWidth; - } - } + nRC = adat_transaction(pRig, &adat_cmd_list_get_mode); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + if (nRC == RIG_OK) { + *mode = pPriv->nRIGMode; + *width = pPriv->nWidth; + } + } + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; return nRC; } @@ -3255,39 +3024,36 @@ int adat_get_mode( RIG *pRig, vfo_t vfo, rmode_t *mode, pbwidth_t *width ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_get_vfo( RIG *pRig, vfo_t *vfo ) +int adat_get_vfo(RIG *pRig, vfo_t *vfo) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_transaction( pRig, &adat_cmd_list_get_vfo ); + nRC = adat_transaction(pRig, &adat_cmd_list_get_vfo); - *vfo = pPriv->nRIGVFONr; - } + *vfo = pPriv->nRIGVFONr; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3295,41 +3061,38 @@ int adat_get_vfo( RIG *pRig, vfo_t *vfo ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_set_vfo( RIG *pRig, vfo_t vfo ) +int adat_set_vfo(RIG *pRig, vfo_t vfo) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_vfo_rnr2anr( vfo, &(pPriv->nCurrentVFO) ); - if( nRC == RIG_OK ) - { - nRC = adat_transaction( pRig, &adat_cmd_list_set_vfo ); - } - } + nRC = adat_vfo_rnr2anr(vfo, &(pPriv->nCurrentVFO)); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + if (nRC == RIG_OK) { + nRC = adat_transaction(pRig, &adat_cmd_list_set_vfo); + } + } - return nRC; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; + + return nRC; } // --------------------------------------------------------------------------- @@ -3337,39 +3100,36 @@ int adat_set_vfo( RIG *pRig, vfo_t vfo ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_get_ptt( RIG *pRig, vfo_t vfo, ptt_t *ptt ) +int adat_get_ptt(RIG *pRig, vfo_t vfo, ptt_t *ptt) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_transaction( pRig, &adat_cmd_list_get_ptt ); + nRC = adat_transaction(pRig, &adat_cmd_list_get_ptt); - *ptt = pPriv->nRIGPTTStatus; - } + *ptt = pPriv->nRIGPTTStatus; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3377,55 +3137,50 @@ int adat_get_ptt( RIG *pRig, vfo_t vfo, ptt_t *ptt ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_set_ptt( RIG *pRig, vfo_t vfo, ptt_t ptt ) +int adat_set_ptt(RIG *pRig, vfo_t vfo, ptt_t ptt) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - switch( ptt ) - { - case RIG_PTT_ON: - pPriv->nOpCode = ADAT_OPCODE_PTT_SWITCH_ON; - break; + switch (ptt) { + case RIG_PTT_ON: + pPriv->nOpCode = ADAT_OPCODE_PTT_SWITCH_ON; + break; - case RIG_PTT_OFF: - pPriv->nOpCode = ADAT_OPCODE_PTT_SWITCH_OFF; - break; + case RIG_PTT_OFF: + pPriv->nOpCode = ADAT_OPCODE_PTT_SWITCH_OFF; + break; - default: - nRC = -RIG_EINVAL; - break; - } + default: + nRC = -RIG_EINVAL; + break; + } - if( nRC == RIG_OK ) - { - nRC = adat_transaction( pRig, &adat_cmd_list_set_ptt ); - } - } + if (nRC == RIG_OK) { + nRC = adat_transaction(pRig, &adat_cmd_list_set_ptt); + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3433,36 +3188,33 @@ int adat_set_ptt( RIG *pRig, vfo_t vfo, ptt_t ptt ) // --------------------------------------------------------------------------- // Status: RELEASED -int adat_power2mW( RIG * pRig, unsigned int *mwpower, float power, - freq_t freq, rmode_t mode ) +int adat_power2mW(RIG *pRig, unsigned int *mwpower, float power, + freq_t freq, rmode_t mode) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if(( pRig == NULL ) || ( mwpower == NULL )) - { - nRC = -RIG_EARG; - } - else - { - *mwpower = power * ADAT_MAX_POWER_IN_mW; - } + if ((pRig == NULL) || (mwpower == NULL)) { + nRC = -RIG_EARG; + } else { + *mwpower = power * ADAT_MAX_POWER_IN_mW; + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3470,36 +3222,33 @@ int adat_power2mW( RIG * pRig, unsigned int *mwpower, float power, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_mW2power( RIG * pRig, float *power, unsigned int mwpower, - freq_t freq, rmode_t mode ) +int adat_mW2power(RIG *pRig, float *power, unsigned int mwpower, + freq_t freq, rmode_t mode) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if(( pRig == NULL ) || ( power == NULL )) - { - nRC = -RIG_EARG; - } - else - { - *power = mwpower / ((float)ADAT_MAX_POWER_IN_mW); - } + if ((pRig == NULL) || (power == NULL)) { + nRC = -RIG_EARG; + } else { + *power = mwpower / ((float)ADAT_MAX_POWER_IN_mW); + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } // --------------------------------------------------------------------------- @@ -3507,49 +3256,43 @@ int adat_mW2power( RIG * pRig, float *power, unsigned int mwpower, // --------------------------------------------------------------------------- // Status: RELEASED -int adat_get_powerstat( RIG *pRig, powerstat_t *status ) +int adat_get_powerstat(RIG *pRig, powerstat_t *status) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - nRC = adat_transaction( pRig, &adat_cmd_list_get_powerstatus ); + nRC = adat_transaction(pRig, &adat_cmd_list_get_powerstatus); - // nRC < 0 -> Power is off. + // nRC < 0 -> Power is off. - if( nRC == RIG_OK ) - { - *status = RIG_POWER_ON; - } - else - { - *status = RIG_POWER_OFF; - nRC = RIG_OK; - } - } + if (nRC == RIG_OK) { + *status = RIG_POWER_ON; + } else { + *status = RIG_POWER_OFF; + nRC = RIG_OK; + } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; - return nRC; + return nRC; } @@ -3558,42 +3301,39 @@ int adat_get_powerstat( RIG *pRig, powerstat_t *status ) // --------------------------------------------------------------------------- // Status: IN WORK -int adat_set_conf( RIG *pRig, token_t token, const char *val ) +int adat_set_conf(RIG *pRig, token_t token, const char *val) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - switch( token ) - { - case TOKEN_ADAT_PRODUCT_NAME: - pPriv->pcProductName = strdup( val ); - break; - default: - nRC = -RIG_EINVAL; - } - } + switch (token) { + case TOKEN_ADAT_PRODUCT_NAME: + pPriv->pcProductName = strdup(val); + break; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + default: + nRC = -RIG_EINVAL; + } + } + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; return nRC; } @@ -3605,40 +3345,37 @@ int adat_set_conf( RIG *pRig, token_t token, const char *val ) int adat_get_conf(RIG *pRig, token_t token, char *val) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - switch( token ) - { - case TOKEN_ADAT_PRODUCT_NAME: - val = pPriv->pcProductName; - break; - default: - nRC = -RIG_EINVAL; - } - } + switch (token) { + case TOKEN_ADAT_PRODUCT_NAME: + val = pPriv->pcProductName; + break; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + default: + nRC = -RIG_EINVAL; + } + } + + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; return nRC; } @@ -3648,34 +3385,31 @@ int adat_get_conf(RIG *pRig, token_t token, char *val) // --------------------------------------------------------------------------- // Status: IN WORK -int adat_reset( RIG *pRig, reset_t reset ) +int adat_reset(RIG *pRig, reset_t reset) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - } + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; return nRC; } @@ -3685,41 +3419,38 @@ int adat_reset( RIG *pRig, reset_t reset ) // --------------------------------------------------------------------------- // Status: IN WORK -int adat_handle_event( RIG *pRig ) +int adat_handle_event(RIG *pRig) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", - gFnLevel, __func__, __FILE__, __LINE__, - pRig ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig); - // Check Params + // Check Params - if( pRig == NULL ) - { - nRC = -RIG_EARG; - } - else - { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - char acBuf[ ADAT_RESPSZ + 1 ]; + if (pRig == NULL) { + nRC = -RIG_EARG; + } else { + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + char acBuf[ ADAT_RESPSZ + 1 ]; - memset( acBuf, 0, ADAT_RESPSZ + 1 ); - adat_receive( pRig, acBuf ); + memset(acBuf, 0, ADAT_RESPSZ + 1); + adat_receive(pRig, acBuf); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d Event data = \"%s\"\n", - gFnLevel, acBuf ); - } + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d Event data = \"%s\"\n", + gFnLevel, acBuf); + } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; return nRC; } @@ -3732,26 +3463,26 @@ int adat_handle_event( RIG *pRig ) DECLARE_INITRIG_BACKEND(adat) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; #if 0 - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY.\n", - gFnLevel, __func__, __FILE__, __LINE__ ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY.\n", + gFnLevel, __func__, __FILE__, __LINE__); #endif - rig_register( &adt_200a_caps ); + rig_register(&adt_200a_caps); #if 0 - rig_debug( RIG_DEBUG_VERBOSE, "ADAT: Rig ADT-200A registered.\n" ); + rig_debug(RIG_DEBUG_VERBOSE, "ADAT: Rig ADT-200A registered.\n"); - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); #endif - gFnLevel--; + gFnLevel--; return nRC; } @@ -3763,13 +3494,13 @@ DECLARE_INITRIG_BACKEND(adat) DECLARE_PROBERIG_BACKEND(adat) { - int nRC = RIG_OK; + int nRC = RIG_OK; - gFnLevel++; + gFnLevel++; - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): ENTRY.\n", - gFnLevel, __func__, __FILE__, __LINE__ ); + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY.\n", + gFnLevel, __func__, __FILE__, __LINE__); if (!port) return RIG_MODEL_NONE; @@ -3784,41 +3515,35 @@ DECLARE_PROBERIG_BACKEND(adat) nRC = serial_open(port); - if( nRC != RIG_OK) - { - nRC = RIG_MODEL_NONE; - } - else - { - char acBuf[ ADAT_RESPSZ + 1 ]; - int nRead = 0; + if (nRC != RIG_OK) { + nRC = RIG_MODEL_NONE; + } else { + char acBuf[ ADAT_RESPSZ + 1 ]; + int nRead = 0; - memset( acBuf, 0, ADAT_RESPSZ + 1 ); + memset(acBuf, 0, ADAT_RESPSZ + 1); - nRC = write_block( port, - ADAT_CMD_DEF_STRING_GET_ID_CODE, - strlen( ADAT_CMD_DEF_STRING_GET_ID_CODE ) ); + nRC = write_block(port, + ADAT_CMD_DEF_STRING_GET_ID_CODE, + strlen(ADAT_CMD_DEF_STRING_GET_ID_CODE)); nRead = read_string(port, acBuf, ADAT_RESPSZ, ADAT_EOM, 1); - close( port->fd ); + close(port->fd); - if(( nRC != RIG_OK || nRead < 0 )) - { - nRC = RIG_MODEL_NONE; - } - else - { - rig_debug( RIG_DEBUG_VERBOSE, "ADAT: %d Received ID = %s.", - gFnLevel, acBuf ); + if ((nRC != RIG_OK || nRead < 0)) { + nRC = RIG_MODEL_NONE; + } else { + rig_debug(RIG_DEBUG_VERBOSE, "ADAT: %d Received ID = %s.", + gFnLevel, acBuf); - nRC = RIG_MODEL_ADT_200A; - } + nRC = RIG_MODEL_ADT_200A; + } } - rig_debug( RIG_DEBUG_TRACE, - "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", - gFnLevel, __func__, __FILE__, __LINE__, - nRC ); - gFnLevel--; + rig_debug(RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC); + gFnLevel--; return nRC; } diff --git a/drake/drake.c b/drake/drake.c index 440ba747a..16563c3ac 100644 --- a/drake/drake.c +++ b/drake/drake.c @@ -83,6 +83,7 @@ int drake_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d if (retval == -RIG_ETIMEOUT) retval = 0; + if (retval < 0) return retval; @@ -127,7 +128,7 @@ int drake_set_freq(RIG *rig, vfo_t vfo, freq_t freq) * 10Hz resolution * TODO: round nearest? */ - freq_len = sprintf((char *) freqbuf,"F%07d" EOM, (unsigned int)freq/10); + freq_len = sprintf((char *) freqbuf, "F%07d" EOM, (unsigned int)freq / 10); retval = drake_transaction(rig, (char *) freqbuf, freq_len, (char *) ackbuf, &ack_len); return retval; @@ -145,14 +146,14 @@ int drake_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) double f; char fmult; - retval = drake_transaction (rig, "RF" EOM, 3, freqbuf, &freq_len); + retval = drake_transaction(rig, "RF" EOM, 3, freqbuf, &freq_len); if (retval != RIG_OK) return retval; /* RA command returns *fffff.ff*mHz */ if (freq_len != 15) { - rig_debug(RIG_DEBUG_ERR,"drake_get_freq: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_freq: wrong answer %s, " "len=%d\n", freqbuf, freq_len); return -RIG_ERJCTED; } @@ -161,10 +162,10 @@ int drake_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) freqbuf[9] = '\0'; /* extract freq */ - sscanf(freqbuf+1, "%lf", &f); + sscanf(freqbuf + 1, "%lf", &f); f *= 1000.0; - if (fmult=='M'||fmult=='m') + if (fmult == 'M' || fmult == 'm') f *= 1000.0; *freq = (freq_t)f; @@ -184,23 +185,28 @@ int drake_set_vfo(RIG *rig, vfo_t vfo) switch (vfo) { case RIG_VFO_A : vfo_function = 'A'; break; + case RIG_VFO_B : vfo_function = 'B'; break; + case RIG_VFO_VFO: vfo_function = 'F'; break; + case RIG_VFO_MEM: vfo_function = 'C'; break; + default: - rig_debug(RIG_DEBUG_ERR,"drake_set_vfo: unsupported VFO %d\n", + rig_debug(RIG_DEBUG_ERR, "drake_set_vfo: unsupported VFO %d\n", vfo); return -RIG_EINVAL; } cmd_len = 0; - if ((vfo_function=='A')||(vfo_function=='B')) + if ((vfo_function == 'A') || (vfo_function == 'B')) cmd_len = sprintf((char *) cmdbuf, "V%c" EOM, vfo_function); - if ((vfo_function=='F')||(vfo_function=='C')) + + if ((vfo_function == 'F') || (vfo_function == 'C')) cmd_len = sprintf((char *) cmdbuf, "%c" EOM, vfo_function); - retval = drake_transaction (rig, (char *) cmdbuf, cmd_len, (char *) ackbuf, &ack_len); + retval = drake_transaction(rig, (char *) cmdbuf, cmd_len, (char *) ackbuf, &ack_len); return retval; } @@ -215,26 +221,29 @@ int drake_get_vfo(RIG *rig, vfo_t *vfo) char mdbuf[BUFSZ]; char cvfo; - retval = drake_transaction (rig, "RA" EOM, 3, mdbuf, &mdbuf_len); + retval = drake_transaction(rig, "RA" EOM, 3, mdbuf, &mdbuf_len); if (retval != RIG_OK) return retval; if (mdbuf_len < 35) { - rig_debug(RIG_DEBUG_ERR,"drake_get_vfo: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_vfo: wrong answer %s, " "len=%d\n", mdbuf, mdbuf_len); return -RIG_ERJCTED; } - if (mdbuf[0]=='*') + if (mdbuf[0] == '*') *vfo = RIG_VFO_MEM; else { cvfo = (mdbuf[9] & 0x38); + switch (cvfo) { case '0' : *vfo = RIG_VFO_B; break; + case '8' : *vfo = RIG_VFO_A; break; + default : rig_debug(RIG_DEBUG_ERR, - "drake_get_vfo: unsupported vfo %c\n", cvfo); + "drake_get_vfo: unsupported vfo %c\n", cvfo); *vfo = RIG_VFO_VFO; return -RIG_EINVAL; } @@ -255,22 +264,28 @@ int drake_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) switch (mode) { case RIG_MODE_CW: mode_sel = MD_CW; break; + case RIG_MODE_ECSSUSB: case RIG_MODE_USB: mode_sel = MD_USB; break; + case RIG_MODE_ECSSLSB: case RIG_MODE_LSB: mode_sel = MD_LSB; break; + case RIG_MODE_FM: mode_sel = MD_FM; break; + case RIG_MODE_AMS: case RIG_MODE_AM: mode_sel = MD_AM; break; + case RIG_MODE_RTTY: mode_sel = MD_RTTY; break; + default: - rig_debug(RIG_DEBUG_ERR,"drake_set_mode: " + rig_debug(RIG_DEBUG_ERR, "drake_set_mode: " "unsupported mode %d\n", mode); return -RIG_EINVAL; } mdbuf_len = sprintf((char *) mdbuf, "M%c" EOM, mode_sel); - retval = drake_transaction (rig, (char *) mdbuf, mdbuf_len, (char *) ackbuf, &ack_len); + retval = drake_transaction(rig, (char *) mdbuf, mdbuf_len, (char *) ackbuf, &ack_len); if (retval != RIG_OK) return retval; @@ -282,25 +297,31 @@ int drake_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) switch (width) { case 500: width_sel = '0'; break; + case 1800: width_sel = '1'; break; + case 2300: width_sel = '2'; break; + case 4000: width_sel = '4'; break; + case 6000: width_sel = '6'; break; + default: - rig_debug(RIG_DEBUG_ERR,"drake_set_mode: " + rig_debug(RIG_DEBUG_ERR, "drake_set_mode: " "unsupported width %d\n", width); return -RIG_EINVAL; } + mdbuf_len = sprintf((char *) mdbuf, "W%c" EOM, width_sel); - retval = drake_transaction (rig, (char *) mdbuf, mdbuf_len, (char *) ackbuf, &ack_len); + retval = drake_transaction(rig, (char *) mdbuf, mdbuf_len, (char *) ackbuf, &ack_len); } if ((mode == RIG_MODE_AMS) || (mode == RIG_MODE_ECSSUSB) || (mode == RIG_MODE_ECSSLSB) || (mode == RIG_MODE_AM) || (mode == RIG_MODE_USB) || (mode == RIG_MODE_LSB)) { mdbuf_len = sprintf((char *) mdbuf, "S%c" EOM, - ((mode == RIG_MODE_AMS) || (mode==RIG_MODE_ECSSUSB) || (mode==RIG_MODE_ECSSLSB)) + ((mode == RIG_MODE_AMS) || (mode == RIG_MODE_ECSSUSB) || (mode == RIG_MODE_ECSSLSB)) ? 'O' : 'F'); - retval = drake_transaction (rig, (char *) mdbuf, mdbuf_len, (char *) ackbuf, &ack_len); + retval = drake_transaction(rig, (char *) mdbuf, mdbuf_len, (char *) ackbuf, &ack_len); } return retval; @@ -314,18 +335,18 @@ int drake_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int drake_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int mdbuf_len, retval; - char mdbuf[BUFSZ]; + char mdbuf[BUFSZ]; char cmode; char cwidth; char csynch; - retval = drake_transaction (rig, "RM" EOM, 3, mdbuf, &mdbuf_len); + retval = drake_transaction(rig, "RM" EOM, 3, mdbuf, &mdbuf_len); if (retval != RIG_OK) return retval; if (mdbuf_len != 8) { - rig_debug(RIG_DEBUG_ERR,"drake_get_mode: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_mode: wrong answer %s, " "len=%d\n", mdbuf, mdbuf_len); return -RIG_ERJCTED; } @@ -334,12 +355,17 @@ int drake_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) cwidth = mdbuf[4]; csynch = mdbuf[5]; - switch(cwidth & 0x37){ + switch (cwidth & 0x37) { case '0': *width = s_Hz(500); break; + case '1': *width = s_Hz(1800); break; + case '2': *width = s_Hz(2300); break; + case '3': *width = s_Hz(4000); break; + case '4': *width = s_Hz(6000); break; + default : rig_debug(RIG_DEBUG_ERR, "drake_get_mode: unsupported width %c\n", @@ -349,10 +375,13 @@ int drake_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } if ((cwidth >= '0') && (cwidth <= '4')) { - switch(cmode & 0x33){ + switch (cmode & 0x33) { case '0': *mode = RIG_MODE_LSB; break; + case '1': *mode = RIG_MODE_RTTY; break; + case '2': *mode = RIG_MODE_FM; *width = s_Hz(12000); break; + default : rig_debug(RIG_DEBUG_ERR, "drake_get_mode: unsupported mode %c\n", @@ -361,10 +390,13 @@ int drake_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return -RIG_EINVAL; } } else { - switch(cmode & 0x33){ + switch (cmode & 0x33) { case '0': *mode = RIG_MODE_USB; break; + case '1': *mode = RIG_MODE_CW; break; + case '2': *mode = RIG_MODE_AM; break; + default : rig_debug(RIG_DEBUG_ERR, "drake_get_mode: unsupported mode %c\n", @@ -377,13 +409,12 @@ int drake_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if ((csynch & 0x34) == '4') { if (*mode == RIG_MODE_AM) *mode = RIG_MODE_AMS; - else - if (*mode == RIG_MODE_USB) - *mode = RIG_MODE_ECSSUSB; - else - if (*mode == RIG_MODE_LSB) - *mode = RIG_MODE_ECSSLSB; + else if (*mode == RIG_MODE_USB) + *mode = RIG_MODE_ECSSUSB; + else if (*mode == RIG_MODE_LSB) + *mode = RIG_MODE_ECSSLSB; } + return RIG_OK; } @@ -396,7 +427,7 @@ int drake_set_ant(RIG *rig, vfo_t vfo, ant_t ant) unsigned char buf[16], ackbuf[16]; int len, ack_len, retval; - len = sprintf((char *) buf,"A%c" EOM, ant==RIG_ANT_1?'1':(ant==RIG_ANT_2?'2':'C')); + len = sprintf((char *) buf, "A%c" EOM, ant == RIG_ANT_1 ? '1' : (ant == RIG_ANT_2 ? '2' : 'C')); retval = drake_transaction(rig, (char *) buf, len, (char *) ackbuf, &ack_len); @@ -413,23 +444,26 @@ int drake_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) char mdbuf[BUFSZ]; char cant; - retval = drake_transaction (rig, "RM" EOM, 3, mdbuf, &mdbuf_len); + retval = drake_transaction(rig, "RM" EOM, 3, mdbuf, &mdbuf_len); if (retval != RIG_OK) return retval; if (mdbuf_len != 8) { - rig_debug(RIG_DEBUG_ERR,"drake_get_ant: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_ant: wrong answer %s, " "len=%d\n", mdbuf, mdbuf_len); return -RIG_ERJCTED; } cant = mdbuf[3]; - switch(cant & 0x3c){ + switch (cant & 0x3c) { case '0': *ant = RIG_ANT_1; break; + case '4': *ant = RIG_ANT_3; break; + case '8': *ant = RIG_ANT_2; break; + default : rig_debug(RIG_DEBUG_ERR, "drake_get_ant: unsupported antenna %c\n", @@ -455,10 +489,10 @@ int drake_set_mem(RIG *rig, vfo_t vfo, int ch) len = sprintf(buf, "C%03d" EOM, ch); - retval = drake_transaction (rig, buf, len, ackbuf, &ack_len); + retval = drake_transaction(rig, buf, len, ackbuf, &ack_len); if (ack_len != 2) { - rig_debug(RIG_DEBUG_ERR,"drake_set_mem: could not set channel %03d.\n", ch); + rig_debug(RIG_DEBUG_ERR, "drake_set_mem: could not set channel %03d.\n", ch); retval = -RIG_ERJCTED; } @@ -476,13 +510,13 @@ int drake_get_mem(RIG *rig, vfo_t vfo, int *ch) char mdbuf[BUFSZ]; int chan; - retval = drake_transaction (rig, "RC" EOM, 3, mdbuf, &mdbuf_len); + retval = drake_transaction(rig, "RC" EOM, 3, mdbuf, &mdbuf_len); if (retval != RIG_OK) return retval; if (mdbuf_len != 6) { - rig_debug(RIG_DEBUG_ERR,"drake_get_mem: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_mem: wrong answer %s, " "len=%d\n", mdbuf, mdbuf_len); return -RIG_ERJCTED; } @@ -490,7 +524,7 @@ int drake_get_mem(RIG *rig, vfo_t vfo, int *ch) mdbuf[4] = '\0'; /* extract channel no */ - sscanf(mdbuf+1, "%03d", &chan); + sscanf(mdbuf + 1, "%03d", &chan); *ch = chan; priv->curr_ch = chan; @@ -514,9 +548,10 @@ int drake_set_chan(RIG *rig, const channel_t *chan) old_chan = 0; /* set to vfo if needed */ - if (old_vfo == RIG_VFO_MEM){ + if (old_vfo == RIG_VFO_MEM) { old_chan = priv->curr_ch; retval = drake_set_vfo(rig, RIG_VFO_VFO); + if (retval != RIG_OK) return retval; } @@ -537,7 +572,7 @@ int drake_set_chan(RIG *rig, const channel_t *chan) (chan->funcs & RIG_FUNC_MN) == RIG_FUNC_MN); mdbuf_len = sprintf(mdbuf, "PR" EOM "%03d" EOM, chan->channel_num); - retval = drake_transaction (rig, mdbuf, mdbuf_len, ackbuf, &ack_len); + retval = drake_transaction(rig, mdbuf, mdbuf_len, ackbuf, &ack_len); if (old_vfo == RIG_VFO_MEM) drake_set_mem(rig, RIG_VFO_CURR, old_chan); @@ -554,7 +589,7 @@ int drake_get_chan(RIG *rig, channel_t *chan) struct drake_priv_data *priv = rig->state.priv; vfo_t old_vfo; int old_chan; - char mdbuf[BUFSZ],freqstr[BUFSZ]; + char mdbuf[BUFSZ], freqstr[BUFSZ]; int mdbuf_len, retval; chan->vfo = RIG_VFO_MEM; @@ -592,16 +627,18 @@ int drake_get_chan(RIG *rig, channel_t *chan) //go to new channel retval = drake_set_mem(rig, RIG_VFO_CURR, chan->channel_num); + if (retval != RIG_OK) return RIG_OK; //now decypher it - retval = drake_transaction (rig, "RA" EOM, 3, mdbuf, &mdbuf_len); + retval = drake_transaction(rig, "RA" EOM, 3, mdbuf, &mdbuf_len); + if (retval != RIG_OK) return retval; if (mdbuf_len < 35) { - rig_debug(RIG_DEBUG_ERR,"drake_get_channel: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_channel: wrong answer %s, " "len=%d\n", mdbuf, mdbuf_len); return -RIG_ERJCTED; } @@ -609,10 +646,13 @@ int drake_get_chan(RIG *rig, channel_t *chan) if ((mdbuf[5] >= '4') && (mdbuf[5] <= '?')) chan->funcs |= RIG_FUNC_NB; - switch(mdbuf[5] & 0x33){ + switch (mdbuf[5] & 0x33) { case '0': chan->levels[rig_setting2idx(RIG_LEVEL_AGC)].i = RIG_AGC_OFF; break; + case '2': chan->levels[rig_setting2idx(RIG_LEVEL_AGC)].i = RIG_AGC_FAST; break; + case '3': chan->levels[rig_setting2idx(RIG_LEVEL_AGC)].i = RIG_AGC_SLOW; break; + default : chan->levels[rig_setting2idx(RIG_LEVEL_AGC)].i = RIG_AGC_FAST; } @@ -622,38 +662,52 @@ int drake_get_chan(RIG *rig, channel_t *chan) if ((mdbuf[6] & 0x3c) == '4') chan->levels[rig_setting2idx(RIG_LEVEL_ATT)].i = 10; - if ((mdbuf[6] & 0x32) =='2') + if ((mdbuf[6] & 0x32) == '2') chan->funcs |= RIG_FUNC_MN; - switch(mdbuf[7] & 0x3c){ + switch (mdbuf[7] & 0x3c) { case '0': chan->ant = RIG_ANT_1; break; + case '4': chan->ant = RIG_ANT_3; break; + case '8': chan->ant = RIG_ANT_2; break; + default : chan->ant = RIG_ANT_NONE; } - switch(mdbuf[8] & 0x37){ + switch (mdbuf[8] & 0x37) { case '0': chan->width = s_Hz(500); break; + case '1': chan->width = s_Hz(1800); break; + case '2': chan->width = s_Hz(2300); break; + case '3': chan->width = s_Hz(4000); break; + case '4': chan->width = s_Hz(6000); break; + default : chan->width = RIG_PASSBAND_NORMAL; } if ((mdbuf[8] >= '0') && (mdbuf[8] <= '4')) { - switch(mdbuf[7] & 0x33){ + switch (mdbuf[7] & 0x33) { case '0': chan->mode = RIG_MODE_LSB; break; + case '1': chan->mode = RIG_MODE_RTTY; break; + case '2': chan->mode = RIG_MODE_FM; chan->width = s_Hz(12000); break; + default : chan->mode = RIG_MODE_NONE; } } else { - switch(mdbuf[7] & 0x33){ + switch (mdbuf[7] & 0x33) { case '0': chan->mode = RIG_MODE_USB; break; + case '1': chan->mode = RIG_MODE_CW; break; + case '2': chan->mode = RIG_MODE_AM; break; + default : chan->mode = RIG_MODE_NONE; } } @@ -667,23 +721,27 @@ int drake_get_chan(RIG *rig, channel_t *chan) chan->mode = RIG_MODE_ECSSLSB; } - strncpy(freqstr,mdbuf+11,9); + strncpy(freqstr, mdbuf + 11, 9); freqstr[9] = 0x00; + if ((mdbuf[21] == 'k') || (mdbuf[21] == 'K')) - chan->freq = strtod(freqstr,NULL) * 1000.0; + chan->freq = strtod(freqstr, NULL) * 1000.0; + if ((mdbuf[21] == 'm') || (mdbuf[21] == 'M')) - chan->freq = strtod(freqstr,NULL) * 1000000.0; + chan->freq = strtod(freqstr, NULL) * 1000000.0; - strncpy(chan->channel_desc, mdbuf+25, 7); + strncpy(chan->channel_desc, mdbuf + 25, 7); //now put the radio back the way it was if (old_vfo != RIG_VFO_MEM) { retval = drake_set_vfo(rig, RIG_VFO_VFO); + if (retval != RIG_OK) return retval; } else { retval = drake_set_mem(rig, RIG_VFO_CURR, old_chan); + if (retval != RIG_OK) return retval; } @@ -701,31 +759,37 @@ int drake_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) char buf[16], ackbuf[16]; int len, ack_len, retval; - switch(op) { + switch (op) { case RIG_OP_UP: - len = sprintf(buf,"U"); + len = sprintf(buf, "U"); break; + case RIG_OP_DOWN: - len = sprintf(buf,"D"); + len = sprintf(buf, "D"); break; + case RIG_OP_CPY: - len = sprintf(buf,"A E B" EOM); + len = sprintf(buf, "A E B" EOM); break; + case RIG_OP_TO_VFO: /* len = sprintf(buf,"C%03d" EOM, priv->curr_ch); */ - len = sprintf(buf,"F" EOM); + len = sprintf(buf, "F" EOM); break; + case RIG_OP_MCL: - len = sprintf(buf,"EC%03d" EOM, priv->curr_ch); + len = sprintf(buf, "EC%03d" EOM, priv->curr_ch); break; + case RIG_OP_FROM_VFO: - len = sprintf(buf,"PR" EOM "%03d" EOM, priv->curr_ch); + len = sprintf(buf, "PR" EOM "%03d" EOM, priv->curr_ch); break; + default: return -RIG_EINVAL; } - retval = drake_transaction(rig, buf, len, buf[len-1]==0x0d ?ackbuf:NULL, &ack_len); + retval = drake_transaction(rig, buf, len, buf[len - 1] == 0x0d ? ackbuf : NULL, &ack_len); return retval; } @@ -739,17 +803,20 @@ int drake_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) char buf[16], ackbuf[16]; int len, ack_len, retval; - switch(func) { + switch (func) { case RIG_FUNC_MN: - len = sprintf(buf,"N%c" EOM, status?'O':'F'); + len = sprintf(buf, "N%c" EOM, status ? 'O' : 'F'); break; + case RIG_FUNC_LOCK: - len = sprintf(buf,"L%c" EOM, status?'O':'F'); + len = sprintf(buf, "L%c" EOM, status ? 'O' : 'F'); break; + case RIG_FUNC_NB: /* TODO: NB narrow */ - len = sprintf(buf,"B%c" EOM, status?'W':'F'); + len = sprintf(buf, "B%c" EOM, status ? 'W' : 'F'); break; + default: return -RIG_EINVAL; } @@ -766,32 +833,34 @@ int drake_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) int drake_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) { int mdbuf_len, retval; - char mdbuf[BUFSZ]; - char mc; + char mdbuf[BUFSZ]; + char mc; - retval = drake_transaction (rig, "RM" EOM, 3, mdbuf, &mdbuf_len); + retval = drake_transaction(rig, "RM" EOM, 3, mdbuf, &mdbuf_len); if (retval != RIG_OK) return retval; if (mdbuf_len != 8) { - rig_debug(RIG_DEBUG_ERR,"drake_get_func: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_func: wrong answer %s, " "len=%d\n", mdbuf, mdbuf_len); return -RIG_ERJCTED; } - switch(func) { + switch (func) { case RIG_FUNC_MN: mc = mdbuf[2]; - *status = ((mc & 0x32) =='2'); + *status = ((mc & 0x32) == '2'); break; + case RIG_FUNC_NB: /* TODO: NB narrow */ mc = mdbuf[1]; *status = ((mc >= '4') && (mc <= '?')); break; + default: - rig_debug(RIG_DEBUG_ERR,"Unsupported get func %d\n",func); + rig_debug(RIG_DEBUG_ERR, "Unsupported get func %d\n", func); return -RIG_EINVAL; } @@ -807,18 +876,21 @@ int drake_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) char buf[16], ackbuf[16]; int len, ack_len, retval; - switch(level) { + switch (level) { case RIG_LEVEL_PREAMP: - len = sprintf(buf,"G%c" EOM, val.i?'+':'0'); + len = sprintf(buf, "G%c" EOM, val.i ? '+' : '0'); break; + case RIG_LEVEL_ATT: - len = sprintf(buf,"G%c" EOM, val.i?'-':'0'); + len = sprintf(buf, "G%c" EOM, val.i ? '-' : '0'); break; + case RIG_LEVEL_AGC: - len = sprintf(buf,"A%c" EOM, - val.i==RIG_AGC_OFF?'O': - (val.i==RIG_AGC_FAST?'F':'S')); + len = sprintf(buf, "A%c" EOM, + val.i == RIG_AGC_OFF ? 'O' : + (val.i == RIG_AGC_FAST ? 'F' : 'S')); break; + default: return -RIG_EINVAL; } @@ -838,97 +910,114 @@ int drake_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) char lvlbuf[BUFSZ]; char mc; - if ((level != RIG_LEVEL_RAWSTR)&&(level != RIG_LEVEL_STRENGTH)) { - retval = drake_transaction (rig, "RM" EOM, 3, lvlbuf, &lvl_len); + if ((level != RIG_LEVEL_RAWSTR) && (level != RIG_LEVEL_STRENGTH)) { + retval = drake_transaction(rig, "RM" EOM, 3, lvlbuf, &lvl_len); + if (retval != RIG_OK) return retval; if (lvl_len != 8) { - rig_debug(RIG_DEBUG_ERR,"drake_get_level: wrong answer %s, " + rig_debug(RIG_DEBUG_ERR, "drake_get_level: wrong answer %s, " "len=%d\n", lvlbuf, lvl_len); return -RIG_ERJCTED; } } - switch(level) { + switch (level) { case RIG_LEVEL_RAWSTR: - retval = drake_transaction (rig, "RSS" EOM, 4, lvlbuf, &lvl_len); + retval = drake_transaction(rig, "RSS" EOM, 4, lvlbuf, &lvl_len); + if (retval != RIG_OK) return retval; if (lvl_len != 5) { - rig_debug(RIG_DEBUG_ERR,"drake_get_level: wrong answer" + rig_debug(RIG_DEBUG_ERR, "drake_get_level: wrong answer" "len=%d\n", lvl_len); return -RIG_ERJCTED; } lvlbuf[3] = '\0'; - val->i = strtol(lvlbuf+1, (char **)NULL, 16); + val->i = strtol(lvlbuf + 1, (char **)NULL, 16); break; + case RIG_LEVEL_STRENGTH: - retval = drake_transaction (rig, "RSS" EOM, 4, lvlbuf, &lvl_len); + retval = drake_transaction(rig, "RSS" EOM, 4, lvlbuf, &lvl_len); + if (retval != RIG_OK) return retval; if (lvl_len != 5) { - rig_debug(RIG_DEBUG_ERR,"drake_get_level: wrong answer" + rig_debug(RIG_DEBUG_ERR, "drake_get_level: wrong answer" "len=%d\n", lvl_len); return -RIG_ERJCTED; } lvlbuf[3] = '\0'; - ss = strtol(lvlbuf+1, (char **)NULL, 16); - val->i = (int)rig_raw2val(ss,&rig->caps->str_cal); + ss = strtol(lvlbuf + 1, (char **)NULL, 16); + val->i = (int)rig_raw2val(ss, &rig->caps->str_cal); break; + case RIG_LEVEL_PREAMP: mc = lvlbuf[2]; + if ((mc & 0x3c) == '8') val->i = 10; else val->i = 0; + break; + case RIG_LEVEL_ATT: mc = lvlbuf[2]; - if ((mc & 0x3c) =='4') + + if ((mc & 0x3c) == '4') val->i = 10; else val->i = 0; + break; + case RIG_LEVEL_AGC: mc = lvlbuf[1]; - switch(mc & 0x33){ + + switch (mc & 0x33) { case '0': val->i = RIG_AGC_OFF; break; + case '2': val->i = RIG_AGC_FAST; break; + case '3': val->i = RIG_AGC_SLOW; break; + default : val->i = RIG_AGC_FAST; } + break; + default: - rig_debug(RIG_DEBUG_ERR,"Unsupported get_level %d\n",level); + rig_debug(RIG_DEBUG_ERR, "Unsupported get_level %d\n", level); return -RIG_EINVAL; } return RIG_OK; } -int drake_set_powerstat (RIG * rig, powerstat_t status) +int drake_set_powerstat(RIG *rig, powerstat_t status) { char buf[16], ackbuf[16]; int len, ack_len, retval; - len = sprintf(buf,"P%c" EOM, status==RIG_POWER_OFF?'F':'O'); + len = sprintf(buf, "P%c" EOM, status == RIG_POWER_OFF ? 'F' : 'O'); retval = drake_transaction(rig, buf, len, ackbuf, &ack_len); return retval; } -int drake_get_powerstat (RIG * rig, powerstat_t *status) +int drake_get_powerstat(RIG *rig, powerstat_t *status) { int mdlen, retval; - char mdbuf[BUFSZ]; + char mdbuf[BUFSZ]; - retval = drake_transaction (rig, "RM" EOM, 3, mdbuf, &mdlen); + retval = drake_transaction(rig, "RM" EOM, 3, mdbuf, &mdlen); if (retval != RIG_OK) return retval; @@ -1010,11 +1099,14 @@ DECLARE_PROBERIG_BACKEND(drake) if (!strcmp(idbuf, "R8B")) { if (cfunc) (*cfunc)(port, RIG_MODEL_DKR8B, data); + return RIG_MODEL_DKR8B; } + if (!strcmp(idbuf, "R8A")) { /* TBC */ if (cfunc) (*cfunc)(port, RIG_MODEL_DKR8A, data); + return RIG_MODEL_DKR8A; } @@ -1022,7 +1114,7 @@ DECLARE_PROBERIG_BACKEND(drake) * not found... */ if (memcmp(idbuf, "ID" EOM, 3)) /* catch loopback serial */ - rig_debug(RIG_DEBUG_VERBOSE,"probe_drake: found unknown device " + rig_debug(RIG_DEBUG_VERBOSE, "probe_drake: found unknown device " "with ID '%s', please report to Hamlib " "developers.\n", idbuf); diff --git a/icom/optoscan.c b/icom/optoscan.c index fdc1b512a..a6e8a4ff4 100644 --- a/icom/optoscan.c +++ b/icom/optoscan.c @@ -43,19 +43,19 @@ const struct confparams opto_ext_parms[] = { - { TOK_TAPECNTL, "tapecntl", "Toggle Tape Switch", "Toggles built in tape switch", 0, RIG_CONF_CHECKBUTTON, {} }, - { TOK_5KHZWIN, "5khzwin", "Toggle 5kHz Search Window", "Toggles 5kHz search window", 0, RIG_CONF_CHECKBUTTON, {} }, - { TOK_SPEAKER, "speaker", "Toggle speaker audio", "Toggles speaker audio", 0, RIG_CONF_CHECKBUTTON, {} }, - { TOK_AUDIO, "audio", "Audio present", "Audio present", NULL, RIG_CONF_CHECKBUTTON, {} }, - { TOK_DTMFPEND, "dtmfpend", "DTMF Digit Pending", "DTMF Digit Pending", NULL, RIG_CONF_CHECKBUTTON, {} }, - { TOK_DTMFOVRR, "dtmfovrr", "DTMF Buffer Overflow", "DTMF Buffer Overflow", NULL, RIG_CONF_CHECKBUTTON, {} }, - { TOK_CTCSSACT, "ctcssact", "CTCSS Tone Active", "CTCSS Tone Active", NULL, RIG_CONF_CHECKBUTTON, {} }, - { TOK_DCSACT, "dcsact", "DCS Code Active", "DCS Code Active", NULL, RIG_CONF_CHECKBUTTON, {} }, - { RIG_CONF_END, NULL, } + { TOK_TAPECNTL, "tapecntl", "Toggle Tape Switch", "Toggles built in tape switch", 0, RIG_CONF_CHECKBUTTON, {} }, + { TOK_5KHZWIN, "5khzwin", "Toggle 5kHz Search Window", "Toggles 5kHz search window", 0, RIG_CONF_CHECKBUTTON, {} }, + { TOK_SPEAKER, "speaker", "Toggle speaker audio", "Toggles speaker audio", 0, RIG_CONF_CHECKBUTTON, {} }, + { TOK_AUDIO, "audio", "Audio present", "Audio present", NULL, RIG_CONF_CHECKBUTTON, {} }, + { TOK_DTMFPEND, "dtmfpend", "DTMF Digit Pending", "DTMF Digit Pending", NULL, RIG_CONF_CHECKBUTTON, {} }, + { TOK_DTMFOVRR, "dtmfovrr", "DTMF Buffer Overflow", "DTMF Buffer Overflow", NULL, RIG_CONF_CHECKBUTTON, {} }, + { TOK_CTCSSACT, "ctcssact", "CTCSS Tone Active", "CTCSS Tone Active", NULL, RIG_CONF_CHECKBUTTON, {} }, + { TOK_DCSACT, "dcsact", "DCS Code Active", "DCS Code Active", NULL, RIG_CONF_CHECKBUTTON, {} }, + { RIG_CONF_END, NULL, } }; static int optoscan_get_status_block(RIG *rig, struct optostat *status_block); -static int optoscan_send_freq(RIG *rig,pltstate_t *state); +static int optoscan_send_freq(RIG *rig, pltstate_t *state); static int optoscan_RTS_toggle(RIG *rig); static int optoscan_start_timer(RIG *rig, pltstate_t *state); static int optoscan_wait_timer(RIG *rig, pltstate_t *state); @@ -66,38 +66,41 @@ static int optoscan_wait_timer(RIG *rig, pltstate_t *state); */ int optoscan_open(RIG *rig) { - struct icom_priv_data *priv; - struct rig_state *rs; - pltstate_t *pltstate; - unsigned char ackbuf[16]; - int ack_len, retval; + struct icom_priv_data *priv; + struct rig_state *rs; + pltstate_t *pltstate; + unsigned char ackbuf[16]; + int ack_len, retval; - rs = &rig->state; - priv = (struct icom_priv_data*)rs->priv; + rs = &rig->state; + priv = (struct icom_priv_data *)rs->priv; - pltstate = malloc(sizeof(pltstate_t)); - if (!pltstate) { - return -RIG_ENOMEM; - } - memset(pltstate, 0, sizeof(pltstate_t)); - priv->pltstate = pltstate; + pltstate = malloc(sizeof(pltstate_t)); - /* select REMOTE control */ - retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_REMOTE, - NULL, 0, ackbuf, &ack_len); - if (retval != RIG_OK) { - free(pltstate); - return retval; - } + if (!pltstate) { + return -RIG_ENOMEM; + } - if (ack_len != 1 || ackbuf[0] != ACK) { - rig_debug(RIG_DEBUG_ERR,"optoscan_open: ack NG (%#.2x), " - "len=%d\n", ackbuf[0], ack_len); - free(pltstate); - return -RIG_ERJCTED; - } + memset(pltstate, 0, sizeof(pltstate_t)); + priv->pltstate = pltstate; - return RIG_OK; + /* select REMOTE control */ + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_REMOTE, + NULL, 0, ackbuf, &ack_len); + + if (retval != RIG_OK) { + free(pltstate); + return retval; + } + + if (ack_len != 1 || ackbuf[0] != ACK) { + rig_debug(RIG_DEBUG_ERR, "optoscan_open: ack NG (%#.2x), " + "len=%d\n", ackbuf[0], ack_len); + free(pltstate); + return -RIG_ERJCTED; + } + + return RIG_OK; } /* @@ -106,60 +109,62 @@ int optoscan_open(RIG *rig) */ int optoscan_close(RIG *rig) { - struct icom_priv_data *priv; - struct rig_state *rs; - unsigned char ackbuf[16]; - int ack_len, retval; + struct icom_priv_data *priv; + struct rig_state *rs; + unsigned char ackbuf[16]; + int ack_len, retval; - rs = &rig->state; - priv = (struct icom_priv_data*)rs->priv; + rs = &rig->state; + priv = (struct icom_priv_data *)rs->priv; - /* select LOCAL control */ - retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_LOCAL, - NULL, 0, ackbuf, &ack_len); - if (retval != RIG_OK) - return retval; + /* select LOCAL control */ + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_LOCAL, + NULL, 0, ackbuf, &ack_len); - if (ack_len != 1 || ackbuf[0] != ACK) { - rig_debug(RIG_DEBUG_ERR,"optoscan_close: ack NG (%#.2x), " - "len=%d\n", ackbuf[0], ack_len); - return -RIG_ERJCTED; - } + if (retval != RIG_OK) + return retval; - free(priv->pltstate); + if (ack_len != 1 || ackbuf[0] != ACK) { + rig_debug(RIG_DEBUG_ERR, "optoscan_close: ack NG (%#.2x), " + "len=%d\n", ackbuf[0], ack_len); + return -RIG_ERJCTED; + } - return RIG_OK; + free(priv->pltstate); + + return RIG_OK; } /* * optoscan_get_info * Assumes rig!=NULL, rig->state.priv!=NULL */ -const char* optoscan_get_info(RIG *rig) +const char *optoscan_get_info(RIG *rig) { - unsigned char ackbuf[16]; - int ack_len, retval; - static char info[64]; + unsigned char ackbuf[16]; + int ack_len, retval; + static char info[64]; - /* select LOCAL control */ - retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_RDID, - NULL, 0, ackbuf, &ack_len); - if (retval != RIG_OK) - return NULL; + /* select LOCAL control */ + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDID, + NULL, 0, ackbuf, &ack_len); - if (ack_len != 7) { - rig_debug(RIG_DEBUG_ERR,"optoscan_get_info: ack NG (%#.2x), " - "len=%d\n", ackbuf[0], ack_len); - return NULL; - } + if (retval != RIG_OK) + return NULL; - sprintf(info, "OptoScan%c%c%c, software version %d.%d, " - "interface version %d.%d\n", - ackbuf[2], ackbuf[3], ackbuf[4], - ackbuf[5] >> 4, ackbuf[5] & 0xf, - ackbuf[6] >> 4, ackbuf[6] & 0xf); + if (ack_len != 7) { + rig_debug(RIG_DEBUG_ERR, "optoscan_get_info: ack NG (%#.2x), " + "len=%d\n", ackbuf[0], ack_len); + return NULL; + } - return info; + sprintf(info, "OptoScan%c%c%c, software version %d.%d, " + "interface version %d.%d\n", + ackbuf[2], ackbuf[3], ackbuf[4], + ackbuf[5] >> 4, ackbuf[5] & 0xf, + ackbuf[6] >> 4, ackbuf[6] & 0xf); + + return info; } /* @@ -168,26 +173,27 @@ const char* optoscan_get_info(RIG *rig) */ int optoscan_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { - unsigned char tonebuf[MAXFRAMELEN]; - int tone_len, retval; + unsigned char tonebuf[MAXFRAMELEN]; + int tone_len, retval; - retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDCTCSS, NULL, 0, - tonebuf, &tone_len); - if (retval != RIG_OK) - return retval; + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDCTCSS, NULL, 0, + tonebuf, &tone_len); - if (tone_len != 4) { - rig_debug(RIG_DEBUG_ERR,"optoscan_get_ctcss_tone: ack NG (%#.2x), " - "len=%d\n", tonebuf[0], tone_len); - return -RIG_ERJCTED; - } + if (retval != RIG_OK) + return retval; - tone_len -= 2; + if (tone_len != 4) { + rig_debug(RIG_DEBUG_ERR, "optoscan_get_ctcss_tone: ack NG (%#.2x), " + "len=%d\n", tonebuf[0], tone_len); + return -RIG_ERJCTED; + } - *tone = from_bcd_be(tonebuf+2, tone_len*2); - rig_debug(RIG_DEBUG_ERR,"optoscan_get_ctcss_tone: *tone=%d\n",*tone); + tone_len -= 2; - return RIG_OK; + *tone = from_bcd_be(tonebuf + 2, tone_len * 2); + rig_debug(RIG_DEBUG_ERR, "optoscan_get_ctcss_tone: *tone=%d\n", *tone); + + return RIG_OK; } @@ -195,72 +201,71 @@ int optoscan_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) * optoscan_get_dcs_code * Assumes rig!=NULL, rig->state.priv!=NULL */ -int optoscan_get_dcs_code(RIG * rig, vfo_t vfo, tone_t *code) +int optoscan_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) { - unsigned char tonebuf[MAXFRAMELEN]; - int tone_len, retval; + unsigned char tonebuf[MAXFRAMELEN]; + int tone_len, retval; - retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDCS, NULL, 0, - tonebuf, &tone_len); - if (retval != RIG_OK) - return retval; + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDCS, NULL, 0, + tonebuf, &tone_len); - if (tone_len != 4) { - rig_debug(RIG_DEBUG_ERR,"optoscan_get_dcs_code: ack NG (%#.2x), " - "len=%d\n", tonebuf[0], tone_len); - return -RIG_ERJCTED; - } + if (retval != RIG_OK) + return retval; - tone_len -= 2; + if (tone_len != 4) { + rig_debug(RIG_DEBUG_ERR, "optoscan_get_dcs_code: ack NG (%#.2x), " + "len=%d\n", tonebuf[0], tone_len); + return -RIG_ERJCTED; + } - *code = from_bcd_be(tonebuf+2, tone_len*2); - rig_debug(RIG_DEBUG_ERR,"optoscan_get_dcs_code: *code=%d\n",*code); + tone_len -= 2; - return RIG_OK; + *code = from_bcd_be(tonebuf + 2, tone_len * 2); + rig_debug(RIG_DEBUG_ERR, "optoscan_get_dcs_code: *code=%d\n", *code); + + return RIG_OK; } int optoscan_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length) { - unsigned char dtmfbuf[MAXFRAMELEN],digit; - int len, retval, digitpos; - unsigned char xlate[] = {'0','1','2','3','4','5','6', - '7','8','9','A','B','C','D', - '*','#'}; - digitpos=0; + unsigned char dtmfbuf[MAXFRAMELEN], digit; + int len, retval, digitpos; + unsigned char xlate[] = {'0', '1', '2', '3', '4', '5', '6', + '7', '8', '9', 'A', 'B', 'C', 'D', + '*', '#' + }; + digitpos = 0; - do { - retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDTMF, - NULL,0,dtmfbuf, &len); - if (retval != RIG_OK) - return retval; + do { + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDTMF, + NULL, 0, dtmfbuf, &len); - if (len != 3) { - rig_debug(RIG_DEBUG_ERR,"optoscan_recv_dtmf: ack NG (%#.2x), len=%d\n", dtmfbuf[0], len); - return -RIG_ERJCTED; - } + if (retval != RIG_OK) + return retval; - digit = dtmfbuf[2]; + if (len != 3) { + rig_debug(RIG_DEBUG_ERR, "optoscan_recv_dtmf: ack NG (%#.2x), len=%d\n", dtmfbuf[0], len); + return -RIG_ERJCTED; + } - if( digit < 0x16 ) - { - digits[digitpos] = xlate[digit]; - digitpos++; - } - } while( (digit != 0x99) && (digitpos < *length) ); + digit = dtmfbuf[2]; - *length = digitpos; - digits[digitpos]=0; + if (digit < 0x16) { + digits[digitpos] = xlate[digit]; + digitpos++; + } + } while ((digit != 0x99) && (digitpos < *length)); - if(*length > 0) - { - rig_debug(RIG_DEBUG_ERR,"optoscan_recv_dtmf: %d digits - %s\n",*length,digits); - } - else - { - rig_debug(RIG_DEBUG_ERR,"optoscan_recv_dtmf: no digits to read.\n"); - } + *length = digitpos; + digits[digitpos] = 0; - return RIG_OK; + if (*length > 0) { + rig_debug(RIG_DEBUG_ERR, "optoscan_recv_dtmf: %d digits - %s\n", *length, digits); + } else { + rig_debug(RIG_DEBUG_ERR, "optoscan_recv_dtmf: no digits to read.\n"); + } + + return RIG_OK; } /* @@ -270,48 +275,52 @@ int optoscan_set_ext_parm(RIG *rig, token_t token, value_t val) { unsigned char epbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; int ack_len; - int retval,subcode; + int retval, subcode; - memset(epbuf,0,MAXFRAMELEN); - memset(ackbuf,0,MAXFRAMELEN); + memset(epbuf, 0, MAXFRAMELEN); + memset(ackbuf, 0, MAXFRAMELEN); - switch(token) { + switch (token) { case TOK_TAPECNTL: - if( val.i == 0 ) { - subcode = S_OPTO_TAPE_OFF; - } - else { - subcode = S_OPTO_TAPE_ON; - } - break; + if (val.i == 0) { + subcode = S_OPTO_TAPE_OFF; + } else { + subcode = S_OPTO_TAPE_ON; + } + + break; + case TOK_5KHZWIN: - if( val.i == 0 ) { - subcode = S_OPTO_5KSCOFF; - } - else { - subcode = S_OPTO_5KSCON; - } - break; + if (val.i == 0) { + subcode = S_OPTO_5KSCOFF; + } else { + subcode = S_OPTO_5KSCON; + } + + break; + case TOK_SPEAKER: - if( val.i == 0 ) { - subcode = S_OPTO_SPKROFF; - } - else { - subcode = S_OPTO_SPKRON; - } - break; + if (val.i == 0) { + subcode = S_OPTO_SPKROFF; + } else { + subcode = S_OPTO_SPKRON; + } + + break; + default: - return -RIG_EINVAL; + return -RIG_EINVAL; } - retval = icom_transaction (rig, C_CTL_MISC, subcode, epbuf, 0, - ackbuf, &ack_len); + retval = icom_transaction(rig, C_CTL_MISC, subcode, epbuf, 0, + ackbuf, &ack_len); + if (retval != RIG_OK) return retval; if (ack_len != 1 || ackbuf[0] != ACK) { rig_debug(RIG_DEBUG_ERR, "%s: ack NG (%#.2x), " - "len=%d\n", __FUNCTION__, ackbuf[0], ack_len); + "len=%d\n", __FUNCTION__, ackbuf[0], ack_len); return -RIG_ERJCTED; } @@ -324,44 +333,52 @@ int optoscan_set_ext_parm(RIG *rig, token_t token, value_t val) */ int optoscan_get_ext_parm(RIG *rig, token_t token, value_t *val) { - struct optostat status_block; - int retval; + struct optostat status_block; + int retval; - retval = optoscan_get_status_block(rig,&status_block); + retval = optoscan_get_status_block(rig, &status_block); - if (retval != RIG_OK) - return retval; + if (retval != RIG_OK) + return retval; - switch(token) { - case TOK_TAPECNTL: - val->i = status_block.tape_enabled; - break; - case TOK_5KHZWIN: - val->i = status_block.fivekhz_enabled; - break; - case TOK_SPEAKER: - val->i = status_block.speaker_enabled; - break; - case TOK_AUDIO: - val->i = status_block.audio_present; - break; - case TOK_DTMFPEND: - val->i = status_block.DTMF_pending; - break; - case TOK_DTMFOVRR: - val->i = status_block.DTMF_overrun; - break; - case TOK_CTCSSACT: - val->i = status_block.CTCSS_active; - break; - case TOK_DCSACT: - val->i = status_block.DCS_active; - break; - default: - return -RIG_ENIMPL; - } + switch (token) { + case TOK_TAPECNTL: + val->i = status_block.tape_enabled; + break; - return RIG_OK; + case TOK_5KHZWIN: + val->i = status_block.fivekhz_enabled; + break; + + case TOK_SPEAKER: + val->i = status_block.speaker_enabled; + break; + + case TOK_AUDIO: + val->i = status_block.audio_present; + break; + + case TOK_DTMFPEND: + val->i = status_block.DTMF_pending; + break; + + case TOK_DTMFOVRR: + val->i = status_block.DTMF_overrun; + break; + + case TOK_CTCSSACT: + val->i = status_block.CTCSS_active; + break; + + case TOK_DCSACT: + val->i = status_block.DCS_active; + break; + + default: + return -RIG_ENIMPL; + } + + return RIG_OK; } /* @@ -370,49 +387,52 @@ int optoscan_get_ext_parm(RIG *rig, token_t token, value_t *val) */ int optoscan_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - unsigned char lvlbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; - int ack_len; - int lvl_cn, lvl_sc; /* Command Number, Subcommand */ - int icom_val; - int retval; + unsigned char lvlbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; + int ack_len; + int lvl_cn, lvl_sc; /* Command Number, Subcommand */ + int icom_val; + int retval; - memset(lvlbuf,0,MAXFRAMELEN); + memset(lvlbuf, 0, MAXFRAMELEN); - /* - * So far, levels of float type are in [0.0..1.0] range - */ - if (RIG_LEVEL_IS_FLOAT(level)) - icom_val = val.f * 255; - else - icom_val = val.i; + /* + * So far, levels of float type are in [0.0..1.0] range + */ + if (RIG_LEVEL_IS_FLOAT(level)) + icom_val = val.f * 255; + else + icom_val = val.i; - switch (level) { - case RIG_LEVEL_AF: - lvl_cn = C_CTL_MISC; - if( icom_val == 0 ) { - lvl_sc = S_OPTO_SPKROFF; - } - else { - lvl_sc = S_OPTO_SPKRON; - } - break; - default: - rig_debug(RIG_DEBUG_ERR,"Unsupported set_level %d", level); - return -RIG_EINVAL; + switch (level) { + case RIG_LEVEL_AF: + lvl_cn = C_CTL_MISC; + + if (icom_val == 0) { + lvl_sc = S_OPTO_SPKROFF; + } else { + lvl_sc = S_OPTO_SPKRON; } - retval = icom_transaction (rig, lvl_cn, lvl_sc, lvlbuf, 0, - ackbuf, &ack_len); - if (retval != RIG_OK) - return retval; + break; - if (ack_len != 1 || ackbuf[0] != ACK) { - rig_debug(RIG_DEBUG_ERR,"optoscan_set_level: ack NG (%#.2x), " - "len=%d\n", ackbuf[0], ack_len); - return -RIG_ERJCTED; - } + default: + rig_debug(RIG_DEBUG_ERR, "Unsupported set_level %d", level); + return -RIG_EINVAL; + } - return RIG_OK; + retval = icom_transaction(rig, lvl_cn, lvl_sc, lvlbuf, 0, + ackbuf, &ack_len); + + if (retval != RIG_OK) + return retval; + + if (ack_len != 1 || ackbuf[0] != ACK) { + rig_debug(RIG_DEBUG_ERR, "optoscan_set_level: ack NG (%#.2x), " + "len=%d\n", ackbuf[0], ack_len); + return -RIG_ERJCTED; + } + + return RIG_OK; } /* @@ -421,76 +441,77 @@ int optoscan_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) */ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - struct optostat status_block; - unsigned char lvlbuf[MAXFRAMELEN]; - int lvl_len; - int lvl_cn, lvl_sc; /* Command Number, Subcommand */ - int icom_val; - int cmdhead; - int retval; + struct optostat status_block; + unsigned char lvlbuf[MAXFRAMELEN]; + int lvl_len = 0; + int lvl_cn, lvl_sc; /* Command Number, Subcommand */ + int icom_val; + int cmdhead; + int retval; - if( level != RIG_LEVEL_AF ) - { - switch (level) { - case RIG_LEVEL_RAWSTR: - lvl_cn = C_RD_SQSM; - lvl_sc = S_SML; - break; - default: - rig_debug(RIG_DEBUG_ERR,"Unsupported get_level %d", level); - return -RIG_EINVAL; - } + if (level != RIG_LEVEL_AF) { + switch (level) { + case RIG_LEVEL_RAWSTR: + lvl_cn = C_RD_SQSM; + lvl_sc = S_SML; + break; - retval = icom_transaction (rig, lvl_cn, lvl_sc, NULL, 0, - lvlbuf, &lvl_len); - if (retval != RIG_OK) - return retval; + default: + rig_debug(RIG_DEBUG_ERR, "Unsupported get_level %d", level); + return -RIG_EINVAL; + } - /* - * strbuf should contain Cn,Sc,Data area - */ - cmdhead = (lvl_sc == -1) ? 1:2; - lvl_len -= cmdhead; + retval = icom_transaction(rig, lvl_cn, lvl_sc, NULL, 0, + lvlbuf, &lvl_len); - if (lvlbuf[0] != ACK && lvlbuf[0] != lvl_cn) { - rig_debug(RIG_DEBUG_ERR,"optoscan_get_level: ack NG (%#.2x), " - "len=%d\n", lvlbuf[0],lvl_len); - return -RIG_ERJCTED; - } + if (retval != RIG_OK) + return retval; - /* - * The result is a 3 digit BCD, but in *big endian* order: 0000..0255 - * (from_bcd is little endian) - */ - icom_val = from_bcd_be(lvlbuf+cmdhead, lvl_len*2); - } - else /* level == RIG_LEVEL_AF */ - { - retval = optoscan_get_status_block(rig,&status_block); + /* + * strbuf should contain Cn,Sc,Data area + */ + cmdhead = (lvl_sc == -1) ? 1 : 2; + lvl_len -= cmdhead; - if (retval != RIG_OK) - return retval; + if (lvlbuf[0] != ACK && lvlbuf[0] != lvl_cn) { + rig_debug(RIG_DEBUG_ERR, "optoscan_get_level: ack NG (%#.2x), " + "len=%d\n", lvlbuf[0], lvl_len); + return -RIG_ERJCTED; + } - icom_val = 0; - if( status_block.speaker_enabled == 1 ) - icom_val = 255; - } + /* + * The result is a 3 digit BCD, but in *big endian* order: 0000..0255 + * (from_bcd is little endian) + */ + icom_val = from_bcd_be(lvlbuf + cmdhead, lvl_len * 2); + } else { /* level == RIG_LEVEL_AF */ + retval = optoscan_get_status_block(rig, &status_block); - switch (level) { - case RIG_LEVEL_RAWSTR: - val->i = icom_val; - break; - default: - if (RIG_LEVEL_IS_FLOAT(level)) - val->f = (float)icom_val/255; - else - val->i = icom_val; - } + if (retval != RIG_OK) + return retval; - rig_debug(RIG_DEBUG_TRACE,"optoscan_get_level: %d %d %d %f\n", lvl_len, - icom_val, val->i, val->f); + icom_val = 0; - return RIG_OK; + if (status_block.speaker_enabled == 1) + icom_val = 255; + } + + switch (level) { + case RIG_LEVEL_RAWSTR: + val->i = icom_val; + break; + + default: + if (RIG_LEVEL_IS_FLOAT(level)) + val->f = (float)icom_val / 255; + else + val->i = icom_val; + } + + rig_debug(RIG_DEBUG_TRACE, "optoscan_get_level: %d %d %d %f\n", lvl_len, + icom_val, val->i, val->f); + + return RIG_OK; } /* OS456 Pipeline tuning algorithm: @@ -519,68 +540,68 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) */ int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) { - pltstate_t *state; - pltune_cb_t cb; - int rc, pin_state; - struct rig_state *rs; + pltstate_t *state; + pltune_cb_t cb; + int rc, pin_state; + struct rig_state *rs; - if(scan != RIG_SCAN_PLT) - return -RIG_ENAVAIL; + if (scan != RIG_SCAN_PLT) + return -RIG_ENAVAIL; - rs=&rig->state; - cb = rig->callbacks.pltune; - state = ((struct icom_priv_data*)rs->priv)->pltstate; + rs = &rig->state; + cb = rig->callbacks.pltune; + state = ((struct icom_priv_data *)rs->priv)->pltstate; - if(state==NULL) - return -RIG_EINTERNAL; + if (state == NULL) + return -RIG_EINTERNAL; - if(state->freq==0) /* pltstate_t is not initialized - perform setup */ - { - /* time for CIV command to be sent. this is subtracted from */ - /* rcvr settle time */ - state->usleep_time = (1000000 / (rig->state.rigport.parm.serial.rate)) - * 13 * 9; + if (state->freq == 0) { /* pltstate_t is not initialized - perform setup */ + /* time for CIV command to be sent. this is subtracted from */ + /* rcvr settle time */ + state->usleep_time = (1000000 / (rig->state.rigport.parm.serial.rate)) + * 13 * 9; - rc=cb(rig,vfo,&(state->next_freq),&(state->next_mode), - &(state->next_width),rig->callbacks.pltune_arg); - if(rc==RIG_SCAN_STOP) - return RIG_OK; /* callback halted loop */ + rc = cb(rig, vfo, &(state->next_freq), &(state->next_mode), + &(state->next_width), rig->callbacks.pltune_arg); - /* Step 1 is implicit, since hamlib does this when it opens the device */ - optoscan_send_freq(rig,state); /*Step 2*/ - } + if (rc == RIG_SCAN_STOP) + return RIG_OK; /* callback halted loop */ - rc=!RIG_SCAN_STOP; - while(rc!=RIG_SCAN_STOP) - { - optoscan_RTS_toggle(rig); /*Step 3*/ - - state->freq = state->next_freq; - state->mode = state->next_mode; - - optoscan_start_timer(rig,state); - - rc=cb(rig,vfo,&(state->next_freq),&(state->next_mode), - &(state->next_width),rig->callbacks.pltune_arg); - if(rc!=RIG_SCAN_STOP) - { - optoscan_send_freq(rig,state); /*Step 4*/ + /* Step 1 is implicit, since hamlib does this when it opens the device */ + optoscan_send_freq(rig, state); /*Step 2*/ } - optoscan_wait_timer(rig,state); /*Step 5*/ + rc = !RIG_SCAN_STOP; - ser_get_car(&rs->rigport,&pin_state); - if( pin_state ) /*Step 6*/ - { - return RIG_OK; /* we've broken squelch - return(). caller can */ - /* get current freq & mode out of state str */ + while (rc != RIG_SCAN_STOP) { + optoscan_RTS_toggle(rig); /*Step 3*/ + + state->freq = state->next_freq; + state->mode = state->next_mode; + + optoscan_start_timer(rig, state); + + rc = cb(rig, vfo, &(state->next_freq), &(state->next_mode), + &(state->next_width), rig->callbacks.pltune_arg); + + if (rc != RIG_SCAN_STOP) { + optoscan_send_freq(rig, state); /*Step 4*/ + } + + optoscan_wait_timer(rig, state); /*Step 5*/ + + ser_get_car(&rs->rigport, &pin_state); + + if (pin_state) { /*Step 6*/ + return RIG_OK; /* we've broken squelch - return(). caller can */ + /* get current freq & mode out of state str */ + } } - } - /* exiting pipeline loop - force state init on next call */ - state->freq=0; + /* exiting pipeline loop - force state init on next call */ + state->freq = 0; - return RIG_OK; + return RIG_OK; } /* @@ -588,131 +609,139 @@ int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) */ static int optoscan_get_status_block(RIG *rig, struct optostat *status_block) { - int retval, ack_len, expected_len; - unsigned char ackbuf[MAXFRAMELEN]; + int retval, ack_len, expected_len; + unsigned char ackbuf[MAXFRAMELEN]; - memset(status_block,0,sizeof(struct optostat)); + memset(status_block, 0, sizeof(struct optostat)); - retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_RDSTAT, NULL, 0, - ackbuf, &ack_len); + retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDSTAT, NULL, 0, + ackbuf, &ack_len); - if (retval != RIG_OK) - return retval; + if (retval != RIG_OK) + return retval; - switch( rig->caps->rig_model ) - { - case RIG_MODEL_OS456: - expected_len=4; - break; - case RIG_MODEL_OS535: - expected_len=5; - break; - default: - rig_debug(RIG_DEBUG_ERR,"optoscan_get_status_block: unknown rig model"); - return -RIG_ERJCTED; - break; - } + switch (rig->caps->rig_model) { + case RIG_MODEL_OS456: + expected_len = 4; + break; - if (ack_len != expected_len ) { - rig_debug(RIG_DEBUG_ERR,"optoscan_get_status_block: ack NG (%#.2x), " - "len=%d\n", ackbuf[0], ack_len); - return -RIG_ERJCTED; - } + case RIG_MODEL_OS535: + expected_len = 5; + break; - if( ackbuf[2] & 1 ) status_block->remote_control = 1; - if( ackbuf[2] & 2 ) status_block->DTMF_pending = 1; - if( ackbuf[2] & 4 ) status_block->DTMF_overrun = 1; - if( ackbuf[2] & 16 ) status_block->squelch_open = 1; - if( ackbuf[2] & 32 ) status_block->CTCSS_active = 1; - if( ackbuf[2] & 64 ) status_block->DCS_active = 1; + default: + rig_debug(RIG_DEBUG_ERR, "optoscan_get_status_block: unknown rig model"); + return -RIG_ERJCTED; + break; + } - if( ackbuf[3] & 1 ) status_block->tape_enabled = 1; - if( ackbuf[3] & 2 ) status_block->speaker_enabled = 1; - if( ackbuf[3] & 4 ) status_block->fivekhz_enabled = 1; - if( ackbuf[3] & 16 ) status_block->audio_present = 1; + if (ack_len != expected_len) { + rig_debug(RIG_DEBUG_ERR, "optoscan_get_status_block: ack NG (%#.2x), " + "len=%d\n", ackbuf[0], ack_len); + return -RIG_ERJCTED; + } - rig_debug(RIG_DEBUG_VERBOSE,"remote_control = %d\n",status_block->remote_control); - rig_debug(RIG_DEBUG_VERBOSE,"DTMF_pending = %d\n",status_block->DTMF_pending); - rig_debug(RIG_DEBUG_VERBOSE,"DTMF_overrun = %d\n",status_block->DTMF_overrun); - rig_debug(RIG_DEBUG_VERBOSE,"squelch_open = %d\n",status_block->squelch_open); - rig_debug(RIG_DEBUG_VERBOSE,"CTCSS_active = %d\n",status_block->CTCSS_active); - rig_debug(RIG_DEBUG_VERBOSE,"DCS_active = %d\n",status_block->DCS_active); - rig_debug(RIG_DEBUG_VERBOSE,"tape_enabled = %d\n",status_block->tape_enabled ); - rig_debug(RIG_DEBUG_VERBOSE,"speaker_enabled = %d\n",status_block->speaker_enabled); - rig_debug(RIG_DEBUG_VERBOSE,"fivekhz_enabled = %d\n",status_block->fivekhz_enabled); - rig_debug(RIG_DEBUG_VERBOSE,"audio_present = %d\n",status_block->audio_present); + if (ackbuf[2] & 1) status_block->remote_control = 1; - return RIG_OK; + if (ackbuf[2] & 2) status_block->DTMF_pending = 1; + + if (ackbuf[2] & 4) status_block->DTMF_overrun = 1; + + if (ackbuf[2] & 16) status_block->squelch_open = 1; + + if (ackbuf[2] & 32) status_block->CTCSS_active = 1; + + if (ackbuf[2] & 64) status_block->DCS_active = 1; + + if (ackbuf[3] & 1) status_block->tape_enabled = 1; + + if (ackbuf[3] & 2) status_block->speaker_enabled = 1; + + if (ackbuf[3] & 4) status_block->fivekhz_enabled = 1; + + if (ackbuf[3] & 16) status_block->audio_present = 1; + + rig_debug(RIG_DEBUG_VERBOSE, "remote_control = %d\n", status_block->remote_control); + rig_debug(RIG_DEBUG_VERBOSE, "DTMF_pending = %d\n", status_block->DTMF_pending); + rig_debug(RIG_DEBUG_VERBOSE, "DTMF_overrun = %d\n", status_block->DTMF_overrun); + rig_debug(RIG_DEBUG_VERBOSE, "squelch_open = %d\n", status_block->squelch_open); + rig_debug(RIG_DEBUG_VERBOSE, "CTCSS_active = %d\n", status_block->CTCSS_active); + rig_debug(RIG_DEBUG_VERBOSE, "DCS_active = %d\n", status_block->DCS_active); + rig_debug(RIG_DEBUG_VERBOSE, "tape_enabled = %d\n", status_block->tape_enabled); + rig_debug(RIG_DEBUG_VERBOSE, "speaker_enabled = %d\n", status_block->speaker_enabled); + rig_debug(RIG_DEBUG_VERBOSE, "fivekhz_enabled = %d\n", status_block->fivekhz_enabled); + rig_debug(RIG_DEBUG_VERBOSE, "audio_present = %d\n", status_block->audio_present); + + return RIG_OK; } -static int optoscan_send_freq(RIG *rig,pltstate_t *state) +static int optoscan_send_freq(RIG *rig, pltstate_t *state) { - unsigned char buff[OPTO_BUFF_SIZE]; - char md,pd; - freq_t freq; - rmode_t mode; + unsigned char buff[OPTO_BUFF_SIZE]; + char md, pd; + freq_t freq; + rmode_t mode; - freq=state->next_freq; - mode=state->next_mode; + freq = state->next_freq; + mode = state->next_mode; - memset(buff,0,OPTO_BUFF_SIZE); + memset(buff, 0, OPTO_BUFF_SIZE); - to_bcd(buff,freq,5*2); /* to_bcd requires nibble len */ + to_bcd(buff, freq, 5 * 2); /* to_bcd requires nibble len */ - rig2icom_mode(rig,mode,0,(unsigned char *) &md, (signed char *) &pd); - buff[5]=md; + rig2icom_mode(rig, mode, 0, (unsigned char *) &md, (signed char *) &pd); + buff[5] = md; - /* read echo'd chars only...there will be no ACK from this command - * - * Note: - * It may have waited fro pltstate->usleep_time before reading the echo'd - * chars, but the read will be blocking anyway. --SF - * */ - return icom_transaction (rig, C_CTL_MISC, S_OPTO_NXT, buff, 6, NULL, NULL); + /* read echo'd chars only...there will be no ACK from this command + * + * Note: + * It may have waited fro pltstate->usleep_time before reading the echo'd + * chars, but the read will be blocking anyway. --SF + * */ + return icom_transaction(rig, C_CTL_MISC, S_OPTO_NXT, buff, 6, NULL, NULL); - return RIG_OK; + return RIG_OK; } static int optoscan_RTS_toggle(RIG *rig) { - struct rig_state *rs; - int state=0; + struct rig_state *rs; + int state = 0; - rs=&rig->state; - ser_get_rts(&rs->rigport,&state); - ser_set_rts(&rs->rigport,!state); + rs = &rig->state; + ser_get_rts(&rs->rigport, &state); + ser_set_rts(&rs->rigport, !state); - return RIG_OK; + return RIG_OK; } static int optoscan_start_timer(RIG *rig, pltstate_t *state) { - gettimeofday(&(state->timer_start),NULL); + gettimeofday(&(state->timer_start), NULL); - return RIG_OK; + return RIG_OK; } static int optoscan_wait_timer(RIG *rig, pltstate_t *state) { - struct icom_priv_caps *priv_caps; - int usec_diff; - int settle_usec; + struct icom_priv_caps *priv_caps; + int usec_diff; + int settle_usec; - priv_caps = (struct icom_priv_caps *)rig->caps->priv; - settle_usec = priv_caps->settle_time * 1000; /*convert settle time (ms) to */ - /* settle time (usec) */ + priv_caps = (struct icom_priv_caps *)rig->caps->priv; + settle_usec = priv_caps->settle_time * 1000; /*convert settle time (ms) to */ + /* settle time (usec) */ - gettimeofday(&(state->timer_current),NULL); + gettimeofday(&(state->timer_current), NULL); - usec_diff = abs( (state->timer_current.tv_usec) - - (state->timer_start.tv_usec) ); + usec_diff = abs((state->timer_current.tv_usec) - + (state->timer_start.tv_usec)); - if( usec_diff < settle_usec ) - { - usleep( settle_usec - usec_diff ); /* sleep balance of settle_time */ - } + if (usec_diff < settle_usec) { + usleep(settle_usec - usec_diff); /* sleep balance of settle_time */ + } - return RIG_OK; + return RIG_OK; } diff --git a/scripts/astylerc b/scripts/astylerc new file mode 100644 index 000000000..b92959106 --- /dev/null +++ b/scripts/astylerc @@ -0,0 +1,32 @@ +# astylerc--custom options for astyle +# Intended to follow the Linux style guide as closely as possible: +# https://www.kernel.org/doc/Documentation/CodingStyle + +# Linux kernel style formatting/indenting. +style=linux + +# Use tabs with a width of 8 spaces. +indent=force-tab=8 + +# Pad empty lines around header blocks (e.g. 'if', 'for', 'while'...). +break-blocks + +# Remove extra space padding around parenthesis on the inside and outside. +unpad-paren + +# Insert space padding around operators. +pad-oper + +# Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...). +pad-header + +# Attach a pointer operator (*) to name (name) and reference operator (&) +# to type (type). +align-pointer=name +align-reference=type + +# Don't break one-line blocks. +keep-one-line-blocks + +# Don't break complex statements and multiple statements residing on a single line. +keep-one-line-statements diff --git a/tests/rigctld.c b/tests/rigctld.c index c43cefdbf..a593da3a3 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -76,15 +76,14 @@ * TODO: add an option to read from a file */ #define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhV" -static struct option long_options[] = -{ +static struct option long_options[] = { {"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'}, {"ptt-file", 1, 0, 'p'}, {"dcd-file", 1, 0, 'd'}, {"ptt-type", 1, 0, 'P'}, {"dcd-type", 1, 0, 'D'}, - {"serial-speed",1, 0, 's'}, + {"serial-speed", 1, 0, 's'}, {"civaddr", 1, 0, 'c'}, {"listen-addr", 1, 0, 'T'}, {"port", 1, 0, 't'}, @@ -106,7 +105,7 @@ struct handle_data { socklen_t clilen; }; -void * handle_socket(void * arg); +void *handle_socket(void *arg); void usage(void); int interactive = 1; /* no cmd because of daemon */ @@ -120,7 +119,7 @@ const char *src_addr = NULL; /* INADDR_ANY */ #define MAXCONFLEN 128 -static void handle_error (enum rig_debug_level_e lvl, const char *msg) +static void handle_error(enum rig_debug_level_e lvl, const char *msg) { int e; #ifdef __MINGW32__ @@ -128,6 +127,7 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg) lpMsgBuf = (LPVOID)"Unknown error"; e = WSAGetLastError(); + if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -136,18 +136,19 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg) MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR)&lpMsgBuf, 0, NULL)) { - rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); LocalFree(lpMsgBuf); } else { - rig_debug (lvl, "%s: Network error %d\n", msg, e); + rig_debug(lvl, "%s: Network error %d\n", msg, e); } + #else e = errno; - rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, strerror (e)); + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); #endif } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { RIG *my_rig; /* handle to rig (instance) */ rig_model_t my_model = RIG_MODEL_DUMMY; @@ -157,7 +158,7 @@ int main (int argc, char *argv[]) int verbose = 0; int show_conf = 0; int dump_caps_opt = 0; - const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL; + const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL; ptt_type_t ptt_type = RIG_PTT_NONE; dcd_type_t dcd_type = RIG_DCD_NONE; int serial_rate = 0; @@ -175,51 +176,63 @@ int main (int argc, char *argv[]) int c; int option_index = 0; - c = getopt_long (argc, argv, SHORT_OPTIONS, - long_options, &option_index); + c = getopt_long(argc, argv, SHORT_OPTIONS, + long_options, &option_index); + if (c == -1) break; - switch(c) { + switch (c) { case 'h': usage(); exit(0); + case 'V': version(); exit(0); + case 'm': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + my_model = atoi(optarg); break; + case 'r': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + rig_file = optarg; break; + case 'p': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + ptt_file = optarg; break; + case 'd': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + dcd_file = optarg; break; + case 'P': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + if (!strcmp(optarg, "RIG")) ptt_type = RIG_PTT_RIG; else if (!strcmp(optarg, "DTR")) @@ -234,12 +247,15 @@ int main (int argc, char *argv[]) ptt_type = RIG_PTT_NONE; else ptt_type = atoi(optarg); + break; + case 'D': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + if (!strcmp(optarg, "RIG")) dcd_type = RIG_DCD_RIG; else if (!strcmp(optarg, "DSR")) @@ -254,59 +270,77 @@ int main (int argc, char *argv[]) dcd_type = RIG_DCD_NONE; else dcd_type = atoi(optarg); + break; + case 'c': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + civaddr = optarg; break; + case 's': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + serial_rate = atoi(optarg); break; + case 'C': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + if (*conf_parms != '\0') strcat(conf_parms, ","); - strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms)); + + strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); break; + case 't': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + portno = optarg; break; + case 'T': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + src_addr = optarg; break; + case 'o': vfo_mode++; break; + case 'v': verbose++; break; + case 'L': show_conf++; break; + case 'l': list_models(); exit(0); + case 'u': dump_caps_opt++; break; + default: usage(); /* unknown option? */ exit(1); @@ -343,17 +377,22 @@ int main (int argc, char *argv[]) */ if (ptt_type != RIG_PTT_NONE) my_rig->state.pttport.type.ptt = ptt_type; + if (dcd_type != RIG_DCD_NONE) my_rig->state.dcdport.type.dcd = dcd_type; + if (ptt_file) strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); + if (dcd_file) strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1); + /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) my_rig->state.rigport.parm.serial.rate = serial_rate; + if (civaddr) - rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); + rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); /* * print out conf parameters @@ -375,7 +414,7 @@ int main (int argc, char *argv[]) retcode = rig_open(my_rig); if (retcode != RIG_OK) { - fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode)); + fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); exit(2); } @@ -398,8 +437,9 @@ int main (int argc, char *argv[]) # endif WSADATA wsadata; - if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) { - fprintf(stderr,"WSAStartup socket error\n"); + + if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { + fprintf(stderr, "WSAStartup socket error\n"); exit(1); } @@ -417,51 +457,57 @@ int main (int argc, char *argv[]) hints.ai_protocol = 0; /* Any protocol */ retcode = getaddrinfo(src_addr, portno, &hints, &result); + if (retcode != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); exit(2); } + saved_result = result; do { sock_listen = socket(result->ai_family, result->ai_socktype, result->ai_protocol); + if (sock_listen < 0) { - handle_error (RIG_DEBUG_ERR, "socket"); + handle_error(RIG_DEBUG_ERR, "socket"); freeaddrinfo(saved_result); /* No longer needed */ exit(2); } if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, (char *)&reuseaddr, sizeof(reuseaddr)) < 0) { - handle_error (RIG_DEBUG_ERR, "setsockopt"); + handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(saved_result); /* No longer needed */ - exit (1); + exit(1); } #ifdef IPV6_V6ONLY + if (AF_INET6 == result->ai_family) { /* allow IPv4 mapped to IPv6 clients Windows and BSD default this to 1 (i.e. disallowed) and we prefer it off */ sockopt = 0; + if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&sockopt, sizeof(sockopt)) < 0) { - handle_error (RIG_DEBUG_ERR, "setsockopt"); + handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(saved_result); /* No longer needed */ - exit (1); + exit(1); } } + #endif if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { break; } - handle_error (RIG_DEBUG_WARN, "binding failed (trying next interface)"); + handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); #ifdef __MINGW32__ - closesocket (sock_listen); + closesocket(sock_listen); #else - close (sock_listen); + close(sock_listen); #endif } while ((result = result->ai_next) != NULL); @@ -469,12 +515,12 @@ int main (int argc, char *argv[]) if (NULL == result) { rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n"); - exit (1); + exit(1); } if (listen(sock_listen, 4) < 0) { - handle_error (RIG_DEBUG_ERR, "listening"); - exit (1); + handle_error(RIG_DEBUG_ERR, "listening"); + exit(1); } /* @@ -491,21 +537,21 @@ int main (int argc, char *argv[]) if (!arg) { rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); - exit (1); + exit(1); } arg->rig = my_rig; - arg->clilen = sizeof (arg->cli_addr); + arg->clilen = sizeof(arg->cli_addr); arg->sock = accept(sock_listen, (struct sockaddr *)&arg->cli_addr, &arg->clilen); if (arg->sock < 0) { - handle_error (RIG_DEBUG_ERR, "accept"); + handle_error(RIG_DEBUG_ERR, "accept"); break; } - if ((retcode = getnameinfo ((struct sockaddr const *)&arg->cli_addr, arg->clilen, host, - sizeof (host), serv, sizeof (serv), NI_NOFQDN)) < 0) { - rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode)); + if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, arg->clilen, host, + sizeof(host), serv, sizeof(serv), NI_NOFQDN)) < 0) { + rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); } rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n", host, serv); @@ -520,6 +566,7 @@ int main (int argc, char *argv[]) rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); break; } + #else handle_socket(arg); #endif @@ -539,7 +586,7 @@ int main (int argc, char *argv[]) /* * This is the function run by the threads */ -void * handle_socket(void *arg) +void *handle_socket(void *arg) { struct handle_data *handle_data_arg = (struct handle_data *)arg; FILE *fsockin; @@ -560,6 +607,7 @@ void * handle_socket(void *arg) #else fsockin = fdopen(handle_data_arg->sock, "rb"); #endif + if (!fsockin) { rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); goto handle_exit; @@ -570,6 +618,7 @@ void * handle_socket(void *arg) #else fsockout = fdopen(handle_data_arg->sock, "wb"); #endif + if (!fsockout) { rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); fclose(fsockin); @@ -579,14 +628,15 @@ void * handle_socket(void *arg) do { retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0); + if (ferror(fsockin) || ferror(fsockout)) retcode = 1; } while (retcode == 0 || retcode == 2); - if ((retcode = getnameinfo ((struct sockaddr const *)&handle_data_arg->cli_addr, - handle_data_arg->clilen, host, sizeof (host), - serv, sizeof (serv), NI_NOFQDN)) < 0) { - rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode)); + if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, + handle_data_arg->clilen, host, sizeof(host), + serv, sizeof(serv), NI_NOFQDN)) < 0) { + rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); } rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n", @@ -636,7 +686,7 @@ void usage(void) " -v, --verbose set verbose mode, cumulative\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n\n", - portno ); + portno); usage_rig(stdout); diff --git a/tests/rotctld.c b/tests/rotctld.c index 9b5547bbe..04c9747ca 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -72,7 +72,7 @@ struct handle_data { socklen_t clilen; }; -void * handle_socket(void * arg); +void *handle_socket(void *arg); void usage(); @@ -83,11 +83,10 @@ void usage(); * TODO: add an option to read from a file */ #define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl" -static struct option long_options[] = -{ +static struct option long_options[] = { {"model", 1, 0, 'm'}, {"rot-file", 1, 0, 'r'}, - {"serial-speed",1, 0, 's'}, + {"serial-speed", 1, 0, 's'}, {"port", 1, 0, 't'}, {"listen-addr", 1, 0, 'T'}, {"list", 0, 0, 'l'}, @@ -101,7 +100,7 @@ static struct option long_options[] = }; int interactive = 1; /* no cmd because of daemon */ -int prompt= 0 ; /* Daemon mode for rigparse return string */ +int prompt = 0 ; /* Daemon mode for rigparse return string */ const char *portno = "4533"; const char *src_addr = NULL; /* INADDR_ANY */ @@ -111,7 +110,7 @@ char send_cmd_term = '\r'; /* send_cmd termination char */ #define MAXCONFLEN 128 -static void handle_error (enum rig_debug_level_e lvl, const char *msg) +static void handle_error(enum rig_debug_level_e lvl, const char *msg) { int e; #ifdef __MINGW32__ @@ -128,18 +127,19 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg) MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR)&lpMsgBuf, 0, NULL)) { - rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); LocalFree(lpMsgBuf); } else { - rig_debug (lvl, "%s: Network error %d\n", msg, e); + rig_debug(lvl, "%s: Network error %d\n", msg, e); } + #else e = errno; - rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, strerror (e)); + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); #endif } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { ROT *my_rot; /* handle to rot (instance) */ rot_model_t my_model = ROT_MODEL_DUMMY; @@ -149,7 +149,7 @@ int main (int argc, char *argv[]) int verbose = 0; int show_conf = 0; int dump_caps_opt = 0; - const char *rot_file=NULL; + const char *rot_file = NULL; int serial_rate = 0; char conf_parms[MAXCONFLEN] = ""; @@ -160,78 +160,98 @@ int main (int argc, char *argv[]) char host[NI_MAXHOST]; char serv[NI_MAXSERV]; - while(1) { + while (1) { int c; int option_index = 0; c = getopt_long(argc, argv, SHORT_OPTIONS, - long_options, &option_index); + long_options, &option_index); + if (c == -1) break; - switch(c) { + switch (c) { case 'h': usage(); exit(0); + case 'V': version(); exit(0); + case 'm': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + my_model = atoi(optarg); break; + case 'r': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + rot_file = optarg; break; + case 's': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + serial_rate = atoi(optarg); break; + case 'C': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + if (*conf_parms != '\0') strcat(conf_parms, ","); - strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms)); + + strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); break; + case 't': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + portno = optarg; break; + case 'T': if (!optarg) { usage(); /* wrong arg count */ exit(1); } + src_addr = optarg; break; + case 'v': verbose++; break; + case 'L': show_conf++; break; + case 'l': list_models(); exit(0); + case 'u': dump_caps_opt++; break; + default: usage(); /* unknown option? */ exit(1); @@ -287,7 +307,7 @@ int main (int argc, char *argv[]) retcode = rot_open(my_rot); if (retcode != RIG_OK) { - fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode)); + fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode)); exit(2); } @@ -311,8 +331,8 @@ int main (int argc, char *argv[]) WSADATA wsadata; - if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) { - fprintf(stderr,"WSAStartup socket error\n"); + if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { + fprintf(stderr, "WSAStartup socket error\n"); exit(1); } @@ -330,6 +350,7 @@ int main (int argc, char *argv[]) hints.ai_protocol = 0; /* Any protocol */ retcode = getaddrinfo(src_addr, portno, &hints, &result); + if (retcode != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); exit(2); @@ -342,19 +363,20 @@ int main (int argc, char *argv[]) result->ai_protocol); if (sock_listen < 0) { - handle_error (RIG_DEBUG_ERR, "socket"); + handle_error(RIG_DEBUG_ERR, "socket"); freeaddrinfo(result); /* No longer needed */ exit(1); } if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, - (char *)&reuseaddr,sizeof(reuseaddr)) < 0) { - handle_error (RIG_DEBUG_ERR, "setsockopt"); + (char *)&reuseaddr, sizeof(reuseaddr)) < 0) { + handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(result); /* No longer needed */ - exit (1); + exit(1); } #ifdef IPV6_V6ONLY + if (AF_INET6 == result->ai_family) { /* allow IPv4 mapped to IPv6 clients, MS & BSD default this to 1 i.e. disallowed */ @@ -362,21 +384,23 @@ int main (int argc, char *argv[]) if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&sockopt, sizeof(sockopt)) < 0) { - handle_error (RIG_DEBUG_ERR, "setsockopt"); + handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(saved_result); /* No longer needed */ - exit (1); + exit(1); } } + #endif if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { break; } - handle_error (RIG_DEBUG_WARN, "binding failed (trying next interface)"); + + handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); #ifdef __MINGW32__ - closesocket (sock_listen); + closesocket(sock_listen); #else - close (sock_listen); + close(sock_listen); #endif } while ((result = result->ai_next) != NULL); @@ -384,12 +408,12 @@ int main (int argc, char *argv[]) if (NULL == result) { rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n"); - exit (1); + exit(1); } if (listen(sock_listen, 4) < 0) { - handle_error (RIG_DEBUG_ERR, "listening"); - exit (1); + handle_error(RIG_DEBUG_ERR, "listening"); + exit(1); } /* @@ -406,7 +430,7 @@ int main (int argc, char *argv[]) if (!arg) { rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); - exit (1); + exit(1); } arg->rot = my_rot; @@ -415,14 +439,14 @@ int main (int argc, char *argv[]) &arg->clilen); if (arg->sock < 0) { - handle_error (RIG_DEBUG_ERR, "accept"); + handle_error(RIG_DEBUG_ERR, "accept"); break; } - if ((retcode = getnameinfo ((struct sockaddr const *)&arg->cli_addr, arg->clilen, - host, sizeof (host), serv, sizeof (serv), - NI_NOFQDN)) < 0) { - rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode)); + if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, arg->clilen, + host, sizeof(host), serv, sizeof(serv), + NI_NOFQDN)) < 0) { + rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); } rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n", @@ -438,6 +462,7 @@ int main (int argc, char *argv[]) rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); break; } + #else handle_socket(arg); #endif @@ -457,7 +482,7 @@ int main (int argc, char *argv[]) /* * This is the function run by the threads */ -void * handle_socket(void *arg) +void *handle_socket(void *arg) { struct handle_data *handle_data_arg = (struct handle_data *)arg; FILE *fsockin; @@ -478,6 +503,7 @@ void * handle_socket(void *arg) #else fsockin = fdopen(handle_data_arg->sock, "rb"); #endif + if (!fsockin) { rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); goto handle_exit; @@ -488,6 +514,7 @@ void * handle_socket(void *arg) #else fsockout = fdopen(handle_data_arg->sock, "wb"); #endif + if (!fsockout) { rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); fclose(fsockin); @@ -496,14 +523,15 @@ void * handle_socket(void *arg) do { retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0); + if (ferror(fsockin) || ferror(fsockout)) retcode = 1; } while (retcode == 0 || retcode == 2); - if ((retcode = getnameinfo ((struct sockaddr const *)&handle_data_arg->cli_addr, - handle_data_arg->clilen, host, sizeof (host), - serv, sizeof (serv), NI_NOFQDN)) < 0) { - rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode)); + if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, + handle_data_arg->clilen, host, sizeof(host), + serv, sizeof(serv), NI_NOFQDN)) < 0) { + rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); } rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n",