From 58871f7715e950ed2962a24a42c7e6f7f962fce9 Mon Sep 17 00:00:00 2001 From: "Frank Singleton, VK3FCS" Date: Sat, 23 Sep 2000 02:46:44 +0000 Subject: [PATCH] added usleep to read_sleep() git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@141 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- common/serial.c | 24 +++++++++++++++++------- common/serial.h | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/serial.c b/common/serial.c index 432bf12da..04c1bebbe 100644 --- a/common/serial.c +++ b/common/serial.c @@ -5,7 +5,7 @@ * Provides useful routines for read/write serial data for communicating * via serial interface . * - * $Id: serial.c,v 1.14 2000-09-21 06:44:44 f4cfe Exp $ + * $Id: serial.c,v 1.15 2000-09-23 02:45:20 javabear Exp $ * * * This program is free software; you can redistribute it and/or @@ -88,7 +88,7 @@ int serial_open(struct rig_state *rs) { switch(rs->serial_rate) { case 300: - speed = B300; + speed = B300; /* yikes... */ break; case 1200: speed = B1200; @@ -106,7 +106,7 @@ int serial_open(struct rig_state *rs) { speed = B38400; break; case 57600: - speed = B57600; + speed = B57600; /* cool.. */ break; default: fprintf(stderr, "open_serial: unsupported rate specified: %d\n", @@ -259,15 +259,25 @@ int serial_open(struct rig_state *rs) { * Read "num" bytes from "fd" and put results into * an array of unsigned char pointed to by "rxbuffer" * - * Sleeps every second until number of bytes to read + * Sleeps read_delay milliseconds until number of bytes to read * is the amount requested. * - * It the reads "num" bytes into rxbuffer. + * It then reads "num" bytes into rxbuffer. + * + * input: + * fd - file descriptor + * rxbuffer - ptr to rx buffer + * num - number of bytes to read + * read_delay - number of msec between read attempts + * + * returns: + * + * n - numbers of bytes read * */ -int read_sleep(int fd, unsigned char *rxbuffer, int num ) { +int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay) { int bytes = 0; int n = 0; @@ -278,7 +288,7 @@ int read_sleep(int fd, unsigned char *rxbuffer, int num ) { printf("bytes = %i\n", bytes); if (bytes == num) break; - sleep(1); /* wait 1 second and try again */ + usleep(read_delay*1000); /* sleep read_delay msecs */ } /* this should not block now */ diff --git a/common/serial.h b/common/serial.h index 9f6aba5e4..018d51d83 100644 --- a/common/serial.h +++ b/common/serial.h @@ -5,7 +5,7 @@ * Provides useful routines for read/write serial data for communicating * via serial interface . * - * $Id: serial.h,v 1.10 2000-09-19 06:58:56 f4cfe Exp $ + * $Id: serial.h,v 1.11 2000-09-23 02:46:44 javabear Exp $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,7 @@ int serial_open(struct rig_state *rs); -int read_sleep(int fd, unsigned char *rxbuffer, int num ); +int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay); 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);