Hamlib/bindings/rotator.swg
Ervin Hegedüs d9fc9c04d7 rig.swg: New properly formatted macro
I made a patch, you can see in that there is the solution, which
describe the error: if a function in hamlib looks 3 argument
(rig, vfo, any 3rd arg), the order of the 2nd and 3rd argument
were reversed, because the macro METHOD1 reversed them.

I've collected these functions, compared its arguments with
hamlib docs (http://hamlib.sourceforge.net/manuals/1.2.15/), and
where 1st arg is rig, 2nd arg is vfo, and 3rd is any kind of
type, changed to METHOD3, which is a new macro, and keeps the
correct order of original function - see the patch. (I didn't
find any info about the expected diff format, so I just created
the `diff -uprN ORIG NEW'.)

To check my theory, I've tested with another function, which uses
vfo type at 2nd argument, eg. rig_set_freq; here is the Python
code:

  my_rig.set_freq(Hamlib.RIG_VFO_A, 7013200.0)

and the original code drop the exception:

    my_rig.set_freq(Hamlib.RIG_VFO_A, 7012500.0)
  File "/usr/local/lib/python2.7/dist-packages/Hamlib.py", line 2513, in
set_freq
    def set_freq(self, *args): return _Hamlib.Rig_set_freq(self, *args)
TypeError: in method 'Rig_set_freq', argument 3 of type 'vfo_t'

As you can see, it's same as my original error above.

So, after I patched the source and recompiled it again, these two
function works correctly - I will test it at soon, but I think
_this_ is good and stable.

Signed-off-by: Nate Bargmann <n0nb@n0nb.us>
2013-02-12 18:35:03 -06:00

140 lines
3.8 KiB
Plaintext

/*
* Hamlib bindings - Rotator interface
* Copyright (c) 2001,2002 by Stephane Fillod
*
*
* 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 Rot {
ROT *rot;
struct rot_caps *caps; /* shortcut to ROT->caps */
struct rot_state *state; /* shortcut to ROT->state */
int error_status;
int do_exception;
} Rot;
typedef const char * const_char_string;
%}
/*
* declare wrapper method with 0,1,2 arguments besides ROT*
*/
#define ROTMETHOD0(f) void f () \
{ self->error_status = rot_##f(self->rot); }
#define ROTMETHOD1(f, t1) void f (t1 _##t1) \
{ self->error_status = rot_##f(self->rot, _##t1); }
#define ROTMETHOD2(f, t1, t2) void f (t1 _##t1##_1, t2 _##t2##_2) \
{ self->error_status = rot_##f(self->rot, _##t1##_1, _##t2##_2); }
%extend Rot {
Rot(rot_model_t rot_model) {
Rot *r;
r = (Rot*)malloc(sizeof(Rot));
if (!r)
return NULL;
r->rot = rot_init(rot_model);
if (!r->rot) {
free(r);
return NULL;
}
/* install shortcuts */
r->caps = r->rot->caps;
r->state = &r->rot->state;
r->do_exception = 0; /* default is disabled */
r->error_status = RIG_OK;
return r;
}
~Rot () {
rot_cleanup(self->rot);
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));
}
ROTMETHOD0(open)
ROTMETHOD0(close)
ROTMETHOD2(set_position, azimuth_t, elevation_t)
extern void get_position(azimuth_t *OUTPUT, elevation_t *OUTPUT);
ROTMETHOD0(stop)
ROTMETHOD0(park)
ROTMETHOD1(reset, rot_reset_t)
ROTMETHOD2(move, int, int)
ROTMETHOD1(token_lookup, const_char_string) /* conf */
void set_conf(const char *name, const char *val) {
token_t tok = rot_token_lookup(self->rot, name);
if (tok == RIG_CONF_END)
self->error_status = -RIG_EINVAL;
else
self->error_status = rot_set_conf(self->rot, tok, val);
}
ROTMETHOD2(set_conf, token_t, const_char_string)
const char *get_conf(token_t tok) {
static char s[128] = "";
self->error_status = rot_get_conf(self->rot, tok, s);
return s;
}
const char *get_conf(const char *name) {
token_t tok = rot_token_lookup(self->rot, name);
static char s[128] = "";
if (tok == RIG_CONF_END)
self->error_status = -RIG_EINVAL;
else
self->error_status = rot_get_conf(self->rot, tok, s);
return s;
}
const char * get_info(void) {
const char *s;
s = rot_get_info(self->rot);
self->error_status = s ? RIG_OK : -RIG_EINVAL;
return s;
}
/* TODO: get_conf_list, .. */
};
%{
/*
* this one returns 2 values, here is a perl example:
* ($az, $elevation) = $rig->get_position();
*/
void Rot_get_position(Rot *self, azimuth_t *azimuth, elevation_t *elevation)
{
self->error_status = rot_get_position(self->rot, azimuth, elevation);
}
%}