summaryrefslogtreecommitdiff
path: root/gpspipe.c
diff options
context:
space:
mode:
authorDaniel_M_Williams <dwilliams@sea-machines.com>2018-12-14 13:26:39 -0800
committerGary E. Miller <gem@rellim.com>2018-12-14 13:26:39 -0800
commit0ee9315efaa81e172e329aaecb44e250f1b87d38 (patch)
tree8dfa5faeb6cab5dbed4616bad58449dfeb29dacd /gpspipe.c
parent4a58ee24b9ec6e1d2753bbdd2cd01a55d2ccde5c (diff)
downloadgpsd-0ee9315efaa81e172e329aaecb44e250f1b87d38.tar.gz
gpspipe: Add -Z option to add Z to timestamp.
Signed-off-by: Gary E. Miller <gem@rellim.com>
Diffstat (limited to 'gpspipe.c')
-rw-r--r--gpspipe.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/gpspipe.c b/gpspipe.c
index ec88001e..6fef3ce1 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -133,6 +133,7 @@ static void usage(void)
"-V Print version and exit.\n"
"-w Dump gpsd native data.\n"
"-x [seconds] Exit after given delay.\n"
+ "-Z sets the timestamp format iso8601: implies '-t'\n"
"You must specify one, or more, of -r, -R, or -w\n"
"You must use -o if you use -d.\n");
}
@@ -141,7 +142,9 @@ int main(int argc, char **argv)
{
char buf[4096];
bool timestamp = false;
+ bool iso8601 = false;
char *format = "%F %T";
+ char *zulu_format = "%FT%T";
char tmstr[200];
bool daemonize = false;
bool binary = false;
@@ -164,7 +167,8 @@ int main(int argc, char **argv)
char *outfile = NULL;
flags = WATCH_ENABLE;
- while ((option = getopt(argc, argv, "?dD:lhrRwStT:vVx:n:s:o:pPu2")) != -1) {
+ while ((option = getopt(argc, argv,
+ "?dD:lhrRwStT:vVx:n:s:o:pPu2Z")) != -1) {
switch (option) {
case 'D':
debug = atoi(optarg);
@@ -233,6 +237,11 @@ int main(int argc, char **argv)
case 'o':
outfile = optarg;
break;
+ case 'Z':
+ timestamp = true;
+ format = zulu_format;
+ iso8601 = true;
+ break;
case '2':
flags |= WATCH_SPLIT24;
break;
@@ -353,6 +362,7 @@ int main(int argc, char **argv)
char tmstr_u[40]; // time with "usec" resolution
struct timespec now;
struct tm *tmp_now;
+ int written;
(void)clock_gettime(CLOCK_REALTIME, &now);
tmp_now = gmtime((time_t *)&(now.tv_sec));
@@ -361,14 +371,24 @@ int main(int argc, char **argv)
switch( option_u ) {
case 2:
+ if(iso8601){
+ written = strlen(tmstr);
+ tmstr[written] = 'Z';
+ tmstr[written+1] = '\0';
+ }
(void)snprintf(tmstr_u, sizeof(tmstr_u),
" %ld.%06ld",
(long)now.tv_sec,
(long)now.tv_nsec/1000);
break;
case 1:
- (void)snprintf(tmstr_u, sizeof(tmstr_u),
- ".%06ld", (long)now.tv_nsec/1000);
+ written = snprintf(tmstr_u, sizeof(tmstr_u),
+ ".%06ld", (long)now.tv_nsec/1000);
+
+ if((0 < written) && (40 > written) && iso8601){
+ tmstr_u[written-1] = 'Z';
+ tmstr_u[written] = '\0';
+ }
break;
default:
*tmstr_u = '\0';