Initial release

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@184 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.0
Stéphane Fillod, F8CFE 2000-10-08 21:20:44 +00:00
rodzic c6f8770576
commit 38181c9784
6 zmienionych plików z 648 dodań i 0 usunięć

58
lib/usleep.c 100644
Wyświetl plik

@ -0,0 +1,58 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C 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.
The GNU C Library 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 the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <config.h>
#ifndef HAVE_USLEEP
#include <sys/types.h>
#include <sys/time.h>
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef apollo
# include <apollo/base.h>
# include <apollo/time.h>
static time_$clock_t DomainTime100mS =
{
0, 100000/4
};
static status_$t DomainStatus;
#endif
/* Sleep USECONDS microseconds, or until a previously set timer goes off. */
unsigned int
usleep (unsigned int useconds)
{
#ifdef apollo
/* The usleep function does not work under the SYS5.3 environment.
Use the Domain/OS time_$wait call instead. */
time_$wait (time_$relative, DomainTime100mS, &DomainStatus);
#else
struct timeval delay;
delay.tv_sec = 0;
delay.tv_usec = useconds;
select (0, 0, 0, 0, &delay);
return 0;
#endif
}
#endif /* !HAVE_USLEEP */

138
src/event.c 100644
Wyświetl plik

@ -0,0 +1,138 @@
/* hamlib - Ham Radio Control Libraries
Copyright (C) 2000 Stephane Fillod and Frank Singleton
This file is part of the hamlib package.
$Id: event.c,v 1.1 2000-10-08 21:19:26 f4cfe Exp $
Hamlib 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.
Hamlib 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 sane; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <hamlib/rig.h>
#include <hamlib/riglist.h>
#include "event.h"
static void sa_sigio(int signum, siginfo_t *si, void *data);
/* This one should be in an include file */
int foreach_opened_rig(int (*cfunc)(RIG *, void *),void *data);
/*
* add_trn_rig
* not exported in Hamlib API.
* Assumes rig->caps->transceive == RIG_TRN_ON
*/
int add_trn_rig(RIG *rig)
{
struct sigaction act;
int status;
/*
* FIXME: multiple open will register several time SIGIO hndlr
*/
act.sa_sigaction = sa_sigio;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
status = sigaction(SIGIO, &act, NULL);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open sigaction failed: %s\n",
strerror(errno));
status = fcntl(rig->state.fd, F_SETOWN, getpid());
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETOWN failed: %s\n",
strerror(errno));
status = fcntl(rig->state.fd, F_SETSIG, SIGIO);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETSIG failed: %s\n",
strerror(errno));
status = fcntl(rig->state.fd, F_SETFL, O_ASYNC);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETASYNC failed: %s\n",
strerror(errno));
return RIG_OK;
}
/*
* remove_trn_rig
* not exported in Hamlib API.
* Assumes rig->caps->transceive == RIG_TRN_ON
*/
int remove_trn_rig(RIG *rig)
{
return -RIG_ENIMPL;
}
/*
* This is used by sa_sigio, the SIGIO handler
* to find out which rig generated this event,
* and decode/process it.
*/
static int search_rig_and_decode(RIG *rig, void *data)
{
siginfo_t *si = (siginfo_t*)data;
int bytes;
#if 0
if (rig->state.fd != si->si_fd)
return -1;
#else
ioctl(rig->state.fd, FIONREAD, &bytes); /* get bytes in buffer */
if (bytes <= 0)
return -1;
#endif
/*
* Do not disturb, the backend is currently receiving data
*/
if (rig->state.hold_decode)
return -1;
if (rig->caps->decode_event)
rig->caps->decode_event(rig);
return 1; /* process each opened rig */
}
/*
* This is the SIGIO handler
*
* lookup in the list of open rigs,
* check the rig is not holding SIGIO,
* then call rig->caps->decode_event() (this is done by search_rig)
*/
static void sa_sigio(int signum, siginfo_t *si, void *data)
{
rig_debug(RIG_DEBUG_VERBOSE, "sa_sigio: activity detected\n");
foreach_opened_rig(search_rig_and_decode, si);
}

36
src/event.h 100644
Wyświetl plik

@ -0,0 +1,36 @@
/*
* hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
*
* event.h - (C) 2000 Stephane Fillod 2000
*
*
* $Id: event.h,v 1.1 2000-10-08 21:19:26 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.
*
*/
#ifndef _EVENT_H
#define _EVENT_H 1
#include <hamlib/rig.h>
int add_trn_rig(RIG *rig);
int remove_trn_rig(RIG *rig);
#endif /* _EVENT_H */

216
src/register.c 100644
Wyświetl plik

