From cf2a551524861bb52d1aca2c9c82078170acb8aa Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 26 Jun 2019 06:39:42 -0500 Subject: [PATCH] Fixup some amplifier code --- amplifiers/elecraft/kpa1500.c | 2 +- amplifiers/elecraft/make.log | 34 ----------- c++/ampclass.cc | 110 ++++++++++++++++++++++++++++++++++ dummy/amp_dummy.c | 2 +- include/hamlib/ampclass.h | 33 +++++----- include/hamlib/amplifier.h | 75 ----------------------- src/amp_conf.c | 40 ------------- src/rig.c | 8 +-- 8 files changed, 131 insertions(+), 173 deletions(-) delete mode 100644 amplifiers/elecraft/make.log create mode 100644 c++/ampclass.cc diff --git a/amplifiers/elecraft/kpa1500.c b/amplifiers/elecraft/kpa1500.c index ff59a3984..d042e657c 100644 --- a/amplifiers/elecraft/kpa1500.c +++ b/amplifiers/elecraft/kpa1500.c @@ -164,7 +164,7 @@ static int kpa1500_cleanup(AMP *amp) * */ -#if 0 +#if 0 // not implemented yet /* * Send command string to amplifier */ diff --git a/amplifiers/elecraft/make.log b/amplifiers/elecraft/make.log deleted file mode 100644 index 66d372466..000000000 --- a/amplifiers/elecraft/make.log +++ /dev/null @@ -1,34 +0,0 @@ - CC kpa.lo -kpa.c: In function ‘kpa_get_freq’: -kpa.c:150:12: warning: returning ‘const char *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion] - return (const char *) - RIG_EINVAL; - ^ -kpa.c:153:3: error: ‘rs’ undeclared (first use in this function) - rs = &->state; - ^~ -kpa.c:153:3: note: each undeclared identifier is reported only once for each function it appears in -kpa.c:156:45: warning: passing argument 3 of ‘kpa_transaction’ makes integer from pointer without a cast [-Wint-conversion] - int retval = kpa_transaction(amp, "^FR;", reponsebuf, sizeof(reponsebuf)); - ^~~~~~~~~~ -kpa.c:68:52: note: expected ‘int’ but argument is of type ‘char *’ - int kpa_transaction(AMP *amp, const char *cmd, int cmd_len, char *response, - ~~~~^~~~~~~ -kpa.c:156:57: warning: passing argument 4 of ‘kpa_transaction’ makes pointer from integer without a cast [-Wint-conversion] - int retval = kpa_transaction(amp, "^FR;", reponsebuf, sizeof(reponsebuf)); - ^~~~~~~~~~~~~~~~~~ -kpa.c:68:67: note: expected ‘char *’ but argument is of type ‘long unsigned int’ - int kpa_transaction(AMP *amp, const char *cmd, int cmd_len, char *response, - ~~~~~~^~~~~~~~ -kpa.c:156:16: error: too few arguments to function ‘kpa_transaction’ - int retval = kpa_transaction(amp, "^FR;", reponsebuf, sizeof(reponsebuf)); - ^~~~~~~~~~~~~~~ -kpa.c:68:5: note: declared here - int kpa_transaction(AMP *amp, const char *cmd, int cmd_len, char *response, - ^~~~~~~~~~~~~~~ -kpa.c:160:12: error: ‘err’ undeclared (first use in this function) - return err; - ^~~ -kpa.c:167:1: warning: control reaches end of non-void function [-Wreturn-type] - } - ^ -make: *** [Makefile:479: kpa.lo] Error 1 diff --git a/c++/ampclass.cc b/c++/ampclass.cc new file mode 100644 index 000000000..ffe475647 --- /dev/null +++ b/c++/ampclass.cc @@ -0,0 +1,110 @@ +/** + * \file src/ampclass.cc + * \brief Ham Radio Control Libraries C++ interface + * \author Stephane Fillod + * \date 2002 + * + * Hamlib C++ interface is a frontend implementing wrapper functions. + */ + +/* + * Hamlib C++ bindings - main file + * Copyright (c) 2002 by Stephane Fillod + * Copyright (c) 2019 by Michael Black W9MDB + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#define CHECK_AMP(cmd) { int _retval = cmd; if (_retval != RIG_OK) \ + THROW(new RigException (_retval)); } + + + +Amplifier::Amplifier(amp_model_t amp_model) +{ + theAmp = amp_init(amp_model); + if (!theAmp) + THROW(new RigException ("Amplifier initialization error")); + + caps = theAmp->caps; + theAmp->state.obj = (amp_ptr_t)this; +} + +Amplifier::~Amplifier() +{ + theAmp->state.obj = NULL; + CHECK_ROT( amp_cleanup(theAmp) ); + caps = NULL; +} + +void Amplifier::open(void) { + CHECK_ROT( amp_open(theAmp) ); +} + +void Amplifier::close(void) { + CHECK_ROT( amp_close(theAmp) ); +} + +void Amplifier::setConf(token_t token, const char *val) +{ + CHECK_ROT( amp_set_conf(theAmp, token, val) ); +} +void Amplifier::setConf(const char *name, const char *val) +{ + CHECK_ROT( amp_set_conf(theAmp, tokenLookup(name), val) ); +} + +void Amplifier::getConf(token_t token, char *val) +{ + CHECK_ROT( amp_get_conf(theAmp, token, val) ); +} +void Amplifier::getConf(const char *name, char *val) +{ + CHECK_ROT( amp_get_conf(theAmp, tokenLookup(name), val) ); +} + +token_t Amplifier::tokenLookup(const char *name) +{ + return amp_token_lookup(theAmp, name); +} + +void Amplifier::reset (amp_reset_t reset) +{ + CHECK_ROT( amp_reset(theAmp, reset) ); +} + +void Amplifier::setFreq(freq_t freq, vfo_t vfo) { + CHECK_RIG( amp_set_freq(theAmp, vfo, freq) ); +} + +freq_t Amplifier::getFreq(vfo_t vfo) +{ + freq_t freq; + + CHECK_RIG( amp_get_freq(theAmp, vfo, &freq) ); + + return freq; +} + diff --git a/dummy/amp_dummy.c b/dummy/amp_dummy.c index 97993a561..c87430894 100644 --- a/dummy/amp_dummy.c +++ b/dummy/amp_dummy.c @@ -283,7 +283,7 @@ static int dummy_amp_get_powerstat(AMP *amp, powerstat_t *status) return RIG_OK; } -#if 0 +#if 0 // not implemented yet static int dummy_amp_get_ext_level(AMP *amp, token_t token, value_t *val) { struct dummy_amp_priv_data *priv = (struct dummy_amp_priv_data *) diff --git a/include/hamlib/ampclass.h b/include/hamlib/ampclass.h index a9c830950..1b95d231f 100644 --- a/include/hamlib/ampclass.h +++ b/include/hamlib/ampclass.h @@ -1,5 +1,5 @@ /* - * Hamlib C++ bindings - rotator API header + * Hamlib C++ bindings - amplifier API header * Copyright (c) 2002 by Stephane Fillod * * @@ -19,30 +19,30 @@ * */ -#ifndef _ROTCLASS_H -#define _ROTCLASS_H 1 +#ifndef _AMPCLASS_H +#define _AMPCLASS_H 1 -#include +#include -class BACKEND_IMPEXP Rotator +class BACKEND_IMPEXP Amplifier { private: - ROT *theRot; // Global ref. to the rot + AMP *theAmp; // Global ref. to the amp protected: public: - Rotator(rot_model_t rot_model); + Amplifier(amp_model_t amp_model); - virtual ~Rotator(); + virtual ~Amplifier(); - const struct rot_caps *caps; + const struct amp_caps *caps; - // This method opens the communication port to the rot + // This method opens the communication port to the amp void open(void); - // This method closes the communication port to the rot + // This method closes the communication port to the amp void close(void); void setConf(token_t token, const char *val); @@ -51,15 +51,12 @@ public: void getConf(const char *name, char *val); token_t tokenLookup(const char *name); - void setPosition(azimuth_t az, elevation_t el); - void getPosition(azimuth_t& az, elevation_t& el); - void stop(); - void park(); - void reset(rot_reset_t reset); + void setFreq(freq_t freq); + freq_t getFreq(freq_t freq); - void move(int direction, int speed); + void reset(amp_reset_t reset); }; -#endif // _ROTCLASS_H +#endif // _AMPCLASS_H diff --git a/include/hamlib/amplifier.h b/include/hamlib/amplifier.h index 5284e090d..48ebd3428 100644 --- a/include/hamlib/amplifier.h +++ b/include/hamlib/amplifier.h @@ -126,81 +126,6 @@ enum amp_level_e #define AMP_LEVEL_IS_FLOAT(l) ((l)&_LEVEL_FLOAT_LIST) #define AMP_LEVEL_IS_STRING(l) ((l)&_LEVEL_STRING_LIST) -/** - * \def AMP_MOVE_UP - * \brief A macro that returns the flag for the \b UP direction. - * - * This macro defines the value of the \b UP direction which can be - * used with the amp_move() function. - * - * \sa amp_move(), AMP_MOVE_DOWN, AMP_MOVE_LEFT, AMP_MOVE_CCW, - * AMP_MOVE_RIGHT, AMP_MOVE_CW - */ -#define AMP_MOVE_UP (1<<1) - -/** - * \def AMP_MOVE_DOWN - * \brief A macro that returns the flag for the \b DOWN direction. - * - * This macro defines the value of the \b DOWN direction which can be - * used with the amp_move() function. - * - * \sa amp_move(), AMP_MOVE_UP, AMP_MOVE_LEFT, AMP_MOVE_CCW, AMP_MOVE_RIGHT, - * AMP_MOVE_CW -*/ -#define AMP_MOVE_DOWN (1<<2) - -/** - * \def AMP_MOVE_LEFT - * \brief A macro that returns the flag for the \b LEFT direction. - * - * This macro defines the value of the \b LEFT direction which can be - * used with the amp_move function. - * - * \sa amp_move(), AMP_MOVE_UP, AMP_MOVE_DOWN, AMP_MOVE_CCW, AMP_MOVE_RIGHT, - * AMP_MOVE_CW - */ -#define AMP_MOVE_LEFT (1<<3) - -/** - * \def AMP_MOVE_CCW - * \brief A macro that returns the flag for the \b counterclockwise direction. - * - * This macro defines the value of the \b counterclockwise direction which - * can be used with the amp_move() function. This value is equivalent to - * AMP_MOVE_LEFT . - * - * \sa amp_move(), AMP_MOVE_UP, AMP_MOVE_DOWN, AMP_MOVE_LEFT, AMP_MOVE_RIGHT, - * AMP_MOVE_CW - */ -#define AMP_MOVE_CCW AMP_MOVE_LEFT - -/** - * \def AMP_MOVE_RIGHT - * \brief A macro that returns the flag for the \b RIGHT direction. - * - * This macro defines the value of the \b RIGHT direction which can be used - * with the amp_move() function. - * - * \sa amp_move(), AMP_MOVE_UP, AMP_MOVE_DOWN, AMP_MOVE_LEFT, AMP_MOVE_CCW, - * AMP_MOVE_CW - */ -#define AMP_MOVE_RIGHT (1<<4) - -/** - * \def AMP_MOVE_CW - * \brief A macro that returns the flag for the \b clockwise direction. - * - * This macro defines the value of the \b clockwise direction wich can be - * used with the amp_move() function. This value is equivalent to - * AMP_MOVE_RIGHT . - * - * \sa amp_move(), AMP_MOVE_UP, AMP_MOVE_DOWN, AMP_MOVE_LEFT, AMP_MOVE_CCW, - * AMP_MOVE_RIGHT - */ -#define AMP_MOVE_CW AMP_MOVE_RIGHT - - /* Basic amp type, can store some useful info about different amplifiers. Each * lib must be able to populate this structure, so we can make useful * enquiries about capablilities. diff --git a/src/amp_conf.c b/src/amp_conf.c index 875a86433..d21ae5247 100644 --- a/src/amp_conf.c +++ b/src/amp_conf.c @@ -74,27 +74,6 @@ static const struct confparams ampfrontend_cfg_params[] = "0", RIG_CONF_NUMERIC, { .n = { 0, 10, 1 } } }, - { - TOK_MIN_AZ, "min_az", "Minimum azimuth", - "Minimum amplifier azimuth in degrees", - "-180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } - }, - { - TOK_MAX_AZ, "max_az", "Maximum azimuth", - "Maximum amplifier azimuth in degrees", - "180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } - }, - { - TOK_MIN_EL, "min_el", "Minimum elevation", - "Minimum amplifier elevation in degrees", - "0", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } - }, - { - TOK_MAX_EL, "max_el", "Maximum elevation", - "Maximum amplifier elevation in degrees", - "90", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } - }, - { RIG_CONF_END, NULL, } }; @@ -445,25 +424,6 @@ int frontamp_get_conf(AMP *amp, token_t token, char *val) strcpy(val, s); break; -#if 0 - - case TOK_MIN_AZ: - sprintf(val, "%f", rs->min_az); - break; - - case TOK_MAX_AZ: - sprintf(val, "%f", rs->max_az); - break; - - case TOK_MIN_EL: - sprintf(val, "%f", rs->min_el); - break; - - case TOK_MAX_EL: - sprintf(val, "%f", rs->max_el); - break; -#endif - default: return -RIG_EINVAL; } diff --git a/src/rig.c b/src/rig.c index a674cefca..6eb923386 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1962,10 +1962,10 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return par_ptt_get(&rig->state.pttport, ptt); case RIG_PTT_CM108: - //if (caps->get_ptt) - //{ - // return caps->get_ptt(rig, vfo, ptt); - //} + if (caps->get_ptt) + { + return caps->get_ptt(rig, vfo, ptt); + } return cm108_ptt_get(&rig->state.pttport, ptt);