gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] gpspipe improvement proposal for hi-res timestamps


From: Andreas Merz
Subject: [gpsd-dev] gpspipe improvement proposal for hi-res timestamps
Date: Sun, 21 Apr 2013 01:04:39 +0200
User-agent: SquirrelMail/1.4.18

Dear developers,

I could not find a description how to correctly contribute a patch to the 
project,
so I would be glad to get some advice from you.

To make the gpspipe.c tool more valuable for a number of applications and 
investigations,
I added a high-resolution time-stamp option and I kindly ask for review and 
integration of
the 2 small patches below in the main stream development.

The proposed option -u will produce the following kind of output, which may
help e.g. to give deeper insight in the timing behaviour of the processing 
chain.

gpspipe -ur | grep RMC
:
2013-04-21 00:50:52.155039: 
$GPRMC,225052,A,4935.6472,N,01104.1246,E,0.3662,293.036,200413,,*2E
2013-04-21 00:50:52.735095: 
$GPRMC,225053,A,4935.6469,N,01104.1246,E,0.3662,293.036,200413,,*25
2013-04-21 00:50:53.706171: 
$GPRMC,225054,A,4935.6466,N,01104.1238,E,0.1460,317.568,200413,,*25
2013-04-21 00:50:55.160161: 
$GPRMC,225055,A,4935.6466,N,01104.1239,E,0.1460,317.568,200413,,*25
2013-04-21 00:50:55.740238: 
$GPRMC,225056,A,4935.6464,N,01104.1231,E,0.1676,299.963,200413,,*29
2013-04-21 00:50:56.710224: 
$GPRMC,225057,A,4935.6460,N,01104.1231,E,0.1676,299.963,200413,,*2C
:

Thanks for your feedback;
best regards

Andreas

============


>From 877843177c737cef881047bf5381311057b37e37 Mon Sep 17 00:00:00 2001
From: Andreas <address@hidden>
Date: Fri, 15 Mar 2013 19:18:21 +0100
Subject: [PATCH 1/2] gpspipe output time with sub-second resolution

For simple logging of NMEA data it is often desirable to have
high resolution time-stamps on each message.
This implementation affects only the client-side, namely gpspipe.
The output is permanently enabled, if the -t option is used.
It is planned to add a -u option to be more flexible.
A more desirable way might be to have usec resolution
timestamps on the gpsd protocol messages.
        modified:   gpspipe.c
---
 gpspipe.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gpspipe.c b/gpspipe.c
index eaa2301..a2b0c4c 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -126,6 +126,7 @@ int main(int argc, char **argv)
     bool raw = false;
     bool watch = false;
     bool profile = false;
+    int option_u = 2;                   // option to show uSeconds
     long count = -1;
     int option;
     unsigned int vflag = 0, l = 0;
@@ -315,12 +316,27 @@ int main(int argc, char **argv)
                    serbuf[j++] = buf[i];
                }
                if (new_line && timestamp) {
-                   time_t now = time(NULL);
+                   char tmstr_u[20];            // time with "usec" resolution
+                   struct timeval now;
+                   gettimeofday( &now, NULL );

-                   struct tm *tmp_now = localtime(&now);
+                   struct tm *tmp_now = localtime(&(now.tv_sec));
                    (void)strftime(tmstr, sizeof(tmstr), format, tmp_now);
                    new_line = 0;
-                   if (fprintf(fp, "%.24s :", tmstr) <= 0) {
+
+                   switch( option_u ) {
+                     case 2:
+                       sprintf(tmstr_u, " %ld.%06ld", now.tv_sec, now.tv_usec);
+                       break;
+                     case 1:
+                       sprintf(tmstr_u, ".%06ld", now.tv_usec);
+                       break;
+                     default:
+                       *tmstr_u=0;
+                       break;
+                   }
+
+                   if (fprintf(fp, "%.24s%s: ", tmstr, tmstr_u) <= 0) {
                        (void)fprintf(stderr,
                                      "gpspipe: write error, %s(%d)\n",
                                      strerror(errno), errno);
-- 
1.7.9.5


>From 56e721159a722947028c19853c162d98e2627432 Mon Sep 17 00:00:00 2001
From: Andreas <address@hidden>
Date: Fri, 15 Mar 2013 19:53:45 +0100
Subject: [PATCH 2/2] add option -u and change default time-tag format for
 gpspipe

It is more desirable to have a stadardized and sortable time-tag
default format instead of a locale-dependent one. Furhermore,
the new option -u appends decimal digits to the seconds
which does not make sense for the some %c formats.
        modified:   gpspipe.c
---
 gpspipe.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gpspipe.c b/gpspipe.c
index a2b0c4c..8bb89e9 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -103,6 +103,7 @@ static void usage(void)
                  "-l Sleep for ten seconds before connecting to gpsd.\n"
                  "-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"
                  "-s [serial dev] emulate a 4800bps NMEA GPS on serial port 
(use with '-r').\n"
                  "-n [count] exit after count packets.\n"
                  "-v Print a little spinner.\n"
@@ -117,7 +118,7 @@ int main(int argc, char **argv)
 {
     char buf[4096];
     bool timestamp = false;
-    char *format = "%c";
+    char *format = "%F %T";
     char tmstr[200];
     bool daemonize = false;
     bool binary = false;
@@ -126,7 +127,7 @@ int main(int argc, char **argv)
     bool raw = false;
     bool watch = false;
     bool profile = false;
-    int option_u = 2;                   // option to show uSeconds
+    int option_u = 0;                   // option to show uSeconds
     long count = -1;
     int option;
     unsigned int vflag = 0, l = 0;
@@ -140,7 +141,7 @@ int main(int argc, char **argv)

     /address@hidden@*/
     flags = WATCH_ENABLE;
-    while ((option = getopt(argc, argv, "?dD:lhrRwStT:vVn:s:o:p")) != -1) {
+    while ((option = getopt(argc, argv, "?dD:lhrRwStT:vVn:s:o:pu")) != -1) {
        switch (option) {
        case 'D':
            debug = atoi(optarg);
@@ -176,6 +177,10 @@ int main(int argc, char **argv)
            timestamp = true;
            format = optarg;
            break;
+       case 'u':
+           timestamp = true;
+           option_u++;
+           break;
        case 'v':
            vflag++;
            break;
-- 
1.7.9.5







reply via email to

[Prev in Thread] Current Thread [Next in Thread]