try to make hamlib more portable

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@511 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.2
Stéphane Fillod, F8CFE 2001-06-02 17:56:37 +00:00
rodzic 3472b63e91
commit 5c50fee821
4 zmienionych plików z 123 dodań i 24 usunięć

Wyświetl plik

@ -1,8 +1,8 @@
/* hamlib - Ham Radio Control Libraries
Copyright (C) 2000 Stephane Fillod and Frank Singleton
Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton
This file is part of the hamlib package.
$Id: event.c,v 1.3 2001-03-04 13:06:36 f4cfe Exp $
$Id: event.c,v 1.4 2001-06-02 17:56:37 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
@ -28,6 +28,7 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
@ -39,7 +40,11 @@
#include <hamlib/riglist.h>
#include "event.h"
static void sa_sigio(int signum, siginfo_t *si, void *data);
#ifdef _WIN32
static void sa_sigiohandler(int signum);
#else
static void sa_sigioaction(int signum, siginfo_t *si, void *data);
#endif
/* This one should be in an include file */
int foreach_opened_rig(int (*cfunc)(RIG *, void *),void *data);
@ -57,9 +62,20 @@ int add_trn_rig(RIG *rig)
/*
* FIXME: multiple open will register several time SIGIO hndlr
*/
act.sa_sigaction = sa_sigio;
#ifdef _WIN32
act.sa_handler = sa_sigiohandler;
#else
act.sa_sigaction = sa_sigioaction;
#endif
sigemptyset(&act.sa_mask);
#ifdef _WIN32
act.sa_flags = 0;
#else
act.sa_flags = SA_SIGINFO;
#endif
status = sigaction(SIGIO, &act, NULL);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open sigaction failed: %s\n",
@ -70,6 +86,7 @@ int add_trn_rig(RIG *rig)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETOWN failed: %s\n",
strerror(errno));
#ifndef _WIN32
status = fcntl(rig->state.fd, F_SETSIG, SIGIO);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETSIG failed: %s\n",
@ -79,6 +96,7 @@ int add_trn_rig(RIG *rig)
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETASYNC failed: %s\n",
strerror(errno));
#endif
return RIG_OK;
}
@ -97,21 +115,36 @@ int remove_trn_rig(RIG *rig)
* This is used by sa_sigio, the SIGIO handler
* to find out which rig generated this event,
* and decode/process it.
*
* assumes rig!=NULL, rig->state.fd>=0
*/
static int search_rig_and_decode(RIG *rig, void *data)
{
fd_set rfds;
struct timeval tv;
int retval;
#if 0
siginfo_t *si = (siginfo_t*)data;
#endif
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;
FD_ZERO(&rfds);
FD_SET(rig->state.fd, &rfds);
/* Read status immediately. */
tv.tv_sec = 0;
tv.tv_usec = 0;
/* don't use FIONREAD to detect activity
* since it is less portable than select
* REM: EINTR possible with 0sec timeout? retval==0?
*/
retval = select(rig->state.fd+1, &rfds, NULL, NULL, &tv);
if (retval < 0) {
rig_debug(RIG_DEBUG_ERR, "search_rig_and_decode: select: %s\n",
strerror(errno));
return -1;
}
#endif
/*
@ -134,11 +167,21 @@ static int search_rig_and_decode(RIG *rig, void *data)
* 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)
#ifdef _WIN32
static void sa_sigiohandler(int signum)
{
rig_debug(RIG_DEBUG_VERBOSE, "sa_sigio: activity detected\n");
rig_debug(RIG_DEBUG_VERBOSE, "sa_sigiohandler: activity detected\n");
foreach_opened_rig(search_rig_and_decode, NULL);
}
#else
static void sa_sigioaction(int signum, siginfo_t *si, void *data)
{
rig_debug(RIG_DEBUG_VERBOSE, "sa_sigioaction: activity detected\n");
foreach_opened_rig(search_rig_and_decode, si);
}
#endif

Wyświetl plik

@ -6,7 +6,7 @@
* Provides useful routines for data handling, used by backend
* as well as by the frontend.
*
* $Id: misc.c,v 1.6 2001-05-04 22:41:22 f4cfe Exp $
* $Id: misc.c,v 1.7 2001-06-02 17:56:37 f4cfe Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -25,6 +25,10 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h> /* Standard input/output definitions */
@ -206,7 +210,7 @@ int rig_need_debug(enum rig_debug_level_e debug_level)
/*
* rig_debug
* Debugging messages are done through stderr
* TODO: add syslog suport if needed
* TODO: add syslog support if needed
*/
void rig_debug(enum rig_debug_level_e debug_level, const char *fmt, ...)
{

Wyświetl plik

@ -2,15 +2,15 @@
* hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
*
* serial.c - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com),
* Stephane Fillod 2000
* Stephane Fillod 2000,2001
* Provides useful routines for read/write serial data for communicating
* via serial interface.
*
* Parts of the PTT handling are inspired from soundmodem, an excellent
* packet softmodem written by Thomas Sailer, HB9JNX.
* Parts of the PTT handling are derived from soundmodem, an excellent
* ham packet softmodem written by Thomas Sailer, HB9JNX.
*
*
* $Id: serial.c,v 1.9 2001-02-15 00:00:11 f4cfe Exp $
* $Id: serial.c,v 1.10 2001-06-02 17:56:37 f4cfe Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -53,9 +53,10 @@
#include <sgtty.h>
#endif
#ifdef __CYGWIN32__
/* include <winsock.h> for FIONREAD?? */
/* TODO: have a look in <winbase.h> for CTS/RTS and DTR/DSR control --SF */
#ifdef _WIN32
/* for CTS/RTS and DTR/DSR control --SF */
#include <windows.h>
#include <winioctl.h>
#endif
#include <hamlib/rig.h>
@ -157,6 +158,9 @@ int serial_open(struct rig_state *rs) {
case 57600:
speed = B57600; /* cool.. */
break;
case 115200:
speed = B115200; /* awsome! */
break;
default:
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported rate specified: %d\n",
rs->serial_rate);
@ -349,6 +353,8 @@ int serial_open(struct rig_state *rs) {
*
*/
/* please, use read_block instead, and forget about non-portable FIONREAD */
#ifdef WANT_DEPRECATED_READSLEEP
int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay) {
int bytes = 0;
@ -372,6 +378,8 @@ int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay) {
return n; /* return bytes read */
}
#endif /* WANT_DEPRECATED_READSLEEP */
/*
* Write a block of count characters to file descriptor,
* with a pause between each character if write_delay is > 0
@ -585,10 +593,32 @@ int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout
* assumes: rs is not NULL
*/
#ifdef _WIN32
int ser_ptt_open(struct rig_state *rs)
{
const char *path = rs->ptt_path;
HANDLE h;
DCB dcb;
h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE) {
rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", path);
return -1;
}
/* Check if it is a comm device */
if (!GetCommState(h, &dcb)) {
rig_debug(RIG_DEBUG_ERR, "Device \"%s\" not a COM device\n", path);
CloseHandle(h);
return -1;
}
return (int)h;
}
#else
int ser_ptt_open(struct rig_state *rs)
{
return open(rs->ptt_path, O_RDWR | O_NOCTTY);
}
#endif
/*
* TODO: to be called before exiting: atexit(parport_cleanup)
@ -611,6 +641,14 @@ int ser_ptt_set(struct rig_state *rs, ptt_t pttx)
unsigned char y;
switch(rs->ptt_type) {
#ifdef _WIN32
/* TODO: log error with 0x%lx GetLastError() */
case RIG_PTT_SERIAL_RTS:
return !EscapeCommFunction((HANDLE)rs->ptt_fd, pttx ? SETRTS : CLRRTS);
case RIG_PTT_SERIAL_DTR:
return !EscapeCommFunction((HANDLE)rs->ptt_fd, pttx ? SETDTR : CLRDTR);
#else
case RIG_PTT_SERIAL_RTS:
y = TIOCM_RTS;
return ioctl(rs->ptt_fd, pttx ? TIOCMBIS : TIOCMBIC, &y);
@ -618,6 +656,7 @@ int ser_ptt_set(struct rig_state *rs, ptt_t pttx)
case RIG_PTT_SERIAL_DTR:
y = TIOCM_DTR;
return ioctl(rs->ptt_fd, pttx ? TIOCMBIS : TIOCMBIC, &y);
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
@ -656,6 +695,8 @@ int ser_ptt_get(struct rig_state *rs, ptt_t *pttx)
int status;
switch(rs->ptt_type) {
#ifdef _WIN32
#else
case RIG_PTT_SERIAL_RTS:
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*pttx = y & TIOCM_RTS ? RIG_PTT_ON:RIG_PTT_OFF;
@ -666,7 +707,7 @@ int ser_ptt_get(struct rig_state *rs, ptt_t *pttx)
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*pttx = y & TIOCM_DTR ? RIG_PTT_ON:RIG_PTT_OFF;
return status;
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
rs->ptt_type);
@ -711,6 +752,8 @@ int ser_dcd_get(struct rig_state *rs, dcd_t *dcdx)
int status;
switch(rs->dcd_type) {
#ifdef _WIN32
#else
case RIG_DCD_SERIAL_CTS:
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*dcdx = y & TIOCM_CTS ? RIG_DCD_ON:RIG_DCD_OFF;
@ -721,7 +764,7 @@ int ser_dcd_get(struct rig_state *rs, dcd_t *dcdx)
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*dcdx = y & TIOCM_DSR ? RIG_DCD_ON:RIG_DCD_OFF;
return status;
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n",
rs->dcd_type);
@ -757,10 +800,17 @@ int par_dcd_get(struct rig_state *rs, dcd_t *dcdx)
return RIG_OK;
}
#ifdef _WIN32
int ser_ptt_close(struct rig_state *rs)
{
return CloseHandle((HANDLE)rs->ptt_fd);
}
#else
int ser_ptt_close(struct rig_state *rs)
{
return close(rs->ptt_fd);
}
#endif
int par_ptt_close(struct rig_state *rs)
{

Wyświetl plik

@ -6,7 +6,7 @@
* Provides useful routines for read/write serial data for communicating
* via serial interface .
*
* $Id: serial.h,v 1.5 2001-02-15 00:00:11 f4cfe Exp $
* $Id: serial.h,v 1.6 2001-06-02 17:56:37 f4cfe Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -33,7 +33,9 @@
int serial_open(struct rig_state *rs);
#if 0
int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay);
#endif
int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout);
int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_delay, int post_write_delay);
int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout);