Skip to content

Commit

Permalink
refactored breadcrumb trail dumpHistoryGPS()
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-ha committed Apr 2, 2023
1 parent af625e9 commit 0dcbeca
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 80 deletions.
7 changes: 3 additions & 4 deletions Griduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,9 @@ void loop() {
waitingForRTC = false;

char msg[128]; // debug
Serial.println("Received first valid date/time from GPS"); // debug
snprintf(msg, sizeof(msg), ". GPS time %d-%02d-%02d at %02d:%02d:%02d",
GPS.year,GPS.month,GPS.day,
GPS.hour,GPS.minute,GPS.seconds);
snprintf(msg, sizeof(msg), "Received first valid GPS time: %d-%02d-%02d at %02d:%02d:%02d",
GPS.year,GPS.month,GPS.day,
GPS.hour,GPS.minute,GPS.seconds);
Serial.println(msg); // debug

// write this to the GPS breadcrumb trail as indication of "power up" event
Expand Down
2 changes: 1 addition & 1 deletion commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void dump_kml() {
}

void dump_gps_history() {
model->dumpHistoryGPS();
trail.dumpHistoryGPS();
}

void erase_gps_history() {
Expand Down
72 changes: 67 additions & 5 deletions model_breadcrumbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
*/

// #include <Arduino.h> //
// #include <Adafruit_GPS.h> // "Ultimate GPS" library
// #include "constants.h" // Griduino constants, colors, typedefs
// #include "hardware.h" //
#include "logger.h" // conditional printing to Serial port
#include "grid_helper.h" // lat/long conversion routines
#include "date_helper.h" // date/time conversions
#include "save_restore.h" // Configuration data in nonvolatile RAM

// ========== extern ===========================================
// extern Adafruit_GPS GPS; // Griduino.ino
extern Logger logger; // Griduino.ino
extern Grids grid; // grid_helper.h
extern Dates date; // date_helper.h
Expand Down Expand Up @@ -82,7 +78,7 @@ class Breadcrumbs {

int saveGPSBreadcrumbTrail() { // returns 1=success, 0=failure
// our breadcrumb trail file is CSV format -- you can open this Arduino file directly in a spreadsheet
// dumpHistoryGPS(); // debug
// trail.dumpHistoryGPS(); // debug

// delete old file and open new file
SaveRestoreStrings config(HISTORY_FILE, HISTORY_VERSION);
Expand Down Expand Up @@ -295,4 +291,70 @@ class Breadcrumbs {
Serial.println("Breadcrumb trail has been erased");
}

void dumpHistoryGPS() {
Serial.print("\nMaximum saved GPS records = ");
Serial.println(numHistory);

Serial.print("Current number of records saved = ");
int count = getHistoryCount();
Serial.println(count);

Serial.print("Next record to be written = ");
Serial.println(nextHistoryItem);

time_t tm = now(); // debug: show current time in seconds
Serial.print("now() = "); // debug
Serial.print(tm); // debug
Serial.println(" seconds since 1-1-1970"); // debug

char sDate[24]; // debug: show current time decoded
date.datetimeToString(sDate, sizeof(sDate), tm); // date_helper.h
char msg[40]; // sizeof("Today is 12-31-2022 12:34:56 GMT") = 32
snprintf(msg, sizeof(msg), "now() = %s GMT", sDate); // debug
Serial.println(msg); // debug

Serial.println("Record, Date GMT, Time GMT, Grid, Lat, Long, Alt(m), Speed(mph), Direction(Degrees), Sats");
int ii;
for (ii = 0; ii < numHistory; ii++) {
Location item = history[ii];
if (!item.isEmpty()) {

time_t tm = item.timestamp; // https://github.com/PaulStoffregen/Time
char sDate[12], sTime[10]; // sizeof("2022-11-25 12:34:56") = 19
date.dateToString(sDate, sizeof(sDate), tm); // date_helper.h
date.timeToString(sTime, sizeof(sTime), tm); //

char grid6[7];
grid.calcLocator(grid6, item.loc.lat, item.loc.lng, 6);

char sLat[12], sLng[12];
floatToCharArray(sLat, sizeof(sLat), history[ii].loc.lat, 5);
floatToCharArray(sLng, sizeof(sLng), history[ii].loc.lng, 5);

char sSpeed[12], sDirection[12], sAltitude[12];
floatToCharArray(sSpeed, sizeof(sSpeed), item.speed, 1);
floatToCharArray(sDirection, sizeof(sDirection), item.direction, 1);
floatToCharArray(sAltitude, sizeof(sAltitude), item.altitude, 0);
uint8_t nSats = item.numSatellites;

char out[128];
snprintf(out, sizeof(out), "%d, %s, %s, %s, %s, %s, %s, %s, %s, %d",
ii, sDate, sTime, grid6, sLat, sLng, sSpeed, sDirection, sAltitude, nSats);
Serial.println(out);

// TimeElements time; // https://github.com/PaulStoffregen/Time
// breakTime(item.timestamp, time); // debug
// snprintf(out, sizeof(out), "item.timestamp = %02d-%02d-%04d %02d:%02d:%02d",
// time.Month, time.Day, 1970+time.Year, time.Hour, time.Minute, time.Second);
// Serial.println(out); // debug
}
}
int remaining = numHistory - ii;
if (remaining > 0) {
Serial.print("... and ");
Serial.print(remaining);
Serial.println(" more");
}
}

}; // end class History
70 changes: 2 additions & 68 deletions model_gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,72 +337,6 @@ class Model {
Serial.println(KML_SUFFIX); // end KML file
}

void dumpHistoryGPS() {
Serial.print("\nMaximum saved GPS records = ");
Serial.println(trail.numHistory);

Serial.print("Current number of records saved = ");
int count = trail.getHistoryCount();
Serial.println(count);

Serial.print("Next record to be written = ");
Serial.println(trail.nextHistoryItem);

time_t tm = now(); // debug: show current time in seconds
Serial.print("now() = "); // debug
Serial.print(tm); // debug
Serial.println(" seconds since 1-1-1970"); // debug

char sDate[24]; // debug: show current time decoded
date.datetimeToString(sDate, sizeof(sDate), tm); // date_helper.h
char msg[40]; // sizeof("Today is 12-31-2022 12:34:56 GMT") = 32
snprintf(msg, sizeof(msg), "now() = %s GMT", sDate); // debug
Serial.println(msg); // debug

Serial.println("Record, Date GMT, Time GMT, Grid, Lat, Long, Alt(m), Speed(mph), Direction(Degrees), Sats");
int ii;
for (ii = 0; ii < trail.numHistory; ii++) {
Location item = trail.history[ii];
if (!item.isEmpty()) {

time_t tm = item.timestamp; // https://github.com/PaulStoffregen/Time
char sDate[12], sTime[10]; // sizeof("2022-11-25 12:34:56") = 19
date.dateToString(sDate, sizeof(sDate), tm); // date_helper.h
date.timeToString(sTime, sizeof(sTime), tm); //

char grid6[7];
grid.calcLocator(grid6, item.loc.lat, item.loc.lng, 6);

char sLat[12], sLng[12];
floatToCharArray(sLat, sizeof(sLat), trail.history[ii].loc.lat, 5);
floatToCharArray(sLng, sizeof(sLng), trail.history[ii].loc.lng, 5);

char sSpeed[12], sDirection[12], sAltitude[12];
floatToCharArray(sSpeed, sizeof(sSpeed), item.speed, 1);
floatToCharArray(sDirection, sizeof(sDirection), item.direction, 1);
floatToCharArray(sAltitude, sizeof(sAltitude), item.altitude, 0);
uint8_t nSats = item.numSatellites;

char out[128];
snprintf(out, sizeof(out), "%d, %s, %s, %s, %s, %s, %s, %s, %s, %d",
ii, sDate, sTime, grid6, sLat, sLng, sSpeed, sDirection, sAltitude, nSats);
Serial.println(out);

// TimeElements time; // https://github.com/PaulStoffregen/Time
// breakTime(item.timestamp, time); // debug
// snprintf(out, sizeof(out), "item.timestamp = %02d-%02d-%04d %02d:%02d:%02d",
// time.Month, time.Day, 1970+time.Year, time.Hour, time.Minute, time.Second);
// Serial.println(out); // debug
}
}
int remaining = trail.numHistory - ii;
if (remaining > 0) {
Serial.print("... and ");
Serial.print(remaining);
Serial.println(" more");
}
}

// grid-crossing detector
bool enteredNewGrid() {
if (compare4digits) {
Expand Down Expand Up @@ -495,7 +429,7 @@ class Model {
}

// Provide formatted GMT date/time "2019-12-31 10:11:12"
void getDateTime(char *result) {
void getCurrentDateTime(char *result) {
// input: result = char[25] = string buffer to modify
int yy = GPS.year;
if (yy >= 19) {
Expand Down Expand Up @@ -557,7 +491,7 @@ class Model {
#ifdef ECHO_GPS
// send GPS statistics to serial console for desktop debugging
char sDate[20]; // strlen("0000-00-00 hh:mm:ss") = 19
getDateTime(sDate);
getCurrentDateTime(sDate);
Serial.print("Model: ");
Serial.print(sDate);
Serial.print(" Fix(");
Expand Down
4 changes: 2 additions & 2 deletions unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ int verifyBreadCrumbs() {
gridView.updateScreen();
delay(500);
trail.saveInterval = 2; // restore setting
return fails; //
return fails; //
}
// =============================================================
// verify painting a trail of bread crumbs (locations)
Expand Down Expand Up @@ -598,7 +598,7 @@ int verifyBreadCrumbTrail2() {
generateSineWave(model); // fill GPS model with known test data

Serial.println(". History as known by verifyBreadCrumbTrail2()...");
model->dumpHistoryGPS(); // did it remember? (go review serial console)
trail.dumpHistoryGPS(); // did it remember? (go review serial console)
gridView.updateScreen(); // does it look like a sine wave? (go look at TFT display)
return r;
}
Expand Down

0 comments on commit 0dcbeca

Please sign in to comment.