Skip to content

Commit a6140ea

Browse files
Periodically try to reopen if GPS disconnected
1 parent ee3eaf6 commit a6140ea

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Diff for: hc_http.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ static void hc_background (int fd, int mode) {
282282
if (nmea_db->fix && nmea_db->gpsdate[0] && nmea_db->gpstime[0]) {
283283
if (!GpsTimeLock) {
284284
houselog_event
285-
("GPS", houselog_host(), "ACQUIRED", "CLOCK %s %s", nmea_db->gpsdate, nmea_db->gpstime);
285+
("GPS", nmea_db->gpsdevice, "ACQUIRED", "CLOCK %s %s", nmea_db->gpsdate, nmea_db->gpstime);
286286
GpsTimeLock = 1;
287287
}
288288
} else {
289289
if (GpsTimeLock) {
290290
houselog_event
291-
("GPS", houselog_host(), "LOST", "CLOCK");
291+
("GPS", nmea_db->gpsdevice, "LOST", "CLOCK");
292292
GpsTimeLock = 0;
293293
}
294294
}

Diff for: hc_nmea.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static void hc_nmea_reset (void) {
182182
gpsCount = 0;
183183
hc_nmea_status_db->fix = 0;
184184
hc_nmea_status_db->fixtime = 0;
185+
hc_nmea_status_db->gpsdevice[0] = 0;
185186
hc_nmea_status_db->gpsdate[0] = 0;
186187
hc_nmea_status_db->gpstime[0] = 0;
187188
hc_nmea_status_db->latitude[0] = 0;
@@ -225,12 +226,7 @@ void hc_nmea_initialize (int argc, const char **argv) {
225226
}
226227

227228
hc_nmea_reset();
228-
gpsTty = open(gpsDevice, O_RDONLY);
229-
230-
// Remove echo of characters from the GPS device.
231-
if (gpsTty >= 0) {
232-
hc_tty_set (gpsTty, gpsSpeed);
233-
}
229+
hc_nmea_listen ();
234230

235231
gpsInitialized = time(0);
236232
}
@@ -605,6 +601,20 @@ void hc_nmea_periodic (const struct timeval *now) {
605601
}
606602

607603
int hc_nmea_listen (void) {
604+
if (gpsTty >= 0) return gpsTty;
605+
606+
static time_t LastTry = 0;
607+
time_t now = time(0);
608+
if (now < LastTry + 5) return gpsTty;
609+
610+
LastTry = now;
611+
gpsTty = open(gpsDevice, O_RDONLY);
612+
if (gpsTty < 0) return gpsTty;
613+
614+
// Remove echo of characters from the GPS device.
615+
hc_tty_set (gpsTty, gpsSpeed);
616+
snprintf (hc_nmea_status_db->gpsdevice,
617+
sizeof(hc_nmea_status_db->gpsdevice), "%s", gpsDevice);
608618
return gpsTty;
609619
}
610620

Diff for: hc_nmea.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef struct {
4444
typedef struct {
4545
char fix;
4646
time_t fixtime;
47+
char gpsdevice[80];
4748
char gpstime[20];
4849
char gpsdate[20];
4950
char latitude[20];

0 commit comments

Comments
 (0)