[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] [PATCH 3/3] Enable Windows version of gpspipe
From: |
Robert Norris |
Subject: |
[gpsd-dev] [PATCH 3/3] Enable Windows version of gpspipe |
Date: |
Fri, 24 Feb 2017 22:55:22 +0000 |
Use recv() rather than read() for Windows compatibility.
Disable options not available on Windows (serial port, daemonize).
TESTED:
Built gpspipe for Windows under cross compiler.
Run gpspipe on a Windows system and successfully connects to an instance of
gpsd and dumps NMEA output to the terminal or a specified output file.
Still builds and runs on a Linux system including the daemon option.
---
gpspipe.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/gpspipe.c b/gpspipe.c
index bd72f153..7650b7ac 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -37,11 +37,21 @@
#include <string.h>
#include <strings.h>
#include <fcntl.h>
+#ifdef HAVE_TERMIOS_H
#include <termios.h>
+#endif /* HAVE_TERMIOS_H */
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef HAVE_SELECT_H
#include <sys/select.h>
+#endif /* HAVE_SELECT_H */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif /* HAVE_SYS_SOCKET_H */
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif /* HAVE_WINSOCK2_H */
#include <unistd.h>
#include "gpsd.h"
@@ -65,6 +75,7 @@ static int debug;
static void open_serial(char *device)
/* open the serial port and set it up */
{
+#ifdef HAVE_TERMIOS_H
/*
* Open modem device for reading and writing and not as controlling
* tty.
@@ -94,13 +105,16 @@ static void open_serial(char *device)
(void)fprintf(stderr, "gpspipe: error configuring serial port\n");
exit(EXIT_FAILURE);
}
+#endif /* HAVE_TERMIOS_H */
}
static void usage(void)
{
(void)fprintf(stderr,
"Usage: gpspipe [OPTIONS] [server[:port[:device]]]\n\n"
+#ifdef HAVE_FORK
"-d Run as a daemon.\n"
+#endif /* HAVE_FORK */
"-o [file] Write output to file.\n"
"-h Show this help.\n"
"-r Dump raw NMEA.\n"
@@ -112,7 +126,9 @@ static void usage(void)
"-t Time stamp the data.\n"
"-T [format] set the timestamp format (strftime(3)-like;
implies '-t')\n"
"-u usec time stamp, implies -t. Use -uu to output sec.usec\n"
+#ifdef HAVE_TERMIOS_H
"-s [serial dev] emulate a 4800bps NMEA GPS on serial port
(use with '-r').\n"
+#endif
"-n [count] exit after count packets.\n"
"-v Print a little spinner.\n"
"-p Include profiling info in the JSON.\n"
@@ -171,9 +187,11 @@ int main(int argc, char **argv)
flags |= WATCH_RAW;
binary = true;
break;
+#ifdef HAVE_FORK
case 'd':
daemonize = true;
break;
+#endif
case 'l':
sleepy = true;
break;
@@ -208,9 +226,11 @@ int main(int argc, char **argv)
(void)fprintf(stderr, "%s: %s (revision %s)\n",
argv[0], VERSION, REVISION);
exit(EXIT_SUCCESS);
+#ifdef HAVE_TERMIOS_H
case 's':
serialport = optarg;
break;
+#endif
case 'o':
outfile = optarg;
break;
@@ -319,7 +339,7 @@ int main(int argc, char **argv)
/* reading directly from the socket avoids decode overhead */
errno = 0;
- r = (int)read(gpsdata.gps_fd, buf, sizeof(buf));
+ r = (int)recv(gpsdata.gps_fd, buf, sizeof(buf), 0);
if (r > 0) {
int i = 0;
int j = 0;
--
2.11.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gpsd-dev] [PATCH 3/3] Enable Windows version of gpspipe,
Robert Norris <=