diff --git a/AUTHORS b/AUTHORS index 157d64cd2..dc7feb721 100644 --- a/AUTHORS +++ b/AUTHORS @@ -28,6 +28,9 @@ S: Status, one of the following: Backends: +[adat: ADT-200A] +M: Frank Goenninger DG1SBG + [alinco: DX77-T] M: Ben Coleman NJ8J diff --git a/Makefile.am b/Makefile.am index 0d21b349f..2ede07808 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ SUBDIRS = macros include lib $(subdirs) src @BACKEND_LIST@ @ROT_BACKEND_LIST@ \ # perl and kylix subdirs are no longer distributed DIST_SUBDIRS = macros include lib $(subdirs) src c++ bindings tests doc \ icom kenwood aor yaesu dummy pcr alinco uniden tentec kachina jrc \ - rpcrig winradio easycomm fodtrack rpcrot drake rotorez \ + rpcrig winradio adat easycomm fodtrack rpcrot drake rotorez \ flexradio sartek lowe rft rs tapr kit skanti prm80 wj racal tuner \ gs232a heathkit spid ars m2 amsat scripts ts7400 celestron diff --git a/NEWS b/NEWS index 67f99f95e..ccc6a1f6a 100644 --- a/NEWS +++ b/NEWS @@ -6,7 +6,7 @@ Copyright (C) 2000-2012 Stephane Fillod, and others Please send Hamlib bug reports to hamlib-developer@lists.sourceforge.net Version 1.2.15 - * New models: TT-599 Eagle, IC-RX7, IC-1275 + * New models: TT-599 Eagle, IC-RX7, IC-1275, HiQSDR, ADAT ADT-200A * New rotator backends: Celestron (telescope mount) * Fixes and features: K3 diff --git a/adat/Makefile.am b/adat/Makefile.am new file mode 100644 index 000000000..4e2835cc9 --- /dev/null +++ b/adat/Makefile.am @@ -0,0 +1,8 @@ +ADATSRC = adt_200a.c adat.c + +pkglib_LTLIBRARIES = hamlib-adat.la +hamlib_adat_la_SOURCES = $(ADATSRC) +hamlib_adat_la_LDFLAGS = -no-undefined -module -avoid-version +hamlib_adat_la_LIBADD = $(top_builddir)/src/libhamlib.la + +noinst_HEADERS = adat.h adt_200a.h diff --git a/adat/adat.c b/adat/adat.c new file mode 100644 index 000000000..3fc43e44c --- /dev/null +++ b/adat/adat.c @@ -0,0 +1,3745 @@ +// --------------------------------------------------------------------------- +// ADAT Hamlib Backend +// --------------------------------------------------------------------------- +// +// adat.c +// +// Created by Frank Goenninger DG1SBG. +// Copyright © 2011, 2012 Frank Goenninger. Creative Commons License. +// +// $Header$ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +// --------------------------------------------------------------------------- +// SYSTEM INCLUDES +// --------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include +#include + +// --------------------------------------------------------------------------- +// HAMLIB INCLUDES +// --------------------------------------------------------------------------- + +#include "hamlib/rig.h" +#include "token.h" +#include "serial.h" +#include "misc.h" +#include "register.h" +#include "num_stdio.h" + +// --------------------------------------------------------------------------- +// ADAT INCLUDES +// --------------------------------------------------------------------------- + +#include "adat.h" + +// --------------------------------------------------------------------------- +// GLOBAL DEFINITIONS +// --------------------------------------------------------------------------- + +#if !defined( NDEDBUG ) +#define ADAT_DEBUG 1 +#endif + +#undef ADAT_DEBUG // manual override ... + +// --------------------------------------------------------------------------- +// ADAT GLOBAL VARIABLES +// --------------------------------------------------------------------------- + +// DEBUG STUFF + +static int gFnLevel = 0; + +// ADAT 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, + ADAT_MODE_RNR_CW, + ADAT_MODE_ANR_CW + }, + + { + 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_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_SU, + ADAT_MODE_RNR_AM_SU, + ADAT_MODE_ANR_AM_SU + }, + + { + 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, + + { + { + 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_C, + ADAT_VFO_RNR_C, + ADAT_VFO_ANR_C + } + } +}; + +// --------------------------------------------------------------------------- +// Individual ADAT CAT commands +// --------------------------------------------------------------------------- + +// -- 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + 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, + + adat_cmd_fn_get_freq, + + 1, + { + ADAT_CMD_DEF_STRING_GET_FREQ + } +}; + +static adat_cmd_list_t adat_cmd_list_get_freq = +{ + 1, + { + &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, + + adat_cmd_fn_set_freq, + + 1, + { + ADAT_CMD_DEF_STRING_SET_FREQ + } +}; + +static adat_cmd_list_t adat_cmd_list_set_freq = +{ + 4, + { + &adat_cmd_display_off, + &adat_cmd_set_freq, + &adat_cmd_get_freq, + &adat_cmd_display_on + } +}; +// -- GET VFO -- + +static adat_cmd_list_t adat_cmd_list_get_vfo = +{ + 1, + { + &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, + + adat_cmd_fn_get_mode, + + 1, + { + ADAT_CMD_DEF_STRING_GET_MODE + } +}; + +static adat_cmd_list_t adat_cmd_list_get_mode = +{ + 1, + { + &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, + + adat_cmd_fn_set_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 = +{ + 3, + { + &adat_cmd_display_off, + &adat_cmd_set_vfo, + &adat_cmd_display_on + } +}; + + +// -- SET MODE -- + +static adat_cmd_def_t adat_cmd_set_mode = +{ + ADAT_CMD_DEF_SET_MODE, + ADAT_CMD_KIND_WITHOUT_RESULT, + + adat_cmd_fn_set_mode, + + 1, + { + ADAT_CMD_DEF_STRING_SET_MODE + } +}; + +static adat_cmd_list_t adat_cmd_list_set_mode = +{ + 4, + { + &adat_cmd_display_off, + &adat_cmd_set_vfo, + &adat_cmd_set_mode, + &adat_cmd_display_on + } +}; + +// -- SET PTT -- + +static adat_cmd_def_t adat_cmd_set_ptt = +{ + ADAT_CMD_DEF_SET_PTT, + ADAT_CMD_KIND_WITHOUT_RESULT, + + adat_cmd_fn_set_ptt, + + 1, + { + ADAT_CMD_DEF_STRING_SET_PTT + } +}; + +static adat_cmd_list_t adat_cmd_list_set_ptt = +{ + 1, + { + // &adat_cmd_display_off, + // &adat_cmd_set_vfo, + &adat_cmd_set_ptt, + // &adat_cmd_display_on + } +}; + +// -- GET PTT -- + +static adat_cmd_def_t adat_cmd_get_ptt = +{ + ADAT_CMD_DEF_GET_PTT, + ADAT_CMD_KIND_WITH_RESULT, + + adat_cmd_fn_get_ptt, + + 1, + { + ADAT_CMD_DEF_STRING_GET_PTT + } +}; + +static adat_cmd_list_t adat_cmd_list_get_ptt = +{ + 1, + { + &adat_cmd_get_ptt + } +}; + +// -- GET POWER STATUS -- + +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 + } +}; + +// -- OPEN ADAT -- + +static adat_cmd_list_t adat_cmd_list_open_adat = +{ + 8, + { + &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, + &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 + } +}; + +// --------------------------------------------------------------------------- +// IMPLEMEMTATION +// --------------------------------------------------------------------------- + +// --------------------------------------------------------------------------- +// trimwhitespace - taken from Stackoverflow +// http://stackoverflow.com/questions/122616/how-do-i-trim-leading-trailing-whitespace-in-a-standard-way +// --------------------------------------------------------------------------- +// Status: RELEASED + +size_t trimwhitespace( char *out, size_t len, const char *str ) +{ + + gFnLevel++; + 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; + } + + const char *end; + size_t out_size; + + // Trim leading space + while(isspace(*str)) str++; + + if(*str == 0) // All spaces? + { + out = NULL; + gFnLevel--; + return 1; + } + + // Trim trailing space + end = str + strlen(str) - 1; + while(end > str && isspace(*end)) end--; + 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; BUG ! + out_size = (end - str) < len-1 ? (end - str) : len; + + // Copy trimmed string and add null terminator + memcpy(out, str, out_size); + out[out_size] = 0; + + 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; +} + +// --------------------------------------------------------------------------- +// adat_print_cmd +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_print_cmd( adat_cmd_def_ptr pCmd ) +{ + int nRC = RIG_OK; + + int nI = 0; + + 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, + "*** -> Command ID = %lld\n", + pCmd->nCmdId ); + + rig_debug( RIG_DEBUG_TRACE, + "*** -> Command kind = %d\n", + pCmd->nCmdKind ); + + 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++; + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %s (%s:%d): EXIT. Return Code = %d\n", + __func__, __FILE__, __LINE__, + nRC ); + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_parse_freq +// --------------------------------------------------------------------------- +// Status: RELEASED + +// Can be used to parse strings with VFO nr and without VFO nr in it: +// "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 nRC = RIG_OK; + + 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; + + char *pcEnd = NULL; + + if( nMode == ADAT_FREQ_PARSE_MODE_WITH_VFO ) + { + // Get VFO from response string + + _nVFO = strtol( pcStr, &pcEnd, 10 ); + + // Save VFO + + *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; + + memset( acValueBuf, 0, ADAT_BUFSZ + 1 ); + memset( acUnitBuf, 0, ADAT_BUFSZ + 1 ); + + // Get Freq Value from response string + + while(( isalpha( *pcEnd ) == 0 ) || + ( *pcEnd == '.' )) + { + acValueBuf[ nI++ ] = *pcEnd; + pcEnd += sizeof( char ); + } + + dTmpFreq = strtod( acValueBuf, (char**) NULL ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d acValueBuf = \"%s\", dTmpFreq = %f, *pcEnd = %c\n", + gFnLevel, acValueBuf, dTmpFreq, *pcEnd ); + + // Get Freq Unit from response string + + nI = 0; + while( isalpha( *pcEnd ) != 0 ) + { + acUnitBuf[ nI++ ] = *pcEnd; + pcEnd += sizeof( char ); + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d acUnitBuf = \"%s\"\n", + gFnLevel, acUnitBuf ); + + // 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 + + *nFreq = 0; + *nVFO = 0; + } + + // Done + + 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; +} + +// --------------------------------------------------------------------------- +// adat_parse_mode +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_parse_mode( char *pcStr, + rmode_t *nRIGMode, + char *pcADATMode ) +{ + 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 ); + + 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 ... + + *nRIGMode = RIG_MODE_NONE; + pcADATMode = NULL; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_mode_rnr2anr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_mode_rnr2anr( rmode_t nRIGMode, + int *nADATMode ) +{ + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; + + gFnLevel++; + + 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++; + } + } + + if( nFini == 0 ) + { + // No valid Mode given + + nRC = -RIG_EINVAL; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_mode_anr2rnr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_mode_anr2rnr( int nADATMode, + rmode_t *nRIGMode ) +{ + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; + + gFnLevel++; + + 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++; + } + } + + if( nFini == 0 ) + { + // No valid Mode given + + nRC = -RIG_EINVAL; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_parse_vfo +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_parse_vfo( char *pcStr, + vfo_t *nRIGVFONr, + int *nADATVFONr ) +{ + 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 ); + + 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++; + } + } + + if( nFini == 0 ) + { + nRC = -RIG_EINVAL; + } + } + else + { + // If input string is NULL ... + + *nRIGVFONr = RIG_VFO_NONE; + *nADATVFONr = 0; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_vfo_rnr2anr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_vfo_rnr2anr( vfo_t nRIGVFONr, + int *nADATVFONr ) +{ + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; + + gFnLevel++; + + 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++; + } + } + + if( nFini == 0 ) + { + // No valid Mode given + + nRC = -RIG_EINVAL; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_vfo_anr2rnr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_vfo_anr2rnr( int nADATVFONr, + vfo_t *nRIGVFONr ) +{ + int nRC = RIG_OK; + int nI = 0; + int nFini = 0; + + gFnLevel++; + + 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++; + } + } + + if( nFini == 0 ) + { + // No valid ADAT VFO Nr given + + nRC = -RIG_EINVAL; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_parse_ptt +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_parse_ptt( char *pcStr, + int *nADATPTTStatus ) +{ + 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 ); + + 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; + } + + // Done + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_ptt_rnr2anr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_ptt_rnr2anr( ptt_t nRIGPTTStatus, + int *nADATPTTStatus ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + case ADAT_PTT_STATUS_RNR_OFF: + *nADATPTTStatus = ADAT_PTT_STATUS_ANR_OFF; + break; + + default: + nRC = -RIG_EINVAL; + break; + } + + // 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_ptt_anr2rnr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_ptt_anr2rnr( int nADATPTTStatus, + ptt_t *nRIGPTTStatus ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + case ADAT_PTT_STATUS_ANR_OFF: + *nRIGPTTStatus = ADAT_PTT_STATUS_RNR_OFF; + break; + + default: + nRC = -RIG_EINVAL; + break; + } + + // 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--; + + return nRC; +} + + + + + + + + + +// --------------------------------------------------------------------------- +// adat_send +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_send( RIG *pRig, + char *pcData ) +{ + int nRC = RIG_OK; + struct rig_state *pRigState = &pRig->state; + + 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 ); + + serial_flush( &pRigState->rigport ); + + 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 ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_receive +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_receive( RIG *pRig, + char *pcData ) +{ + int nRC = RIG_OK; + struct rig_state *pRigState = &pRig->state; + + gFnLevel++; + + 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 ); + + 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 ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_priv_set_cmd +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_priv_set_cmd( RIG *pRig, char *pcCmd, int nCmdKind ) +{ + int nRC = RIG_OK; + + 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 ); + + 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 ); + + pPriv->pcCmd = strdup( pcCmd ); + pPriv->nCmdKind = nCmdKind; + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_priv_set_result +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_priv_set_result( RIG *pRig, char *pcResult ) +{ + int nRC = RIG_OK; + + 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 ); + + 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 ); + + pPriv->pcResult = strdup( pcResult ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcResult = \"%s\"\n", + gFnLevel, pPriv->pcResult ); + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_priv_clear_result +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_priv_clear_result( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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( pPriv->pcResult != NULL ) + free( pPriv->pcResult ); + + pPriv->pcResult = NULL; + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_get_single_cmd_result +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_get_single_cmd_result( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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; + + memset( acBuf, 0, ADAT_RESPSZ + 1 ); + memset( acBuf2, 0, ADAT_RESPSZ + 1 ); + + nRC = adat_receive( pRig, acBuf ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d acBuf ........ = 0x%08x\n", + gFnLevel, acBuf ); + + nBufLength = strlen( acBuf ); + pcBufEnd = acBuf + nBufLength - 1; + pcPos = acBuf; + + 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 ... ;-) + + pcResult = pcPos; // Save position + + if( pcPos < pcBufEnd ) + { + nLength = strlen( pcPos ); + + if( nLength > 0 ) + { + char *pcPos2 = strchr( pcPos, (char) 0x0d ); + if( pcPos2 != NULL ) + *pcPos2 = '\0'; // Truncate \0d\0a + + pcPos = strchr( pcPos, ' ' ); + + if(( pcPos != NULL ) && ( pcPos < pcBufEnd )) + { + pcPos += sizeof( char ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pcPos ........ = 0x%08x\n", + gFnLevel, pcPos ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pcBufEnd ..... = 0x%08x\n", + gFnLevel, pcBufEnd ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d nBufLength ... = %d\n", + gFnLevel, nBufLength ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pcPos2 ....... = 0x%08x\n", + gFnLevel, pcPos2 ); + + trimwhitespace( acBuf2, strlen( pcPos ), pcPos ); + pcResult = acBuf2; + } + } + else + { + nRC = -RIG_EINVAL; + } + } + else + { + nRC = -RIG_EINVAL; + } + + if( nRC == RIG_OK ) + { + adat_priv_set_result( pRig, pcResult ); + } + else + { + adat_priv_clear_result( pRig ); + } + } + } + + serial_flush( &pRigState->rigport ); + + pPriv->nRC = 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; +} + +// --------------------------------------------------------------------------- +// adat_cmd_recover_from_error +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_recover_from_error( RIG *pRig, int nError ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + // Recover from communication error + + if(( nError == RIG_ETIMEOUT ) || + ( nError == RIG_EPROTO ) || + ( nError == RIG_EIO )) + { + rig_close( pRig ); + sleep( ADAT_SLEEP_AFTER_RIG_CLOSE ); + + rig_open( pRig ); + } + + // Reset critical Priv values + + pPriv->nRC = RIG_OK; + + // Execute recovery commands + + (void) adat_transaction( pRig, &adat_cmd_list_recover_from_error ); + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_callsign +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_callsign( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcCallsign = \"%s\"\n", + gFnLevel, pPriv->pcCallsign ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_set_callsign +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_cmd_fn_set_callsign( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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 ]; + + memset( acBuf, 0, ADAT_BUFSZ + 1 ); + + 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 ); + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_serial_nr +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_serial_nr( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcSerialNr = \"%s\"\n", + gFnLevel, pPriv->pcSerialNr ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_fw_version +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_fw_version( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcFWVersion = \"%s\"\n", + gFnLevel, pPriv->pcFWVersion ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_hw_version +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_hw_version( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcHWVersion = \"%s\"\n", + gFnLevel, pPriv->pcHWVersion ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_gui_fw_version +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_gui_fw_version( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcGUIFWVersion = \"%s\"\n", + gFnLevel, pPriv->pcGUIFWVersion ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_id_code +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_id_code( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcIDCode = \"%s\"\n", + gFnLevel, pPriv->pcIDCode ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_options +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_options( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d pPriv->pcOptions = \"%s\"\n", + gFnLevel, pPriv->pcOptions ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_mode +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_mode( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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 ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_set_mode +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_set_mode( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + // Translate Mode from RIG Mode Nr to ADAT Mode Nr + + nRC = adat_mode_rnr2anr( pPriv->nRIGMode, &(pPriv->nADATMode) ); + + if( nRC == RIG_OK ) + { + // Prepare Command + + char acBuf[ 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 ); + + nRC = adat_priv_set_cmd( pRig, acBuf, ADAT_CMD_KIND_WITHOUT_RESULT ); + + // Execute Command + + 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; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_freq +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_freq( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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) ); + + 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) ); + } + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_set_freq +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_set_freq( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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 ]; + + // Get frequency of selected VFO + + memset( acBuf, 0, ADAT_BUFSZ + 1 ); + + 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 ); + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_set_vfo +// --------------------------------------------------------------------------- +// Status: RELEASED + +// Setting a VFO on an ADAT is actually two steps: +// 1. Switching on that VFO +// 2. Setting this VFO as the main VFO + +int adat_cmd_fn_set_vfo( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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 ]; + + // Switch on VFO + + memset( acBuf, 0, ADAT_BUFSZ + 1 ); + + 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 ); + 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; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_get_ptt +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_get_ptt( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + 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) ); + } + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// adat_cmd_fn_set_ptt +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cmd_fn_set_ptt( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + + memset( acBuf, 0, ADAT_BUFSZ + 1 ); + + // Switch PTT + + 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; + + 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; + } + + 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 ); + } + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + + + +// --------------------------------------------------------------------------- +// adat_transaction +// --------------------------------------------------------------------------- +// Status: RELEASED + +// 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 nRC = RIG_OK; + int nFini = 0; // = 1 -> Stop executing commands + + gFnLevel++; + + 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; + + 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; + + pCmd = pCmdList->adat_cmds[ nI ]; + + 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 ); + + // 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->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 ] ); + + 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 ]; + + memset( acBuf, 0, ADAT_RESPSZ + 1 ); + + nRC = adat_receive( pRig, acBuf ); + pPriv->pcResult = strdup( acBuf ); + } + } + + nJ++; + } + } + } + } + + if( nRC != RIG_OK ) + { + (void) adat_cmd_recover_from_error( pRig, nRC ); + } + + nI++; + } + else + { + nFini = 1; + } + + // sleep between cmds - ADAT needs time to act upoon cmds + + 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; +} + +// --------------------------------------------------------------------------- +// adat_new_priv_data +// --------------------------------------------------------------------------- +// Status: RELEASED + +adat_priv_data_ptr adat_new_priv_data( RIG *pRig ) +{ + int nRC = 0; + adat_priv_data_ptr pPriv = NULL; + + gFnLevel++; + + 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 + + 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 ); + + // 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 ); + + pRig->state.priv = (void *) pPriv; + } +#else + pRig->state.priv = (void *) pPriv; +#endif + } + else + { + nRC = -RIG_ENOMEM; + } + } + else + { + nRC = -RIG_EARG; + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Value = 0x%x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pPriv ); + gFnLevel--; + + return pPriv; +} + +// --------------------------------------------------------------------------- +// adat_del_priv_data +// --------------------------------------------------------------------------- +// Status: RELEASED + +void adat_del_priv_data( adat_priv_data_t **ppPriv ) +{ + int nRC = 0; + + gFnLevel++; + + 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)->pcProductName != NULL ) + { + free( (*ppPriv)->pcProductName ); + } + + if( (*ppPriv)->pcSerialNr != NULL ) + { + free( (*ppPriv)->pcSerialNr ); + } + + if( (*ppPriv)->pcHWVersion != NULL ) + { + free( (*ppPriv)->pcHWVersion ); + } + + if( (*ppPriv)->pcFWVersion != NULL ) + { + free( (*ppPriv)->pcFWVersion ); + } + + if( (*ppPriv)->pcGUIFWVersion != NULL ) + { + free( (*ppPriv)->pcGUIFWVersion ); + } + + if( (*ppPriv)->pcOptions != NULL ) + { + free( (*ppPriv)->pcOptions ); + } + + if( (*ppPriv)->pcIDCode != NULL ) + { + free( (*ppPriv)->pcIDCode ); + } + + if( (*ppPriv)->pcCallsign != NULL ) + { + free( (*ppPriv)->pcCallsign ); + } + + // Free priv struct itself + + free( (*ppPriv) ); + *ppPriv = NULL; + } + else + { + nRC = -RIG_EARG; + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT.\n", + gFnLevel, __func__, __FILE__, __LINE__); + gFnLevel--; + + return; +}; + +// --------------------------------------------------------------------------- +// Function adat_init +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_init( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + if( pRig == NULL ) + { + nRC = -RIG_EARG; + } + else + { + adat_priv_data_ptr pPriv = NULL; + + // Get new Priv Data + + pPriv = adat_new_priv_data( pRig ); + if( pPriv == NULL ) + { + nRC = -RIG_ENOMEM; + } + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_cleanup +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_cleanup( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + 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; + } + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_open +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_open( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + if( pRig == NULL ) + { + nRC = -RIG_EARG; + } + else + { + // grace period for the radio to be there + + sleep( ADAT_SLEEP_AFTER_RIG_OPEN ); + + // Now get basic info from ADAT TRX + + nRC = adat_transaction( pRig, &adat_cmd_list_open_adat ); + } + + // Done ! + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_info +// --------------------------------------------------------------------------- +// Status: RELEASED + +const char * adat_get_info( RIG *pRig ) +{ + int nRC = RIG_OK; + static char acBuf[ 512 ]; + + gFnLevel++; + + 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 ); + + 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; + + 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 ); + } + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Value ='%s'\n", + gFnLevel, __func__, __FILE__, __LINE__, + acBuf ); + gFnLevel--; + + return acBuf; +} + +// --------------------------------------------------------------------------- +// Function adat_set_freq +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_set_freq( RIG *pRig, vfo_t vfo, freq_t freq ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + if( pRig == NULL ) + { + nRC = -RIG_EARG; + } + else + { + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + + pPriv->nFreq = 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_freq +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_get_freq( RIG *pRig, vfo_t vfo, freq_t *freq ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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 ); + + *freq = pPriv->nFreq; + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_set_level +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_set_level( RIG *pRig, vfo_t vfo, setting_t level, value_t val ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_level +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_get_level( RIG *pRig, vfo_t vfo, setting_t level, value_t *val ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_set_mode +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_set_mode(RIG *pRig, vfo_t vfo, rmode_t mode, pbwidth_t width ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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) ); + + if( width == RIG_PASSBAND_NORMAL ) + width = rig_passband_normal( pRig, mode ); + + pPriv->nWidth = width; + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_mode +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_get_mode( RIG *pRig, vfo_t vfo, rmode_t *mode, pbwidth_t *width ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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; + } + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_vfo +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_get_vfo( RIG *pRig, vfo_t *vfo ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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 ); + + *vfo = pPriv->nRIGVFONr; + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_set_vfo +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_set_vfo( RIG *pRig, vfo_t vfo ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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 ); + } + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_ptt +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_get_ptt( RIG *pRig, vfo_t vfo, ptt_t *ptt ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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 ); + + *ptt = pPriv->nRIGPTTStatus; + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_set_ptt +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_set_ptt( RIG *pRig, vfo_t vfo, ptt_t ptt ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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; + + case RIG_PTT_OFF: + pPriv->nOpCode = ADAT_OPCODE_PTT_SWITCH_OFF; + break; + + default: + nRC = -RIG_EINVAL; + break; + } + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_power2mW +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_power2mW( RIG * pRig, unsigned int *mwpower, float power, + freq_t freq, rmode_t mode ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_mW2power +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_mW2power( RIG * pRig, float *power, unsigned int mwpower, + freq_t freq, rmode_t mode ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_powerstat +// --------------------------------------------------------------------------- +// Status: RELEASED + +int adat_get_powerstat( RIG *pRig, powerstat_t *status ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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 < 0 -> Power is off. + + 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--; + + return nRC; +} + + +// --------------------------------------------------------------------------- +// Function adat_set_conf +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_set_conf( RIG *pRig, token_t token, const char *val ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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; + } + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_get_conf +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_get_conf(RIG *pRig, token_t token, char *val) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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; + } + } + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_reset +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_reset( RIG *pRig, reset_t reset ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // Check Params + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// Function adat_handle_event +// --------------------------------------------------------------------------- +// Status: IN WORK + +int adat_handle_event( RIG *pRig ) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = 0x%08x\n", + gFnLevel, __func__, __FILE__, __LINE__, + pRig ); + + // 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 ]; + + 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 %s (%s:%d): EXIT. Return Code = %d\n", + gFnLevel, __func__, __FILE__, __LINE__, + nRC ); + gFnLevel--; + + return nRC; +} + + +// --------------------------------------------------------------------------- +// initrigs_adat is called by rig_backend_load +// --------------------------------------------------------------------------- +// Status: RELEASED + +DECLARE_INITRIG_BACKEND(adat) +{ + int nRC = RIG_OK; + + gFnLevel++; + +#if 0 + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY.\n", + gFnLevel, __func__, __FILE__, __LINE__ ); +#endif + rig_register( &adt_200a_caps ); + +#if 0 + 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 ); +#endif + gFnLevel--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// proberig_adat +// --------------------------------------------------------------------------- +// Status: UNTESTED + +DECLARE_PROBERIG_BACKEND(adat) +{ + int nRC = RIG_OK; + + gFnLevel++; + + rig_debug( RIG_DEBUG_TRACE, + "*** ADAT: %d %s (%s:%d): ENTRY.\n", + gFnLevel, __func__, __FILE__, __LINE__ ); + + if (!port) + return RIG_MODEL_NONE; + + if (port->type.rig != RIG_PORT_SERIAL) + return RIG_MODEL_NONE; + + port->write_delay = port->post_write_delay = 10; + port->parm.serial.stop_bits = 0; + port->retry = 1; + + + nRC = serial_open(port); + + if( nRC != RIG_OK) + { + nRC = RIG_MODEL_NONE; + } + else + { + char acBuf[ ADAT_RESPSZ + 1 ]; + int nRead = 0; + + 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 ) ); + nRead = read_string(port, acBuf, ADAT_RESPSZ, ADAT_EOM, 1); + 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 ); + + 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--; + + return nRC; +} + +// --------------------------------------------------------------------------- +// END OF FILE +// --------------------------------------------------------------------------- + diff --git a/adat/adat.h b/adat/adat.h new file mode 100644 index 000000000..98bc10da6 --- /dev/null +++ b/adat/adat.h @@ -0,0 +1,586 @@ +// --------------------------------------------------------------------------- +// ADAT +// --------------------------------------------------------------------------- +// +// adat.h +// +// Created by Frank Goenninger DG1SBG. +// Copyright © 2011, 2012 Frank Goenninger. Creative Commons License. +// +// $Header$ + +#if !defined( __ADAT_INCLUDED__ ) +#define __ADAT_INCLUDED__ + +// --------------------------------------------------------------------------- +// SYSTEM INCLUDES +// --------------------------------------------------------------------------- + + +// --------------------------------------------------------------------------- +// HAMLIB INCLUDES +// --------------------------------------------------------------------------- + +#include "hamlib/rig.h" + +// --------------------------------------------------------------------------- +// GLOBAL DEFINITIONS +// --------------------------------------------------------------------------- + +#define ADAT_BUFSZ 256 +#define ADAT_RESPSZ 256 + +#define ADAT_CR "\x0d" +#define ADAT_EOL "\x0a" +#define ADAT_BOM "$" // Begin of message +#define ADAT_EOM ADAT_CR // End of message + +#define ADAT_ON 1 +#define ADAT_OFF 0 + +#define ADAT_TOGGLE_ON ADAT_ON +#define ADAT_TOGGLE_OFF ADAT_OFF + +#define ADAT_FREQ_UNIT_HZ "Hz" +#define ADAT_FREQ_UNIT_HZ_LEN 2 + +#define ADAT_FREQ_UNIT_KHZ "kHz" +#define ADAT_FREQ_UNIT_KHZ_LEN 3 + +#define ADAT_FREQ_UNIT_MHZ "MHz" +#define ADAT_FREQ_UNIT_MHZ_LEN 3 + +#define ADAT_FREQ_UNIT_GHZ "GHz" +#define ADAT_FREQ_UNIT_GHZ_LEN 3 + +#define TOKEN_ADAT_PRODUCT_NAME TOKEN_BACKEND(1) + +#define ADAT_SLEEP_MICROSECONDS_BETWEEN_CMDS (11*1000) // = 11 ms +#define ADAT_SLEEP_AFTER_RIG_CLOSE 2 // unit: seconds +#define ADAT_SLEEP_AFTER_RIG_OPEN 2 // unit: seconds + +// ADAT VFO SET/GET DEFINITIONS + +#define ADAT_NR_VFOS 3 + +// Each mode is defined by three values: +// ADAT_VFO_STR_... -> The string as given back by TRX when asked by +// $VFO? +// ADAT_VFO_RNR_... -> The Hamlib number of the mode: RIG_VFO_... +// ADAT_VFO_ANR_... -> The ADAT Nr representing the VFO when setting it + +#define ADAT_VFO_STR_A "A" +#define ADAT_VFO_RNR_A RIG_VFO_A +#define ADAT_VFO_ANR_A 1 + +#define ADAT_VFO_STR_B "B" +#define ADAT_VFO_RNR_B RIG_VFO_B +#define ADAT_VFO_ANR_B 2 + +#define ADAT_VFO_STR_C "C" +#define ADAT_VFO_RNR_C RIG_VFO_C +#define ADAT_VFO_ANR_C 3 + +// ADAT MODE DEFINITIONS + +#define ADAT_MODE_LENGTH 5 +#define ADAT_NR_MODES 8 + +// Each mode is defined by three values: +// ADAT_MODE_STR_... -> The string as given back by TRX when asked by +// $MOD? +// ADAT_MODE_RNR_... -> The Hamlib number of the mode: RIG_MODE_... +// ADAT_MODE_ANR_... -> The ADAT Nr representing the mode when setting it + +#define ADAT_MODE_STR_CW_R "CW-R" +#define ADAT_MODE_RNR_CW_R RIG_MODE_CWR +#define ADAT_MODE_ANR_CW_R 0 + +#define ADAT_MODE_STR_CW "CW" +#define ADAT_MODE_RNR_CW RIG_MODE_CW +#define ADAT_MODE_ANR_CW 1 + +#define ADAT_MODE_STR_LSB "LSB" +#define ADAT_MODE_RNR_LSB RIG_MODE_LSB +#define ADAT_MODE_ANR_LSB 2 + +#define ADAT_MODE_STR_USB "USB" +#define ADAT_MODE_RNR_USB RIG_MODE_USB +#define ADAT_MODE_ANR_USB 3 + +#define ADAT_MODE_STR_AM "AM" +#define ADAT_MODE_RNR_AM RIG_MODE_AM +#define ADAT_MODE_ANR_AM 5 + +#define ADAT_MODE_STR_AM_SL "AM-SL" +#define ADAT_MODE_RNR_AM_SL RIG_MODE_SAL +#define ADAT_MODE_ANR_AM_SL 6 + +#define ADAT_MODE_STR_AM_SU "AM-SU" +#define ADAT_MODE_RNR_AM_SU RIG_MODE_SAH +#define ADAT_MODE_ANR_AM_SU 7 + +#define ADAT_MODE_STR_FM "FM" +#define ADAT_MODE_RNR_FM RIG_MODE_FM +#define ADAT_MODE_ANR_FM 8 + +// ADAT PTT DEFINITIONS + +#define ADAT_PTT_STATUS_ANR_ON ADAT_ON +#define ADAT_PTT_STATUS_RNR_ON RIG_PTT_ON + +#define ADAT_PTT_STATUS_ANR_OFF ADAT_OFF +#define ADAT_PTT_STATUS_RNR_OFF RIG_PTT_OFF + +// ADAT POWER LEVEL DEFINITIONS + +#define ADAT_PWR_LVL_ANR_00 0 +#define ADAT_PWR_LVL_RNR_00 100 // 100 mW + +#define ADAT_PWR_LVL_ANR_01 1 +#define ADAT_PWR_LVL_RNR_01 300 // 300 mW + +#define ADAT_PWR_LVL_ANR_02 2 +#define ADAT_PWR_LVL_RNR_02 1000 // ... + +#define ADAT_PWR_LVL_ANR_03 3 +#define ADAT_PWR_LVL_RNR_03 2000 + +#define ADAT_PWR_LVL_ANR_04 4 +#define ADAT_PWR_LVL_RNR_04 3000 + +#define ADAT_PWR_LVL_ANR_05 5 +#define ADAT_PWR_LVL_RNR_05 5000 + +#define ADAT_PWR_LVL_ANR_06 6 +#define ADAT_PWR_LVL_RNR_06 7000 + +#define ADAT_PWR_LVL_ANR_07 7 +#define ADAT_PWR_LVL_RNR_07 10000 + +#define ADAT_PWR_LVL_ANR_08 8 +#define ADAT_PWR_LVL_RNR_08 15000 + +#define ADAT_PWR_LVL_ANR_09 9 +#define ADAT_PWR_LVL_RNR_09 20000 + +#define ADAT_PWR_LVL_ANR_10 10 +#define ADAT_PWR_LVL_RNR_10 25000 + +#define ADAT_PWR_LVL_ANR_11 11 +#define ADAT_PWR_LVL_RNR_11 30000 + +#define ADAT_PWR_LVL_ANR_12 12 +#define ADAT_PWR_LVL_RNR_12 35000 + +#define ADAT_PWR_LVL_ANR_13 13 +#define ADAT_PWR_LVL_RNR_13 40000 + +#define ADAT_PWR_LVL_ANR_14 14 // Default value after reset +#define ADAT_PWR_LVL_RNR_14 45000 + +#define ADAT_PWR_LVL_ANR_15 15 +#define ADAT_PWR_LVL_RNR_15 50000 // 50 W + +#define ADAT_MAX_POWER_IN_mW ADAT_PWR_LVL_RNR_15 + +// ADAT CHANNEL CAPS + +#define ADAT_MEM_CAPS \ + { \ + .vfo = 1, \ + .ant = 1, \ + .freq = 1, \ + .mode = 1, \ + .width = 1, \ + .tx_freq = 1, \ + .tx_mode = 1, \ + .tx_width = 1, \ + .tx_vfo = 1, \ + .rit = 1, \ + .xit = 1, \ + .tuning_step = 1, \ + .channel_desc = 1 \ + } + +#define ADAT_MEM_DESC_SIZE 64 + +// ADAT OPCODES - Kind of an internal command within ADAT Hamlib Backend + +#define ADAT_OPCODE_BASE_PTT 110000 + +#define ADAT_OPCODE_PTT_SWITCH_ON (ADAT_OPCODE_BASE_PTT + 1) +#define ADAT_OPCODE_PTT_SWITCH_OFF (ADAT_OPCODE_BASE_PTT + 2) + +// --------------------------------------------------------------------------- +// Individual ADAT CAT commands +// --------------------------------------------------------------------------- + +#define ADAT_CMD_DEF_ADAT_SPECIAL (1<<30) + +// -- NIL -- (Marks the end of a cmd list) + +#define ADAT_CMD_DEF_NIL 0 + +// -- ADAT SPECIAL: DISPLAY OFF -- + +#define ADAT_CMD_DEF_STRING_DISPLAY_OFF "$VRU>"ADAT_CR + +// -- ADAT SPECIAL: DISPLAY ON -- + +#define ADAT_CMD_DEF_STRING_DISPLAY_ON "$VRU<"ADAT_CR + +// -- ADAT SPECIAL: GET SERIAL NR -- + +#define ADAT_CMD_DEF_STRING_GET_SERIAL_NR "$CIS?"ADAT_CR + +// -- ADAT SPECIAL: GET FIRMWARE VERSION -- + +#define ADAT_CMD_DEF_STRING_GET_FW_VERSION "$CIF?"ADAT_CR + +// -- ADAT SPECIAL: GET HARDWARE VERSION -- + +#define ADAT_CMD_DEF_STRING_GET_HW_VERSION "$CIH?"ADAT_CR + +// -- ADAT SPECIAL: GET FIRMWARE VERSION -- + +#define ADAT_CMD_DEF_STRING_GET_ID_CODE "$CID?"ADAT_CR + +// -- ADAT SPECIAL: GET GUI FIRMWARE VERSION -- + +#define ADAT_CMD_DEF_STRING_GET_GUI_FW_VERSION "$CIG?"ADAT_CR + +// -- ADAT SPECIAL: GET OPTIONS -- + +#define ADAT_CMD_DEF_STRING_GET_OPTIONS "$CIO?"ADAT_CR + +// -- ADAT SPECIAL: GET CALLSIGN -- + +#define ADAT_CMD_DEF_STRING_GET_CALLSIGN "$CAL?"ADAT_CR + +// -- ADAT SPECIAL: SET CALLSIGN -- + +#define ADAT_CMD_DEF_STRING_SET_CALLSIGN "$CAL:" + +// -- HAMLIB DEFINED COMMANDS -- + +// -- GET FREQ -- + +#define ADAT_CMD_DEF_GET_FREQ (1<<0) +#define ADAT_CMD_DEF_STRING_GET_FREQ "$FRA?"ADAT_CR + +// -- SET FREQ -- + +#define ADAT_CMD_DEF_SET_FREQ (1<<1) +#define ADAT_CMD_DEF_STRING_SET_FREQ "$FR1:" + +// -- GET VFO -- + +// -- GET MODE -- + +#define ADAT_CMD_DEF_GET_MODE (1<<2) +#define ADAT_CMD_DEF_STRING_GET_MODE "$MOD?"ADAT_CR + +// -- SET VFO -- + +#define ADAT_CMD_DEF_SET_VFO (1<<3) +#define ADAT_CMD_DEF_STRING_SWITCH_ON_VFO "$VO%1d>%s" +#define ADAT_CMD_DEF_STRING_SET_VFO_AS_MAIN_VFO "$VO%1d%%%s" + +// -- SET MODE -- + +#define ADAT_CMD_DEF_SET_MODE (1<<4) +#define ADAT_CMD_DEF_STRING_SET_MODE "$MOD:" + +// -- SET PTT -- + +#define ADAT_CMD_DEF_SET_PTT (1<<5) +#define ADAT_CMD_DEF_STRING_SET_PTT "$MOX%s%s" +#define ADAT_CMD_PTT_STR_OFF "<" +#define ADAT_CMD_PTT_STR_ON ">" + +// -- GET PTT -- + +#define ADAT_CMD_DEF_GET_PTT (1<<6) +#define ADAT_CMD_DEF_STRING_GET_PTT "$MTR?"ADAT_CR + +// -- GET POWER STATUS -- + +// -- GET INFO -- + +// -- OPEN ADAT -- + +// -- ADAT SPECIAL: RECOVER FROM ERROR -- + +// --------------------------------------------------------------------------- +// ADAT PRIVATE DATA +// --------------------------------------------------------------------------- + +typedef struct _adat_priv_data +{ + int nOpCode; + + char *pcProductName; // Future use (USB direct I/O) + + // ADAT device info + + char *pcSerialNr; + char *pcIDCode; + char *pcOptions; + char *pcFWVersion; + char *pcHWVersion; + char *pcGUIFWVersion; + + char *pcCallsign; + + // ADAT Operational Settings: will change during TRX use + + int nCurrentVFO; + vfo_t nRIGVFONr; + + freq_t nFreq; + char acRXFreq[ ADAT_BUFSZ ]; + char acTXFreq[ ADAT_BUFSZ ]; + + rmode_t nRIGMode; + char acADATMode[ ADAT_MODE_LENGTH + 1 ]; + int nADATMode; + + pbwidth_t nWidth; + + int nADATPTTStatus; + ptt_t nRIGPTTStatus; + + + value_t mNB1; + value_t mNB2; + + value_t mAGC; + value_t mRFGain; + value_t mIFShift; + value_t mRawStr; + + // ADAT Command-related Values + + char *pcCmd; + int nCmdKind; + + char *pcResult; + int nRC; + +} adat_priv_data_t, +* adat_priv_data_ptr; + +// --------------------------------------------------------------------------- +// ADAT CAT COMMAND DATA TYPE DECLARATIONS +// --------------------------------------------------------------------------- + +typedef unsigned long long adat_cmd_id_t; // Bit mask for commands. Each command +// is represented by 1 bit. + +// adat_cmd_def : ADAT COMMAND DEFINITION. +// Basic idea: Each command can be made of several strings to be sent +// to the ADAT device. Therefore it is possible to build aggregated +// commands which will be executed as a set of individual commands +// executed by adat_transaction(). The last value as returned by the +// commands will be set as overall command result. + +typedef enum +{ + ADAT_CMD_KIND_WITH_RESULT = 0, // After sending a command to the ADAT, + // a result has to be read. + ADAT_CMD_KIND_WITHOUT_RESULT = 1 + +} adat_cmd_kind_t; + +typedef struct _adat_cmd_def_t +{ + adat_cmd_id_t nCmdId; // Bit indicating this cmd + adat_cmd_kind_t nCmdKind; // Defines if result expected + + int (*pfCmdFn)( RIG *pRig ); // Fn to be called to execute this cmd + + int nNrCmdStrs; // Oh my, C as a language ... I'd love to + // switch to Common Lisp ... What a hack here ... + char *pacCmdStrs[]; // Commands to be executed if no CmdFn given + +} adat_cmd_def_t, +* adat_cmd_def_ptr; + +typedef struct _adat_cmd_table_t +{ + int nNrCmds; + adat_cmd_def_ptr adat_cmds[]; + +} adat_cmd_table_t, +* adat_cmd_table_ptr; + +typedef struct _adat_cmd_list_t +{ + int nNrCmds; + adat_cmd_def_ptr adat_cmds[]; + +} adat_cmd_list_t, +* adat_cmd_list_ptr; + +// --------------------------------------------------------------------------- +// OTHER ADAT DATA TYPES +// --------------------------------------------------------------------------- + +typedef enum +{ + ADAT_FREQ_PARSE_MODE_WITH_VFO = 0, + ADAT_FREQ_PARSE_MODE_WITHOUT_VFO = 1 + +} adat_freq_parse_mode_t; + +// ADAT MODE DEFINITION + +typedef struct _adat_mode_def +{ + char *pcADATModeStr; + rmode_t nRIGMode; + int nADATMode; + +} adat_mode_def_t, +* adat_mode_def_ptr; + +typedef struct _adat_mode_list +{ + int nNrModes; + + adat_mode_def_t adat_modes[ ADAT_NR_MODES ]; + +} adat_mode_list_t, +* adat_mode_list_ptr; + +// ADAT VFO DEFINITION + +typedef struct _adat_vfo_def +{ + char *pcADATVFOStr; + vfo_t nRIGVFONr; + int nADATVFONr; + +} adat_vfo_def_t, +* adat_vfo_def_ptr; + +typedef struct _adat_vfo_list +{ + int nNrVFOs; + + adat_vfo_def_t adat_vfos[ ADAT_NR_VFOS ]; + +} adat_vfo_list_t, +* adat_vfo_list_ptr; + +// --------------------------------------------------------------------------- +// ADAT INTERNAL FUNCTION DECLARATIONS +// --------------------------------------------------------------------------- + +// Helper functions + +size_t trimwhitespace( char *, size_t, const char * ); +int adat_print_cmd( adat_cmd_def_ptr ); + +int adat_parse_freq( char *, adat_freq_parse_mode_t, int *, freq_t * ); + +int adat_parse_mode( char *, rmode_t *, char * ); +int adat_mode_rnr2anr( rmode_t, int * ); +int adat_mode_anr2rnr( int, rmode_t * ); + +int adat_parse_vfo( char *, vfo_t *, int * ); +int adat_vfo_rnr2anr( vfo_t, int * ); +int adat_vfo_anr2rnr( int, vfo_t * ); + +int adat_parse_ptt( char *, int * ); +int adat_ptt_rnr2anr( ptt_t, int * ); +int adat_ptt_anr2rnr( int, ptt_t * ); + + +int adat_send( RIG *, char * ); +int adat_receive( RIG *, char * ); + +int adat_priv_set_cmd( RIG *, char *, int ); +int adat_priv_set_result( RIG *, char * ); +int adat_priv_clear_result( RIG * ); + +int adat_get_single_cmd_result( RIG * ); + +int adat_cmd_recover_from_error( RIG *, int ); + +int adat_transaction( RIG *, adat_cmd_list_ptr ); + +adat_priv_data_ptr adat_new_priv_data( RIG * ); +void adat_del_priv_data( adat_priv_data_t ** ); + +// Command implementation + +int adat_cmd_fn_get_serial_nr( RIG * ); +int adat_cmd_fn_get_fw_version( RIG * ); +int adat_cmd_fn_get_hw_version( RIG * ); +int adat_cmd_fn_get_gui_fw_version( RIG * ); +int adat_cmd_fn_get_id_code( RIG * ); +int adat_cmd_fn_get_options( RIG * ); + +int adat_cmd_fn_set_callsign( RIG * ); +int adat_cmd_fn_get_callsign( RIG * ); + +int adat_cmd_fn_set_freq( RIG * ); +int adat_cmd_fn_get_freq( RIG * ); + +int adat_cmd_fn_get_mode( RIG * ); +int adat_cmd_fn_set_mode( RIG * ); + +int adat_cmd_fn_get_vfo( RIG * ); +int adat_cmd_fn_set_vfo( RIG * ); + +int adat_cmd_fn_get_ptt( RIG * ); +int adat_cmd_fn_set_ptt( RIG * ); + +// --------------------------------------------------------------------------- +// ADAT FUNCTION DECLARATIONS +// --------------------------------------------------------------------------- + +int adat_init( RIG * ); +int adat_cleanup( RIG * ); +int adat_reset( RIG *, reset_t ); +int adat_open( RIG * ); + +int adat_set_conf( RIG *, token_t, const char *val ); +int adat_get_conf( RIG *, token_t, char *val ); + +int adat_set_freq( RIG *, vfo_t, freq_t ); +int adat_get_freq( RIG *, vfo_t, freq_t * ); + +int adat_set_vfo( RIG *, vfo_t ); +int adat_get_vfo( RIG *, vfo_t * ); + +int adat_set_ptt( RIG *, vfo_t, ptt_t ); +int adat_get_ptt( RIG *, vfo_t, ptt_t * ); + +int adat_set_mode( RIG *, vfo_t, rmode_t, pbwidth_t ); +int adat_get_mode( RIG *, vfo_t, rmode_t *, pbwidth_t * ); + +int adat_set_func( RIG *, vfo_t, setting_t func, int ); +int adat_get_func( RIG *, vfo_t, setting_t func, int * ); + +int adat_set_level( RIG *, vfo_t, setting_t level, value_t ); +int adat_get_level( RIG *, vfo_t, setting_t level, value_t * ); + +int adat_handle_event( RIG * ); + +const char * adat_get_info( RIG * ); + +int adat_mW2power( RIG *, float *, unsigned int, freq_t, rmode_t ); +int adat_power2mW( RIG *, unsigned int *, float, freq_t, rmode_t ); + +int adat_get_powerstat( RIG *, powerstat_t * ); + +extern const struct rig_caps adt_200a_caps; + +// --------------------------------------------------------------------------- +// END OF FILE +// --------------------------------------------------------------------------- + +#endif diff --git a/adat/adt_200a.c b/adat/adt_200a.c new file mode 100644 index 000000000..f8411cd70 --- /dev/null +++ b/adat/adt_200a.c @@ -0,0 +1,201 @@ +// --------------------------------------------------------------------------- +// ADT-200A HAMLIB BACKEND +// --------------------------------------------------------------------------- +// +// adt_200a.c +// +// Created by Frank Goenninger DG1SBG. +// Copyright © 2011, 2012 Frank Goenninger. Creative Commons License. +// +// $Header$ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +// --------------------------------------------------------------------------- +// ADT-200A INCLUDES +// --------------------------------------------------------------------------- + +#include "adt_200a.h" + +// --------------------------------------------------------------------------- +// GLOBAL DEFINITIONS +// --------------------------------------------------------------------------- + +// GLOBAL VARS + +// static const struct confparams adt_200a_cfg_params[] = +// { +// { TOKEN_PRODUCT_NAME, "usb_product_name", "USB Product Name", "USB Product Name (DSP Bo +// Model + ' Serial '+ ID Code, e.g. 'TRX3C Serial C945D5B' )", +// ADT_200A_PRODUCT_NAME, RIG_CONF_STRING, { .n = { 0,0,0 } } +// }, +// +// { RIG_CONF_END, NULL, } +//}; + + +// --------------------------------------------------------------------------- +// ADT-200A HAMLIB CAPS / DESCRIPTION +// --------------------------------------------------------------------------- + +const struct rig_caps adt_200a_caps = +{ + .rig_model = RIG_MODEL_ADT_200A, + .model_name = "ADT-200A", + .mfg_name = "ADAT www.adat.ch", + .version = "1.36", + .copyright = "Frank Goenninger, DG1SBG. License: Creative Commons", + .status = RIG_STATUS_BETA, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_RIG, + .dcd_type = RIG_DCD_NONE, + .port_type = RIG_PORT_SERIAL, + .serial_rate_min = 115200, + .serial_rate_max = 115200, + .serial_data_bits = 8, + .serial_stop_bits = 1, + .serial_parity = RIG_PARITY_NONE, + .serial_handshake = RIG_HANDSHAKE_NONE, + .write_delay = 0, + .post_write_delay = 20, + .timeout = 250, + .retry = 3, + + .has_get_func = ADT_200A_FUNCS, + .has_set_func = ADT_200A_FUNCS, + .has_get_level = ADT_200A_GET_LEVEL, + .has_set_level = RIG_LEVEL_SET(ADT_200A_SET_LEVEL), + .has_get_parm = RIG_PARM_NONE, + .has_set_parm = RIG_PARM_NONE, + .level_gran = {}, + .parm_gran = {}, + .ctcss_list = NULL, + .dcs_list = NULL, + .preamp = { 5, 10, RIG_DBLST_END, }, + .attenuator = { 5, 10, 15, 20, 25, RIG_DBLST_END, }, + .max_rit = ADT_200A_RIT, + .max_xit = ADT_200A_XIT, + .max_ifshift = Hz(500), + .targetable_vfo = RIG_TARGETABLE_NONE, + .transceive = 0, + .bank_qty = 1, + + .chan_desc_sz = ADAT_MEM_DESC_SIZE, + .chan_list = + { + { 0, 99, RIG_MTYPE_MEM, ADAT_MEM_CAPS }, + RIG_CHAN_END, + }, + + .rx_range_list1 = + { + { kHz(10), MHz(30), ADT_200A_MODES, -1, -1, ADT_200A_VFO }, + RIG_FRNG_END, + }, + + .tx_range_list1 = + { + { kHz(10), MHz(30), ADT_200A_MODES, mW(100), W(50), ADT_200A_VFO }, + RIG_FRNG_END, + }, + + .rx_range_list2 = + { + { kHz(10), MHz(30), ADT_200A_MODES, -1, -1, ADT_200A_VFO }, + RIG_FRNG_END, + }, + + .tx_range_list2 = + { + { kHz(10), MHz(30), ADT_200A_MODES, mW(100), W(50), ADT_200A_VFO }, + RIG_FRNG_END, + }, + + .tuning_steps = + { + { ADT_200A_MODES, RIG_TS_ANY }, // TODO: get actual list here + RIG_TS_END, + }, + + .filters = + { + { RIG_MODE_CW|RIG_MODE_CWR, Hz(50) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(75) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(100) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(150) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(200) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(300) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(750) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(1000) }, + { RIG_MODE_CW|RIG_MODE_CWR, Hz(1200) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(300) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(500) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(750) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(1000) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(1200) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(1500) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(1800) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(2000) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(2200) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(2400) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(2700) }, + { RIG_MODE_LSB|RIG_MODE_USB, Hz(3500) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(3000) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(3500) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(4000) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(4500) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(5000) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(6000) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(7000) }, + { RIG_MODE_AM|RIG_MODE_SAL|RIG_MODE_SAH, Hz(8000) }, + { RIG_MODE_FM, Hz(6000) }, + { RIG_MODE_FM, Hz(7000) }, + { RIG_MODE_FM, Hz(8000) }, + { RIG_MODE_FM, Hz(9000) }, + { RIG_MODE_FM, Hz(10000) }, + { RIG_MODE_FM, Hz(11000) }, + { RIG_MODE_FM, Hz(12000) }, + RIG_FLT_END, + }, + + // .cfgparams = adt_200a_cfg_params, + + .rig_init = adat_init, + .rig_cleanup = adat_cleanup, + .rig_open = adat_open, + .reset = adat_reset, + + .set_conf = adat_set_conf, + .get_conf = adat_get_conf, + + .set_freq = adat_set_freq, + .get_freq = adat_get_freq, + + .get_level = adat_get_level, + .set_level = adat_set_level, + + .set_mode = adat_set_mode, + .get_mode = adat_get_mode, + + .get_vfo = adat_get_vfo, + .set_vfo = adat_set_vfo, + + .get_ptt = adat_get_ptt, + .set_ptt = adat_set_ptt, + + .decode_event = adat_handle_event, + + .get_info = adat_get_info, + + .power2mW = adat_power2mW, + .mW2power = adat_mW2power, + + .get_powerstat = adat_get_powerstat +}; + +// --------------------------------------------------------------------------- +// END OF FILE +// --------------------------------------------------------------------------- diff --git a/adat/adt_200a.h b/adat/adt_200a.h new file mode 100644 index 000000000..2e79ef6b7 --- /dev/null +++ b/adat/adt_200a.h @@ -0,0 +1,105 @@ +// --------------------------------------------------------------------------- +// ADT-200A +// --------------------------------------------------------------------------- +// +// adt_200a.h +// +// Created by Frank Goenninger DG1SBG. +// Copyright © 2011, 2012 Frank Goenninger. Creative Commons License. +// +// $Header$ + +#if !defined( __ADT_200A_INCLUDED__ ) +#define __ADT_200A_INCLUDED__ + +// --------------------------------------------------------------------------- +// ADAT INCLUDES +// --------------------------------------------------------------------------- + +#include "adat.h" + +// --------------------------------------------------------------------------- +// ADT-200A USB DEFINITIONS +// --------------------------------------------------------------------------- + +#define ADT_200A_VENDOR_ID 0x0403 +#define ADT_200A_PRODUCT_ID 0x6001 + +#define ADT_200A_VENDOR_NAME "FTDI" +#define ADT_200A_PRODUCT_NAME "TRX3C Serial C945D5B" + +#define ADT_200A_USB_INTERFACE_NR 0x00 +#define ADT_200A_USB_CONFIGURATION_VALUE 0x01 +#define ADT_200A_ALTERNATE_SETTIMG 0x00 + +#define ADT_200A_USB_INPUT_ENDPOINT 0x81 +#define ADT_200A_USB_INPUT_MAX_PACKET_SIZE 64 + +#define ADT_200A_USB_OUTPUT_ENDPOINT b0x02 +#define ADT_200A_USB_OUTPUT_MAX_PACKET_SIZE 64 + +// --------------------------------------------------------------------------- +// ADT-200A CAPS DEFINITIONS +// --------------------------------------------------------------------------- + +#define ADT_200A_GET_LEVEL \ + ( \ + RIG_LEVEL_PREAMP | \ + RIG_LEVEL_ATT | \ + RIG_LEVEL_AF | \ + RIG_LEVEL_NR | \ + RIG_LEVEL_CWPITCH | \ + RIG_LEVEL_RFPOWER | \ + RIG_LEVEL_MICGAIN | \ + RIG_LEVEL_KEYSPD | \ + RIG_LEVEL_METER | \ + RIG_LEVEL_BKIN_DLYMS | \ + RIG_LEVEL_RAWSTR | \ + RIG_LEVEL_SWR | \ + RIG_LEVEL_ALC ) + +#define ADT_200A_SET_LEVEL \ + ( \ + RIG_LEVEL_PREAMP | \ + RIG_LEVEL_ATT | \ + RIG_LEVEL_AF | \ + RIG_LEVEL_NR | \ + RIG_LEVEL_CWPITCH | \ + RIG_LEVEL_RFPOWER | \ + RIG_LEVEL_MICGAIN | \ + RIG_LEVEL_KEYSPD | \ + RIG_LEVEL_METER | \ + RIG_LEVEL_BKIN_DLYMS | \ + RIG_LEVEL_ALC ) + +#define ADT_200A_MODES \ + ( \ + RIG_MODE_AM | \ + RIG_MODE_CW | \ + RIG_MODE_USB | \ + RIG_MODE_LSB | \ + RIG_MODE_FM | \ + RIG_MODE_CWR | \ + RIG_MODE_SAL | \ + RIG_MODE_SAH ) + +// ADT-200A VFO #defines + +#define ADT_200A_FRA RIG_VFO_N(0) +#define ADT_200A_FRB RIG_VFO_N(1) +#define ADT_200A_FRC RIG_VFO_N(2) + +#define ADT_200A_VFO (ADT_200A_FRA|ADT_200A_FRB|ADT_200A_FRC) + +#define ADT_200A_RIT 9999 +#define ADT_200A_XIT 9999 + +// ADT-200A FUNCs + +#define ADT_200A_FUNCS (RIG_FUNC_VOX|RIG_FUNC_NB|RIG_FUNC_NR) + +// --------------------------------------------------------------------------- +// END OF FILE +// --------------------------------------------------------------------------- + +#endif diff --git a/bindings/ignore.swg b/bindings/ignore.swg index 42d108395..199a35d06 100644 --- a/bindings/ignore.swg +++ b/bindings/ignore.swg @@ -63,6 +63,8 @@ %ignore RIG_BACKEND_TUNER; %ignore RIG_RS; %ignore RIG_BACKEND_RS; +%ignore RIG_ADAT; +%ignore RIG_BACKEND_ADAT; %ignore ROT_DUMMY; %ignore ROT_BACKEND_DUMMY; diff --git a/configure.ac b/configure.ac index ea57fda35..f0f39d878 100644 --- a/configure.ac +++ b/configure.ac @@ -257,7 +257,7 @@ fi AC_SUBST(RIGMATRIX) -BACKEND_LIST="icom kenwood aor yaesu dummy pcr alinco uniden tentec kachina jrc drake lowe rft rs kit skanti prm80 tapr flexradio wj racal tuner" +BACKEND_LIST="icom kenwood aor yaesu dummy pcr alinco uniden tentec kachina jrc drake lowe rft rs kit skanti prm80 tapr flexradio wj racal tuner adat" ROT_BACKEND_LIST="dummy easycomm fodtrack gs232a heathkit kit rotorez sartek spid ars m2 amsat ts7400 celestron" BINDINGS="" BINDING_ALL="" @@ -538,6 +538,7 @@ rotorez/Makefile flexradio/Makefile m2/Makefile amsat/Makefile +adat/Makefile ts7400/Makefile celestron/Makefile scripts/Makefile diff --git a/include/hamlib/riglist.h b/include/hamlib/riglist.h index 15b2739af..24dad4c5e 100644 --- a/include/hamlib/riglist.h +++ b/include/hamlib/riglist.h @@ -507,6 +507,14 @@ #define RIG_MODEL_PRM8060 RIG_MAKE_MODEL(RIG_PRM80, 1) #define RIG_MODEL_PRM8070 RIG_MAKE_MODEL(RIG_PRM80, 2) + /* + * ADAT by HB9CBU + * + * ADDED: frgo (DG1SBG), 2012-01-01 + */ +#define RIG_ADAT 29 +#define RIG_BACKEND_ADAT "adat" +#define RIG_MODEL_ADT_200A RIG_MAKE_MODEL(RIG_ADAT, 1) /* * TODO: @@ -554,6 +562,7 @@ typedef int rig_model_t; { RIG_TUNER, RIG_BACKEND_TUNER }, \ { RIG_RS, RIG_BACKEND_RS }, \ { RIG_PRM80, RIG_BACKEND_PRM80 }, \ + { RIG_ADAT, RIG_BACKEND_ADAT }, \ { 0, NULL }, /* end */ \ }