summaryrefslogtreecommitdiff
path: root/serial.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-01-29 14:33:05 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-01-29 14:33:05 -0500
commit646f855d4cdd6d7c27333d511b1d49eaea277af4 (patch)
tree6b092b6fd21c55452d595a73eaed2b3faf29a2be /serial.c
parenta83ecfd712d37442445523ef0d14c04477ac9289 (diff)
downloadgpsd-646f855d4cdd6d7c27333d511b1d49eaea277af4.tar.gz
Rare I/O with timeout seems to work. This replaces the adaptive-delay code.
Diffstat (limited to 'serial.c')
-rw-r--r--serial.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/serial.c b/serial.c
index e511b324..4655cc24 100644
--- a/serial.c
+++ b/serial.c
@@ -610,12 +610,39 @@ ssize_t gpsd_serial_write(struct gps_device_t * session,
}
void gpsd_optimize_io(struct gps_device_t *session,
- const int minlength, const bool textual)
+ const int minlength, const bool textual UNUSED)
/* optimize I/O mode depending on the minimum packet size */
{
- gpsd_report(&session->context->errout, LOG_SHOUT,
- "tty params optimized for min length %d of %s packets\n",
- minlength, textual ? "textual" : "binary");
+ /* bail out if this is not actually a tty */
+ if (isatty(session->gpsdata.gps_fd) == 0)
+ return;
+
+ /*
+ * This is an optimization hack. The idea is to get away from
+ * character-at-a-time I/O in order to slow down the rate at
+ * which the main select loop spins (those calls eat power
+ * noticeably in environments like Android phones and the
+ * Raspberry Pi). We tell the tty layer to wait until it has
+ * either accumulated characters corresponding to the minimum
+ * possible length of a packet or timed out.
+ *
+ * FIXME: Use cooked I/O for textual packets.
+ */
+ if (minlength > 1) {
+ session->ttyset.c_cc[VMIN] = minlength;
+ session->ttyset.c_cc[VTIME] = 1; /* 0.1 sec */
+ } else {
+ /* raw character-at-at-time I/O, no timeout */
+ session->ttyset.c_cc[VMIN] = 1;
+ session->ttyset.c_cc[VTIME] = 0;
+ }
+
+ if (tcsetattr(session->gpsdata.gps_fd, TCSANOW, &session->ttyset) != 0)
+ return;
+
+ gpsd_report(&session->context->errout, LOG_IO,
+ "tty params optimized for min length %d of %s packets\n",
+ minlength, textual ? "textual" : "binary");
}