new netrigctl/netrotctl protocol with return value

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2428 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.8
Stéphane Fillod, F8CFE 2008-10-27 22:23:36 +00:00
rodzic 638628e18d
commit f541b221fe
10 zmienionych plików z 469 dodań i 912 usunięć

Plik diff jest za duży Load Diff

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Netrotctl backend - main file
* Copyright (c) 2001-2008 by Stephane Fillod
*
* $Id: netrotctl.c,v 1.1 2008-09-21 19:34:15 fillods Exp $
* $Id: netrotctl.c,v 1.2 2008-10-27 22:23:36 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
@ -38,7 +38,27 @@
#define CMD_MAX 32
#define BUF_MAX 64
#define ROTCTL_ERROR "ERROR "
/*
* Helper function with protocol return code parsing
*/
static int netrotctl_transaction(ROT *rot, char *cmd, int len, char *buf)
{
int ret;
ret = write_block(&rot->state.rotport, cmd, len);
if (ret != RIG_OK)
return ret;
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret < 0)
return ret;
if (!memcmp(buf, NETROTCTL_RET, strlen(NETROTCTL_RET)))
return atoi(buf+strlen(NETROTCTL_RET));
return ret;
}
static int netrotctl_open(ROT *rot)
{
@ -54,52 +74,43 @@ static int netrotctl_open(ROT *rot)
len = sprintf(cmd, "\\dump_state\n");
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
if (!memcmp(buf, ROTCTL_ERROR, strlen(ROTCTL_ERROR)))
return atoi(buf+strlen(ROTCTL_ERROR));
prot_ver = atoi(buf);
#define ROTCTLD_PROT_VER 0
if (prot_ver < ROTCTLD_PROT_VER)
return -RIG_EPROTO;
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
model = atoi(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
rs->min_az = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
rs->max_az = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
rs->min_el = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
rs->max_el = atof(buf);
return RIG_OK;
@ -116,20 +127,18 @@ static int netrotctl_set_position(ROT *rot, azimuth_t az, elevation_t el)
{
int ret, len;
char cmd[CMD_MAX];
char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %f %f\n", __FUNCTION__,
az, el);
len = sprintf(cmd, "P %f %f\n", az, el);
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret > 0)
return -RIG_EPROTO;
else
return ret;
}
static int netrotctl_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
@ -142,33 +151,17 @@ static int netrotctl_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
len = sprintf(cmd, "p\n");
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
if (!memcmp(buf, ROTCTL_ERROR, strlen(ROTCTL_ERROR)))
return atoi(buf+strlen(ROTCTL_ERROR));
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
*az = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
*el = atof(buf);
if (ret <= 0)
return (ret < 0) ? ret : -RIG_EPROTO;
/* read dummy END */
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
*el = atof(buf);
return RIG_OK;
}
@ -178,19 +171,17 @@ static int netrotctl_stop(ROT *rot)
{
int ret, len;
char cmd[CMD_MAX];
char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
len = sprintf(cmd, "S\n");
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret > 0)
return -RIG_EPROTO;
else
return ret;
}
@ -198,57 +189,51 @@ static int netrotctl_park(ROT *rot)
{
int ret, len;
char cmd[CMD_MAX];
char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
len = sprintf(cmd, "K\n");
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret > 0)
return -RIG_EPROTO;
else
return ret;
}
static int netrotctl_reset(ROT *rot, rot_reset_t reset)
{
int ret, len;
char cmd[CMD_MAX];
char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
len = sprintf(cmd, "R %d\n", reset);
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret > 0)
return -RIG_EPROTO;
else
return ret;
}
static int netrotctl_move(ROT *rot, int direction, int speed)
{
int ret, len;
char cmd[CMD_MAX];
char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
len = sprintf(cmd, "M %d %d\n", direction, speed);
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret > 0)
return -RIG_EPROTO;
else
return ret;
}
static const char *netrotctl_get_info(ROT *rot)
@ -261,27 +246,12 @@ static const char *netrotctl_get_info(ROT *rot)
len = sprintf(cmd, "_\n");
ret = write(rot->state.rotport.fd, cmd, len);
if (ret != len) {
rig_debug(RIG_DEBUG_ERR,"%s: write failed: %s\n", __FUNCTION__,
strerror(errno));
ret = netrotctl_transaction(rot, cmd, len, buf);
if (ret < 0)
return NULL;
}
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret < 0) {
return NULL;
}
if (!memcmp(buf, ROTCTL_ERROR, strlen(ROTCTL_ERROR)))
return NULL;
buf [ret] = '\0';
/* read dummy END */
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return NULL;
}
return buf;
}
@ -295,9 +265,9 @@ const struct rot_caps netrotctl_caps = {
.rot_model = ROT_MODEL_NETROTCTL,
.model_name = "NET rotctl",
.mfg_name = "Hamlib",
.version = "0.1",
.version = "0.2",
.copyright = "LGPL",
.status = RIG_STATUS_ALPHA,
.status = RIG_STATUS_BETA,
.rot_type = ROT_TYPE_OTHER,
.port_type = RIG_PORT_NETWORK,
.timeout = 2000,

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - API header
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
*
* $Id: rig.h,v 1.128 2008-10-25 11:36:02 y32kn Exp $
* $Id: rig.h,v 1.129 2008-10-27 22:23:36 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
@ -100,6 +100,9 @@ enum rig_errcode_e {
RIG_EDOM /*!< Argument out of domain of func */
};
/** \brief Token in the netrigctl protocol for returning error code */
#define NETRIGCTL_RET "RPRT "
/**
*\brief Hamlib debug levels
*
@ -240,9 +243,7 @@ enum rig_status_e {
* !! Use of RIG_STATUS_NEW is deprecated. Do not use it anymore */
};
/*
* Map all RIG_STATUS_NEW references to RIG_STATUS_UNTESTED for backward compatibility
*/
/** \brief Map all deprecated RIG_STATUS_NEW references to RIG_STATUS_UNTESTED for backward compatibility */
#define RIG_STATUS_NEW RIG_STATUS_UNTESTED
/**

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - Rotator API header
* Copyright (c) 2000-2005 by Stephane Fillod
*
* $Id: rotator.h,v 1.15 2008-05-01 12:19:57 fillods Exp $
* $Id: rotator.h,v 1.16 2008-10-27 22:23:36 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
@ -72,6 +72,9 @@ typedef struct rot ROT;
typedef float elevation_t;
typedef float azimuth_t;
/** \brief Token in the netrotctl protocol for returning error code */
#define NETROTCTL_RET "RPRT "
/*! \def ROT_RESET_ALL
* \brief A macro that returns the flag for the \b reset operation.
* \sa rot_reset(), rot_reset_t

Wyświetl plik

@ -5,7 +5,7 @@
* It takes commands in interactive mode as well as
* from command line options.
*
* $Id: rigctl.c,v 1.67 2008-05-23 14:26:09 fillods Exp $
* $Id: rigctl.c,v 1.68 2008-10-27 22:23:36 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -84,6 +84,7 @@ static struct option long_options[] =
int interactive = 1; /* if no cmd on command line, switch to interactive */
int prompt = 1; /* Print prompt in rigctl */
int opt_end= 0; /* only used by rigctld */
int main (int argc, char *argv[])
{

Wyświetl plik

@ -5,7 +5,7 @@
* It takes commands in interactive mode as well as
* from command line options.
*
* $Id: rigctl_parse.c,v 1.8 2008-09-21 19:24:47 fillods Exp $
* $Id: rigctl_parse.c,v 1.9 2008-10-27 22:23:36 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -274,6 +274,7 @@ static int scanfc(FILE *fin, const char *format, void *p)
extern int interactive;
extern int prompt;
extern int opt_end;
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc)
@ -467,13 +468,17 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc)
#endif
if (retcode != RIG_OK) {
if ((cmd_entry->flags & ARG_OUT) && interactive && !prompt)
fprintf(fout, "ERROR %d\n", retcode); /* only for rigctld */
if (interactive && !prompt)
fprintf(fout, NETRIGCTL_RET "%d\n", retcode); /* only for rigctld */
else
fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode));
} else {
if ((cmd_entry->flags & ARG_OUT) && interactive && !prompt) /* only for rigctld */
fprintf(fout, "END\n");
if (interactive && !prompt) { /* only for rigctld */
if (!(cmd_entry->flags & ARG_OUT) && !opt_end) /* netrigctl RIG_OK */
fprintf(fout, NETRIGCTL_RET "0\n");
else if ((cmd_entry->flags & ARG_OUT) && opt_end) /* Nate's protocol */
fprintf(fout, "END\n");
}
}
fflush(fout);

