summaryrefslogtreecommitdiff
path: root/gpsd.c
diff options
context:
space:
mode:
authorChris Kuethe <chris.kuethe@gmail.com>2007-10-17 21:18:08 +0000
committerChris Kuethe <chris.kuethe@gmail.com>2007-10-17 21:18:08 +0000
commitd59c69724fbd2949880f69aae729f437b06fcb7e (patch)
tree4275f916ed4add905cb125142418d996128fa6cf /gpsd.c
parent83957437595c04942835831f2fb61fec4d109e4c (diff)
downloadgpsd-d59c69724fbd2949880f69aae729f437b06fcb7e.tar.gz
Introduce not-very-documented test mode.
Briefly, it causes gpsd to read data from a file, and spew messages to stdout. These could be captured to act as a simpler form of regression test.
Diffstat (limited to 'gpsd.c')
-rw-r--r--gpsd.c63
1 files changed, 48 insertions, 15 deletions
diff --git a/gpsd.c b/gpsd.c
index d754164f..880e671b 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -91,24 +91,25 @@ static bool nowait = false;
static jmp_buf restartbuf;
/*@ -initallelements -nullassign -nullderef @*/
static struct gps_context_t context = {
- .valid = 0,
- .readonly = false,
- .sentdgps = false,
- .dgnss_service = dgnss_none,
- .fixcnt = 0,
- .dsock = -1,
- .dgnss_privdata = NULL,
- .rtcmbytes = 0,
+ .valid = 0,
+ .readonly = false,
+ .testmode = false,
+ .sentdgps = false,
+ .dgnss_service = dgnss_none,
+ .fixcnt = 0,
+ .dsock = -1,
+ .dgnss_privdata = NULL,
+ .rtcmbytes = 0,
.rtcmbuf = {'\0'},
- .rtcmtime = 0,
- .leap_seconds = LEAP_SECONDS,
+ .rtcmtime = 0,
+ .leap_seconds = LEAP_SECONDS,
.century = CENTURY_BASE,
#ifdef NTPSHM_ENABLE
- .enable_ntpshm = false,
+ .enable_ntpshm = false,
.shmTime = {0},
- .shmTimeInuse = {0},
+ .shmTimeInuse = {0},
# ifdef PPS_ENABLE
- .shmTimePPS = false,
+ .shmTimePPS = false,
# endif /* PPS_ENABLE */
#endif /* NTPSHM_ENABLE */
};
@@ -399,6 +400,8 @@ static /*@null@*/ /*@observer@*/ struct subscriber_t* allocate_client(void)
static void detach_client(struct subscriber_t *sub)
{
char *c_ip = sock2ip(sub->fd);
+ if (context.testmode)
+ return;
(void)shutdown(sub->fd, SHUT_RDWR);
(void)close(sub->fd);
gpsd_report(LOG_INF, "detaching %s (sub%d, fd %d) in detach_client\n",
@@ -418,6 +421,11 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, ssize_t len)
{
ssize_t status;
+ if (context.testmode){
+ gpsd_report(LOG_SHOUT, "TEST: %s", buf);
+ return len;
+ }
+
if (debuglevel >= 3) {
if (isprint(buf[0]))
gpsd_report(LOG_IO, "=> client(%d): %s", sub_index(sub), buf);
@@ -447,7 +455,8 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, ssize_t len)
else if (errno == EWOULDBLOCK && timestamp() - sub->active > NOREAD_TIMEOUT)
gpsd_report(LOG_INF, "client(%d) timed out.\n", sub_index(sub));
else
- gpsd_report(LOG_INF, "client(%d) write: %s\n", sub_index(sub), strerror(errno));
+ gpsd_report(LOG_INF, "client(%d) write: %s\n", sub_index(sub),
+ strerror(errno));
detach_client(sub);
return status;
}
@@ -1269,7 +1278,7 @@ int main(int argc, char *argv[])
(void)setlocale(LC_NUMERIC, "C");
#endif
debuglevel = 0;
- while ((option = getopt(argc, argv, "F:D:S:bhNnP:V"
+ while ((option = getopt(argc, argv, "F:D:S:bhNnP:VT"
#ifdef RTCM104_SERVICE
"R:"
#endif /* RTCM104_SERVICE */
@@ -1301,6 +1310,11 @@ int main(int argc, char *argv[])
case 'P':
pid_file = optarg;
break;
+ case 'T':
+ nowait = true;
+ go_background = false;
+ context.testmode = true;
+ break;
case 'V':
(void)printf("gpsd %s\n", VERSION);
exit(0);
@@ -1641,6 +1655,8 @@ int main(int argc, char *argv[])
adjust_max_fd(channel->gpsdata.gps_fd, false);
gpsd_deactivate(channel);
notify_watchers(channel, "GPSD,X=0\r\n");
+ if (context.testmode)
+ exit(0);
}
else {
/* handle laggy response to a firmware version query*/
@@ -1673,6 +1689,12 @@ int main(int argc, char *argv[])
&sub->fixbuffer, &sub->oldfix);
}
}
+ if (context.testmode && sub->device){
+ gps_merge_fix(&sub->fixbuffer, changed,
+ &sub->device->gpsdata.fix);
+ gpsd_error_model(sub->device, &sub->fixbuffer,
+ &sub->oldfix);
+ }
}
#ifdef RTCM104_SERVICE
/* copy each RTCM-104 correction to all GPSes */
@@ -1701,6 +1723,17 @@ int main(int argc, char *argv[])
(void)handle_gpsd_request(sub, cmds, (int)strlen(cmds));
}
}
+ if (context.testmode){
+ char cmds[4] = "";
+ if (changed &~ ONLINE_SET) {
+ if (changed & (LATLON_SET | MODE_SET))
+ (void)strlcat(cmds, "o", 4);
+ if (changed & SATELLITE_SET)
+ (void)strlcat(cmds, "y", 4);
+ }
+ if (cmds[0] != '\0')
+ (void)handle_gpsd_request(sub, cmds, (int)strlen(cmds));
+ }
#ifdef DBUS_ENABLE
if (changed &~ ONLINE_SET) {
if (changed & (LATLON_SET | MODE_SET))