/* * Hamlib tcl/tk bindings - rotator * Copyright (c) 2001,2002 by Stephane Fillod * * $Id: tclrot.c,v 1.1 2002-01-22 00:34:48 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program 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 Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include "tclrot.h" #define ARG_IN1 0x01 #define ARG_OUT1 0x02 #define ARG_IN2 0x04 #define ARG_OUT2 0x08 #define ARG_IN3 0x10 #define ARG_OUT3 0x20 #define ARG_IN4 0x40 #define ARG_OUT4 0x80 #define ARG_IN (ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4) #define ARG_OUT (ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4) struct cmd_table { const char *name; int (*rot_routine)(ROT*, const struct cmd_table*, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); int flags; const char *arg1; const char *arg2; const char *arg3; }; #define declare_proto_rot(f) static int (f)(ROT *rot, \ const struct cmd_table *cmd, \ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) declare_proto_rot(open); declare_proto_rot(close); declare_proto_rot(set_conf); declare_proto_rot(get_conf); declare_proto_rot(set_pos); declare_proto_rot(get_pos); declare_proto_rot(get_info); /* */ static struct cmd_table cmd_list[] = { { "open", open }, { "close", close }, { "set_conf", set_conf, ARG_IN, "Token", "Value" }, { "get_conf", get_conf, ARG_IN1|ARG_OUT2, "Token", "Value" }, { "set_pos", set_pos, ARG_IN, "Azimuth", "Elevation" }, { "get_pos", get_pos, ARG_OUT, "Azimuth", "Elevation" }, { "get_info", get_info, ARG_OUT, "Info" }, { NULL, NULL }, }; #define MAXNAMSIZ 32 #define MAXNBOPT 100 /* max number of different options */ /* * TODO: use Lex and some kind of hash table */ static struct cmd_table *parse_cmd(const char *name) { int i; for (i=0; irot_routine)(tcl_rot, cmd_entry, interp, objc, objv); if (retcode != RIG_OK ) { /* FIXME: set Tcl error, and retcode can be TCL_ERROR! */ fprintf(stderr, "%s: %s\n", cmd_entry->name, rigerror(retcode)); return TCL_ERROR; } return TCL_OK; } /* * static int (f)(ROT *rot, const struct cmd_table *cmd, * Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) */ declare_proto_rot(open) { return rot_open(rot); } declare_proto_rot(close) { return rot_close(rot); } declare_proto_rot(set_conf) { token_t tok; tok = rot_token_lookup(rot, Tcl_GetString(objv[2])); return rot_set_conf(rot, tok, Tcl_GetString(objv[3])); } declare_proto_rot(get_conf) { int status; token_t tok; Tcl_Obj *resultPtr; char buf[255]; resultPtr = Tcl_GetObjResult(interp); tok = rot_token_lookup(rot, Tcl_GetString(objv[2])); status = rot_get_conf(rot, tok, buf); if (status != RIG_OK) return status; Tcl_SetStringObj(resultPtr, buf, -1); return RIG_OK; } declare_proto_rot(set_pos) { int status; double da, de; status = Tcl_GetDoubleFromObj(interp, objv[2], &da); if (status != TCL_OK) return status; status = Tcl_GetDoubleFromObj(interp, objv[3], &de); if (status != TCL_OK) return status; return rot_set_position(rot, (azimuth_t)da, (elevation_t)de); } declare_proto_rot(get_pos) { int status; azimuth_t az; elevation_t el; Tcl_Obj *resultPtr; resultPtr = Tcl_GetObjResult(interp); status = rot_get_position(rot, &az, &el); if (status != RIG_OK) return status; /* FIXME: return also elevation */ Tcl_SetDoubleObj(resultPtr, (double)az); return RIG_OK; } declare_proto_rot(get_info) { const char *s; Tcl_Obj *resultPtr; resultPtr = Tcl_GetObjResult(interp); s = rot_get_info(rot); Tcl_SetStringObj(resultPtr, s ? s : "None", -1); return RIG_OK; }