Wyświetl plik

@ -4,7 +4,7 @@
* This program test/control a radio using Hamlib.
* It takes commands from network connection.
*
* $Id: rigctld.c,v 1.8 2008-09-21 20:32:07 fillods Exp $
* $Id: rigctld.c,v 1.9 2008-10-27 22:23:36 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -68,7 +68,7 @@
* 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:p:d:P:D:s:c:lC:t:T:LuovhV"
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:lC:t:T:LeuovhV"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@ -86,6 +86,7 @@ static struct option long_options[] =
{"show-conf",0, 0, 'L'},
{"dump-caps", 0, 0, 'u'},
{"vfo", 0, 0, 'o'},
{"end-marker", 0, 0, 'e'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
@ -104,6 +105,7 @@ void usage(void);
int interactive = 1; /* no cmd because of daemon */
int prompt= 0 ; /* Daemon mode for rigparse return string */
int opt_end= 0 ; /* END marker for rigctld */
int portno = 4532;
uint32_t src_addr = INADDR_ANY;
@ -271,6 +273,9 @@ int main (int argc, char *argv[])
case 'u':
dump_caps_opt++;
break;
case 'e':
opt_end = 1;
break;
default:
usage(); /* unknown option? */
exit(1);
@ -351,8 +356,10 @@ int main (int argc, char *argv[])
* Prepare listening socket
*/
sock_listen = socket(AF_INET, SOCK_STREAM, 0);
if (sock_listen < 0)
if (sock_listen < 0) {
perror("ERROR opening socket");
exit(2);
}
memset((char *) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
@ -502,6 +509,7 @@ void usage(void)
" -l, --list list all model numbers and exit\n"
" -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
" -e, --end-marker use END marker in rigctld protocol\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

@ -5,7 +5,7 @@
* It takes commands in interactive mode as well as
* from command line options.
*
* $Id: rotctl.c,v 1.11 2008-09-12 22:55:09 fillods Exp $
* $Id: rotctl.c,v 1.12 2008-10-27 22:23:36 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -71,6 +71,7 @@ static struct option long_options[] =
int interactive = 1; /* if no cmd on command line, switch to interactive */
int prompt = 1; /* Print prompt in rotctl */
int opt_end= 0 ; /* only used by rotctld */
int main (int argc, char *argv[])
{

Wyświetl plik

@ -5,7 +5,7 @@
* It takes commands in interactive mode as well as
* from command line options.
*
* $Id: rotctl_parse.c,v 1.2 2008-09-21 19:27:54 fillods Exp $
* $Id: rotctl_parse.c,v 1.3 2008-10-27 22:23:36 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -159,6 +159,7 @@ static int scanfc(FILE *fin, const char *format, void *p)
extern int interactive;
extern int prompt;
extern int opt_end;
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
{
@ -332,13 +333,17 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
#endif
if (retcode != RIG_OK) {
if ((cmd_entry->flags & ARG_OUT) && interactive && !prompt)
fprintf(fout, "ERROR %d\n", retcode); /* only for rotctld */
if (interactive && !prompt)
fprintf(fout, NETROTCTL_RET "%d\n", retcode); /* only for rotctld */
else
fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode));
} else {
if ((cmd_entry->flags & ARG_OUT) && interactive && !prompt) /* only for rotctld */
fprintf(fout, "END\n");
if (interactive && !prompt) { /* only for rotctld */
if (!(cmd_entry->flags & ARG_OUT) && !opt_end) /* netrotctl RIG_OK */
fprintf(fout, NETROTCTL_RET "0\n");
else if ((cmd_entry->flags & ARG_OUT) && opt_end) /* Nate's protocol */
fprintf(fout, "END\n");
}
}
fflush(fout);

Wyświetl plik

@ -4,7 +4,7 @@
* This program test/control a rotator using Hamlib.
* It takes commands from network connection.
*
* $Id: rotctld.c,v 1.4 2008-09-21 20:32:08 fillods Exp $
* $Id: rotctld.c,v 1.5 2008-10-27 22:23:36 fillods Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -76,7 +76,7 @@ void usage();
* 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:t:T:LvhVl"
#define SHORT_OPTIONS "m:r:s:C:t:T:LevhVl"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@ -87,6 +87,7 @@ static struct option long_options[] =
{"list", 0, 0, 'l'},
{"set-conf", 1, 0, 'C'},
{"show-conf",0, 0, 'L'},
{"end-marker", 0, 0, 'e'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
@ -95,6 +96,7 @@ static struct option long_options[] =
int interactive = 1; /* no cmd because of daemon */
int prompt= 0 ; /* Daemon mode for rigparse return string */
int opt_end= 0 ; /* END marker for rotctld */
int portno = 4533;
uint32_t src_addr = INADDR_ANY;
@ -193,6 +195,9 @@ int main (int argc, char *argv[])
case 'l':
list_models();
exit(0);
case 'e':
opt_end = 1;
break;
default:
usage(); /* unknown option? */
exit(1);
@ -394,6 +399,7 @@ void usage()
" -C, --set-conf=PARM=VAL set config parameters\n"
" -L, --show-conf list all config parameters\n"
" -l, --list list all model numbers and exit\n"
" -e, --end-marker use END marker in rotctld protocol\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",