kopia lustrzana https://github.com/Hamlib/Hamlib
Fix serial i/o on Windows.
Fix bytes read count accumulation in Windows serial I/O. read_string from communications port doesn't handle timeout on anything but the first character read. Honour VMIN tty parameter correctly.Hamlib-3.0
rodzic
3cde4f4c2d
commit
849f1e1bf8
|
@ -1387,26 +1387,32 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
if ( index->open_flags & O_NONBLOCK )
|
||||
{
|
||||
/* pull mucho-cpu here? */
|
||||
do {
|
||||
do
|
||||
{
|
||||
#ifdef DEBUG_VERBOSE
|
||||
report( "vmin=0\n" );
|
||||
#endif /* DEBUG_VERBOSE */
|
||||
ClearErrors( index, &stat);
|
||||
/*
|
||||
|
||||
if (stat.cbInQue < index->ttyset->c_cc[VMIN])
|
||||
{
|
||||
/*
|
||||
usleep(1000);
|
||||
usleep(50);
|
||||
*/
|
||||
*/
|
||||
/* we should use -1 instead of 0 for disabled timeout */
|
||||
now = GetTickCount();
|
||||
if ( index->ttyset->c_cc[VTIME] &&
|
||||
now-start >= (index->ttyset->c_cc[VTIME]*100)) {
|
||||
/*
|
||||
if (index->ttyset->c_cc[VTIME] &&
|
||||
now-start >= (index->ttyset->c_cc[VTIME]*100))
|
||||
{
|
||||
/*
|
||||
sprintf( message, "now = %i start = %i time = %i total =%i\n", now, start, index->ttyset->c_cc[VTIME]*100, total);
|
||||
report( message );
|
||||
*/
|
||||
*/
|
||||
return total; /* read timeout */
|
||||
}
|
||||
} while( stat.cbInQue < size && size > 1 );
|
||||
}
|
||||
} while (size > 1 && stat.cbInQue < index->ttyset->c_cc[VMIN]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1421,7 +1427,7 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
do {
|
||||
ClearErrors( index, &stat);
|
||||
usleep(1000);
|
||||
} while ( c > clock() );
|
||||
} while (stat.cbInQue < index->ttyset->c_cc[VMIN] && c > clock());
|
||||
|
||||
}
|
||||
|
||||
|
@ -1441,8 +1447,6 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
( int ) nBytes, (char *) dest + total );
|
||||
report( message );
|
||||
#endif /* DEBUG_VERBOSE */
|
||||
size -= nBytes;
|
||||
total += nBytes;
|
||||
|
||||
if ( !err )
|
||||
{
|
||||
|
@ -1453,9 +1457,9 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
nBytes = 0;
|
||||
break;
|
||||
case ERROR_MORE_DATA:
|
||||
/*
|
||||
/*
|
||||
usleep(1000);
|
||||
*/
|
||||
*/
|
||||
report( "ERROR_MORE_DATA\n" );
|
||||
break;
|
||||
case ERROR_IO_PENDING:
|
||||
|
@ -1490,31 +1494,34 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
}
|
||||
sprintf(message, "end nBytes=%ld] ", nBytes);
|
||||
report( message );
|
||||
/*
|
||||
/*
|
||||
usleep(1000);
|
||||
*/
|
||||
*/
|
||||
report( "ERROR_IO_PENDING\n" );
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
/*
|
||||
usleep(1000);
|
||||
*/
|
||||
*/
|
||||
YACK();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
size -= nBytes;
|
||||
total += nBytes;
|
||||
|
||||
/*
|
||||
usleep(1000);
|
||||
*/
|
||||
*/
|
||||
ClearErrors( index, &stat);
|
||||
return( total );
|
||||
}
|
||||
}
|
||||
LEAVE( "serial_read" );
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef asdf
|
||||
int win32_serial_read( int fd, void *vb, int size )
|
||||
|
@ -1614,8 +1621,6 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
( int ) nBytes, (char *) dest + total );
|
||||
report( message );
|
||||
#endif /* DEBUG_VERBOSE */
|
||||
size -= nBytes;
|
||||
total += nBytes;
|
||||
|
||||
if ( !err )
|
||||
{
|
||||
|
@ -1682,6 +1687,9 @@ int win32_serial_read( int fd, void *vb, int size )
|
|||
}
|
||||
else
|
||||
{
|
||||
size -= nBytes;
|
||||
total += nBytes;
|
||||
|
||||
/*
|
||||
usleep(1000);
|
||||
*/
|
||||
|
|
24
src/iofunc.c
24
src/iofunc.c
|
@ -504,8 +504,17 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
|
|||
efds = rfds;
|
||||
|
||||
retval = port_select(p, p->fd+1, &rfds, NULL, &efds, &tv);
|
||||
if (retval == 0) /* Timed out */
|
||||
break;
|
||||
if (retval == 0) {
|
||||
/* Record timeout time and caculate elapsed time */
|
||||
gettimeofday(&end_time, NULL);
|
||||
timersub(&end_time, &start_time, &elapsed_time);
|
||||
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
rig_debug(RIG_DEBUG_WARN, "%s(): Timed out %d.%d seconds after %d chars\n",
|
||||
__func__, elapsed_time.tv_sec, elapsed_time.tv_usec, total_count);
|
||||
|
||||
return -RIG_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (retval < 0) {
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
|
@ -543,17 +552,6 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
|
|||
*/
|
||||
rxbuffer[total_count] = '\000';
|
||||
|
||||
if (total_count == 0) {
|
||||
/* Record timeout time and caculate elapsed time */
|
||||
gettimeofday(&end_time, NULL);
|
||||
timersub(&end_time, &start_time, &elapsed_time);
|
||||
|
||||
rig_debug(RIG_DEBUG_WARN, "%s(): Timed out %d.%d seconds without reading a character.\n",
|
||||
__func__, elapsed_time.tv_sec, elapsed_time.tv_usec);
|
||||
|
||||
return -RIG_ETIMEOUT;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE,"%s(): RX %d characters\n", __func__, total_count);
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue