pull/224/head
Michael Black 2020-03-14 10:00:59 -05:00
commit caac74f557
8 zmienionych plików z 183 dodań i 16 usunięć

Wyświetl plik

@ -0,0 +1,147 @@
/*
* Hamlib bindings - Amplifier interface
* Copyright (c) 2001,2002 by Stephane Fillod
* Copyright (c) 2020 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
*
*/
%inline %{
typedef struct Amp {
AMP *amp;
struct amp_caps *caps; /* shortcut to AMP->caps */
struct amp_state *state; /* shortcut to AMP->state */
int error_status;
int do_exception;
} Amp;
%}
/*
* declare wrapper method with 0,1,2 arguments besides AMP*
*/
#define AMPMETHOD0(f) void f () \
{ self->error_status = amp_##f(self->amp); }
#define AMPMETHOD1(f, t1) void f (t1 _##t1) \
{ self->error_status = amp_##f(self->amp, _##t1); }
#define AMPMETHOD2(f, t1, t2) void f (t1 _##t1##_1, t2 _##t2##_2) \
{ self->error_status = amp_##f(self->amp, _##t1##_1, _##t2##_2); }
#define AMPMETHOD3(f, t1, t2, t3) void f (t1 _##t1##_1, t2 _##t2##_2, t3 _##t3##_3) \
{ self->error_status = amp_##f(self->amp, _##t1##_1, _##t2##_2, t3 _##t3##_3); }
#define AMPMETHOD4(f, t1, t2, t3, t4) void f (t1 _##t1##_1, t2 _##t2##_3, t3 _##t3##_3, ##t4##_4) \
{ self->error_status = amp_##f(self->amp, _##t1##_1, _##t2##_3, t3 _##t3##_3, ##t4##_4); }
%extend Amp {
Amp(amp_model_t amp_model) {
Amp *r;
r = (Amp*)malloc(sizeof(Amp));
if (!r)
return NULL;
r->amp = amp_init(amp_model);
if (!r->amp) {
free(r);
return NULL;
}
/* install shortcuts */
r->caps = r->amp->caps;
r->state = &r->amp->state;
r->do_exception = 0; /* default is disabled */
r->error_status = RIG_OK;
return r;
}
~Amp () {
amp_cleanup(self->amp);
free(self);
}
/*
* return code checking
*/
%exception {
arg1->error_status = RIG_OK;
$action
if (arg1->error_status != RIG_OK && arg1->do_exception)
SWIG_exception(SWIG_UnknownError, rigerror(arg1->error_status));
}
AMPMETHOD0(open)
AMPMETHOD0(close)
AMPMETHOD1(reset, amp_reset_t)
AMPMETHOD1(token_lookup, const_char_string) /* conf */
/* set functions */
AMPMETHOD1(set_freq, freq_t)
AMPMETHOD1(set_powerstat, powerstat_t)
void set_conf(const char *name, const char *val) {
token_t tok = amp_token_lookup(self->amp, name);
if (tok == RIG_CONF_END)
self->error_status = -RIG_EINVAL;
else
self->error_status = amp_set_conf(self->amp, tok, val);
}
AMPMETHOD2(set_conf, token_t, const_char_string)
/*
* declare wrapper method with one output argument besides AMP*
*/
#define AMPMETHOD1VGET(f, t1) t1 f \
{ t1 _##t1; self->error_status = amp_##f(self->amp, &_##t1); return _##t1; }
/* get functions */
const char *get_conf(token_t tok) {
static char s[128] = "";
self->error_status = amp_get_conf(self->amp, tok, s);
return s;
}
const char *get_conf(const char *name) {
token_t tok = amp_token_lookup(self->amp, name);
static char s[128] = "";
if (tok == RIG_CONF_END)
self->error_status = -RIG_EINVAL;
else
self->error_status = amp_get_conf(self->amp, tok, s);
return s;
}
const char * get_info(void) {
const char *s;
s = amp_get_info(self->amp);
self->error_status = s ? RIG_OK : -RIG_EINVAL;
return s;
}
};
%{
void Amp_get_freq(Amp *self, freq_t *freq)
{
self->error_status = amp_get_freq(self->amp, freq);
}
void Amp_get_powerstat(Amp *self, powerstat_t *status)
{
self->error_status = amp_get_powerstat(self->amp, status);
}
%}

Wyświetl plik

@ -33,7 +33,10 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#include <hamlib/rotator.h> #include <hamlib/rotator.h>
#include "misc.h" #include <hamlib/amplifier.h>
//mdblack98 -- Commented this out -- is anybody using the functions in misc.h?
//If so, then those functions should be moved to rig.h
//#include "misc.h"
#include <limits.h> #include <limits.h>
@ -48,8 +51,10 @@
%include stdint.i %include stdint.i
%include exception.i %include exception.i
#ifndef SWIGLUA #ifndef SWIGLUA
#ifndef SWIGJAVA
%include cstring.i %include cstring.i
#endif #endif
#endif
#ifdef SWIGPYTHON #ifdef SWIGPYTHON
%include python/file.i %include python/file.i
@ -178,19 +183,24 @@
%apply int *OUTPUT { int *degrees, double *minutes, int *sw }; %apply int *OUTPUT { int *degrees, double *minutes, int *sw };
%apply double *OUTPUT { double *longitude, double *latitude }; %apply double *OUTPUT { double *longitude, double *latitude };
#ifndef SWIGJAVA
// If SWIGJAVA ever maps char * we can enable these
%apply char *OUTPUT { char *locator_res }; %apply char *OUTPUT { char *locator_res };
%apply char *OUTPUT { char *hamlib_version2 }; %apply char *OUTPUT { char *hamlib_version2 };
%apply char *OUTPUT { char *hamlib_copyright2 }; %apply char *OUTPUT { char *hamlib_copyright2 };
%apply char *OUTPUT { char *returnstr }; %apply char *OUTPUT { char *returnstr };
#endif
#ifndef SWIGLUA #ifndef SWIGLUA
#ifndef SWIG_CSTRING_UNIMPL #ifndef SWIG_CSTRING_UNIMPL
#ifndef SWIGJAVA
/* longlat2locator */ /* longlat2locator */
%cstring_bounded_output(char *locator_res, 13) %cstring_bounded_output(char *locator_res, 13)
%cstring_bounded_output(char *hamlib_version2, 4) %cstring_bounded_output(char *hamlib_version2, 4)
%cstring_bounded_output(char *hamlib_copyright2, 4) %cstring_bounded_output(char *hamlib_copyright2, 4)
#endif #endif
#endif #endif
#endif
%immutable confparams::name; %immutable confparams::name;
%immutable confparams::label; %immutable confparams::label;
@ -234,6 +244,11 @@ typedef const char * const_char_string;
*/ */
%include "rotator.swg" %include "rotator.swg"
/*
* The Amp "class"
*/
%include "amplifier.swg"
/* /*
* Put binding specific code in separate files * Put binding specific code in separate files
* *

Wyświetl plik

@ -210,6 +210,7 @@
%ignore hamlib_copyright2; %ignore hamlib_copyright2;
%ignore hamlib_version2; %ignore hamlib_version2;
%ignore macro_name;
#ifdef SWIGLUA #ifdef SWIGLUA
%ignore Rig::set_level(setting_t,int,vfo_t); %ignore Rig::set_level(setting_t,int,vfo_t);

Wyświetl plik

@ -272,7 +272,9 @@ typedef channel_t * const_channel_t_p;
%ignore MAX_RETURNSTR; %ignore MAX_RETURNSTR;
#define MAX_RETURNSTR 256 #define MAX_RETURNSTR 256
#ifndef SWIGJAVA
%apply char *OUTPUT { char *returnstr }; %apply char *OUTPUT { char *returnstr };
#endif
/* /*
* Rig class alike * Rig class alike
@ -281,8 +283,10 @@ typedef channel_t * const_channel_t_p;
#ifndef SWIGLUA #ifndef SWIGLUA
#ifndef SWIG_CSTRING_UNIMPL #ifndef SWIG_CSTRING_UNIMPL
#ifndef SWIGJAVA
%cstring_bounded_output(char *returnstr, MAX_RETURNSTR); %cstring_bounded_output(char *returnstr, MAX_RETURNSTR);
#endif #endif
#endif
#endif #endif
Rig(int rig_model) { Rig(int rig_model) {

Wyświetl plik

@ -145,15 +145,14 @@ enum amp_level_e
* sharing the struct amp_caps of the backend, while keeping their own * sharing the struct amp_caps of the backend, while keeping their own
* customized data. * customized data.
* *
* n.b.: Don't move fields around, as the backends depend on it when * mdblack98: Don't move fields around and add new fields at end of caps
* initializing their caps. * Shared libraries depend on constant structure to maintain compatibility
*/ */
#define AMP_MODEL(arg) .amp_model=arg,.macro_name=#arg #define AMP_MODEL(arg) .amp_model=arg,.macro_name=#arg
struct amp_caps struct amp_caps
{ {
amp_model_t amp_model; /*!< Amplifier model. */ amp_model_t amp_model; /*!< Amplifier model. */
const char *model_name; /*!< Model name. */ const char *model_name; /*!< Model name. */
const char *macro_name; /*!< Macro name. */
const char *mfg_name; /*!< Manufacturer. */ const char *mfg_name; /*!< Manufacturer. */
const char *version; /*!< Driver version. */ const char *version; /*!< Driver version. */
const char *copyright; /*!< Copyright info. */ const char *copyright; /*!< Copyright info. */
@ -219,6 +218,8 @@ struct amp_caps
unsigned ext_levels; unsigned ext_levels;
const struct confparams *extlevels; const struct confparams *extlevels;
const struct confparams *extparms; const struct confparams *extparms;
const char *macro_name; /*!< Macro name. */
}; };

Wyświetl plik

@ -162,7 +162,7 @@ struct rig_state;
/** /**
* \brief Rig structure definition (see rig for details). * \brief Rig structure definition (see rig for details).
*/ */
typedef struct rig RIG; typedef struct s_rig RIG;
#define RIGNAMSIZ 30 #define RIGNAMSIZ 30
#define RIGVERSIZ 8 #define RIGVERSIZ 8
@ -1854,7 +1854,7 @@ struct rig_callbacks {
* *
* \sa rig_init(), rig_caps(), rig_state() * \sa rig_init(), rig_caps(), rig_state()
*/ */
struct rig { struct s_rig {
struct rig_caps *caps; /*!< Pointer to rig capabilities (read only) */ struct rig_caps *caps; /*!< Pointer to rig capabilities (read only) */
struct rig_state state; /*!< Rig state */ struct rig_state state; /*!< Rig state */
struct rig_callbacks callbacks; /*!< registered event callbacks */ struct rig_callbacks callbacks; /*!< registered event callbacks */

Wyświetl plik

@ -52,7 +52,7 @@ struct rot_state;
* \typedef typedef struct rot ROT * \typedef typedef struct rot ROT
* \brief Rotator structure definition (see rot for details). * \brief Rotator structure definition (see rot for details).
*/ */
typedef struct rot ROT; typedef struct s_rot ROT;
/** /**
@ -220,7 +220,6 @@ typedef enum {
struct rot_caps { struct rot_caps {
rot_model_t rot_model; /*!< Rotator model. */ rot_model_t rot_model; /*!< Rotator model. */
const char *model_name; /*!< Model name. */ const char *model_name; /*!< Model name. */
const char *macro_name; /*!< Macro name. */
const char *mfg_name; /*!< Manufacturer. */ const char *mfg_name; /*!< Manufacturer. */
const char *version; /*!< Driver version. */ const char *version; /*!< Driver version. */
const char *copyright; /*!< Copyright info. */ const char *copyright; /*!< Copyright info. */
@ -256,7 +255,6 @@ struct rot_caps {
const struct confparams *cfgparams; /*!< Configuration parametres. */ const struct confparams *cfgparams; /*!< Configuration parametres. */
const rig_ptr_t priv; /*!< Private data. */ const rig_ptr_t priv; /*!< Private data. */
const char *rot_model_macro_name; /*!< Model macro name */
/* /*
* Rot Admin API * Rot Admin API
@ -287,6 +285,7 @@ struct rot_caps {
/* get firmware info, etc. */ /* get firmware info, etc. */
const char * (*get_info)(ROT *rot); const char * (*get_info)(ROT *rot);
const char *macro_name; /*!< Macro name. */
/* more to come... */ /* more to come... */
}; };
@ -339,7 +338,7 @@ struct rot_state {
* *
* \sa rot_init(), rot_caps(), rot_state() * \sa rot_init(), rot_caps(), rot_state()
*/ */
struct rot { struct s_rot {
struct rot_caps *caps; /*!< Rotator caps. */ struct rot_caps *caps; /*!< Rotator caps. */
struct rot_state state; /*!< Rotator state. */ struct rot_state state; /*!< Rotator state. */
}; };

Wyświetl plik

@ -810,8 +810,6 @@ int icom_set_default_vfo(RIG *rig)
rig_debug(RIG_DEBUG_TRACE, "%s: setting default as MAIN/VFOA\n", rig_debug(RIG_DEBUG_TRACE, "%s: setting default as MAIN/VFOA\n",
__func__); __func__);
retval = rig_set_vfo(rig, RIG_VFO_MAIN); // we'll default to Main in this case retval = rig_set_vfo(rig, RIG_VFO_MAIN); // we'll default to Main in this case
priv->curr_vfo = RIG_VFO_MAIN;
if (retval != RIG_OK) if (retval != RIG_OK)
{ {
return retval; return retval;
@ -823,6 +821,8 @@ int icom_set_default_vfo(RIG *rig)
{ {
return retval; return retval;
} }
priv->curr_vfo = RIG_VFO_MAIN;
} }
if (VFO_HAS_MAIN_SUB_ONLY) if (VFO_HAS_MAIN_SUB_ONLY)
@ -3698,11 +3698,11 @@ int icom_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq)
if (VFO_HAS_MAIN_SUB_A_B_ONLY) if (VFO_HAS_MAIN_SUB_A_B_ONLY)
{ {
// Then we return the VFO to where it was // Then we return the VFO to the rx_vfo
if (save_vfo == RIG_VFO_MAIN && priv->split_on) { save_vfo = RIG_VFO_A; } save_vfo = rx_vfo;
rig_debug(RIG_DEBUG_TRACE, "%s: SATMODE split_on rig so setting vfo to %s\n", __func__, rig_debug(RIG_DEBUG_TRACE, "%s: SATMODE split_on=%d rig so setting vfo to %s\n", __func__,
rig_strvfo(save_vfo)); priv->split_on, rig_strvfo(save_vfo));
if (RIG_OK != (rc = icom_set_vfo(rig, save_vfo))) if (RIG_OK != (rc = icom_set_vfo(rig, save_vfo)))
{ {