@ -0,0 +1,216 @@
/* hamlib - Ham Radio Control Libraries
register.c - Copyright (C) 2000 Stephane Fillod and Frank Singleton
Provides registering for dynamically loadable backends.
$Id: register.c,v 1.1 2000-10-08 21:19:26 f4cfe Exp $
Hamlib 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.
Hamlib 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 sane; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H)
#include <dlfcn.h>
/* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY.
* They all seem to use a mode of 1 to indicate RTLD_NOW and some do
* not support RTLD_LAZY at all. Hence, unless defined, we define
* both macros as 1 to play it safe. */
# ifndef RTLD_NOW
# define RTLD_NOW 1
# endif
# ifndef RTLD_LAZY
# define RTLD_LAZY 1
# endif
#endif
#include <hamlib/rig.h>
#include <hamlib/riglist.h>
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
struct rig_list {
const struct rig_caps *caps;
void *handle; /* handle returned by dlopen() */
struct rig_list *next;
};
#define RIGLSTHASHSZ 16
#define HASH_FUNC(a) ((a)%RIGLSTHASHSZ)
/*
* The rig_hash_table is a hash table pointing to a list of next==NULL
* terminated caps.
*/
static struct rig_list *rig_hash_table[RIGLSTHASHSZ] = { NULL, };
/*
* Basically, this is a hash insert function that doesn't check for dup!
*/
int rig_register(const struct rig_caps *caps)
{
int hval;
struct rig_list *p;
if (!caps)
return -RIG_EINVAL;
rig_debug(RIG_DEBUG_VERBOSE, "rig_register (%d)\n",caps->rig_model);
#ifdef WANT_DUP_CHECK
if (rig_get_caps(caps->rig_model)!=NULL)
return -RIG_EINVAL;
#endif
p = (struct rig_list*)malloc(sizeof(struct rig_list));
if (!p)
return -RIG_ENOMEM;
hval = HASH_FUNC(caps->rig_model);
p->caps = caps;
p->handle = NULL;
p->next = rig_hash_table[hval];
rig_hash_table[hval] = p;
return RIG_OK;
}
/*
* Get rig capabilities.
* ie. rig_hash_table lookup
*/
const struct rig_caps *rig_get_caps(rig_model_t rig_model)
{
struct rig_list *p;
for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p=p->next) {
if (p->caps->rig_model == rig_model)
return p->caps;
}
return NULL; /* sorry, caps not registered! */
}
int rig_unregister(rig_model_t rig_model)
{
int hval;
struct rig_list *p,*q;
hval = HASH_FUNC(rig_model);
q = NULL;
for (p = rig_hash_table[hval]; p; p=p->next) {
if (p->caps->rig_model == rig_model) {
if (q == NULL)
rig_hash_table[hval] = p->next;
else
q->next = p->next;
free(p);
return RIG_OK;
}
q = p;
}
return -RIG_EINVAL; /* sorry, caps not registered! */
}
/*
* rig_list_foreach
* executes cfunc on all the elements stored in the rig hash list
*/
int rig_list_foreach(int (*cfunc)(const struct rig_caps*, void *),void *data)
{
struct rig_list *p;
int i;
if (!cfunc)
return -RIG_EINVAL;
for (i=0; i<RIGLSTHASHSZ; i++) {
for (p=rig_hash_table[i]; p; p=p->next)
if ((*cfunc)(p->caps,data) == 0)
return RIG_OK;
}
return RIG_OK;
}
/*
* rig_load_backend
* Dynamically load a rig backend through dlopen mechanism
*/
int rig_load_backend(const char *be_name)
{
#ifdef HAVE_DLOPEN
# define PREFIX "libhamlib-"
# define POSTFIX ".so" /* ".so.%u" */
void *be_handle;
int (*be_init)(void *);
int status;
int mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
char libname[PATH_MAX];
char initfuncname[64]="init_";
rig_debug(RIG_DEBUG_VERBOSE, "rig: loading backend %s\n",be_name);
/*
* add hamlib directory here
*/
snprintf (libname, sizeof (libname), PREFIX"%s"POSTFIX,
be_name /* , V_MAJOR */);
be_handle = dlopen (libname, mode);
if (!be_handle) {
rig_debug(RIG_DEBUG_ERR, "rig: dlopen() failed (%s)\n",
dlerror());
return -RIG_EINVAL;
}
strcat(initfuncname, be_name);
be_init = (int (*)(void *)) dlsym (be_handle, initfuncname);
if (!be_init) {
rig_debug(RIG_DEBUG_ERR, "rig: dlsym(%s) failed (%s)\n",
initfuncname, strerror (errno));
dlclose(be_handle);
return -RIG_EINVAL;
}
status = (*be_init)(be_handle);
return status;
# undef PREFIX
# undef POSTFIX
#else /* HAVE_DLOPEN */
rig_debug(RIG_DEBUG_ERR, "rig_backend_load: ignoring attempt to load `%s'; no dl support\n",
be_name);
return -RIG_ENOIMPL;
#endif /* HAVE_DLOPEN */
}

