added ability to change RPC program number

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1173 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.4
Stéphane Fillod, F8CFE 2002-09-13 06:59:54 +00:00
rodzic fdd237f95e
commit 49b2a47456
6 zmienionych plików z 326 dodań i 35 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH RIGD "8" "August 23, 2002" "Hamlib"
.TH RIGD "8" "September 12, 2002" "Hamlib"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -66,6 +66,9 @@ Use \fBid\fP as the CI-V address to communicate with the rig. Only for Icom rigs
.B \-C, \-\-set\-conf=parm=val[,parm=val]*
Set config parameter.
.TP
.B \-t, --prog=number
Use \fBnumber\fP as the RPC program number. The default is 536871065.
.TP
.B \-v, \-\-verbose
Set verbose mode, cumulative.
.TP

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib RPC backend - main file
* Copyright (c) 2001,2002 by Stephane Fillod
*
* $Id: rpcrig_backend.c,v 1.9 2002-08-23 20:01:09 fillods Exp $
* $Id: rpcrig_backend.c,v 1.10 2002-09-13 06:58:55 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
@ -33,19 +33,34 @@
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include <math.h>
#include <limits.h>
#include <hamlib/rig.h>
#include <serial.h>
#include <misc.h>
#include <token.h>
#include <netdb.h>
#include <rpc/rpc.h>
#include "rpcrig.h"
#include "rpcrig_backend.h"
#define RIGPROTO "udp"
/*
* Borrowed from stringify.h
* Indirect stringification. Doing two levels allows the parameter to be a
* macro itself. For example, compile with -DFOO=bar, __stringify(FOO)
* converts to "bar".
*/
#define r_stringify_1(x) #x
#define r_stringify(x) r_stringify_1(x)
struct rpcrig_priv_data {
CLIENT *cl;
unsigned long prognum;
};
#define SETBODY1(f, rpc_type, rig_arg) \
@ -118,8 +133,26 @@ struct rpcrig_priv_data {
return res->rigstatus;
static unsigned long extract_prognum(const char val[])
{
if (val[0] == '+') {
return RIGPROG + atol(val+1);
} else
if (val[0] < '0' || val[0] > '9') {
struct rpcent *ent;
ent = getrpcbyname (val);
if (ent)
return ent->r_number;
else
return 0;
} else
return atol(val);
}
static int rpcrig_init(RIG *rig)
{
struct rpcrig_priv_data *priv;
if (!rig || !rig->caps)
return -RIG_EINVAL;
@ -128,8 +161,11 @@ static int rpcrig_init(RIG *rig)
/* whoops! memory shortage! */
return -RIG_ENOMEM;
}
priv = (struct rpcrig_priv_data*)rig->state.priv;
rig->state.rigport.type.rig = RIG_PORT_RPC;
strcpy(rig->state.rigport.pathname, "localhost");
priv->prognum = RIGPROG;
return RIG_OK;
}
@ -158,22 +194,35 @@ static int rpcrig_open(RIG *rig)
rigstate_res *rs_res;
rig_model_t model;
const struct rig_caps *caps;
char *server;
char *server, *s;
int i;
rs = &rig->state;
priv = (struct rpcrig_priv_data*)rs->priv;
server = rs->rigport.pathname;
server = strdup(rs->rigport.pathname);
s = strchr(server, ':');
if (s) {
unsigned long prognum;
*s = '\0';
prognum = extract_prognum(s+1);
if (prognum == 0) {
free(server);
return -RIG_ECONF;
}
priv->prognum = prognum;
}
priv->cl = clnt_create(server, RIGPROG, RIGVERS, "udp");
priv->cl = clnt_create(server, priv->prognum, RIGVERS, RIGPROTO);
if (priv->cl == NULL) {
clnt_pcreateerror(server);
free(server);
return -RIG_ECONF;
}
mdl_res = getmodel_1(NULL, priv->cl);
if (mdl_res == NULL) {
clnt_perror(priv->cl, server);
clnt_destroy(priv->cl);
free(server);
priv->cl = NULL;
return -RIG_EPROTO;
}
@ -201,9 +250,11 @@ static int rpcrig_open(RIG *rig)
if (rs_res == NULL) {
clnt_perror(priv->cl, server);
clnt_destroy(priv->cl);
free(server);
priv->cl = NULL;
return -RIG_EPROTO;
}
free(server);
rs->has_get_func = rs_res->rigstate_res_u.state.has_get_func;
rs->has_set_func = rs_res->rigstate_res_u.state.has_set_func;
rs->has_get_level = rs_res->rigstate_res_u.state.has_get_level;
@ -854,6 +905,66 @@ static int rpcrig_send_morse(RIG *rig, vfo_t vfo, const char *msg)
#define TOK_PROGNUM TOKEN_BACKEND(1)
static const struct confparams rpcrig_cfg_params[] = {
{ TOK_PROGNUM, "prognum", "Program number", "RPC program number",
r_stringify(RIGPROG), RIG_CONF_NUMERIC, { .n = { 100000, ULONG_MAX, 1 } }
},
{ RIG_CONF_END, NULL, }
};
/*
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int rpcrig_set_conf(RIG *rig, token_t token, const char *val)
{
struct rpcrig_priv_data *priv;
struct rig_state *rs;
rs = &rig->state;
priv = (struct rpcrig_priv_data*)rs->priv;
switch(token) {
case TOK_PROGNUM:
{
unsigned long prognum;
prognum = extract_prognum(val);
if (prognum == 0)
return -RIG_EINVAL;
priv->prognum = prognum;
break;
}
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes rig!=NULL,
* Assumes rig!=NULL, rig->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value.
*/
int rpcrig_get_conf(RIG *rig, token_t token, char *val)
{
struct rpcrig_priv_data *priv;
struct rig_state *rs;
rs = &rig->state;
priv = (struct rpcrig_priv_data*)rs->priv;
switch(token) {
case TOK_PROGNUM:
sprintf(val, "%ld", priv->prognum);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* Dummy rig capabilities.
*/
@ -891,6 +1002,10 @@ struct rig_caps rpcrig_caps = {
.rig_open = rpcrig_open,
.rig_close = rpcrig_close,
.cfgparams = rpcrig_cfg_params,
.set_conf = rpcrig_set_conf,
.get_conf = rpcrig_get_conf,
.set_freq = rpcrig_set_freq,
.get_freq = rpcrig_get_freq,
.set_mode = rpcrig_set_mode,
@ -963,4 +1078,3 @@ int initrigs_rpcrig(void *be_handle)
return RIG_OK;
}

Wyświetl plik

@ -4,7 +4,7 @@
* This program let programs control a radio through
* the mean of RPC services using Hamlib.
*
* $Id: rpcrigd.c,v 1.4 2002-08-23 19:55:53 fillods Exp $
* $Id: rpcrigd.c,v 1.5 2002-09-13 06:58:55 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -36,6 +36,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
/* TODO: autoconf should check for getopt support, include libs otherwise */
@ -60,7 +61,7 @@ void rigprog_1(struct svc_req *rqstp, register SVCXPRT *transp);
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* NB: do NOT use -W since it's reserved by POSIX.
*/
#define SHORT_OPTIONS "m:r:p:P:d:D:c:s:C:vhV"
#define SHORT_OPTIONS "m:r:p:P:d:D:c:s:C:t:vhV"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@ -72,6 +73,7 @@ static struct option long_options[] =
{"serial-speed", 1, 0, 's'},
{"civaddr", 1, 0, 'c'},
{"set-conf", 1, 0, 'C'},
{"prog", 1, 0, 't'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
@ -101,6 +103,22 @@ int set_conf(RIG *my_rig, char *conf_parms)
}
static unsigned long extract_prognum(const char val[])
{
if (val[0] == '+') {
return RIGPROG + atol(val+1);
} else
if (val[0] < '0' || val[0] > '9') {
struct rpcent *ent;
ent = getrpcbyname (val);
if (ent)
return ent->r_number;
else
return 0;
} else
return atol(val);
}
RIG *the_rpc_rig;
@ -122,6 +140,7 @@ main (int argc, char *argv[])
char *civaddr = NULL; /* NULL means no need to set conf */
int serial_rate = 0;
char conf_parms[MAXCONFLEN] = "";
unsigned long prognum = RIGPROG;
/* Arguments parsing */
@ -228,6 +247,13 @@ main (int argc, char *argv[])
strcat(conf_parms, ",");
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
break;
case 't':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
prognum = extract_prognum(optarg);
break;
case 'v':
verbose++;
break;
@ -294,30 +320,30 @@ main (int argc, char *argv[])
/* Setup the RPC service and fire it up */
pmap_unset (RIGPROG, RIGVERS);
pmap_unset (prognum, RIGVERS);
transp = svcudp_create(RPC_ANYSOCK);
if (transp == NULL) {
fprintf (stderr, "%s", "cannot create udp service.");
fprintf (stderr, "cannot create udp service.");
exit(1);
}
if (!svc_register(transp, RIGPROG, RIGVERS, rigprog_1, IPPROTO_UDP)) {
fprintf (stderr, "%s", "unable to register (RIGPROG, RIGVERS, udp).");
if (!svc_register(transp, prognum, RIGVERS, rigprog_1, IPPROTO_UDP)) {
fprintf (stderr, "unable to register (%lu, %u, udp).", prognum, RIGVERS);
exit(1);
}
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
if (transp == NULL) {
fprintf (stderr, "%s", "cannot create tcp service.");
fprintf (stderr, "cannot create tcp service.");
exit(1);
}
if (!svc_register(transp, RIGPROG, RIGVERS, rigprog_1, IPPROTO_TCP)) {
fprintf (stderr, "%s", "unable to register (RIGPROG, RIGVERS, tcp).");
if (!svc_register(transp, prognum, RIGVERS, rigprog_1, IPPROTO_TCP)) {
fprintf (stderr, "unable to register (%lu, %u, tcp).", prognum, RIGVERS);
exit(1);
}
svc_run ();
fprintf (stderr, "%s", "svc_run returned");
fprintf (stderr, "svc_run returned");
/* the rig gets automatically closed in rigd_exit() */
@ -349,6 +375,7 @@ void usage()
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address (for Icom rigs only)\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -t, --prog=NUMBER set RPC program number\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"

Wyświetl plik

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH ROTD "8" "3 January 2002" "Hamlib"
.TH ROTD "8" "12 September 2002" "Hamlib"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -21,7 +21,7 @@ rotd \- Hamlib rotator service daemon
.B rpc.rotd
[\fIOPTION\fR]...
.SH DESCRIPTION
The \fBrotd\fP program is a Hamlib rig daemon that handles RPC client requests.
The \fBrotd\fP program is a Hamlib rotator daemon that handles RPC client requests.
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
@ -38,15 +38,18 @@ A summary of options is included below.
.B \-m, \-\-model=id
Select rotator model number. See model list.
.TP
.B \-r, --rig-file=device
.B \-r, --rot-file=device
Use \fBdevice\fP as the file name of the rotator to operate on.
.TP
.B \-s, --serial-speed=baud
Set serial speed to \fBbaud\fP rate. Uses maximal rig speed as default.
Set serial speed to \fBbaud\fP rate. Uses maximal rotator speed as default.
.TP
.B \-C, \-\-set\-conf=parm=val[,parm=val]*
Set config parameter.
.TP
.B \-t, --prog=number
Use \fBnumber\fP as the RPC program number. The default is 536873369.
.TP
.B \-v, \-\-verbose
Set verbose mode, cumulative.
.TP

Wyświetl plik

@ -3,7 +3,7 @@
* Copyright (c) 2001,2002 by Stephane Fillod
* Contributed by Francois Retief <fgretief@sun.ac.za>
*
* $Id: rpcrot_backend.c,v 1.3 2002-08-16 17:43:02 fillods Exp $
* $Id: rpcrot_backend.c,v 1.4 2002-09-13 06:59:54 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
@ -34,10 +34,13 @@
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include <math.h>
#include <netdb.h>
#include <limits.h>
#include <hamlib/rotator.h>
#include <serial.h>
#include <misc.h>
#include <token.h>
#include <rpc/rpc.h>
#include "rpcrot.h"
@ -45,12 +48,45 @@
struct rpcrot_priv_data {
CLIENT *cl;
unsigned long prognum;
};
#define ROTPROTO "udp"
/*
* Borrowed from stringify.h
* Indirect stringification. Doing two levels allows the parameter to be a
* macro itself. For example, compile with -DFOO=bar, __stringify(FOO)
* converts to "bar".
*/
#define r_stringify_1(x) #x
#define r_stringify(x) r_stringify_1(x)
/* ************************************************************************* */
static unsigned long extract_prognum(const char val[])
{
if (val[0] == '+') {
return ROTPROG + atol(val+1);
} else
if (val[0] < '0' || val[0] > '9') {
struct rpcent *ent;
ent = getrpcbyname (val);
if (ent)
return ent->r_number;
else
return 0;
} else
return atol(val);
}
static int rpcrot_init(ROT *rot)
{
struct rpcrot_priv_data *priv;
if (!rot || !rot->caps)
return -RIG_EINVAL;
@ -59,8 +95,11 @@ static int rpcrot_init(ROT *rot)
/* whoops! memory shortage! */
return -RIG_ENOMEM;
}
priv = (struct rpcrot_priv_data*)rot->state.priv;
rot->state.rotport.type.rig = RIG_PORT_RPC;
strcpy(rot->state.rotport.pathname, "localhost");
priv->prognum = ROTPROG;
return RIG_OK;
}
@ -91,21 +130,34 @@ static int rpcrot_open(ROT *rot)
rotstate_res *rs_res;
rot_model_t model;
const struct rot_caps *caps;
char *server;
char *server, *s;
rs = &rot->state;
priv = (struct rpcrot_priv_data *)rs->priv;
server = rs->rotport.pathname;
server = strdup(rs->rotport.pathname);
s = strchr(server, ':');
if (s) {
unsigned long prognum;
*s = '\0';
prognum = extract_prognum(s+1);
if (prognum == 0) {
free(server);
return -RIG_ECONF;
}
priv->prognum = prognum;
}
priv->cl = clnt_create(server, ROTPROG, ROTVERS, "udp");
priv->cl = clnt_create(server, priv->prognum, ROTVERS, ROTPROTO);
if (priv->cl == NULL) {
clnt_pcreateerror(server);
free(server);
return -RIG_ECONF;
}
mdl_res = getmodel_1(NULL, priv->cl);
if (mdl_res == NULL) {
clnt_perror(priv->cl, server);
clnt_destroy(priv->cl);
free(server);
priv->cl = NULL;
return -RIG_EPROTO;
}
@ -125,10 +177,13 @@ static int rpcrot_open(ROT *rot)
if (rs_res == NULL) {
clnt_perror(priv->cl, server);
clnt_destroy(priv->cl);
free(server);
priv->cl = NULL;
return -RIG_EPROTO;
}
free(server);
if (rs_res->rotstatus != RIG_OK) {
rig_debug(RIG_DEBUG_VERBOSE, "%s: error from remote - %s\n", __FUNCTION__, rigerror(rs_res->rotstatus));
return rs_res->rotstatus;
@ -254,6 +309,65 @@ static int rpcrot_move(ROT *rot, int direction, int speed)
return *result;
}
#define TOK_PROGNUM TOKEN_BACKEND(1)
static const struct confparams rpcrot_cfg_params[] = {
{ TOK_PROGNUM, "prognum", "Program number", "RPC program number",
r_stringify(ROTPROG), RIG_CONF_NUMERIC, { .n = { 100000, ULONG_MAX, 1 } }
},
{ RIG_CONF_END, NULL, }
};
/*
* Assumes rot!=NULL, rot->state.priv!=NULL
*/
int rpcrot_set_conf(ROT *rot, token_t token, const char *val)
{
struct rpcrot_priv_data *priv;
struct rot_state *rs;
rs = &rot->state;
priv = (struct rpcrot_priv_data*)rs->priv;
switch(token) {
case TOK_PROGNUM:
{
unsigned long prognum;
prognum = extract_prognum(val);
if (prognum == 0)
return -RIG_EINVAL;
priv->prognum = prognum;
break;
}
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes rot!=NULL,
* Assumes rot!=NULL, rot->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value.
*/
int rpcrot_get_conf(ROT *rot, token_t token, char *val)
{
struct rpcrot_priv_data *priv;
struct rot_state *rs;
rs = &rot->state;
priv = (struct rpcrot_priv_data*)rs->priv;
switch(token) {
case TOK_PROGNUM:
sprintf(val, "%ld", priv->prognum);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
/* ************************************************************************* */
struct rot_caps rpcrot_caps = {
@ -272,6 +386,10 @@ struct rot_caps rpcrot_caps = {
.rot_open = rpcrot_open,
.rot_close = rpcrot_close,
.cfgparams = rpcrot_cfg_params,
.set_conf = rpcrot_set_conf,
.get_conf = rpcrot_get_conf,
.set_position = rpcrot_set_position,
.get_position = rpcrot_get_position,
.stop = rpcrot_stop,

Wyświetl plik

@ -1,10 +1,10 @@
/*
* rpcrotd - (C) Stephane Fillod 2001
* rpcrotd - (C) Stephane Fillod 2001-2002
*
* This program let programs control a rotator through
* the mean of RPC services using Hamlib.
*
* $Id: rpcrotd.c,v 1.1 2002-01-16 16:45:11 fgretief Exp $
* $Id: rpcrotd.c,v 1.2 2002-09-13 06:59:54 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -35,6 +35,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
/* TODO: autoconf should check for getopt support, include libs otherwise */
@ -59,13 +60,14 @@ void rotprog_1(struct svc_req *rqstp, register SVCXPRT *transp);
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:s:C:vhV"
#define SHORT_OPTIONS "m:r:s:C:t:vhV"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rot-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'},
{"set-conf", 1, 0, 'C'},
{"prog", 1, 0, 't'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
@ -95,6 +97,21 @@ int set_conf(ROT *my_rot, char *conf_parms)
}
static unsigned long extract_prognum(const char val[])
{
if (val[0] == '+') {
return ROTPROG + atol(val+1);
} else
if (val[0] < '0' || val[0] > '9') {
struct rpcent *ent;
ent = getrpcbyname (val);
if (ent)
return ent->r_number;
else
return 0;
} else
return atol(val);
}
ROT *the_rpc_rot;
@ -113,6 +130,7 @@ main (int argc, char *argv[])
const char *rot_file=NULL;
int serial_rate = 0;
char conf_parms[MAXCONFLEN] = "";
unsigned long prognum = ROTPROG;
/* Arguments parsing */
@ -162,6 +180,13 @@ main (int argc, char *argv[])
strcat(conf_parms, ",");
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
break;
case 't':
if (!optarg) {
usage(); /* wrong arg count */
exit(1);
}
prognum = extract_prognum(optarg);
break;
case 'v':
verbose++;
break;
@ -213,15 +238,15 @@ main (int argc, char *argv[])
/* Setup the RPC service and fire it up */
pmap_unset (ROTPROG, ROTVERS);
pmap_unset (prognum, ROTVERS);
transp = svcudp_create(RPC_ANYSOCK); /* Looks like we can spesify a socket number here?? */
if (transp == NULL) {
fprintf (stderr, "%s", "cannot create udp service.");
fprintf (stderr, "cannot create udp service.");
exit(1);
}
if (!svc_register(transp, ROTPROG, ROTVERS, rotprog_1, IPPROTO_UDP)) {
fprintf (stderr, "%s", "unable to register (ROTPROG, ROTVERS, udp).");
if (!svc_register(transp, prognum, ROTVERS, rotprog_1, IPPROTO_UDP)) {
fprintf (stderr, "unable to register (%lu, %u, udp).", prognum, ROTVERS);
exit(1);
}
@ -230,13 +255,13 @@ main (int argc, char *argv[])
fprintf (stderr, "%s", "cannot create tcp service.");
exit(1);
}
if (!svc_register(transp, ROTPROG, ROTVERS, rotprog_1, IPPROTO_TCP)) {
fprintf (stderr, "%s", "unable to register (ROTPROG, ROTVERS, tcp).");
if (!svc_register(transp, prognum, ROTVERS, rotprog_1, IPPROTO_TCP)) {
fprintf (stderr, "unable to register (%lu, %u, tcp).", prognum, ROTVERS);
exit(1);
}
svc_run ();
fprintf (stderr, "%s", "svc_run returned");
fprintf (stderr, "svc_run returned");
/* the rotator gets automatically closed in rotd_exit() */
@ -257,9 +282,10 @@ void usage()
printf(
" -m, --model=ID select rotator model number. See model list\n"
" -r, --rig-file=DEVICE set device of the rotator to operate on\n"
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -C, --set-conf=PARM=VAL set config parameters\n"
" -t, --prog=NUMBER set RPC program number\n"
" -v, --verbose set verbose mode, cumulative\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n"