1/*
2 *  Hamlib bindings - Rotator interface
3 *  Copyright (c) 2001,2002 by Stephane Fillod
4 *
5 *
6 *   This library is free software; you can redistribute it and/or
7 *   modify it under the terms of the GNU Lesser General Public
8 *   License as published by the Free Software Foundation; either
9 *   version 2.1 of the License, or (at your option) any later version.
10 *
11 *   This library is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 *   Lesser General Public License for more details.
15 *
16 *   You should have received a copy of the GNU Lesser General Public
17 *   License along with this library; if not, write to the Free Software
18 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 *
20 */
21
22%inline %{
23
24typedef struct Rot {
25	ROT *rot;
26	struct rot_caps *caps;		/* shortcut to ROT->caps */
27	struct rot_state *state;	/* shortcut to ROT->state */
28	int error_status;
29	int do_exception;
30} Rot;
31
32%}
33
34/*
35 * declare wrapper method with 0,1,2 arguments besides ROT*
36 */
37#define ROTMETHOD0(f) void f () \
38				{ self->error_status = rot_##f(self->rot); }
39#define ROTMETHOD1(f, t1) void f (t1 _##t1) \
40				{ self->error_status = rot_##f(self->rot, _##t1); }
41#define ROTMETHOD2(f, t1, t2) void f (t1 _##t1##_1, t2 _##t2##_2) \
42				{ self->error_status = rot_##f(self->rot, _##t1##_1, _##t2##_2); }
43
44%extend Rot {
45	Rot(rot_model_t rot_model) {
46		Rot *r;
47
48		r = (Rot*)malloc(sizeof(Rot));
49		if (!r)
50			return NULL;
51		r->rot = rot_init(rot_model);
52		if (!r->rot) {
53			free(r);
54			return NULL;
55		}
56		/* install shortcuts */
57		r->caps = r->rot->caps;
58		r->state = &r->rot->state;
59		r->do_exception = 0;    /* default is disabled */
60		r->error_status = RIG_OK;
61		return r;
62	}
63	~Rot () {
64		rot_cleanup(self->rot);
65		free(self);
66	}
67
68/*
69 * return code checking
70 */
71%exception {
72	arg1->error_status = RIG_OK;
73	$action
74	if (arg1->error_status != RIG_OK && arg1->do_exception)
75		SWIG_exception(SWIG_UnknownError, rigerror(arg1->error_status));
76}
77
78	ROTMETHOD0(open)
79	ROTMETHOD0(close)
80
81	ROTMETHOD2(set_position, azimuth_t, elevation_t)
82        extern void get_position(azimuth_t *OUTPUT, elevation_t *OUTPUT);
83	ROTMETHOD0(stop)
84	ROTMETHOD0(park)
85	ROTMETHOD1(reset, rot_reset_t)
86	ROTMETHOD2(move, int, int)
87
88	ROTMETHOD1(token_lookup, const_char_string)	/* conf */
89
90	void set_conf(const char *name, const char *val) {
91		token_t tok = rot_token_lookup(self->rot, name);
92		if (tok == RIG_CONF_END)
93			self->error_status = -RIG_EINVAL;
94		else
95			self->error_status = rot_set_conf(self->rot, tok, val);
96	}
97
98	ROTMETHOD2(set_conf, token_t, const_char_string)
99
100        const char *get_conf(token_t tok) {
101                static char s[128] = "";
102                self->error_status = rot_get_conf(self->rot, tok, s);
103                return s;
104        }
105
106        const char *get_conf(const char *name) {
107                token_t tok = rot_token_lookup(self->rot, name);
108                static char s[128] = "";
109                if (tok == RIG_CONF_END)
110                        self->error_status = -RIG_EINVAL;
111                else
112                        self->error_status = rot_get_conf(self->rot, tok, s);
113                return s;
114        }
115
116        const char * get_info(void) {
117                const char *s;
118                s = rot_get_info(self->rot);
119                self->error_status = s ? RIG_OK : -RIG_EINVAL;
120                return s;
121        }
122
123	/* TODO: get_conf_list, .. */
124};
125
126%{
127
128/*
129 * this one returns 2 values, here is a perl example:
130 *      ($az, $elevation) = $rig->get_position();
131 */
132void Rot_get_position(Rot *self, azimuth_t *azimuth, elevation_t *elevation)
133{
134        self->error_status = rot_get_position(self->rot, azimuth, elevation);
135}
136
137%}
138