diff options
-rw-r--r-- | contrib/ashctl.c | 7 | ||||
-rw-r--r-- | contrib/binlog.c | 6 | ||||
-rw-r--r-- | contrib/binreplay.c | 6 | ||||
-rw-r--r-- | contrib/motosend.c | 9 | ||||
-rw-r--r-- | driver_garmin.c | 7 | ||||
-rw-r--r-- | drivers.c | 15 | ||||
-rw-r--r-- | gpsctl.c | 9 | ||||
-rw-r--r-- | gpsd.c | 8 | ||||
-rw-r--r-- | gpsmon.c | 14 | ||||
-rw-r--r-- | ntpshmmon.c | 9 | ||||
-rw-r--r-- | serial.c | 7 |
11 files changed, 82 insertions, 15 deletions
diff --git a/contrib/ashctl.c b/contrib/ashctl.c index fdf04bfd..f1cfdcf4 100644 --- a/contrib/ashctl.c +++ b/contrib/ashctl.c @@ -157,6 +157,7 @@ static int nmea_send(int fd, const char *fmt, ... ) size_t status; char buf[BUFSIZ]; va_list ap; + struct timespec delay; va_start(ap, fmt) ; (void)vsnprintf(buf, sizeof(buf)-5, fmt, ap); @@ -167,7 +168,11 @@ static int nmea_send(int fd, const char *fmt, ... ) tcflush(fd, TCIOFLUSH); status = (size_t)write(fd, buf, strlen(buf)); tcdrain(fd); - usleep(100000); + /* wait 100,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 100000000L; + nanosleep(&delay, NULL); + if (status == strlen(buf)) { return (int)status; } else { diff --git a/contrib/binlog.c b/contrib/binlog.c index 8e5e8d9e..0cfd4781 100644 --- a/contrib/binlog.c +++ b/contrib/binlog.c @@ -19,6 +19,7 @@ int main(int argc, char **argv) { int speed, n, ifd, ofd; struct termios term; char buf[BUFSIZ]; + struct timespec delay; if (argc != 4){ fprintf(stderr, "usage: binlog <speed> <port> <logfile>\n"); @@ -61,7 +62,10 @@ int main(int argc, char **argv) { int l = read(ifd, buf, BUFSIZ); if (l > 0) assert(write(ofd, buf, l) > 0); - usleep(1000); + /* wait 1,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 1000000L; + nanosleep(&delay, NULL); bzero(buf, BUFSIZ); spinner( n++ ); } diff --git a/contrib/binreplay.c b/contrib/binreplay.c index 36389e09..8b68bc1d 100644 --- a/contrib/binreplay.c +++ b/contrib/binreplay.c @@ -31,6 +31,7 @@ int main( int argc, char **argv){ char *buf, tn[32]; int ifd, ofd, sfd; int dflag = 0, c, sleeptime, len, speed = 0; + struct timespec delay; while((c = getopt(argc, argv, "d:r:s:")) != -1) { switch(c){ @@ -117,7 +118,10 @@ int main( int argc, char **argv){ tcflush(sfd, TCIFLUSH); } spinner( len ); - usleep(sleeptime); + /* wait sleeptime Sec */ + delay.tv_sec = (time_t)(sleeptime / 1000000000L); + delay.tv_nsec = sleeptime % 1000000000L; + nanosleep(&delay, NULL); } munmap(buf, sb.st_size); diff --git a/contrib/motosend.c b/contrib/motosend.c index 30731588..a3202dab 100644 --- a/contrib/motosend.c +++ b/contrib/motosend.c @@ -31,6 +31,7 @@ int main(int argc, char **argv) { struct termios term; char buf[BSIZ]; time_t s, t; + struct timespec delay; if (argc != 5){ fprintf(stderr, "usage: motosend <speed> <port> msgtype moto-body-hex\n"); @@ -82,8 +83,12 @@ int main(int argc, char **argv) { tcflush(fd, TCIOFLUSH); t = 0; n = 0; while (1){ - usleep(1000); - bzero(buf, BSIZ); + /* wait 1,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 1000000L; + nanosleep(&delay, NULL); + + bzero(buf, BSIZ); if ((l = read(fd, buf, BSIZ)) == -1) if (!(EINTR == errno || EAGAIN == errno)) err(1, "read"); diff --git a/driver_garmin.c b/driver_garmin.c index c80b8428..4ecb960b 100644 --- a/driver_garmin.c +++ b/driver_garmin.c @@ -1027,6 +1027,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) unsigned char pkt_len = 0; unsigned char chksum = 0; gps_mask_t mask = 0; + struct timespec delay; gpsd_log(&session->context->errout, LOG_RAW, "Garmin: garmin_ser_parse()\n"); if (6 > len) { @@ -1158,7 +1159,11 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) // sending ACK too soon might hang the session // so send ACK last, after a pause - (void)usleep(300); + /* wait 300 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 300000L; + nanosleep(&delay, NULL); + Send_ACK(); gpsd_log(&session->context->errout, LOG_DATA, "Garmin: garmin_ser_parse( )\n"); @@ -287,10 +287,15 @@ const struct gps_type_t driver_nmea0183 = { static void garmin_mode_switch(struct gps_device_t *session, int mode) /* only does anything in one direction, going to Garmin binary driver */ { + struct timespec delay; + if (mode == MODE_BINARY) { (void)nmea_send(session, "$PGRMC1,1,2,1,,,,2,W,N"); (void)nmea_send(session, "$PGRMI,,,,,,,R"); - (void)usleep(333); /* standard Garmin settling time */ + /* wait 333 uSec, standard Garmin settling time */ + delay.tv_sec = 0; + delay.tv_nsec = 333000L; + nanosleep(&delay, NULL); } } #endif /* RECONFIGURE_ENABLE */ @@ -603,11 +608,17 @@ static const struct gps_type_t driver_tripmate = { static void earthmate_event_hook(struct gps_device_t *session, event_t event) { + struct timespec delay; + if (session->context->readonly) return; if (event == event_triggermatch) { (void)gpsd_write(session, "EARTHA\r\n", 8); - (void)usleep(10000); + /* wait 10,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 10000000L; + nanosleep(&delay, NULL); + (void)gpsd_switch_driver(session, "Zodiac"); } } @@ -43,11 +43,18 @@ static bool hunting = true; static void settle(struct gps_device_t *session) /* allow the device to settle after a control operation */ { + struct timespec delay; + /* * See the 'deep black magic' comment in serial.c:set_serial(). */ (void)tcdrain(session->gpsdata.gps_fd); - (void)usleep(50000); + + /* wait 50,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 50000000L; + nanosleep(&delay, NULL); + (void)tcdrain(session->gpsdata.gps_fd); } #endif /* defined(RECONFIGURE_ENABLE) || defined(CONTROLSEND_ENABLE) */ @@ -999,6 +999,7 @@ static void set_serial(struct gps_device_t *device, unsigned int stopbits = device->gpsdata.dev.stopbits; char parity = device->gpsdata.dev.parity; int wordsize = 8; + struct timespec delay; #ifndef __clang_analyzer__ while (isspace((unsigned char) *modestring)) @@ -1041,7 +1042,12 @@ static void set_serial(struct gps_device_t *device, * across any given type of UART. */ (void)tcdrain(device->gpsdata.gps_fd); - (void)usleep(50000); + + /* wait 50,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 50000000L; + nanosleep(&delay, NULL); + gpsd_set_speed(device, speed, parity, stopbits); } } @@ -861,6 +861,7 @@ static bool do_command(const char *line) { #ifdef RECONFIGURE_ENABLE unsigned int v; + struct timespec delay; #endif /* RECONFIGURE_ENABLE */ #ifdef CONTROLSEND_ENABLE unsigned char buf[BUFLEN]; @@ -963,7 +964,12 @@ static bool do_command(const char *line) switcher->mode_switcher(&session, (int)v); context.readonly = true; (void)tcdrain(session.gpsdata.gps_fd); - (void)usleep(50000); + + /* wait 50,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 50000000L; + nanosleep(&delay, NULL); + /* * Session device change will be set to NMEA when * gpsmon resyncs. So stash the current type to @@ -1035,7 +1041,11 @@ static bool do_command(const char *line) * buffer. */ (void)tcdrain(session.gpsdata.gps_fd); - (void)usleep(50000); + /* wait 50,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 50000000L; + nanosleep(&delay, NULL); + (void)gpsd_set_speed(&session, speed, parity, stopbits); } else diff --git a/ntpshmmon.c b/ntpshmmon.c index 8706f414..aa89806b 100644 --- a/ntpshmmon.c +++ b/ntpshmmon.c @@ -98,6 +98,7 @@ int main(int argc, char **argv) do { /* the current segment */ struct shm_stat_t shm_stat; + struct timespec delay; for (i = 0; i < NTPSEGMENTS; i++) { long long diff; /* 32 bit long is too short for a timespec */ @@ -164,7 +165,7 @@ int main(int argc, char **argv) * That is a 200 millSec cycle, minimum 20 milliSec duration * we will wait 1 milliSec out of caution * - * and, of course, usleep() may sleep a lot longer than we ask... + * and, of course, nanosleep() may sleep a lot longer than we ask... */ if ( timeout ) { /* do not read time unless it matters */ @@ -173,7 +174,11 @@ int main(int argc, char **argv) break; } } - (void)usleep((useconds_t)1000); + + /* wait 1,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 1000000L; + nanosleep(&delay, NULL); } while ( 0 < nsamples ); exit(EXIT_SUCCESS); @@ -255,6 +255,7 @@ void gpsd_set_speed(struct gps_device_t *session, speed_t speed, char parity, unsigned int stopbits) { speed_t rate; + struct timespec delay; /* * Yes, you can set speeds that aren't in the hunt loop. If you @@ -380,7 +381,11 @@ void gpsd_set_speed(struct gps_device_t *session, * occasional failure to lock. */ (void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH); - (void)usleep(200000); + + /* wait 200,000 uSec */ + delay.tv_sec = 0; + delay.tv_nsec = 200000000L; + nanosleep(&delay, NULL); (void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH); } gpsd_log(&session->context->errout, LOG_INF, |