|
14 | 14 | */
|
15 | 15 | #include "ws_sdcard.h"
|
16 | 16 |
|
17 |
| -/**************************************************************************/ |
18 | 17 | /*!
|
19 | 18 | @brief Initializes the SD card.
|
20 | 19 | @param pin_cs
|
21 | 20 | The chip select pin for the SD card.
|
22 | 21 | @returns True if the SD card was successfully initialized, False
|
23 | 22 | otherwise.
|
24 | 23 | */
|
25 |
| -/**************************************************************************/ |
26 | 24 | bool ws_sdcard::InitSdCard(uint8_t pin_cs) {
|
27 | 25 | WsV2.pin_sd_cs = pin_cs;
|
28 | 26 | #ifdef SD_USE_SPI_1
|
@@ -1310,14 +1308,12 @@ bool ws_sdcard::LogDS18xSensorEventToSD(
|
1310 | 1308 | return true;
|
1311 | 1309 | }
|
1312 | 1310 |
|
1313 |
| -/**************************************************************************/ |
1314 | 1311 | /*!
|
1315 | 1312 | @brief Logs an I2C sensor event to the SD card.
|
1316 | 1313 | @param msg_device_event
|
1317 | 1314 | The I2cDeviceEvent message to log.
|
1318 | 1315 | @returns True if the event was successfully logged, False otherwise.
|
1319 | 1316 | */
|
1320 |
| -/**************************************************************************/ |
1321 | 1317 | bool ws_sdcard::LogI2cDeviceEvent(
|
1322 | 1318 | wippersnapper_i2c_I2cDeviceEvent *msg_device_event) {
|
1323 | 1319 | JsonDocument doc;
|
@@ -1347,14 +1343,70 @@ bool ws_sdcard::LogI2cDeviceEvent(
|
1347 | 1343 | return true;
|
1348 | 1344 | }
|
1349 | 1345 |
|
| 1346 | +/*! |
| 1347 | + @brief Logs a GPS event to the SD card. |
| 1348 | + @param msg_gps_event |
| 1349 | + The GPSEvent message to log. |
| 1350 | + @returns True if the event was successfully logged, False otherwise. |
| 1351 | +*/ |
| 1352 | +bool ws_sdcard::LogGPSEventToSD(wippersnapper_gps_GPSEvent *msg_gps_event) { |
| 1353 | + JsonDocument doc; |
| 1354 | + |
| 1355 | + // Log RMC responses |
| 1356 | + for (pb_size_t rmc_resp = 0; rmc_resp < msg_gps_event->rmc_responses_count; rmc_resp++) { |
| 1357 | + WS_DEBUG_PRINTLN("[SD] Logging RMC response..."); |
| 1358 | + // Log GPS DateTime |
| 1359 | + if (msg_gps_event->rmc_responses[rmc_resp].has_datetime) { |
| 1360 | + wippersnapper_gps_GPSDateTime gps_dt = msg_gps_event->rmc_responses[rmc_resp].datetime; |
| 1361 | + DateTime gps_datetime(gps_dt.year, gps_dt.month, gps_dt.day, |
| 1362 | + gps_dt.hour, gps_dt.minute, gps_dt.seconds); |
| 1363 | + doc["timestamp"] = gps_datetime.unixtime(); |
| 1364 | + } |
| 1365 | + // Log GPS data |
| 1366 | + doc["fix_status"] = msg_gps_event->rmc_responses[rmc_resp].fix_status; |
| 1367 | + doc["latitude"] = msg_gps_event->rmc_responses[rmc_resp].lat; |
| 1368 | + doc["lat_dir"] = msg_gps_event->rmc_responses[rmc_resp].lat_dir; |
| 1369 | + doc["longitude"] = msg_gps_event->rmc_responses[rmc_resp].lon; |
| 1370 | + doc["lon_dir"] = msg_gps_event->rmc_responses[rmc_resp].lon_dir; |
| 1371 | + doc["speed"] = msg_gps_event->rmc_responses[rmc_resp].speed; |
| 1372 | + doc["angle"] = msg_gps_event->rmc_responses[rmc_resp].angle; |
| 1373 | + if (!LogJSONDoc(doc)) |
| 1374 | + return false; |
| 1375 | + } |
| 1376 | + |
| 1377 | + // Log GGA responses |
| 1378 | + for (pb_size_t gga_resp = 0; gga_resp < msg_gps_event->gga_responses_count; gga_resp++) { |
| 1379 | + WS_DEBUG_PRINTLN("[SD] Logging GGA response..."); |
| 1380 | + // Log GPS DateTime |
| 1381 | + if (msg_gps_event->gga_responses[gga_resp].has_datetime) { |
| 1382 | + wippersnapper_gps_GPSDateTime gps_dt = msg_gps_event->gga_responses[gga_resp].datetime; |
| 1383 | + DateTime gps_datetime(gps_dt.year, gps_dt.month, gps_dt.day, |
| 1384 | + gps_dt.hour, gps_dt.minute, gps_dt.seconds); |
| 1385 | + doc["timestamp"] = gps_datetime.unixtime(); |
| 1386 | + } |
| 1387 | + // Log GPS data |
| 1388 | + doc["latitude"] = msg_gps_event->gga_responses[gga_resp].lat; |
| 1389 | + doc["lat_dir"] = msg_gps_event->gga_responses[gga_resp].lat_dir; |
| 1390 | + doc["longitude"] = msg_gps_event->gga_responses[gga_resp].lon; |
| 1391 | + doc["lon_dir"] = msg_gps_event->gga_responses[gga_resp].lon_dir; |
| 1392 | + doc["fix_quality"] = msg_gps_event->gga_responses[gga_resp].fix_quality; |
| 1393 | + doc["num_satellites"] = msg_gps_event->gga_responses[gga_resp].num_satellites; |
| 1394 | + doc["hdop"] = msg_gps_event->gga_responses[gga_resp].hdop; |
| 1395 | + doc["altitude"] = msg_gps_event->gga_responses[gga_resp].altitude; |
| 1396 | + doc["geoid_height"] = msg_gps_event->gga_responses[gga_resp].geoid_height; |
| 1397 | + if (!LogJSONDoc(doc)) |
| 1398 | + return false; |
| 1399 | + } |
| 1400 | + |
| 1401 | + return true; |
| 1402 | +} |
| 1403 | + |
1350 | 1404 | #ifdef OFFLINE_MODE_DEBUG
|
1351 |
| -/**************************************************************************/ |
1352 | 1405 | /*!
|
1353 | 1406 | @brief Waits for a valid JSON string to be received via the hardware's
|
1354 | 1407 | serial input or from a hardcoded test JSON string.
|
1355 | 1408 | @returns True if a valid JSON string was received, False otherwise.
|
1356 | 1409 | */
|
1357 |
| -/**************************************************************************/ |
1358 | 1410 | void ws_sdcard::waitForSerialConfig() {
|
1359 | 1411 | json_test_data = "{"
|
1360 | 1412 | "\"exportVersion\": \"1.0.0\","
|
|
0 commit comments