From 1c968c776810aad465c28759e050c57966c99685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Sun, 7 Oct 2001 21:42:13 +0000 Subject: [PATCH] Initial release git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@668 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- depcomp | 411 +++++++++++++++++++++++ rpc/Makefile.am | 42 +++ rpc/rpcrig.h | 91 +++++ rpc/rpcrig.x | 54 +++ rpc/rpcrig_backend.c | 772 +++++++++++++++++++++++++++++++++++++++++++ rpc/rpcrig_backend.h | 31 ++ rpc/rpcrig_clnt.c | 55 +++ rpc/rpcrig_proc.c | 83 +++++ rpc/rpcrig_svc.c | 71 ++++ rpc/rpcrig_xdr.c | 68 ++++ rpc/rpcrigd.c | 291 ++++++++++++++++ 11 files changed, 1969 insertions(+) create mode 100755 depcomp create mode 100644 rpc/Makefile.am create mode 100644 rpc/rpcrig.h create mode 100644 rpc/rpcrig.x create mode 100644 rpc/rpcrig_backend.c create mode 100644 rpc/rpcrig_backend.h create mode 100644 rpc/rpcrig_clnt.c create mode 100644 rpc/rpcrig_proc.c create mode 100644 rpc/rpcrig_svc.c create mode 100644 rpc/rpcrig_xdr.c create mode 100644 rpc/rpcrigd.c diff --git a/depcomp b/depcomp new file mode 100755 index 000000000..65899658e --- /dev/null +++ b/depcomp @@ -0,0 +1,411 @@ +#! /bin/sh + +# depcomp - compile a program generating dependencies as side-effects +# Copyright 1999, 2000 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva . + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi +# `libtool' can also be set to `yes' or `no'. + +depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`} +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. + "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +## The second -e expression handles DOS-style file names with drive letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the `deleted header file' problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. + tr ' ' ' +' < "$tmpdepfile" | +## Some versions of gcc put a space before the `:'. On the theory +## that the space means something, we add a space to the output as +## well. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like `#:fec' to the end of the + # dependency line. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ + tr ' +' ' ' >> $depfile + echo >> $depfile + + # The second pass generates a dummy entry for each header file. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> $depfile + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. This file always lives in the current directory. + # Also, the AIX compiler puts `$object:' at the start of each line; + # $object doesn't have directory information. + stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` + tmpdepfile="$stripped.u" + outname="$stripped.o" + if test "$libtool" = yes; then + "$@" -Wc,-M + else + "$@" -M + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + + if test -f "$tmpdepfile"; then + # Each line is of the form `foo.o: dependent.h'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" + sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +tru64) + # The Tru64 AIX compiler uses -MD to generate dependencies as a side + # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in `foo.d' instead, so we check for that too. + # Subdirectories are respected. + + tmpdepfile1="$object.d" + tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'` + if test "$libtool" = yes; then + "$@" -Wc,-MD + else + "$@" -MD + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + if test -f "$tmpdepfile1"; then + tmpdepfile="$tmpdepfile1" + else + tmpdepfile="$tmpdepfile2" + fi + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" + # That's a space and a tab in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + else + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + test -z "$dashmflag" && dashmflag=-M + ( IFS=" " + case " $* " in + *" --mode=compile "*) # this is libtool, let us make it quiet + for arg + do # cycle over the arguments + case "$arg" in + "--mode=compile") + # insert --quiet before "--mode=compile" + set fnord "$@" --quiet + shift # fnord + ;; + esac + set fnord "$@" "$arg" + shift # fnord + shift # "$arg" + done + ;; + esac + "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + tr ' ' ' +' < "$tmpdepfile" | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + # X makedepend + ( + shift + cleared=no + for arg in "$@"; do + case $cleared in no) + set ""; shift + cleared=yes + esac + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift;; + -*) + ;; + *) + set fnord "$@" "$arg"; shift;; + esac + done + obj_suffix="`echo $object | sed 's/^.*\././'`" + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + tail +3 "$tmpdepfile" | tr ' ' ' +' | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + ( IFS=" " + case " $* " in + *" --mode=compile "*) + for arg + do # cycle over the arguments + case $arg in + "--mode=compile") + # insert --quiet before "--mode=compile" + set fnord "$@" --quiet + shift # fnord + ;; + esac + set fnord "$@" "$arg" + shift # fnord + shift # "$arg" + done + ;; + esac + "$@" -E | + sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | + sed '$ s: \\$::' > "$tmpdepfile" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + ( IFS=" " + case " $* " in + *" --mode=compile "*) + for arg + do # cycle over the arguments + case $arg in + "--mode=compile") + # insert --quiet before "--mode=compile" + set fnord "$@" --quiet + shift # fnord + ;; + esac + set fnord "$@" "$arg" + shift # fnord + shift # "$arg" + done + ;; + esac + "$@" -E | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" + echo " " >> "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 diff --git a/rpc/Makefile.am b/rpc/Makefile.am new file mode 100644 index 000000000..6f48a5ac3 --- /dev/null +++ b/rpc/Makefile.am @@ -0,0 +1,42 @@ +# rpcrig_xdr.c rpcrig_svc.c rpcrig_clnt.c and rpcrig.h are generated by rpcgen +# have to provide: rpcrig_proc.c rpcrigd.c rpcrig_backend.c +RPCRIG_SVC = rpcrig_xdr.c rpcrig_svc.c rpcrig_proc.c rpcrigd.c +RPCRIG_CLNT = rpcrig_xdr.c rpcrig_clnt.c rpcrig_backend.c + +# The RPC server +bin_PROGRAMS = rpc.rigd +LDADD = ../src/libhamlib.la ../lib/libmisc.a # -lnsl +DEPENDENCIES = ../src/libhamlib.la +rpc_rigd_SOURCES = $(RPCRIG_SVC) + +# The RPC backend +lib_LTLIBRARIES = libhamlib-rpcrig.la +libhamlib_rpcrig_la_SOURCES = $(RPCRIG_CLNT) +libhamlib_rpcrig_la_LDFLAGS = -no-undefined -module -avoid-version -lnsl +#libhamlib_rpcrig_la_LIBADD = ../src/libhamlib.la + +lib_LIBRARIES = libhamlib-rpcrig.a +libhamlib_rpcrig_a_SOURCES = $(RPCRIG_CLNT) +libhamlib_rpcrig_a_LIBADD = ../src/libhamlib.la # -lnsl + +noinst_HEADERS = rpcrig.h + +RPCGEN = rpcgen + + +rpcrig.h: rpcrig.x + rm -f $@ + $(RPCGEN) -h rpcrig.x -o $@ + +rpcrig_clnt.c: rpcrig.x + rm -f $@ + $(RPCGEN) -l rpcrig.x -o $@ + +rpcrig_svc.c: rpcrig.x + rm -f $@ + $(RPCGEN) -m rpcrig.x -o $@ + +rpcrig_xdr.c: rpcrig.x + rm -f $@ + $(RPCGEN) -c rpcrig.x -o $@ + diff --git a/rpc/rpcrig.h b/rpc/rpcrig.h new file mode 100644 index 000000000..78a4a36f5 --- /dev/null +++ b/rpc/rpcrig.h @@ -0,0 +1,91 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _RPCRIG_H_RPCGEN +#define _RPCRIG_H_RPCGEN + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef u_int vfo_x; + +struct freq_s { + u_int f1; + u_int f2; +}; +typedef struct freq_s freq_s; + +typedef u_int model_x; + +struct freq_res { + int rigstatus; + union { + freq_s freq; + } freq_res_u; +}; +typedef struct freq_res freq_res; + +struct freq_arg { + vfo_x vfo; + freq_s freq; +}; +typedef struct freq_arg freq_arg; + +#define RIGPROG 0x20000099 +#define RIGVERS 1 + +#if defined(__STDC__) || defined(__cplusplus) +#define GETMODEL 1 +extern model_x * getmodel_1(void *, CLIENT *); +extern model_x * getmodel_1_svc(void *, struct svc_req *); +#define SETFREQ 10 +extern int * setfreq_1(freq_arg *, CLIENT *); +extern int * setfreq_1_svc(freq_arg *, struct svc_req *); +#define GETFREQ 11 +extern freq_res * getfreq_1(vfo_x *, CLIENT *); +extern freq_res * getfreq_1_svc(vfo_x *, struct svc_req *); +extern int rigprog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); + +#else /* K&R C */ +#define GETMODEL 1 +extern model_x * getmodel_1(); +extern model_x * getmodel_1_svc(); +#define SETFREQ 10 +extern int * setfreq_1(); +extern int * setfreq_1_svc(); +#define GETFREQ 11 +extern freq_res * getfreq_1(); +extern freq_res * getfreq_1_svc(); +extern int rigprog_1_freeresult (); +#endif /* K&R C */ + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_vfo_x (XDR *, vfo_x*); +extern bool_t xdr_freq_s (XDR *, freq_s*); +extern bool_t xdr_model_x (XDR *, model_x*); +extern bool_t xdr_freq_res (XDR *, freq_res*); +extern bool_t xdr_freq_arg (XDR *, freq_arg*); + +#else /* K&R C */ +extern bool_t xdr_vfo_x (); +extern bool_t xdr_freq_s (); +extern bool_t xdr_model_x (); +extern bool_t xdr_freq_res (); +extern bool_t xdr_freq_arg (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_RPCRIG_H_RPCGEN */ diff --git a/rpc/rpcrig.x b/rpc/rpcrig.x new file mode 100644 index 000000000..aeb7d8c78 --- /dev/null +++ b/rpc/rpcrig.x @@ -0,0 +1,54 @@ +/* + * Hamlib Interface - RPC definitions + * Copyright (c) 2000,2001 by Stephane Fillod and Frank Singleton + * + * $Id: rpcrig.x,v 1.1 2001-10-07 21:42:13 f4cfe 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. + * + */ + +typedef unsigned int vfo_x; + +/* Too bad, there's no long long support in RPC language */ +struct freq_s { + unsigned int f1; + unsigned int f2; +}; + +typedef unsigned int model_x; + +union freq_res switch (int rigstatus) { +case 0: + freq_s freq; +default: + void; +}; + +struct freq_arg { + vfo_x vfo; + freq_s freq; +}; + +program RIGPROG { + version RIGVERS { + model_x GETMODEL(void) = 1; + /* string GETLIBVERSION(void) = 2 */ + int SETFREQ(freq_arg) = 10; + freq_res GETFREQ(vfo_x) = 11; + } = 1; +} = 0x20000099; + + diff --git a/rpc/rpcrig_backend.c b/rpc/rpcrig_backend.c new file mode 100644 index 000000000..5a43f8a09 --- /dev/null +++ b/rpc/rpcrig_backend.c @@ -0,0 +1,772 @@ +/* + * Hamlib RPC backend - main file + * Copyright (c) 2001 by Stephane Fillod + * + * $Id: rpcrig_backend.c,v 1.1 2001-10-07 21:42:13 f4cfe 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 /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include /* POSIX terminal control definitions */ +#include +#include + +#if defined(__CYGWIN__) +# undef HAMLIB_DLL +# include +# include +# include +# define HAMLIB_DLL +# include +#else +# include +# include +# include +#endif + +#include +#include "rpcrig.h" + +#include "rpcrig_backend.h" + + +/********************************************************************/ +void freq_t2freq_s(freq_t freqt, freq_s *freqs) +{ + freqs->f1 = freqt & 0xffffffff; + freqs->f2 = (freqt>>32) & 0xffffffff; +} +freq_t freq_s2freq_t(freq_s *freqs) +{ + return freqs->f1 | ((freq_t)freqs->f2 << 32); +} + +struct rpcrig_priv_data { + CLIENT *cl; +}; + +static int rpcrig_init(RIG *rig) +{ + if (!rig || !rig->caps) + return -RIG_EINVAL; + + rig->state.priv = malloc(sizeof(struct rpcrig_priv_data)); + if (!rig->state.priv) { + /* whoops! memory shortage! */ + return -RIG_ENOMEM; + } + rig->state.rigport.type.rig = RIG_PORT_NONE; + + return RIG_OK; +} + +static int rpcrig_cleanup(RIG *rig) +{ + if (!rig) + return -RIG_EINVAL; + + if (rig->state.priv) + free(rig->state.priv); + + rig->state.priv = NULL; + + return RIG_OK; +} + +static int rpcrig_open(RIG *rig) +{ + struct rpcrig_priv_data *priv; + struct rig_state *rs; + model_x *result; + char *server = "localhost"; + rig_model_t model; + const struct rig_caps *caps; + int i; + + rs = &rig->state; + priv = (struct rpcrig_priv_data*)rs->priv; + + priv->cl = clnt_create(server, RIGPROG, RIGVERS, "udp"); + if (priv->cl == NULL) { + clnt_pcreateerror(server); + return -RIG_ECONF; + } + result = getmodel_1(NULL, priv->cl); + if (result == NULL) { + clnt_perror(priv->cl, server); + return -RIG_EPROTO; + } + model = *result; + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ ": model %d\n", model); + caps = rig_get_caps(model); + + /* + * TODO: get these from RPC instead + */ +#if 0 + rs->vfo_list = 0; + for (i=0; irx_range_list[i].start != 0 && + rs->rx_range_list[i].end != 0) + rs->vfo_list |= rs->rx_range_list[i].vfo; + if (rs->tx_range_list[i].start != 0 && + rs->tx_range_list[i].end != 0) + rs->vfo_list |= rs->tx_range_list[i].vfo; + } + + memcpy(rs->preamp, caps->preamp, sizeof(int)*MAXDBLSTSIZ); + memcpy(rs->attenuator, caps->attenuator, sizeof(int)*MAXDBLSTSIZ); + memcpy(rs->tuning_steps, caps->tuning_steps, + sizeof(struct tuning_step_list)*TSLSTSIZ); + memcpy(rs->filters, caps->filters, + sizeof(struct filter_list)*FLTLSTSIZ); + memcpy(rs->chan_list, caps->chan_list, sizeof(chan_t)*CHANLSTSIZ); + + rs->has_get_func = caps->has_get_func; + rs->has_set_func = caps->has_set_func; + rs->has_get_level = caps->has_get_level; + rs->has_set_level = caps->has_set_level; + rs->has_get_parm = caps->has_get_parm; + rs->has_set_parm = caps->has_set_parm; + + rs->max_rit = caps->max_rit; + rs->max_xit = caps->max_xit; + rs->max_ifshift = caps->max_ifshift; + rs->announces = caps->announces; +#endif + + return RIG_OK; +} + +static int rpcrig_close(RIG *rig) +{ + struct rpcrig_priv_data *priv; + + priv = (struct rpcrig_priv_data*)rig->state.priv; + + clnt_destroy(priv->cl); + + return RIG_OK; +} + +static int rpcrig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) +{ + struct rpcrig_priv_data *priv; + struct rig_state *rs; + int *result; + freq_arg farg; + char *server = "localhost"; + + rs = &rig->state; + priv = (struct rpcrig_priv_data*)rs->priv; + + freq_t2freq_s(freq, &farg.freq); + result = setfreq_1(&farg, priv->cl); + if (result == NULL) { + clnt_perror(priv->cl, server); + return -RIG_EPROTO; + } + + return *result; +} + + +static int rpcrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) +{ + struct rpcrig_priv_data *priv; + struct rig_state *rs; + freq_res *fres; + vfo_x v; + char *server = "localhost"; + + rs = &rig->state; + priv = (struct rpcrig_priv_data*)rs->priv; + + v = vfo; + fres = getfreq_1(&v, priv->cl); + if (fres == NULL) { + clnt_perror(priv->cl, server); + return -RIG_EPROTO; + } + if (fres->rigstatus == RIG_OK) + *freq = freq_s2freq_t(&fres->freq_res_u.freq); + + return fres->rigstatus; +} + + +static int rpcrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_vfo(RIG *rig, vfo_t vfo) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_vfo(RIG *rig, vfo_t *vfo) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_dcs_sql(RIG *rig, vfo_t vfo, unsigned int code) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_dcs_sql(RIG *rig, vfo_t vfo, unsigned int *code) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_width) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_set_split(RIG *rig, vfo_t vfo, split_t split) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_split(RIG *rig, vfo_t vfo, split_t *split) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_power2mW(RIG *rig, unsigned int *mwpower, float power, freq_t freq, rmode_t mode) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_mW2power(RIG *rig, float *power, unsigned int mwpower, freq_t freq, rmode_t mode) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_powerstat(RIG *rig, powerstat_t status) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_powerstat(RIG *rig, powerstat_t *status) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_parm(RIG *rig, setting_t parm, value_t val) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_parm(RIG *rig, setting_t parm, value_t *val) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_ant(RIG *rig, vfo_t vfo, ant_t ant) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_bank(RIG *rig, vfo_t vfo, int bank) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_mem(RIG *rig, vfo_t vfo, int ch) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_mem(RIG *rig, vfo_t vfo, int *ch) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_set_channel(RIG *rig, const channel_t *chan) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_channel(RIG *rig, channel_t *chan) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_set_trn(RIG *rig, vfo_t vfo, int trn) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + +static int rpcrig_get_trn(RIG *rig, vfo_t vfo, int *trn) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static const char *rpcrig_get_info(RIG *rig) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return ""; +} + + +static int rpcrig_send_dtmf(RIG *rig, vfo_t vfo, const char *digits) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + +static int rpcrig_send_morse(RIG *rig, vfo_t vfo, const char *msg) +{ + rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); + + return RIG_OK; +} + + + +/* + * Dummy rig capabilities. + */ + +#define RPCRIG_FUNC 0 +#define RPCRIG_SET_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AF) +#define RPCRIG_LEVEL (RPCRIG_SET_LEVEL | RIG_LEVEL_STRENGTH) + +#define RPCRIG_MODES (RIG_MODE_AM | RIG_MODE_CW | \ + RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM | RIG_MODE_WFM) + +struct rig_caps rpcrig_caps = { + rig_model: RIG_MODEL_RPC, + model_name: "RPC rig", + mfg_name: "Hamlib", + version: "0.1", + copyright: "LGPL", + status: RIG_STATUS_NEW, + rig_type: RIG_TYPE_OTHER, + targetable_vfo: 0, + ptt_type: RIG_PTT_NONE, + dcd_type: RIG_DCD_NONE, + port_type: RIG_PORT_NONE, + has_get_func: RPCRIG_FUNC, + has_set_func: RPCRIG_FUNC, + has_get_level: RPCRIG_LEVEL, + has_set_level: RPCRIG_SET_LEVEL, + has_get_parm: RIG_PARM_NONE, /* FIXME */ + has_set_parm: RIG_PARM_NONE, /* FIXME */ + ctcss_list: NULL, /* FIXME */ + dcs_list: NULL, /* FIXME */ + chan_list: { RIG_CHAN_END, }, /* FIXME */ + transceive: RIG_TRN_OFF, + attenuator: { 10, 20, 30, RIG_DBLST_END, }, + rx_range_list2: { {start:kHz(150),end:MHz(1500),modes:RPCRIG_MODES, + low_power:-1,high_power:-1,RIG_VFO_A|RIG_VFO_B}, + RIG_FRNG_END, }, + tx_range_list2: { RIG_FRNG_END, }, + tuning_steps: { {RPCRIG_MODES,1}, RIG_TS_END, }, + priv: NULL, /* priv */ + + rig_init: rpcrig_init, + rig_cleanup: rpcrig_cleanup, + rig_open: rpcrig_open, + rig_close: rpcrig_close, + + set_freq: rpcrig_set_freq, + get_freq: rpcrig_get_freq, + set_mode: rpcrig_set_mode, + get_mode: rpcrig_get_mode, + set_vfo: rpcrig_set_vfo, + get_vfo: rpcrig_get_vfo, + + set_powerstat: rpcrig_set_powerstat, + get_powerstat: rpcrig_get_powerstat, + set_level: rpcrig_set_level, + get_level: rpcrig_get_level, + set_func: rpcrig_set_func, + get_func: rpcrig_get_func, + set_parm: rpcrig_set_parm, + get_parm: rpcrig_get_parm, + + get_info: rpcrig_get_info, + + + set_ptt: rpcrig_set_ptt, + get_ptt: rpcrig_get_ptt, + get_dcd: rpcrig_get_dcd, + set_rptr_shift: rpcrig_set_rptr_shift, + get_rptr_shift: rpcrig_get_rptr_shift, + set_rptr_offs: rpcrig_set_rptr_offs, + get_rptr_offs: rpcrig_get_rptr_offs, + set_ctcss_tone: rpcrig_set_ctcss_tone, + get_ctcss_tone: rpcrig_get_ctcss_tone, + set_dcs_code: rpcrig_set_dcs_code, + get_dcs_code: rpcrig_get_dcs_code, + set_ctcss_sql: rpcrig_set_ctcss_sql, + get_ctcss_sql: rpcrig_get_ctcss_sql, + set_dcs_sql: rpcrig_set_dcs_sql, + get_dcs_sql: rpcrig_get_dcs_sql, + set_split_freq: rpcrig_set_split_freq, + get_split_freq: rpcrig_get_split_freq, + set_split_mode: rpcrig_set_split_mode, + get_split_mode: rpcrig_get_split_mode, + set_split: rpcrig_set_split, + get_split: rpcrig_get_split, + set_rit: rpcrig_set_rit, + get_rit: rpcrig_get_rit, + set_xit: rpcrig_set_xit, + get_xit: rpcrig_get_xit, + set_ts: rpcrig_set_ts, + get_ts: rpcrig_get_ts, + power2mW: rpcrig_power2mW, + mW2power: rpcrig_mW2power, + set_ant: rpcrig_set_ant, + get_ant: rpcrig_get_ant, + set_bank: rpcrig_set_bank, + set_mem: rpcrig_set_mem, + get_mem: rpcrig_get_mem, + vfo_op: rpcrig_vfo_op, + send_dtmf: rpcrig_send_dtmf, + recv_dtmf: rpcrig_recv_dtmf, + send_morse: rpcrig_send_morse, + set_channel: rpcrig_set_channel, + get_channel: rpcrig_get_channel, + set_trn: rpcrig_set_trn, + get_trn: rpcrig_get_trn, +}; + +int init_rpcrig(void *be_handle) +{ + rig_debug(RIG_DEBUG_VERBOSE, "rpcrig: _init called\n"); + + rig_register(&rpcrig_caps); + + return RIG_OK; +} + + diff --git a/rpc/rpcrig_backend.h b/rpc/rpcrig_backend.h new file mode 100644 index 000000000..75da893a8 --- /dev/null +++ b/rpc/rpcrig_backend.h @@ -0,0 +1,31 @@ +/* + * Hamlib RPC backend - main header + * Copyright (c) 2001 by Stephane Fillod + * + * $Id: rpcrig_backend.h,v 1.1 2001-10-07 21:42:13 f4cfe 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. + * + */ + +#ifndef _RPCRIG_H +#define _RPCRIG_H 1 + + +extern const struct rig_caps rpcrig_caps; + +extern HAMLIB_EXPORT(int) init_rpcrig(void *be_handle); + +#endif /* _RPCRIG_H */ diff --git a/rpc/rpcrig_clnt.c b/rpc/rpcrig_clnt.c new file mode 100644 index 000000000..5929f84e4 --- /dev/null +++ b/rpc/rpcrig_clnt.c @@ -0,0 +1,55 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include /* for memset */ +#include "rpcrig.h" + +/* Default timeout can be changed using clnt_control() */ +static struct timeval TIMEOUT = { 25, 0 }; + +model_x * +getmodel_1(void *argp, CLIENT *clnt) +{ + static model_x clnt_res; + + memset((char *)&clnt_res, 0, sizeof(clnt_res)); + if (clnt_call (clnt, GETMODEL, + (xdrproc_t) xdr_void, (caddr_t) argp, + (xdrproc_t) xdr_model_x, (caddr_t) &clnt_res, + TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&clnt_res); +} + +int * +setfreq_1(freq_arg *argp, CLIENT *clnt) +{ + static int clnt_res; + + memset((char *)&clnt_res, 0, sizeof(clnt_res)); + if (clnt_call (clnt, SETFREQ, + (xdrproc_t) xdr_freq_arg, (caddr_t) argp, + (xdrproc_t) xdr_int, (caddr_t) &clnt_res, + TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&clnt_res); +} + +freq_res * +getfreq_1(vfo_x *argp, CLIENT *clnt) +{ + static freq_res clnt_res; + + memset((char *)&clnt_res, 0, sizeof(clnt_res)); + if (clnt_call (clnt, GETFREQ, + (xdrproc_t) xdr_vfo_x, (caddr_t) argp, + (xdrproc_t) xdr_freq_res, (caddr_t) &clnt_res, + TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&clnt_res); +} diff --git a/rpc/rpcrig_proc.c b/rpc/rpcrig_proc.c new file mode 100644 index 000000000..5c220bc84 --- /dev/null +++ b/rpc/rpcrig_proc.c @@ -0,0 +1,83 @@ +/* + * Hamlib RPC server - procedures + * Copyright (c) 2001 by Stephane Fillod + * + * $Id: rpcrig_proc.c,v 1.1 2001-10-07 21:42:13 f4cfe 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 /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include + +#include +#include "rpcrig.h" +#include + +extern RIG *the_rpc_rig; + +void freq_t2freq_s(freq_t freqt, freq_s *freqs) +{ + freqs->f1 = freqt & 0xffffffff; + freqs->f2 = (freqt>>32) & 0xffffffff; +} +freq_t freq_s2freq_t(freq_s *freqs) +{ + return freqs->f1 | ((freq_t)freqs->f2 << 32); +} + +model_x *getmodel_1_svc(void *arg, struct svc_req *svc) +{ + static model_x res; + + /* free previous result */ + //xdr_free(xdr_model, &res); + + res = the_rpc_rig->caps->rig_model; + + return &res; +} + +int *setfreq_1_svc(freq_arg *farg, struct svc_req *svc) +{ + static int res; + + res = rig_set_freq(the_rpc_rig, farg->vfo, freq_s2freq_t(&farg->freq)); + + return &res; +} + +freq_res *getfreq_1_svc(vfo_x *vfo, struct svc_req *svc) +{ + static freq_res res; + freq_t f; + + res.rigstatus = rig_get_freq(the_rpc_rig, *vfo, &f); + freq_t2freq_s(f, &res.freq_res_u.freq); + + return &res; +} + + diff --git a/rpc/rpcrig_svc.c b/rpc/rpcrig_svc.c new file mode 100644 index 000000000..78ac74fd1 --- /dev/null +++ b/rpc/rpcrig_svc.c @@ -0,0 +1,71 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "rpcrig.h" +#include +#include +#include +#include +#include +#include +#include + +#ifndef SIG_PF +#define SIG_PF void(*)(int) +#endif + +void +rigprog_1(struct svc_req *rqstp, register SVCXPRT *transp) +{ + union { + freq_arg setfreq_1_arg; + vfo_x getfreq_1_arg; + } argument; + char *result; + xdrproc_t _xdr_argument, _xdr_result; + char *(*local)(char *, struct svc_req *); + + switch (rqstp->rq_proc) { + case NULLPROC: + (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); + return; + + case GETMODEL: + _xdr_argument = (xdrproc_t) xdr_void; + _xdr_result = (xdrproc_t) xdr_model_x; + local = (char *(*)(char *, struct svc_req *)) getmodel_1_svc; + break; + + case SETFREQ: + _xdr_argument = (xdrproc_t) xdr_freq_arg; + _xdr_result = (xdrproc_t) xdr_int; + local = (char *(*)(char *, struct svc_req *)) setfreq_1_svc; + break; + + case GETFREQ: + _xdr_argument = (xdrproc_t) xdr_vfo_x; + _xdr_result = (xdrproc_t) xdr_freq_res; + local = (char *(*)(char *, struct svc_req *)) getfreq_1_svc; + break; + + default: + svcerr_noproc (transp); + return; + } + memset ((char *)&argument, 0, sizeof (argument)); + if (!svc_getargs (transp, _xdr_argument, (caddr_t) &argument)) { + svcerr_decode (transp); + return; + } + result = (*local)((char *)&argument, rqstp); + if (result != NULL && !svc_sendreply(transp, _xdr_result, result)) { + svcerr_systemerr (transp); + } + if (!svc_freeargs (transp, _xdr_argument, (caddr_t) &argument)) { + fprintf (stderr, "%s", "unable to free arguments"); + exit (1); + } + return; +} diff --git a/rpc/rpcrig_xdr.c b/rpc/rpcrig_xdr.c new file mode 100644 index 000000000..a2ef3c4be --- /dev/null +++ b/rpc/rpcrig_xdr.c @@ -0,0 +1,68 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "rpcrig.h" + +bool_t +xdr_vfo_x (XDR *xdrs, vfo_x *objp) +{ + register int32_t *buf; + + if (!xdr_u_int (xdrs, objp)) + return FALSE; + return TRUE; +} + +bool_t +xdr_freq_s (XDR *xdrs, freq_s *objp) +{ + register int32_t *buf; + + if (!xdr_u_int (xdrs, &objp->f1)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->f2)) + return FALSE; + return TRUE; +} + +bool_t +xdr_model_x (XDR *xdrs, model_x *objp) +{ + register int32_t *buf; + + if (!xdr_u_int (xdrs, objp)) + return FALSE; + return TRUE; +} + +bool_t +xdr_freq_res (XDR *xdrs, freq_res *objp) +{ + register int32_t *buf; + + if (!xdr_int (xdrs, &objp->rigstatus)) + return FALSE; + switch (objp->rigstatus) { + case 0: + if (!xdr_freq_s (xdrs, &objp->freq_res_u.freq)) + return FALSE; + break; + default: + break; + } + return TRUE; +} + +bool_t +xdr_freq_arg (XDR *xdrs, freq_arg *objp) +{ + register int32_t *buf; + + if (!xdr_vfo_x (xdrs, &objp->vfo)) + return FALSE; + if (!xdr_freq_s (xdrs, &objp->freq)) + return FALSE; + return TRUE; +} diff --git a/rpc/rpcrigd.c b/rpc/rpcrigd.c new file mode 100644 index 000000000..1b2e67f88 --- /dev/null +++ b/rpc/rpcrigd.c @@ -0,0 +1,291 @@ +/* + * rpcrigd - (C) Stephane Fillod 2001 + * + * This program let programs control a radio through + * the mean of RPC services using Hamlib. + * + * $Id: rpcrigd.c,v 1.1 2001-10-07 21:42:13 f4cfe Exp $ + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "rpcrig.h" +#include +#include +#include +#include +#include +#include +#include +#include + + +/* TODO: autoconf should check for getopt support, include libs otherwise */ +#include + +#include + + + +/* + * Prototypes + */ +void usage(); +void version(); +void rigd_exit(); + +void rigprog_1(struct svc_req *rqstp, register SVCXPRT *transp); + + +/* + * Reminder: when adding long options, + * keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks. + * 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:P:d:D:c:vhVl" +static struct option long_options[] = +{ + {"model", 1, 0, 'm'}, + {"rig-file", 1, 0, 'r'}, + {"ptt-file", 1, 0, 'p'}, + {"dcd-file", 1, 0, 'd'}, + {"ptt-type", 1, 0, 'P'}, + {"dcd-type", 1, 0, 'D'}, + {"civaddr", 1, 0, 'c'}, + {"list", 0, 0, 'l'}, + {"verbose", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 'V'}, + {0, 0, 0, 0} +}; + + + +RIG *the_rpc_rig; + +int +main (int argc, char *argv[]) +{ + register SVCXPRT *transp; + + rig_model_t my_model = RIG_MODEL_DUMMY; + int retcode; /* generic return code from functions */ + + int verbose = 0; + const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL; + ptt_type_t ptt_type = RIG_PTT_NONE; + dcd_type_t dcd_type = RIG_DCD_NONE; + char *civaddr = NULL; /* NULL means no need to set conf */ + + /* Arguments parsing */ + + while(1) { + int c; + int option_index = 0; + + c = getopt_long (argc, argv, SHORT_OPTIONS, + long_options, &option_index); + if (c == -1) + break; + + switch(c) { + case 'h': + usage(); + exit(0); + case 'V': + version(); + exit(0); + case 'm': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + my_model = atoi(optarg); + break; + case 'r': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + rig_file = optarg; + break; + case 'p': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + ptt_file = optarg; + break; + case 'd': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + dcd_file = optarg; + break; + case 'P': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + ptt_type = atoi(optarg); + break; + case 'D': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + dcd_type = atoi(optarg); + break; + case 'c': + if (!optarg) { + usage(); /* wrong arg count */ + exit(1); + } + civaddr = optarg; + break; + case 'v': + verbose++; + break; + default: + usage(); /* unknown option? */ + exit(1); + } + } + if (verbose < 2) + rig_set_debug(RIG_DEBUG_WARN); + + + /* Opening the local rig */ + + the_rpc_rig = rig_init(my_model); + + if (!the_rpc_rig) { + fprintf(stderr, "Unknown rig num %d, or initialization error.\n", + my_model); + fprintf(stderr, "Please check with --list option.\n"); + exit(2); + } + + if (rig_file) + strncpy(the_rpc_rig->state.rigport.pathname, rig_file, FILPATHLEN); + + /* + * ex: RIG_PTT_PARALLEL and /dev/parport0 + */ + if (ptt_type != RIG_PTT_NONE) + the_rpc_rig->state.pttport.type.ptt = ptt_type; + if (dcd_type != RIG_DCD_NONE) + the_rpc_rig->state.dcdport.type.dcd = dcd_type; + if (ptt_file) + strncpy(the_rpc_rig->state.pttport.pathname, ptt_file, FILPATHLEN); + if (dcd_file) + strncpy(the_rpc_rig->state.dcdport.pathname, dcd_file, FILPATHLEN); + if (civaddr) + rig_set_conf(the_rpc_rig, rig_token_lookup(the_rpc_rig, "civaddr"), civaddr); + + + if ((retcode = rig_open(the_rpc_rig)) != RIG_OK) { + fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode)); + exit(2); + } + + atexit(rigd_exit); + + if (verbose > 0) + printf("Opened rig model %d, '%s'\n", the_rpc_rig->caps->rig_model, + the_rpc_rig->caps->model_name); + + + /* Setup the RPC service and fire it up */ + + + pmap_unset (RIGPROG, RIGVERS); + + transp = svcudp_create(RPC_ANYSOCK); + if (transp == NULL) { + fprintf (stderr, "%s", "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)."); + exit(1); + } + + transp = svctcp_create(RPC_ANYSOCK, 0, 0); + if (transp == NULL) { + fprintf (stderr, "%s", "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)."); + exit(1); + } + + svc_run (); + fprintf (stderr, "%s", "svc_run returned"); + + /* the rig gets automatically closed in rigd_exit() */ + + exit (1); + /* NOTREACHED */ +} + + +void rigd_exit() +{ + rig_close(the_rpc_rig); + rig_cleanup(the_rpc_rig); +} + + + +void usage() +{ + printf("Usage: rpc.rigd [OPTION]... [COMMAND]...\n" + "Offer RPC services to remotely control a connected radio transceiver or receiver.\n\n"); + + printf( + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" + " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" + " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" + " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" + " -c, --civaddr=ID set CI-V address (for Icom rigs only)\n" + " -l, --list list all model numbers and exit\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" + ); + + printf("\nReport bugs to .\n"); + +} + +void version() +{ + printf("rpcrigd, %s\n\n", hamlib_version); + printf("%s\n", hamlib_copyright); +} + +