summaryrefslogtreecommitdiff
path: root/gpxlogger.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2010-04-14 17:28:16 -0400
committerEric S. Raymond <esr@thyrsus.com>2010-04-14 17:28:16 -0400
commit8b81fe9c51c6baebf6396797292614888093bf40 (patch)
tree1053cd332a61fe13a823fbfee11e97d393924ba2 /gpxlogger.c
parente567bcf25239f6bfecbb8bfd5a4ea2025c271afc (diff)
downloadgpsd-8b81fe9c51c6baebf6396797292614888093bf40.tar.gz
Reindent two more programs. That's everything except xgpsspeed/Tachometer.c.
All regression tests pass.
Diffstat (limited to 'gpxlogger.c')
-rw-r--r--gpxlogger.c169
1 files changed, 87 insertions, 82 deletions
diff --git a/gpxlogger.c b/gpxlogger.c
index 67dca95c..761d33b0 100644
--- a/gpxlogger.c
+++ b/gpxlogger.c
@@ -39,18 +39,22 @@ static char *progname;
static time_t int_time, old_int_time;
static bool intrack = false;
static bool first = true;
-static time_t timeout = 5; /* seconds */
+static time_t timeout = 5; /* seconds */
#ifdef CLIENTDEBUG_ENABLE
static int debug;
#endif /* CLIENTDEBUG_ENABLE */
-static void print_gpx_header(void)
+static void print_gpx_header(void)
{
(void)printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
(void)printf("<gpx version=\"1.1\" creator=\"navsys logger\"\n");
- (void)printf(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
+ (void)
+ printf
+ (" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
(void)printf(" xmlns=\"http://www.topografix.com/GPX/1.1\"\n");
- (void)printf(" xsi:schemaLocation=\"http://www.topografix.com/GPS/1/1\n");
+ (void)
+ printf
+ (" xsi:schemaLocation=\"http://www.topografix.com/GPS/1/1\n");
(void)printf(" http://www.topografix.com/GPX/1/1/gpx.xsd\">\n");
(void)printf(" <metadata>\n");
(void)printf(" <name>NavSys GPS logger dump</name>\n");
@@ -60,14 +64,14 @@ static void print_gpx_header(void)
(void)fflush(stdout);
}
-static void print_gpx_trk_end (void)
+static void print_gpx_trk_end(void)
{
(void)printf(" </trkseg>\n");
(void)printf(" </trk>\n");
(void)fflush(stdout);
}
-static void print_gpx_footer (void)
+static void print_gpx_footer(void)
{
if (intrack)
print_gpx_trk_end();
@@ -75,7 +79,7 @@ static void print_gpx_footer (void)
(void)fclose(stdout);
}
-static void print_gpx_trk_start (void)
+static void print_gpx_trk_start(void)
{
(void)printf(" <trk>\n");
(void)printf(" <trkseg>\n");
@@ -84,17 +88,16 @@ static void print_gpx_trk_start (void)
static void print_fix(struct gps_fix_t *fix, struct tm *time)
{
- (void)printf(" <trkpt lat=\"%f\" lon=\"%f\">\n",
+ (void)printf(" <trkpt lat=\"%f\" lon=\"%f\">\n",
fix->latitude, fix->longitude);
- (void)printf(" <ele>%f</ele>\n",
- fix->altitude);
+ (void)printf(" <ele>%f</ele>\n", fix->altitude);
(void)printf(" <time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\n",
- time->tm_year+1900, time->tm_mon+1, time->tm_mday,
+ time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec);
- if (fix->mode==MODE_NO_FIX)
- (void)fprintf (stdout, " <fix>none</fix>\n");
+ if (fix->mode == MODE_NO_FIX)
+ (void)fprintf(stdout, " <fix>none</fix>\n");
else
- (void)fprintf (stdout, " <fix>%dd</fix>\n", fix->mode);
+ (void)fprintf(stdout, " <fix>%dd</fix>\n", fix->mode);
#if 0
/*
* Can't print this more detailed report because in D-Bus mode
@@ -103,19 +106,19 @@ static void print_fix(struct gps_fix_t *fix, struct tm *time)
*/
if ((gpsdata->status >= 2) && (gpsdata->fix.mode >= MODE_3D)) {
/* dgps or pps */
- if (gpsdata->fix.mode == 4) { /* military pps */
+ if (gpsdata->fix.mode == 4) { /* military pps */
(void)printf(" <fix>pps</fix>\n");
- } else { /* civilian dgps or sbas */
+ } else { /* civilian dgps or sbas */
(void)printf(" <fix>dgps</fix>\n");
}
- } else { /* no dgps or pps */
+ } else { /* no dgps or pps */
if (gpsdata->fix.mode == MODE_3D) {
(void)printf(" <fix>3d</fix>\n");
} else if (gpsdata->fix.mode == MODE_2D) {
(void)printf(" <fix>2d</fix>\n");
} else if (gpsdata->fix.mode == MODE_NOFIX) {
(void)printf(" <fix>none</fix>\n");
- } /* don't print anything if no fix indicator */
+ } /* don't print anything if no fix indicator */
}
/* print # satellites used in fix, if reasonable to do so */
@@ -126,14 +129,14 @@ static void print_fix(struct gps_fix_t *fix, struct tm *time)
#endif
(void)printf(" </trkpt>\n");
- (void)fflush (stdout);
+ (void)fflush(stdout);
}
static void conditionally_log_fix(struct gps_fix_t *gpsfix)
{
- int_time = (time_t)floor(gpsfix->time);
+ int_time = (time_t) floor(gpsfix->time);
if ((int_time != old_int_time) && gpsfix->mode >= MODE_2D) {
- struct tm time;
+ struct tm time;
/*
* Make new track if the jump in time is above
* timeout. Handle jumps both forward and
@@ -154,19 +157,19 @@ static void conditionally_log_fix(struct gps_fix_t *gpsfix)
if (first)
first = false;
}
-
+
old_int_time = int_time;
(void)gmtime_r(&(int_time), &time);
print_fix(gpsfix, &time);
}
}
-static void quit_handler (int signum)
+static void quit_handler(int signum)
{
/* don't clutter the logs on Ctrl-C */
if (signum != SIGINT)
syslog(LOG_INFO, "exiting, signal %d received", signum);
- print_gpx_footer ();
+ print_gpx_footer();
exit(0);
}
@@ -192,36 +195,35 @@ static struct gps_fix_t gpsfix;
*/
#define EMIX(x, y) (((x) > (y)) ? (x) : (y))
-DBusConnection* connection;
+DBusConnection *connection;
static char gpsd_devname[BUFSIZ];
-static DBusHandlerResult handle_gps_fix (DBusMessage* message)
+static DBusHandlerResult handle_gps_fix(DBusMessage * message)
{
- DBusError error;
+ DBusError error;
/* this packet format was designed before we split eph */
double eph = EMIX(gpsfix.epx, gpsfix.epy);
- dbus_error_init (&error);
-
- dbus_message_get_args (message,
- &error,
- DBUS_TYPE_DOUBLE, &gpsfix.time,
- DBUS_TYPE_INT32, &gpsfix.mode,
- DBUS_TYPE_DOUBLE, &gpsfix.ept,
- DBUS_TYPE_DOUBLE, &gpsfix.latitude,
- DBUS_TYPE_DOUBLE, &gpsfix.longitude,
- DBUS_TYPE_DOUBLE, &eph,
- DBUS_TYPE_DOUBLE, &gpsfix.altitude,
- DBUS_TYPE_DOUBLE, &gpsfix.epv,
- DBUS_TYPE_DOUBLE, &gpsfix.track,
- DBUS_TYPE_DOUBLE, &gpsfix.epd,
- DBUS_TYPE_DOUBLE, &gpsfix.speed,
- DBUS_TYPE_DOUBLE, &gpsfix.eps,
- DBUS_TYPE_DOUBLE, &gpsfix.climb,
- DBUS_TYPE_DOUBLE, &gpsfix.epc,
- DBUS_TYPE_STRING, &gpsd_devname,
- DBUS_TYPE_INVALID);
+ dbus_error_init(&error);
+
+ dbus_message_get_args(message,
+ &error,
+ DBUS_TYPE_DOUBLE, &gpsfix.time,
+ DBUS_TYPE_INT32, &gpsfix.mode,
+ DBUS_TYPE_DOUBLE, &gpsfix.ept,
+ DBUS_TYPE_DOUBLE, &gpsfix.latitude,
+ DBUS_TYPE_DOUBLE, &gpsfix.longitude,
+ DBUS_TYPE_DOUBLE, &eph,
+ DBUS_TYPE_DOUBLE, &gpsfix.altitude,
+ DBUS_TYPE_DOUBLE, &gpsfix.epv,
+ DBUS_TYPE_DOUBLE, &gpsfix.track,
+ DBUS_TYPE_DOUBLE, &gpsfix.epd,
+ DBUS_TYPE_DOUBLE, &gpsfix.speed,
+ DBUS_TYPE_DOUBLE, &gpsfix.eps,
+ DBUS_TYPE_DOUBLE, &gpsfix.climb,
+ DBUS_TYPE_DOUBLE, &gpsfix.epc,
+ DBUS_TYPE_STRING, &gpsd_devname, DBUS_TYPE_INVALID);
conditionally_log_fix(&gpsfix);
return DBUS_HANDLER_RESULT_HANDLED;
@@ -231,49 +233,52 @@ static DBusHandlerResult handle_gps_fix (DBusMessage* message)
* Message dispatching function
*
*/
-static DBusHandlerResult signal_handler (
- DBusConnection* connection, DBusMessage* message)
+static DBusHandlerResult signal_handler(DBusConnection * connection,
+ DBusMessage * message)
{
/* dummy, need to use the variable for some reason */
connection = NULL;
-
- if (dbus_message_is_signal (message, "org.gpsd", "fix"))
- return handle_gps_fix (message);
+
+ if (dbus_message_is_signal(message, "org.gpsd", "fix"))
+ return handle_gps_fix(message);
/*
* ignore all other messages
*/
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static int dbus_mainloop(void)
{
- GMainLoop* mainloop;
+ GMainLoop *mainloop;
DBusError error;
- mainloop = g_main_loop_new (NULL, FALSE);
+ mainloop = g_main_loop_new(NULL, FALSE);
- dbus_error_init (&error);
- connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
- if (dbus_error_is_set (&error)) {
- syslog (LOG_CRIT, "%s: %s", error.name, error.message);
+ dbus_error_init(&error);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (dbus_error_is_set(&error)) {
+ syslog(LOG_CRIT, "%s: %s", error.name, error.message);
return 3;
}
-
- dbus_bus_add_match (connection, "type='signal'", &error);
- if (dbus_error_is_set (&error)) {
- syslog (LOG_CRIT, "unable to add match for signals %s: %s", error.name, error.message);
+
+ dbus_bus_add_match(connection, "type='signal'", &error);
+ if (dbus_error_is_set(&error)) {
+ syslog(LOG_CRIT, "unable to add match for signals %s: %s", error.name,
+ error.message);
return 4;
}
- if (!dbus_connection_add_filter (connection, (DBusHandleMessageFunction)signal_handler, NULL, NULL)) {
- syslog (LOG_CRIT, "unable to register filter with the connection");
+ if (!dbus_connection_add_filter
+ (connection, (DBusHandleMessageFunction) signal_handler, NULL,
+ NULL)) {
+ syslog(LOG_CRIT, "unable to register filter with the connection");
return 5;
}
-
- dbus_connection_setup_with_g_main (connection, NULL);
- g_main_loop_run (mainloop);
+ dbus_connection_setup_with_g_main(connection, NULL);
+
+ g_main_loop_run(mainloop);
return 0;
}
@@ -288,10 +293,11 @@ static int dbus_mainloop(void)
static struct fixsource_t source;
static void process(struct gps_data_t *gpsdata,
- char *buf UNUSED, size_t len UNUSED)
+ char *buf UNUSED, size_t len UNUSED)
{
/* this is where we implement source-device filtering */
- if (gpsdata->dev.path[0]!='\0' && source.device!=NULL && strcmp(source.device, gpsdata->dev.path) != 0)
+ if (gpsdata->dev.path[0] != '\0' && source.device != NULL
+ && strcmp(source.device, gpsdata->dev.path) != 0)
return;
conditionally_log_fix(&gpsdata->fix);
@@ -314,7 +320,7 @@ static int socket_mainloop(void)
gps_set_raw_hook(gpsdata, process);
(void)gps_stream(gpsdata, WATCH_ENABLE, NULL);
- for(;;) {
+ for (;;) {
int data;
struct timeval tv;
@@ -326,14 +332,14 @@ static int socket_mainloop(void)
data = select(gpsdata->gps_fd + 1, &fds, NULL, NULL, &tv);
if (data == -1) {
- (void)fprintf(stderr,"%s\n", strerror(errno));
+ (void)fprintf(stderr, "%s\n", strerror(errno));
break;
- }
- else if (data)
+ } else if (data)
(void)gps_poll(gpsdata);
}
return 0;
}
+
/*@+mustfreefresh@*/
/**************************************************************************
@@ -342,18 +348,17 @@ static int socket_mainloop(void)
*
**************************************************************************/
-static void usage(void)
+static void usage(void)
{
fprintf(stderr,
"Usage: %s [-V] [-h] [-i timeout] [-j casoc] [server[:port:[device]]]\n",
progname);
fprintf(stderr,
- "\tdefaults to '%s -i 5 -j 0 localhost:2947'\n",
- progname);
+ "\tdefaults to '%s -i 5 -j 0 localhost:2947'\n", progname);
exit(1);
}
-int main (int argc, char** argv)
+int main(int argc, char **argv)
{
int ch;
@@ -367,7 +372,7 @@ int main (int argc, char** argv)
break;
#endif /* CLIENTDEBUG_ENABLE */
case 'i': /* set polling interfal */
- timeout = (time_t)atoi(optarg);
+ timeout = (time_t) atoi(optarg);
if (timeout < 1)
timeout = 1;
if (timeout >= 3600)
@@ -378,7 +383,7 @@ int main (int argc, char** argv)
(void)fprintf(stderr, "gpxlogger revision " REVISION "\n");
exit(0);
default:
- usage();
+ usage();
/* NOTREACHED */
}
}
@@ -402,8 +407,8 @@ int main (int argc, char** argv)
//openlog ("gpxlogger", LOG_PID | LOG_NDELAY , LOG_DAEMON);
//syslog (LOG_INFO, "---------- STARTED ----------");
-
- print_gpx_header ();
+
+ print_gpx_header();
#ifdef DBUS_ENABLE
/* To force socket use in the default way just give a 'localhost' arg */