2002-09-08 22:31:01 +00:00
|
|
|
/*
|
|
|
|
* Hamlib bindings - Rotator interface
|
|
|
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
|
|
|
*
|
|
|
|
*
|
2011-08-20 23:22:51 +00:00
|
|
|
* 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.
|
2002-09-08 22:31:01 +00:00
|
|
|
*
|
2011-08-20 23:22:51 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2002-09-08 22:31:01 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-20 23:22:51 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2002-09-08 22:31:01 +00:00
|
|
|
*
|
2011-08-20 23:22:51 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2002-09-08 22:31:01 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2011-08-20 23:22:51 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-09-08 22:31:01 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
%inline %{
|
|
|
|
|
|
|
|
typedef struct Rot {
|
|
|
|
ROT *rot;
|
|
|
|
struct rot_caps *caps; /* shortcut to ROT->caps */
|
|
|
|
struct rot_state *state; /* shortcut to ROT->state */
|
2002-09-16 06:50:13 +00:00
|
|
|
int error_status;
|
|
|
|
int do_exception;
|
2002-09-08 22:31:01 +00:00
|
|
|
} Rot;
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decalre wrapper method with 0,1,2 arguments besides ROT*
|
|
|
|
*/
|
2002-09-16 06:50:13 +00:00
|
|
|
#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); }
|
2002-09-08 22:31:01 +00:00
|
|
|
|
|
|
|
%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;
|
2002-09-16 06:50:13 +00:00
|
|
|
r->do_exception = 0; /* default is disabled */
|
|
|
|
r->error_status = RIG_OK;
|
2002-09-08 22:31:01 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
~Rot () {
|
|
|
|
rot_cleanup(self->rot);
|
|
|
|
free(self);
|
|
|
|
}
|
2002-09-16 06:50:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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));
|
|
|
|
}
|
|
|
|
|
2002-09-08 22:31:01 +00:00
|
|
|
ROTMETHOD0(open)
|
|
|
|
ROTMETHOD0(close)
|
|
|
|
|
|
|
|
ROTMETHOD2(set_position, azimuth_t, elevation_t)
|
2002-10-07 21:44:51 +00:00
|
|
|
extern void get_position(azimuth_t *OUTPUT, elevation_t *OUTPUT);
|
2002-09-08 22:31:01 +00:00
|
|
|
ROTMETHOD0(stop)
|
|
|
|
ROTMETHOD0(park)
|
|
|
|
ROTMETHOD1(reset, rot_reset_t)
|
|
|
|
ROTMETHOD2(move, int, int)
|
|
|
|
|
|
|
|
ROTMETHOD1(token_lookup, const_char_string) /* conf */
|
|
|
|
|
2002-10-07 21:44:51 +00:00
|
|
|
void set_conf(const char *name, const char *val) {
|
2002-09-08 22:31:01 +00:00
|
|
|
token_t tok = rot_token_lookup(self->rot, name);
|
2002-10-07 21:44:51 +00:00
|
|
|
if (tok == RIG_CONF_END)
|
|
|
|
self->error_status = -RIG_EINVAL;
|
|
|
|
else
|
|
|
|
self->error_status = rot_set_conf(self->rot, tok, val);
|
2002-09-08 22:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ROTMETHOD2(set_conf, token_t, const_char_string)
|
|
|
|
|
2002-10-07 21:44:51 +00:00
|
|
|
const char *get_conf(token_t tok) {
|
|
|
|
static char s[128] = "";
|
|
|
|
self->error_status = rot_get_conf(self->rot, tok, s);
|
|
|
|
return s;
|
|
|
|
}
|
2002-09-08 22:31:01 +00:00
|
|
|
|
2002-10-07 21:44:51 +00:00
|
|
|
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, .. */
|
2002-09-08 22:31:01 +00:00
|
|
|
};
|
|
|
|
|
2002-10-07 21:44:51 +00:00
|
|
|
%{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
%}
|