Fixes for BRK/RTS/DTR handling under win32

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1782 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.2
Stéphane Fillod, F8CFE 2004-08-01 23:13:17 +00:00
rodzic 7bac83a841
commit c08cc78724
3 zmienionych plików z 85 dodań i 100 usunięć

Wyświetl plik

@ -457,6 +457,7 @@ int termios_to_bytesize( int cflag )
} }
} }
#if 0
/*---------------------------------------------------------- /*----------------------------------------------------------
get_dos_port() get_dos_port()
@ -478,6 +479,7 @@ const char *get_dos_port( char const *name )
LEAVE( "get_dos_port" ); LEAVE( "get_dos_port" );
return( ( const char * ) name ); return( ( const char * ) name );
} }
#endif
/*---------------------------------------------------------- /*----------------------------------------------------------
ClearErrors() ClearErrors()
@ -2667,10 +2669,13 @@ fstat()
comments: this is just to keep the eventLoop happy. comments: this is just to keep the eventLoop happy.
----------------------------------------------------------*/ ----------------------------------------------------------*/
#if 0
int fstat( int fd, ... ) int fstat( int fd, ... )
{ {
return( 0 ); return( 0 );
} }
#endif
/*---------------------------------------------------------- /*----------------------------------------------------------
ioctl() ioctl()
@ -2697,7 +2702,7 @@ ioctl()
----------------------------------------------------------*/ ----------------------------------------------------------*/
int ioctl( int fd, int request, ... ) int win32_serial_ioctl( int fd, int request, ... )
{ {
unsigned long dwStatus = 0; unsigned long dwStatus = 0;
va_list ap; va_list ap;
@ -2749,6 +2754,17 @@ int ioctl( int fd, int request, ... )
va_end( ap ); va_end( ap );
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
case TIOCCBRK:
case TIOCSBRK:
arg = va_arg( ap, int * );
if ( EscapeCommFunction( index->hComm,
( request == TIOCSBRK ) ? SETBREAK :
CLRBREAK ) )
report( "EscapeCommFunction: True\n" );
else
report( "EscapeCommFunction: False\n" );
break;
case TIOCMGET: case TIOCMGET:
arg = va_arg( ap, int * ); arg = va_arg( ap, int * );
/* DORITOS */ /* DORITOS */
@ -2782,15 +2798,50 @@ int ioctl( int fd, int request, ... )
*/ */
va_end( ap ); va_end( ap );
return( 0 ); return( 0 );
/* TIOCMIS, TIOCMBIC and TIOCMSET all do the same thing... */
case TIOCMBIS: case TIOCMBIS:
arg = va_arg( ap, int * ); arg = va_arg( ap, int * );
va_end( ap ); if ( *arg & TIOCM_DTR )
return -ENOIOCTLCMD; {
index->MSR |= TIOCM_DTR;
if (EscapeCommFunction( index->hComm, SETDTR))
report( "EscapeCommFunction: True\n" );
else
report( "EscapeCommFunction: False\n" );
}
if ( *arg & TIOCM_RTS )
{
index->MSR |= TIOCM_RTS;
if(EscapeCommFunction( index->hComm, SETRTS))
report( "EscapeCommFunction: True\n" );
else
report( "EscapeCommFunction: False\n" );
}
break;
case TIOCMBIC: case TIOCMBIC:
arg = va_arg( ap, int * ); arg = va_arg( ap, int * );
va_end( ap ); if ( *arg & TIOCM_DTR )
return -ENOIOCTLCMD; {
index->MSR &= ~TIOCM_DTR;
if ( EscapeCommFunction( index->hComm, CLRDTR))
report( "EscapeCommFunction: True\n" );
else
report( "EscapeCommFunction: False\n" );
}
if ( *arg & TIOCM_RTS )
{
index->MSR &= ~TIOCM_RTS;
if( EscapeCommFunction( index->hComm, CLRRTS))
report( "EscapeCommFunction: True\n" );
else
report( "EscapeCommFunction: False\n" );
}
break;
case TIOCMSET: case TIOCMSET:
arg = va_arg( ap, int * ); arg = va_arg( ap, int * );
if (( *arg & TIOCM_DTR) == (index->MSR & TIOCM_DTR) ) if (( *arg & TIOCM_DTR) == (index->MSR & TIOCM_DTR) )
@ -3204,7 +3255,7 @@ int win32_serial_select( int n, fd_set *readfds, fd_set *writefds,
int timeout_usec = timeout ? timeout->tv_sec*1000000 + timeout->tv_usec : INT_MAX; int timeout_usec = timeout ? timeout->tv_sec*1000000 + timeout->tv_usec : INT_MAX;
while (timeout_usec > 0) { while (timeout_usec > 0) {
sprintf( message, "wait for data in read buffer%d\n", Stat.cbInQue ); sprintf( message, "wait for data in read buffer%d\n", (int)Stat.cbInQue );
report( message ); report( message );
if (Stat.cbInQue != 0) { if (Stat.cbInQue != 0) {

Wyświetl plik

@ -119,6 +119,7 @@ int win32_serial_open(const char *File, int flags, ... );
int win32_serial_close(int fd); int win32_serial_close(int fd);
int win32_serial_read(int fd, void *b, int size); int win32_serial_read(int fd, void *b, int size);
int win32_serial_write(int fd, const char *Str, int length); int win32_serial_write(int fd, const char *Str, int length);
int win32_serial_ioctl(int fd, int request, ... );
/* /*
* lcc winsock.h conflicts * lcc winsock.h conflicts
*/ */
@ -131,6 +132,7 @@ int win32_serial_select(int, struct fd_set *, struct fd_set *, struct fd_set *,
#define CLOSE win32_serial_close #define CLOSE win32_serial_close
#define READ win32_serial_read #define READ win32_serial_read
#define WRITE win32_serial_write #define WRITE win32_serial_write
#define IOCTL win32_serial_ioctl
void termios_interrupt_event_loop( int , int ); void termios_interrupt_event_loop( int , int );
void termios_setflags( int , int[] ); void termios_setflags( int , int[] );
@ -146,7 +148,6 @@ int termios_to_bytesize(int);
int bytesize_to_termios(int); int bytesize_to_termios(int);
int tcgetattr(int Fd, struct termios *s_termios); int tcgetattr(int Fd, struct termios *s_termios);
int tcsetattr(int Fd, int when, struct termios *); int tcsetattr(int Fd, int when, struct termios *);
int win32_serial_close(int );
speed_t cfgetospeed(struct termios *s_termios); speed_t cfgetospeed(struct termios *s_termios);
speed_t cfgetispeed(struct termios *s_termios); speed_t cfgetispeed(struct termios *s_termios);
int cfsetspeed(struct termios *, speed_t speed); int cfsetspeed(struct termios *, speed_t speed);
@ -158,7 +159,6 @@ int tcsetpgrp ( int , int );
int tcdrain ( int ); int tcdrain ( int );
int tcflow ( int , int ); int tcflow ( int , int );
int tcsendbreak ( int , int ); int tcsendbreak ( int , int );
int ioctl(int fd, int request, ... );
/* /*
int fstat(int fd, ... ); int fstat(int fd, ... );
*/ */
@ -396,6 +396,8 @@ void termiosSetParityError( int, char );
/* unused ioctls */ /* unused ioctls */
#define TCSBRK 0x5409 #define TCSBRK 0x5409
#define TIOCCBRK 0x540a
#define TIOCSBRK 0x540b
#define TIOCOUTQ 0x5411 #define TIOCOUTQ 0x5411
#define TIOCMGET 0x5415 #define TIOCMGET 0x5415
#define TIOCMBIS 0x5416 #define TIOCMBIS 0x5416

Wyświetl plik

@ -1,10 +1,10 @@
/* /*
* Hamlib Interface - serial communication low-level support * Hamlib Interface - serial communication low-level support
* Copyright (c) 2000-2003 by Stephane Fillod and Frank Singleton * Copyright (c) 2000-2004 by Stephane Fillod and Frank Singleton
* Parts of the PTT handling are derived from soundmodem, an excellent * Parts of the PTT handling are derived from soundmodem, an excellent
* ham packet softmodem written by Thomas Sailer, HB9JNX. * ham packet softmodem written by Thomas Sailer, HB9JNX.
* *
* $Id: serial.c,v 1.39 2004-04-16 20:04:11 fillods Exp $ * $Id: serial.c,v 1.40 2004-08-01 23:13:17 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
@ -72,6 +72,7 @@
#else #else
#define OPEN open #define OPEN open
#define CLOSE close #define CLOSE close
#define IOCTL ioctl
#endif #endif
#include <hamlib/rig.h> #include <hamlib/rig.h>
@ -177,9 +178,9 @@ int serial_setup(port_t *rp)
#if defined(HAVE_TERMIOS_H) || defined(WIN32) #if defined(HAVE_TERMIOS_H) || defined(WIN32)
tcgetattr(fd, &options); tcgetattr(fd, &options);
#elif defined(HAVE_TERMIO_H) #elif defined(HAVE_TERMIO_H)
ioctl (fd, TCGETA, &options); IOCTL (fd, TCGETA, &options);
#else /* sgtty */ #else /* sgtty */
ioctl (fd, TIOCGETP, &sg); IOCTL (fd, TIOCGETP, &sg);
#endif #endif
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
@ -368,14 +369,14 @@ int serial_setup(port_t *rp)
return -RIG_ECONF; /* arg, so close! */ return -RIG_ECONF; /* arg, so close! */
} }
#elif defined(HAVE_TERMIO_H) #elif defined(HAVE_TERMIO_H)
if (ioctl(fd, TCSETA, &options) == -1) { if (IOCTL(fd, TCSETA, &options) == -1) {
rig_debug(RIG_DEBUG_ERR, "open_serial: ioctl(TCSETA) failed: %s\n", rig_debug(RIG_DEBUG_ERR, "open_serial: ioctl(TCSETA) failed: %s\n",
strerror(errno)); strerror(errno));
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; /* arg, so close! */ return -RIG_ECONF; /* arg, so close! */
} }
#else /* sgtty */ #else /* sgtty */
if (ioctl(fd, TIOCSETP, &sg) == -1) { if (IOCTL(fd, TIOCSETP, &sg) == -1) {
rig_debug(RIG_DEBUG_ERR, "open_serial: ioctl(TIOCSETP) failed: %s\n", rig_debug(RIG_DEBUG_ERR, "open_serial: ioctl(TIOCSETP) failed: %s\n",
strerror(errno)); strerror(errno));
CLOSE(fd); CLOSE(fd);
@ -398,74 +399,31 @@ int serial_flush( port_t *p )
return RIG_OK; return RIG_OK;
} }
/*
* ser_ptt_set and par_ptt_set
* ser_ptt_open/ser_ptt_close & par_ptt_open/par_ptt_close
*
* ser_open/ser_close,par_open/par_close to be used for PTT and DCD
*
* assumes: p is not NULL
*/
#if defined(WIN32)
int ser_open(port_t *p) int ser_open(port_t *p)
{ {
const char *path = p->pathname; return (p->fd = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY));
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;
}
p->handle = h;
return 0;
} }
#else
int ser_open(port_t *p)
{
return (p->fd = open(p->pathname, O_RDWR | O_NOCTTY));
}
#endif
int ser_close(port_t *p) int ser_close(port_t *p)
{ {
#if defined(WIN32) return CLOSE(p->fd);
return CloseHandle(p->handle);
#else
return close(p->fd);
#endif
} }
int ser_set_rts(port_t *p, int state) int ser_set_rts(port_t *p, int state)
{ {
#if defined(WIN32)
/*
* TODO: log error with 0x%lx GetLastError()
*/
return !EscapeCommFunction(p->handle, state ? SETRTS : CLRRTS);
#else
unsigned int y = TIOCM_RTS; unsigned int y = TIOCM_RTS;
#if defined(TIOCMBIS) && defined(TIOCMBIC) #if defined(TIOCMBIS) && defined(TIOCMBIC)
return ioctl(p->fd, state ? TIOCMBIS : TIOCMBIC, &y); return IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y);
#else #else
if (ioctl(p->fd, TIOCMGET, &y) < 0) { if (IOCTL(p->fd, TIOCMGET, &y) < 0) {
return -RIG_EIO; return -RIG_EIO;
} }
if (state) if (state)
y |= TIOCM_RTS; y |= TIOCM_RTS;
else else
y &= ~TIOCM_RTS; y &= ~TIOCM_RTS;
return ioctl(p->fd, TIOCMSET, &y); return IOCTL(p->fd, TIOCMSET, &y);
#endif
#endif #endif
} }
@ -475,64 +433,47 @@ int ser_set_rts(port_t *p, int state)
*/ */
int ser_get_rts(port_t *p, int *state) int ser_get_rts(port_t *p, int *state)
{ {
#if defined(WIN32)
/* TODO... */
return -RIG_ENIMPL;
#else
int status; int status;
unsigned int y; unsigned int y;
status = ioctl(p->fd, TIOCMGET, &y); status = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_RTS) ? RIG_PTT_ON:RIG_PTT_OFF; *state = (y & TIOCM_RTS) ? RIG_PTT_ON:RIG_PTT_OFF;
return RIG_OK; return RIG_OK;
#endif
} }
int ser_set_dtr(port_t *p, int state) int ser_set_dtr(port_t *p, int state)
{ {
#if defined(WIN32)
return !EscapeCommFunction(p->handle, state ? SETDTR : CLRDTR);
#else
unsigned int y = TIOCM_DTR; unsigned int y = TIOCM_DTR;
#if defined(TIOCMBIS) && defined(TIOCMBIC) #if defined(TIOCMBIS) && defined(TIOCMBIC)
return ioctl(p->fd, state ? TIOCMBIS : TIOCMBIC, &y); return IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y);
#else #else
if (ioctl(p->fd, TIOCMGET, &y) < 0) { if (IOCTL(p->fd, TIOCMGET, &y) < 0) {
return -RIG_EIO; return -RIG_EIO;
} }
if (state) if (state)
y |= TIOCM_DTR; y |= TIOCM_DTR;
else else
y &= ~TIOCM_DTR; y &= ~TIOCM_DTR;
return ioctl(p->fd, TIOCMSET, &y); return IOCTL(p->fd, TIOCMSET, &y);
#endif
#endif #endif
} }
int ser_get_dtr(port_t *p, int *state) int ser_get_dtr(port_t *p, int *state)
{ {
#if defined(WIN32)
/* TODO... */
return -RIG_ENIMPL;
#else
int status; int status;
unsigned int y; unsigned int y;
status = ioctl(p->fd, TIOCMGET, &y); status = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_DTR) ? RIG_PTT_ON:RIG_PTT_OFF; *state = (y & TIOCM_DTR) ? RIG_PTT_ON:RIG_PTT_OFF;
return status; return status;
#endif
} }
int ser_set_brk(port_t *p, int state) int ser_set_brk(port_t *p, int state)
{ {
#if defined(WIN32)
return !EscapeCommFunction(p->handle, state ? SETBREAK : CLRBREAK);
#else
#if defined(TIOCSBRK) && defined(TIOCCBRK) #if defined(TIOCSBRK) && defined(TIOCCBRK)
return ioctl(p->fd, state ? TIOCSBRK : TIOCCBRK, 0 ); return IOCTL(p->fd, state ? TIOCSBRK : TIOCCBRK, 0 );
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
#endif
} }
/* /*
@ -541,16 +482,11 @@ int ser_set_brk(port_t *p, int state)
*/ */
int ser_get_dcd(port_t *p, int *state) int ser_get_dcd(port_t *p, int *state)
{ {
#if defined(WIN32)
/* TODO... */
return -RIG_ENIMPL;
#else
int status; int status;
unsigned int y; unsigned int y;
status = ioctl(p->fd, TIOCMGET, &y); status = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_CAR) ? RIG_DCD_ON:RIG_DCD_OFF; *state = (y & TIOCM_CAR) ? RIG_DCD_ON:RIG_DCD_OFF;
return RIG_OK; return RIG_OK;
#endif
} }
/* /*
@ -598,15 +534,12 @@ int ser_dcd_get(port_t *p, dcd_t *dcdx)
{ {
switch(p->type.dcd) { switch(p->type.dcd) {
#if defined(WIN32)
/* TODO... */
#else
case RIG_DCD_SERIAL_CTS: case RIG_DCD_SERIAL_CTS:
{ {
unsigned int y; unsigned int y;
int status; int status;
status = ioctl(p->fd, TIOCMGET, &y); status = IOCTL(p->fd, TIOCMGET, &y);
*dcdx = y & TIOCM_CTS ? RIG_DCD_ON:RIG_DCD_OFF; *dcdx = y & TIOCM_CTS ? RIG_DCD_ON:RIG_DCD_OFF;
return status; return status;
} }
@ -616,11 +549,10 @@ int ser_dcd_get(port_t *p, dcd_t *dcdx)
unsigned int y; unsigned int y;
int status; int status;
status = ioctl(p->fd, TIOCMGET, &y); status = IOCTL(p->fd, TIOCMGET, &y);
*dcdx = y & TIOCM_DSR ? RIG_DCD_ON:RIG_DCD_OFF; *dcdx = y & TIOCM_DSR ? RIG_DCD_ON:RIG_DCD_OFF;
return status; return status;
} }
#endif
case RIG_DCD_SERIAL_CAR: case RIG_DCD_SERIAL_CAR:
return ser_get_dcd(p, &dcdx); return ser_get_dcd(p, &dcdx);
default: default: