diff --git a/hc_http.c b/hc_http.c index 7709a11..632509a 100644 --- a/hc_http.c +++ b/hc_http.c @@ -282,13 +282,13 @@ static void hc_background (int fd, int mode) { if (nmea_db->fix && nmea_db->gpsdate[0] && nmea_db->gpstime[0]) { if (!GpsTimeLock) { houselog_event - ("GPS", houselog_host(), "ACQUIRED", "CLOCK %s %s", nmea_db->gpsdate, nmea_db->gpstime); + ("GPS", nmea_db->gpsdevice, "ACQUIRED", "CLOCK %s %s", nmea_db->gpsdate, nmea_db->gpstime); GpsTimeLock = 1; } } else { if (GpsTimeLock) { houselog_event - ("GPS", houselog_host(), "LOST", "CLOCK"); + ("GPS", nmea_db->gpsdevice, "LOST", "CLOCK"); GpsTimeLock = 0; } } diff --git a/hc_nmea.c b/hc_nmea.c index 55ac175..bece3ae 100644 --- a/hc_nmea.c +++ b/hc_nmea.c @@ -182,6 +182,7 @@ static void hc_nmea_reset (void) { gpsCount = 0; hc_nmea_status_db->fix = 0; hc_nmea_status_db->fixtime = 0; + hc_nmea_status_db->gpsdevice[0] = 0; hc_nmea_status_db->gpsdate[0] = 0; hc_nmea_status_db->gpstime[0] = 0; hc_nmea_status_db->latitude[0] = 0; @@ -225,12 +226,7 @@ void hc_nmea_initialize (int argc, const char **argv) { } hc_nmea_reset(); - gpsTty = open(gpsDevice, O_RDONLY); - - // Remove echo of characters from the GPS device. - if (gpsTty >= 0) { - hc_tty_set (gpsTty, gpsSpeed); - } + hc_nmea_listen (); gpsInitialized = time(0); } @@ -605,6 +601,20 @@ void hc_nmea_periodic (const struct timeval *now) { } int hc_nmea_listen (void) { + if (gpsTty >= 0) return gpsTty; + + static time_t LastTry = 0; + time_t now = time(0); + if (now < LastTry + 5) return gpsTty; + + LastTry = now; + gpsTty = open(gpsDevice, O_RDONLY); + if (gpsTty < 0) return gpsTty; + + // Remove echo of characters from the GPS device. + hc_tty_set (gpsTty, gpsSpeed); + snprintf (hc_nmea_status_db->gpsdevice, + sizeof(hc_nmea_status_db->gpsdevice), "%s", gpsDevice); return gpsTty; } diff --git a/hc_nmea.h b/hc_nmea.h index 4d112fd..5ec1610 100644 --- a/hc_nmea.h +++ b/hc_nmea.h @@ -44,6 +44,7 @@ typedef struct { typedef struct { char fix; time_t fixtime; + char gpsdevice[80]; char gpstime[20]; char gpsdate[20]; char latitude[20];