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,11 +1387,15 @@ int win32_serial_read( int fd, void *vb, int size )
|
||||||
if ( index->open_flags & O_NONBLOCK )
|
if ( index->open_flags & O_NONBLOCK )
|
||||||
{
|
{
|
||||||
/* pull mucho-cpu here? */
|
/* pull mucho-cpu here? */
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
#ifdef DEBUG_VERBOSE
|
#ifdef DEBUG_VERBOSE
|
||||||
report( "vmin=0\n" );
|
report( "vmin=0\n" );
|
||||||
#endif /* DEBUG_VERBOSE */
|
#endif /* DEBUG_VERBOSE */
|
||||||
ClearErrors( index, &stat);
|
ClearErrors( index, &stat);
|
||||||
|
|
||||||
|
if (stat.cbInQue < index->ttyset->c_cc[VMIN])
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
usleep(50);
|
usleep(50);
|
||||||
|
@ -1399,14 +1403,16 @@ int win32_serial_read( int fd, void *vb, int size )
|
||||||
/* we should use -1 instead of 0 for disabled timeout */
|
/* we should use -1 instead of 0 for disabled timeout */
|
||||||
now = GetTickCount();
|
now = GetTickCount();
|
||||||
if (index->ttyset->c_cc[VTIME] &&
|
if (index->ttyset->c_cc[VTIME] &&
|
||||||
now-start >= (index->ttyset->c_cc[VTIME]*100)) {
|
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);
|
sprintf( message, "now = %i start = %i time = %i total =%i\n", now, start, index->ttyset->c_cc[VTIME]*100, total);
|
||||||
report( message );
|
report( message );
|
||||||
*/
|
*/
|
||||||
return total; /* read timeout */
|
return total; /* read timeout */
|
||||||
}
|
}
|
||||||
} while( stat.cbInQue < size && size > 1 );
|
}
|
||||||
|
} while (size > 1 && stat.cbInQue < index->ttyset->c_cc[VMIN]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1421,7 +1427,7 @@ int win32_serial_read( int fd, void *vb, int size )
|
||||||
do {
|
do {
|
||||||
ClearErrors( index, &stat);
|
ClearErrors( index, &stat);
|
||||||
usleep(1000);
|
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 );
|
( int ) nBytes, (char *) dest + total );
|
||||||
report( message );
|
report( message );
|
||||||
#endif /* DEBUG_VERBOSE */
|
#endif /* DEBUG_VERBOSE */
|
||||||
size -= nBytes;
|
|
||||||
total += nBytes;
|
|
||||||
|
|
||||||
if ( !err )
|
if ( !err )
|
||||||
{
|
{
|
||||||
|
@ -1505,6 +1509,9 @@ int win32_serial_read( int fd, void *vb, int size )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
size -= nBytes;
|
||||||
|
total += nBytes;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
*/
|
*/
|
||||||
|
@ -1614,8 +1621,6 @@ int win32_serial_read( int fd, void *vb, int size )
|
||||||
( int ) nBytes, (char *) dest + total );
|
( int ) nBytes, (char *) dest + total );
|
||||||
report( message );
|
report( message );
|
||||||
#endif /* DEBUG_VERBOSE */
|
#endif /* DEBUG_VERBOSE */
|
||||||
size -= nBytes;
|
|
||||||
total += nBytes;
|
|
||||||
|
|
||||||
if ( !err )
|
if ( !err )
|
||||||
{
|
{
|
||||||
|
@ -1682,6 +1687,9 @@ int win32_serial_read( int fd, void *vb, int size )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
size -= nBytes;
|
||||||
|
total += nBytes;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
usleep(1000);
|
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;
|
efds = rfds;
|
||||||
|
|
||||||
retval = port_select(p, p->fd+1, &rfds, NULL, &efds, &tv);
|
retval = port_select(p, p->fd+1, &rfds, NULL, &efds, &tv);
|
||||||
if (retval == 0) /* Timed out */
|
if (retval == 0) {
|
||||||
break;
|
/* 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) {
|
if (retval < 0) {
|
||||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
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';
|
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);
|
rig_debug(RIG_DEBUG_TRACE,"%s(): RX %d characters\n", __func__, total_count);
|
||||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue