new backend ala rpcrig/rpcrot, but using rigctld/rotctld and simpler protocol

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2396 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.8
Stéphane Fillod, F8CFE 2008-09-21 19:34:16 +00:00
rodzic 0e7d1eacea
commit b8fe3df910
9 zmienionych plików z 2214 dodań i 10 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
lib_LTLIBRARIES = hamlib-dummy.la
hamlib_dummy_la_SOURCES = dummy.c rot_dummy.c
hamlib_dummy_la_SOURCES = dummy.c rot_dummy.c netrigctl.c netrotctl.c
hamlib_dummy_la_LDFLAGS = -no-undefined -module -avoid-version
hamlib_dummy_la_LIBADD = $(top_builddir)/src/libhamlib.la

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Dummy backend - main file
* Copyright (c) 2001-2008 by Stephane Fillod
*
* $Id: dummy.c,v 1.41 2008-05-04 14:08:55 fillods Exp $
* $Id: dummy.c,v 1.42 2008-09-21 19:34:15 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
@ -1159,6 +1159,7 @@ DECLARE_INITRIG_BACKEND(dummy)
rig_debug(RIG_DEBUG_VERBOSE, "dummy: _init called\n");
rig_register(&dummy_caps);
rig_register(&netrigctl_caps);
return RIG_OK;
}

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Dummy backend - main header
* Copyright (c) 2001,2002 by Stephane Fillod
* Copyright (c) 2001-2008 by Stephane Fillod
*
* $Id: dummy.h,v 1.6 2003-04-16 22:30:39 fillods Exp $
* $Id: dummy.h,v 1.7 2008-09-21 19:34:15 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
@ -25,5 +25,6 @@
extern const struct rig_caps dummy_caps;
extern const struct rig_caps netrigctl_caps;
#endif /* _DUMMY_H */

1871
dummy/netrigctl.c 100644

Plik diff jest za duży Load Diff

327
dummy/netrotctl.c 100644
Wyświetl plik

@ -0,0 +1,327 @@
/*
* 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 $
*
* 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 <stdlib.h>
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <math.h>
#include <errno.h>
#include "hamlib/rotator.h"
#include "iofunc.h"
#include "misc.h"
#include "rot_dummy.h"
#define CMD_MAX 32
#define BUF_MAX 64
#define ROTCTL_ERROR "ERROR "
static int netrotctl_open(ROT *rot)
{
int ret, len;
struct rot_state *rs = &rot->state;
rot_model_t model;
int prot_ver;
char cmd[CMD_MAX];
char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
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 = 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;
}
model = atoi(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
rs->min_az = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
rs->max_az = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
rs->min_el = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
rs->max_el = atof(buf);
return RIG_OK;
}
static int netrotctl_close(ROT *rot)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
return RIG_OK;
}
static int netrotctl_set_position(ROT *rot, azimuth_t az, elevation_t el)
{
int ret, len;
char cmd[CMD_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;
}
static int netrotctl_get_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\n", __FUNCTION__);
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));
*az = atof(buf);
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
*el = atof(buf);
/* read dummy END */
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
if (ret <= 0) {
return -RIG_EIO;
}
return RIG_OK;
}
static int netrotctl_stop(ROT *rot)
{
int ret, len;
char cmd[CMD_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;
}
static int netrotctl_park(ROT *rot)
{
int ret, len;
char cmd[CMD_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;
}
static int netrotctl_reset(ROT *rot, rot_reset_t reset)
{
int ret, len;
char cmd[CMD_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;
}
static int netrotctl_move(ROT *rot, int direction, int speed)
{
int ret, len;
char cmd[CMD_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;
}
static const char *netrotctl_get_info(ROT *rot)
{
int ret, len;
char cmd[CMD_MAX];
static char buf[BUF_MAX];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
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));
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;
}
/*
* NET rotctl capabilities.
*/
const struct rot_caps netrotctl_caps = {
.rot_model = ROT_MODEL_NETROTCTL,
.model_name = "NET rotctl",
.mfg_name = "Hamlib",
.version = "0.1",
.copyright = "LGPL",
.status = RIG_STATUS_ALPHA,
.rot_type = ROT_TYPE_OTHER,
.port_type = RIG_PORT_NETWORK,
.timeout = 2000,
.retry = 3,
.min_az = -180.,
.max_az = 180.,
.min_el = 0.,
.max_el = 90.,
.priv = NULL, /* priv */
/* .rot_init = netrotctl_init, */
/* .rot_cleanup = netrotctl_cleanup, */
.rot_open = netrotctl_open,
.rot_close = netrotctl_close,
.set_position = netrotctl_set_position,
.get_position = netrotctl_get_position,
.park = netrotctl_park,
.stop = netrotctl_stop,
.reset = netrotctl_reset,
.move = netrotctl_move,
.get_info = netrotctl_get_info,
};

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Dummy backend - main file
* Copyright (c) 2001-2003 by Stephane Fillod
* Copyright (c) 2001-2008 by Stephane Fillod
*
* $Id: rot_dummy.c,v 1.6 2003-04-16 22:30:39 fillods Exp $
* $Id: rot_dummy.c,v 1.7 2008-09-21 19:34:16 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
@ -193,6 +193,7 @@ DECLARE_INITROT_BACKEND(dummy)
rig_debug(RIG_DEBUG_VERBOSE, "dummy: _init called\n");
rot_register(&dummy_rot_caps);
rot_register(&netrotctl_caps);
return RIG_OK;
}

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Dummy backend - main header
* Copyright (c) 2001,2002 by Stephane Fillod
* Copyright (c) 2001-2008 by Stephane Fillod
*
* $Id: rot_dummy.h,v 1.2 2003-04-16 22:30:39 fillods Exp $
* $Id: rot_dummy.h,v 1.3 2008-09-21 19:34:16 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
@ -25,5 +25,6 @@
extern const struct rot_caps dummy_rot_caps;
extern const struct rot_caps netrotctl_caps;
#endif /* _ROT_DUMMY_H */

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - list of known rigs
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
*
* $Id: riglist.h,v 1.69 2008-09-01 19:01:11 fillods Exp $
* $Id: riglist.h,v 1.70 2008-09-21 19:34:16 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
@ -54,6 +54,7 @@
#define RIG_DUMMY 0
#define RIG_BACKEND_DUMMY "dummy"
#define RIG_MODEL_DUMMY RIG_MAKE_MODEL(RIG_DUMMY, 1)
#define RIG_MODEL_NETRIGCTL RIG_MAKE_MODEL(RIG_DUMMY, 2)
/*
* Yaesu

Wyświetl plik

@ -3,7 +3,7 @@
* Copyright (c) 2000-2008 by Stephane Fillod
* Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton
*
* $Id: rotlist.h,v 1.12 2008-05-23 14:09:58 fillods Exp $
* $Id: rotlist.h,v 1.13 2008-09-21 19:34:16 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
@ -60,6 +60,7 @@
#define ROT_DUMMY 0
#define ROT_BACKEND_DUMMY "dummy"
#define ROT_MODEL_DUMMY ROT_MAKE_MODEL(ROT_DUMMY, 1)
#define ROT_MODEL_NETROTCTL ROT_MAKE_MODEL(ROT_DUMMY, 2)
/*
* RPC Network pseudo-backend