117
tests/listrigs.c 100644
Wyświetl plik

@ -0,0 +1,117 @@
/*
* listrigs.c - Copyright (C) 2000 Stephane Fillod
* This programs list all the available the rig capabilities.
*
*
* $Id: listrigs.c,v 1.1 2000-10-08 21:20:44 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.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <hamlib/rig.h>
int print_caps_sum(const struct rig_caps *caps, void *data)
{
printf("%d\t%s\t%-12s\t%s\t",caps->rig_model,caps->mfg_name,
caps->model_name, caps->version);
switch (caps->status) {
case RIG_STATUS_ALPHA:
printf("Alpha\t");
break;
case RIG_STATUS_UNTESTED:
printf("Untested\t");
break;
case RIG_STATUS_BETA:
printf("Beta\t");
break;
case RIG_STATUS_STABLE:
printf("Stable\t");
break;
case RIG_STATUS_BUGGY:
printf("Buggy\t");
break;
case RIG_STATUS_NEW:
printf("New\t");
break;
default:
printf("Unknown\t");
}
switch (caps->rig_type) {
case RIG_TYPE_TRANSCEIVER:
printf("Transceiver\n");
break;
case RIG_TYPE_HANDHELD:
printf("Handheld\n");
break;
case RIG_TYPE_MOBILE:
printf("Mobile\n");
break;
case RIG_TYPE_RECEIVER:
printf("Receiver\n");
break;
case RIG_TYPE_SCANNER:
printf("Scanner\n");
break;
case RIG_TYPE_COMPUTER:
printf("Computer\n");
break;
default:
printf("Unknown\n");
}
return -1; /* !=0, we want them all ! */
}
int main (int argc, char *argv[])
{
int status;
status = rig_load_backend("icom");
if (status != RIG_OK ) {
printf("rig_load_backend: error = %s \n", rigerror(status));
exit(3);
}
status = rig_load_backend("ft747");
if (status != RIG_OK ) {
printf("rig_load_backend: ft747 error = %s \n", rigerror(status));
exit(3);
}
status = rig_load_backend("ft847");
if (status != RIG_OK ) {
printf("rig_load_backend: ft847 error = %s \n", rigerror(status));
exit(3);
}
printf("Rig#\tMfg\tModel \tVers.\tStatus\tType\n");
status = rig_list_foreach(print_caps_sum,NULL);
if (status != RIG_OK ) {
printf("rig_list_foreach: error = %s \n", rigerror(status));
exit(3);
}
return 0;
}

83
tests/testtrn.c 100644
Wyświetl plik

@ -0,0 +1,83 @@
/*
* Hamlib sample program to test transceive mode (async event)
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <hamlib/rig.h>
#define SERIAL_PORT "/dev/ttyS0"
int myfreq_event(RIG *rig, freq_t freq)
{
printf("Rig changed freq to %LiHz\n",freq);
return 0;
}
int main ()
{
RIG *my_rig; /* handle to rig (nstance) */
int retcode; /* generic return code from functions */
int i;
printf("testrig:hello, I am your main() !\n");
/*
* allocate memory, setup & open port
*/
retcode = rig_load_backend("icom");
if (retcode != RIG_OK ) {
printf("rig_load_backend: error = %s \n", rigerror(retcode));
exit(3);
}
my_rig = rig_init(RIG_MODEL_IC706MKIIG);
if (!my_rig)
exit(1); /* whoops! something went wrong (mem alloc?) */
strncpy(my_rig->state.rig_path,SERIAL_PORT,FILPATHLEN);
if (rig_open(my_rig))
exit(2);
printf("Port %s opened ok\n", SERIAL_PORT);
/*
* Below are examples of set/get routines.
* Must add checking of functionality map prior to command execution -- FS
*
*/
retcode = rig_set_freq(my_rig, 439700000);
if (retcode != RIG_OK ) {
printf("rig_set_freq: error = %s \n", rigerror(retcode));
}
my_rig->callbacks.freq_event = myfreq_event;
retcode = rig_set_trn(my_rig, RIG_TRN_ON);
if (retcode != RIG_OK ) {
printf("rig_set_trn: error = %s \n", rigerror(retcode));
}
for (i=0;i<12;i++)
sleep(60); /* or anything smarter */
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
printf("port %s closed ok \n",SERIAL_PORT);
return 0;
}