kopia lustrzana https://github.com/Hamlib/Hamlib
implementation of PORT_NETWORK
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2395 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.8
rodzic
257cdfc32c
commit
0e7d1eacea
|
@ -1,15 +1,16 @@
|
||||||
INCLUDES = @INCLUDES@ @INCLTDL@
|
INCLUDES = @INCLUDES@ @INCLTDL@
|
||||||
RIGSRC = rig.c serial.c misc.c register.c event.c cal.c conf.c tones.c \
|
RIGSRC = rig.c serial.c misc.c register.c event.c cal.c conf.c tones.c \
|
||||||
rotator.c locator.c rot_reg.c rot_conf.c iofunc.c ext.c \
|
rotator.c locator.c rot_reg.c rot_conf.c iofunc.c ext.c \
|
||||||
mem.c settings.c parallel.c usb_port.c debug.c
|
mem.c settings.c parallel.c usb_port.c debug.c network.c
|
||||||
|
|
||||||
lib_LTLIBRARIES = libhamlib.la
|
lib_LTLIBRARIES = libhamlib.la
|
||||||
libhamlib_la_SOURCES = $(RIGSRC)
|
libhamlib_la_SOURCES = $(RIGSRC)
|
||||||
libhamlib_la_LDFLAGS = $(WINLDFLAGS) -no-undefined -version-info @ABI_VERSION@:8:0
|
libhamlib_la_LDFLAGS = $(WINLDFLAGS) -no-undefined -version-info @ABI_VERSION@:8:0
|
||||||
libhamlib_la_CFLAGS = -DIN_HAMLIB $(AM_CFLAGS) -DHAMLIB_MODULE_DIR=\"$(libdir)\"
|
libhamlib_la_CFLAGS = -DIN_HAMLIB $(AM_CFLAGS) -DHAMLIB_MODULE_DIR=\"$(libdir)\"
|
||||||
libhamlib_la_LIBADD = @LIBLTDL@ $(top_builddir)/lib/libmisc.la @MATH_LIBS@ $(LIBUSB_LIBS)
|
libhamlib_la_LIBADD = @LIBLTDL@ $(top_builddir)/lib/libmisc.la \
|
||||||
|
@NET_LIBS@ @MATH_LIBS@ $(LIBUSB_LIBS)
|
||||||
|
|
||||||
noinst_HEADERS = event.h misc.h serial.h iofunc.h cal.h tones.h \
|
noinst_HEADERS = event.h misc.h serial.h iofunc.h cal.h tones.h \
|
||||||
rot_conf.h token.h idx_builtin.h register.h par_nt.h \
|
rot_conf.h token.h idx_builtin.h register.h par_nt.h \
|
||||||
parallel.h usb_port.h
|
parallel.h usb_port.h network.h
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Hamlib Interface - network communication low-level support
|
||||||
|
* Copyright (c) 2000-2008 by Stephane Fillod
|
||||||
|
*
|
||||||
|
* $Id: network.c,v 1.1 2008-09-21 19:30:34 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup rig_internal
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Network port IO
|
||||||
|
* \file network.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WINVER 0x0501
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h> /* Standard input/output definitions */
|
||||||
|
#include <string.h> /* String function definitions */
|
||||||
|
#include <unistd.h> /* UNIX standard function definitions */
|
||||||
|
#include <fcntl.h> /* File control definitions */
|
||||||
|
#include <errno.h> /* Error number definitions */
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_NETINET_IN_H
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h> /* TODO */
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ARPA_INET_H
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_SOCKET_H
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#elif HAVE_WS2TCPIP_H
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "hamlib/rig.h"
|
||||||
|
#include "network.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Open network port using rig.state data
|
||||||
|
* \param rp port data structure (must spec port id eg hostname:port)
|
||||||
|
* \return RIG_OK or < 0 if error
|
||||||
|
*/
|
||||||
|
int network_open(hamlib_port_t *rp) {
|
||||||
|
|
||||||
|
int fd; /* File descriptor for the port */
|
||||||
|
int status;
|
||||||
|
struct addrinfo hints, *res;
|
||||||
|
char *portstr;
|
||||||
|
char hostname[FILPATHLEN];
|
||||||
|
|
||||||
|
if (!rp)
|
||||||
|
return -RIG_EINVAL;
|
||||||
|
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = PF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
strcpy(hostname, rp->pathname);
|
||||||
|
portstr = strchr(hostname, ':');
|
||||||
|
if (!portstr)
|
||||||
|
return -RIG_ECONF;
|
||||||
|
*portstr++ = '\0';
|
||||||
|
|
||||||
|
status=getaddrinfo(hostname, portstr, &hints, &res);
|
||||||
|
if (status != 0) {
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "Cannot get host \"%s\": %s\n",
|
||||||
|
rp->pathname, gai_strerror(errno));
|
||||||
|
return -RIG_ECONF;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
|
if (fd < 0)
|
||||||
|
return -RIG_EIO;
|
||||||
|
|
||||||
|
status = connect(fd, res->ai_addr, res->ai_addrlen);
|
||||||
|
freeaddrinfo(res);
|
||||||
|
if (status < 0) {
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "Cannot open NET device \"%s\": %s\n",
|
||||||
|
rp->pathname, strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return -RIG_EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp->fd = fd;
|
||||||
|
|
||||||
|
return RIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @} */
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Hamlib Interface - network communication header
|
||||||
|
* Copyright (c) 2000-2008 by Stephane Fillod
|
||||||
|
*
|
||||||
|
* $Id: network.h,v 1.1 2008-09-21 19:30:35 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NETWORK_H
|
||||||
|
#define _NETWORK_H 1
|
||||||
|
|
||||||
|
#include <hamlib/rig.h>
|
||||||
|
#include "iofunc.h"
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Hamlib internal use, see rig.c */
|
||||||
|
int network_open(hamlib_port_t *p);
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* _NETWORK_H */
|
15
src/rig.c
15
src/rig.c
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - main file
|
* Hamlib Interface - main file
|
||||||
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
|
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
|
||||||
*
|
*
|
||||||
* $Id: rig.c,v 1.97 2008-09-12 11:49:32 fillods Exp $
|
* $Id: rig.c,v 1.98 2008-09-21 19:30:35 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -64,6 +64,7 @@
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "parallel.h"
|
#include "parallel.h"
|
||||||
#include "usb_port.h"
|
#include "usb_port.h"
|
||||||
|
#include "network.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,6 +296,10 @@ RIG * HAMLIB_API rig_init(rig_model_t rig_model)
|
||||||
strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
|
strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RIG_PORT_NETWORK:
|
||||||
|
strncpy(rs->rigport.pathname, "localhost:4532", FILPATHLEN);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
strncpy(rs->rigport.pathname, "", FILPATHLEN);
|
strncpy(rs->rigport.pathname, "", FILPATHLEN);
|
||||||
}
|
}
|
||||||
|
@ -480,8 +485,12 @@ int HAMLIB_API rig_open(RIG *rig)
|
||||||
case RIG_PORT_RPC:
|
case RIG_PORT_RPC:
|
||||||
break; /* ez :) */
|
break; /* ez :) */
|
||||||
|
|
||||||
case RIG_PORT_NETWORK: /* not implemented yet! */
|
case RIG_PORT_NETWORK:
|
||||||
return -RIG_ENIMPL;
|
status = network_open(&rs->rigport);
|
||||||
|
if (status < 0)
|
||||||
|
return status;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -RIG_EINVAL;
|
return -RIG_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - main file
|
* Hamlib Interface - main file
|
||||||
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
|
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
|
||||||
*
|
*
|
||||||
* $Id: rotator.c,v 1.22 2008-05-04 15:36:23 fillods Exp $
|
* $Id: rotator.c,v 1.23 2008-09-21 19:30:35 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -57,6 +57,8 @@
|
||||||
#include "hamlib/rotator.h"
|
#include "hamlib/rotator.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "parallel.h"
|
#include "parallel.h"
|
||||||
|
#include "usb_port.h"
|
||||||
|
#include "network.h"
|
||||||
#include "rot_conf.h"
|
#include "rot_conf.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
|
||||||
|
@ -231,6 +233,10 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
|
||||||
strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
|
strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RIG_PORT_NETWORK:
|
||||||
|
strncpy(rs->rotport.pathname, "localhost:4533", FILPATHLEN);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
strncpy(rs->rotport.pathname, "", FILPATHLEN);
|
strncpy(rs->rotport.pathname, "", FILPATHLEN);
|
||||||
}
|
}
|
||||||
|
@ -316,12 +322,22 @@ int HAMLIB_API rot_open(ROT *rot)
|
||||||
rs->rotport.fd = status;
|
rs->rotport.fd = status;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RIG_PORT_USB:
|
||||||
|
status = usb_port_open(&rs->rotport);
|
||||||
|
if (status < 0)
|
||||||
|
return status;
|
||||||
|
break;
|
||||||
|
|
||||||
case RIG_PORT_NONE:
|
case RIG_PORT_NONE:
|
||||||
case RIG_PORT_RPC:
|
case RIG_PORT_RPC:
|
||||||
break; /* ez :) */
|
break; /* ez :) */
|
||||||
|
|
||||||
case RIG_PORT_NETWORK: /* not implemented yet! */
|
case RIG_PORT_NETWORK:
|
||||||
return -RIG_ENIMPL;
|
status = network_open(&rs->rotport);
|
||||||
|
if (status < 0)
|
||||||
|
return status;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -RIG_EINVAL;
|
return -RIG_EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -391,6 +407,9 @@ int HAMLIB_API rot_close(ROT *rot)
|
||||||
case RIG_PORT_PARALLEL:
|
case RIG_PORT_PARALLEL:
|
||||||
par_close(&rs->rotport);
|
par_close(&rs->rotport);
|
||||||
break;
|
break;
|
||||||
|
case RIG_PORT_USB:
|
||||||
|
usb_port_close(&rs->rotport);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
close(rs->rotport.fd);
|
close(rs->rotport.fd);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue