Skip to content

Commit cf052ac

Browse files
committed
GPS - Add support for GPS location in the logfile as a timestamp, #699
1 parent 4756622 commit cf052ac

File tree

9 files changed

+49
-12
lines changed

9 files changed

+49
-12
lines changed

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ lib_deps =
9898
https://github.com/bblanchon/ArduinoStreamUtils.git
9999
https://github.com/Sensirion/arduino-i2c-scd4x.git
100100
adafruit/Adafruit GPS Library
101+
adafruit/Adafruit uBlox
101102

102103
; Common build environment for ESP32 platform
103104
[common:esp32]

src/Wippersnapper_V2.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
*/
3131
#ifdef WS_DEBUG
3232
#define WS_DEBUG_PRINT(...) \
33-
{ WS_PRINTER.print(__VA_ARGS__); } /**< Print debug message to serial */
33+
{ \
34+
WS_PRINTER.print(__VA_ARGS__); \
35+
} /**< Print debug message to serial */
3436
#define WS_DEBUG_PRINTLN(...) \
3537
{ \
3638
WS_PRINTER.println(__VA_ARGS__); \
@@ -42,9 +44,11 @@
4244
} /**< Print debug message in hexadecimal */
4345
#else
4446
#define WS_DEBUG_PRINT(...) \
45-
{} /**< Debug print */
47+
{ \
48+
} /**< Debug print */
4649
#define WS_DEBUG_PRINTLN(...) \
47-
{} /**< Debug println */
50+
{ \
51+
} /**< Debug println */
4852
#endif
4953

5054
/*!
@@ -83,6 +87,7 @@
8387
#include "Adafruit_MQTT.h" // MQTT Client
8488
#include "Adafruit_SleepyDog.h" // Watchdog
8589
#include "Arduino.h" // Wiring
90+
#include "RTClib.h" // RTC
8691
#include <SPI.h> // SPI
8792
#include <Wire.h> // I2C
8893

src/Wippersnapper_demo.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
// All text above must be included in any redistribution.
1111

1212
#include "ws_adapters.h"
13-
//ws_adapter_wifi wipper;
14-
ws_adapter_offline wipper;
13+
ws_adapter_wifi wipper;
1514
#define WS_DEBUG // Enable debug output!
1615

1716
void setup() {

src/components/gps/controller.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
/*!
1919
* @brief Constructor for GPSController.
2020
*/
21-
GPSController::GPSController() { _gps_model = new GPSModel(); }
21+
GPSController::GPSController() {
22+
_gps_model = new GPSModel();
23+
has_gps = false;
24+
}
2225

2326
/*!
2427
* @brief Destructor for GPSController.
@@ -29,6 +32,7 @@ GPSController::~GPSController() {
2932
delete _gps_model;
3033
_gps_model = nullptr;
3134
}
35+
has_gps = false;
3236
}
3337

3438
/*!
@@ -63,6 +67,7 @@ bool GPSController::AddGPS(TwoWire *wire, uint32_t i2c_addr,
6367

6468
_gps_drivers.push_back(gps_hw);
6569
WS_DEBUG_PRINTLN("[gps] GPS hardware added successfully!");
70+
has_gps = true;
6671
return true;
6772
}
6873

@@ -98,9 +103,18 @@ bool GPSController::AddGPS(HardwareSerial *serial, uint32_t baudrate,
98103

99104
_gps_drivers.push_back(gps_hw);
100105
WS_DEBUG_PRINTLN("[gps] GPS hardware added successfully!");
106+
has_gps = true;
101107
return true;
102108
}
103109

110+
/*!
111+
* @brief Gets the current GPS datetime.
112+
* @return The current GPS datetime.
113+
*/
114+
DateTime GPSController::GetGPSDateTime() {
115+
return _gps_model->GetPrvGPSDateTime();
116+
}
117+
104118
/*!
105119
* @brief Updates the GPSController, polling the GPS hardware for data.
106120
* This function checks if the read period has elapsed and processes the GPS
@@ -165,6 +179,7 @@ void GPSController::update() {
165179
WS_DEBUG_PRINTLN("...ok!");
166180
}
167181
} else {
182+
// Set the Datetime for the GPSEvent
168183
// Log the GPSEvent to SD card
169184
if (!WsV2._sdCardV2->LogEventGps(_gps_model->GetGPSEvent())) {
170185
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to log GPSEvent!");

src/components/gps/controller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class GPSController {
3636
bool AddGPS(TwoWire *wire, uint32_t i2c_addr,
3737
wippersnapper_gps_GPSConfig *gps_config);
3838
void update();
39+
bool has_gps;
40+
DateTime GetGPSDateTime();
3941

4042
private:
4143
GPSModel *_gps_model; ///< GPS model instance

src/components/gps/model.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,37 @@ bool GPSModel::AddGpsEventGGA(wippersnapper_gps_GPSDateTime datetime,
195195
return true;
196196
}
197197

198+
/*!
199+
* @brief Returns the previous GPS datetime as a DateTime object.
200+
* @returns A DateTime object representing the previous GPS datetime.
201+
*/
202+
DateTime GPSModel::GetPrvGPSDateTime() {
203+
// Create a DateTime object from the previous GPS datetime
204+
return DateTime(_prv_msg_gps_datetime.year, _prv_msg_gps_datetime.month,
205+
_prv_msg_gps_datetime.day, _prv_msg_gps_datetime.hour,
206+
_prv_msg_gps_datetime.minute, _prv_msg_gps_datetime.seconds);
207+
}
208+
198209
bool GPSModel::ProcessNMEASentence(char *sentence, GPSHardware *drv) {
199210
// Check for prefix: $GP or $GN
200211
if (strncmp(sentence, "$GP", 3) != 0 && strncmp(sentence, "$GN", 3) != 0)
201212
return false;
202213

203-
wippersnapper_gps_GPSDateTime datetime = CreateGpsDatetime(
214+
_prv_msg_gps_datetime = CreateGpsDatetime(
204215
drv->GetHour(), drv->GetMinute(), drv->GetSeconds(),
205216
drv->GetMilliseconds(), drv->GetDay(), drv->GetMonth(), drv->GetYear());
206217
char lat_dir = drv->GetLatDir();
207218
char lon_dir = drv->GetLonDir();
208219
if (sentence[3] == 'R' && sentence[4] == 'M' && sentence[5] == 'C') {
209220
// Process RMC sentence
210-
if (!AddGpsEventRMC(datetime, drv->GetFix(), drv->GetLat(), &lat_dir,
211-
drv->GetLon(), &lon_dir, drv->GetSpeed(),
221+
if (!AddGpsEventRMC(_prv_msg_gps_datetime, drv->GetFix(), drv->GetLat(),
222+
&lat_dir, drv->GetLon(), &lon_dir, drv->GetSpeed(),
212223
drv->GetAngle()))
213224
return false;
214225
} else if (sentence[3] == 'G' && sentence[4] == 'G' && sentence[5] == 'A') {
215226
// Process GGA sentence
216-
if (!AddGpsEventGGA(datetime, drv->GetFix(), drv->GetLat(), &lat_dir,
217-
drv->GetLon(), &lon_dir, drv->GetNumSats(),
227+
if (!AddGpsEventGGA(_prv_msg_gps_datetime, drv->GetFix(), drv->GetLat(),
228+
&lat_dir, drv->GetLon(), &lon_dir, drv->GetNumSats(),
218229
drv->GetHDOP(), drv->GetAltitude(),
219230
drv->GetGeoidHeight()))
220231
return false;

src/components/gps/model.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ class GPSModel {
4848
uint8_t fix_status, float lat, char *lat_dir, float lon,
4949
char *lon_dir, uint8_t num_sats, float hdop, float alt,
5050
float geoid_height);
51+
DateTime GetPrvGPSDateTime();
5152

5253
private:
5354
wippersnapper_gps_GPSConfig _msg_gps_config; ///< GPS configuration message
5455
wippersnapper_gps_GPSEvent _msg_gps_event; ///< GPS event message
56+
wippersnapper_gps_GPSDateTime
57+
_prv_msg_gps_datetime; ///< Previous GPS datetime
5558
};
5659
#endif // WS_GPS_MODEL_H

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ uint32_t ws_sdcard::GetTimestamp() {
10211021
TickSoftRTC();
10221022
return cur_time; // early-return as we are not converting this "soft rtc" to
10231023
// unixtime
1024+
} else if (WsV2._gps_controller->has_gps) {
1025+
now = WsV2._gps_controller->GetGPSDateTime();
10241026
} else { // we're either using a simulator or have undefined behavior
10251027
return 0;
10261028
}

src/provisioning/sdcard/ws_sdcard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
#ifndef WS_SDCARD_H
1616
#define WS_SDCARD_H
17-
#include "RTClib.h"
1817
#include "SdFat_Adafruit_Fork.h"
1918
#include "StreamUtils.h"
2019
#include "Wippersnapper_V2.h"

0 commit comments

Comments
 (0)