kopia lustrzana https://github.com/Hamlib/Hamlib
split rig and rot commands into tclrig.c and tclrot.c
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@893 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.3
rodzic
8f501050ed
commit
27e30ab322
142
tcl/hamlibtcl.c
142
tcl/hamlibtcl.c
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Hamlib tcl/tk bindings - main file
|
* Hamlib tcl/tk bindings - main file
|
||||||
* Copyright (c) 2001 by Stephane Fillod
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: hamlibtcl.c,v 1.2 2001-07-13 19:08:15 f4cfe Exp $
|
* $Id: hamlibtcl.c,v 1.3 2002-01-22 00:53:01 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -27,138 +27,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <tcl.h>
|
#include <tcl.h>
|
||||||
#include <hamlib/rig.h>
|
#include <hamlib/rig.h>
|
||||||
|
#include <hamlib/rotator.h>
|
||||||
|
#include <misc.h>
|
||||||
|
|
||||||
/*
|
#include "tclrig.h"
|
||||||
* since there's no long long support in tcl API,
|
#include "tclrot.h"
|
||||||
* freq_t is mapped to double object, which has enough
|
|
||||||
* significant digits for frequencies up to tens of GHz.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
int DoRig(ClientData clientData, Tcl_Interp *interp,
|
|
||||||
int objc, Tcl_Obj *CONST objv[]);
|
|
||||||
int DoRigLib(ClientData clientData, Tcl_Interp *interp,
|
|
||||||
int objc, Tcl_Obj *CONST objv[]);
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
DoRigLib(ClientData clientData, Tcl_Interp *interp,
|
|
||||||
int objc, Tcl_Obj *CONST objv[])
|
|
||||||
{
|
|
||||||
Tcl_Obj *resultPtr;
|
|
||||||
int error;
|
|
||||||
char *subcmd;
|
|
||||||
|
|
||||||
/* objc gives the number of "objects" = arguments to
|
|
||||||
the command */
|
|
||||||
if (objc != 2 && objc != 3) {
|
|
||||||
Tcl_WrongNumArgs(interp, 1, objv, "cmd ?model?");
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Process the arguments
|
|
||||||
objv is an array holding the arguments */
|
|
||||||
|
|
||||||
/* Use Tcl_GetIntFromObj to put an integer value
|
|
||||||
into a variable from the argument list */
|
|
||||||
|
|
||||||
subcmd = Tcl_GetString(objv[1]);
|
|
||||||
resultPtr = Tcl_GetObjResult(interp);
|
|
||||||
|
|
||||||
/* TODO: make use of flex here! */
|
|
||||||
|
|
||||||
if (!strcasecmp(subcmd, "version")) {
|
|
||||||
Tcl_SetStringObj(resultPtr, hamlib_version, -1);
|
|
||||||
} else if (!strcasecmp(subcmd, "help")) {
|
|
||||||
Tcl_SetStringObj(resultPtr, "no help yet!", -1);
|
|
||||||
} else if (!strcasecmp(subcmd, "init")) {
|
|
||||||
rig_model_t model;
|
|
||||||
RIG *tcl_rig;
|
|
||||||
char rigcmd_name[16];
|
|
||||||
static int rigcmd_cpt=0;
|
|
||||||
|
|
||||||
error = Tcl_GetIntFromObj(interp, objv[2], (int*)&model);
|
|
||||||
if (error != TCL_OK)
|
|
||||||
return error;
|
|
||||||
tcl_rig = rig_init(model);
|
|
||||||
if (!tcl_rig)
|
|
||||||
return TCL_ERROR;
|
|
||||||
sprintf(rigcmd_name, "rig%d", rigcmd_cpt++);
|
|
||||||
Tcl_CreateObjCommand(interp, rigcmd_name, DoRig,
|
|
||||||
(ClientData)tcl_rig, (Tcl_CmdDeleteProc *)NULL);
|
|
||||||
Tcl_SetStringObj(resultPtr, rigcmd_name, -1);
|
|
||||||
} else {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
return TCL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
DoRig(ClientData clientData, Tcl_Interp *interp,
|
|
||||||
int objc, Tcl_Obj *CONST objv[])
|
|
||||||
{
|
|
||||||
Tcl_Obj *resultPtr;
|
|
||||||
int error;
|
|
||||||
char *subcmd;
|
|
||||||
RIG *tcl_rig = (RIG*)clientData;
|
|
||||||
|
|
||||||
if (!tcl_rig)
|
|
||||||
return TCL_ERROR;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* objc gives the number of "objects" = arguments to
|
|
||||||
the command */
|
|
||||||
if (!(objc == 2 || objc == 3)) {
|
|
||||||
Tcl_WrongNumArgs(interp, 1, objv, "var1 var2 ?var3?");
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Process the arguments
|
|
||||||
objv is an array holding the arguments */
|
|
||||||
|
|
||||||
/* Use Tcl_GetIntFromObj to put an integer value
|
|
||||||
into a variable from the argument list */
|
|
||||||
|
|
||||||
subcmd = Tcl_GetString(objv[1]);
|
|
||||||
resultPtr = Tcl_GetObjResult(interp);
|
|
||||||
|
|
||||||
/* TODO: make use of flex here! */
|
|
||||||
|
|
||||||
if (!strcasecmp(subcmd, "open")) {
|
|
||||||
rig_open(tcl_rig);
|
|
||||||
return TCL_OK;
|
|
||||||
} else if (!strcasecmp(subcmd, "set_freq")) {
|
|
||||||
double d;
|
|
||||||
freq_t freq;
|
|
||||||
|
|
||||||
error = Tcl_GetDoubleFromObj(interp, objv[2], &d);
|
|
||||||
if (error != TCL_OK)
|
|
||||||
return error;
|
|
||||||
freq = (freq_t)d;
|
|
||||||
|
|
||||||
rig_set_freq(tcl_rig, RIG_VFO_CURR, freq);
|
|
||||||
return TCL_OK;
|
|
||||||
} else if (!strcasecmp(subcmd, "get_strength")) {
|
|
||||||
int strength;
|
|
||||||
|
|
||||||
rig_get_strength(tcl_rig, RIG_VFO_CURR, &strength);
|
|
||||||
Tcl_SetIntObj(resultPtr, strength);
|
|
||||||
return TCL_OK;
|
|
||||||
} else if (!strcasecmp(subcmd, "close")) {
|
|
||||||
|
|
||||||
rig_close(tcl_rig);
|
|
||||||
return TCL_OK;
|
|
||||||
} else if (!strcasecmp(subcmd, "cleanup")) {
|
|
||||||
|
|
||||||
rig_cleanup(tcl_rig);
|
|
||||||
return TCL_OK;
|
|
||||||
} else {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
return TCL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Hamlib_Init(Tcl_Interp *interp)
|
int Hamlib_Init(Tcl_Interp *interp)
|
||||||
|
@ -173,6 +46,9 @@ int Hamlib_Init(Tcl_Interp *interp)
|
||||||
Tcl_CreateObjCommand(interp, "rig", DoRigLib,
|
Tcl_CreateObjCommand(interp, "rig", DoRigLib,
|
||||||
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
|
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
|
||||||
|
|
||||||
|
Tcl_CreateObjCommand(interp, "rot", DoRotLib,
|
||||||
|
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
|
||||||
|
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue