Skip to content

Commit 0544d80

Browse files
authored
Remove GPS wait options / Use GPS time as system time
- Remove options for various GPS fix status waits, closes #251 - remove GPS Fix option from all places - recheck time set function followup to #242 - collect (GPS) statistic information when setting system time - use GPS time not UTC time - information TimeZone GPS in header of CSV - refresh "wait for GPS" startup messages displayed - introduce timeutils and move time related methods from gps and obsutils to timeutils - distinguish if time was set via ntp (UTC) or gps (GPS)
1 parent e7c4d9d commit 0544d80

File tree

16 files changed

+429
-313
lines changed

16 files changed

+429
-313
lines changed

docs/software/firmware/csv_format.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ understand.
3939
| `PresetId` | `Wade` | Id to identify the selected preset. A owner might define multiple presets |
4040
| `BluetoothEnabled` | `1` | 1 if bluetooth is enabled, 0 otherwise
4141
| `TrackId` | `38605ba-76...` | A uuid that can be used to uniquely identify the track.
42+
| `TimeZone` | `GPS` | The time zone used to write Date and Time data. Typically this is GPS which is some leap seconds ahead of UTC (as of today 18). UTC is also a allowed value and the default if not TimeZone is given.
4243

4344
## CSV
4445

@@ -82,12 +83,12 @@ Based on http://dataprotocols.org/csv-dialect/ the definition is:
8283

8384
Headline | Format | Range | Sample | Description |
8485
--- | --- | --- | --- | --- |
85-
`Date` | TT.MM.YYYY | | 24.11.2020 | UTC, typically as received by the GPS module in that second. If there is no GPS module present, system time is used. If there was no reception of a time signal yet, this might be unix time (starting 1.1.1970) which can be used as offset between the csv lines. Expect none linearity when time is set.
86-
`Time` | HH:MM:SS | | 12:00:00 | UTC time, see also above
86+
`Date` | TT.MM.YYYY | | 24.11.2020 | Time, typically as received by the GPS module. If there was no reception of a time signal yet, this might be unix time (starting 1.1.1970) which can be used as offset between the csv lines. Expect none linearity when time is set.
87+
`Time` | HH:MM:SS | | 12:00:00 | TimeZone is GPS or UTC according to the TimeZone metadata.
8788
`Millis` | int32 | 0-2^31 | 1234567 | Millisecond counter will continuously increase throughout the file, for time difference calculation
8889
`Comment` | char[] | | | Space to leave a short text comment
89-
`Latitude` | double | -90.0-90.0 | 9.123456 | Latitude as degrees
90-
`Longitude` | double | -180.0-180.0 | 42.123456 | Longitude in degrees
90+
`Latitude` | double | -90.0-90.0 | 42.123456 | Latitude as degrees
91+
`Longitude` | double | -180.0-180.0 | 9.123456 | Longitude in degrees
9192
`Altitude` | double | -9999.9-17999.9 | 480.12 | meters above mean sea level (GPGGA)
9293
`Course` | double | 0-359.9 | 42 | Course over ground in degrees (GPRMC)
9394
`Speed` | double | 0-359.9 | 42.0 | Speed over ground in km/h

docs/software/firmware/obs_cfg.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ relevant put the order of the array content.
3737
// Bitfield display config, see DisplayOptions for details,
3838
// as noted all subject to change!
3939
"displayConfig": 15,
40-
// For what GPS fix should the OBS wait at startup?
41-
// -2: FIX POS; -1: Time only; 0: No wait
42-
"gpsFix": -2,
4340
// PIN to be entered when accessing the OBS web interface.
4441
// a new one will be created when empty. The PIN is also displayed
4542
// on the OBS display when needed.

src/OpenBikeSensorFirmware.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ void setup() {
325325
gps.handle();
326326
gps.setStatisticsIntervalInSeconds(1); // get regular updates.
327327

328-
int gpsWaitFor = cfg.getProperty<int>(ObsConfig::PROPERTY_GPS_FIX);
329-
while (!gps.hasState(gpsWaitFor, displayTest)) {
328+
while (!gps.hasFix(displayTest)) {
330329
currentTimeMillis = millis();
331330
gps.handle();
332331
sensorManager->getDistances();
@@ -345,9 +344,9 @@ void setup() {
345344
// now we have a fix only rate updates, could be set to 0?
346345
gps.setStatisticsIntervalInSeconds(0);
347346

348-
gps.handle(1000); // Added for user experience
349-
gps.pollStatistics();
350347
gps.enableSbas();
348+
gps.handle(1100); // Added for user experience
349+
gps.pollStatistics();
351350
displayTest->clear();
352351
}
353352

@@ -410,7 +409,7 @@ void loop() {
410409
if (startTimeMillis == 0) {
411410
startTimeMillis = (currentTimeMillis / measureInterval) * measureInterval;
412411
}
413-
currentSet->time = Gps::currentTime();
412+
currentSet->time = time(nullptr);
414413
currentSet->millis = currentTimeMillis;
415414
currentSet->batteryLevel = voltageMeter->read();
416415
currentSet->isInsidePrivacyArea = gps.isInsidePrivacyArea();

src/config.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const String ObsConfig::PROPERTY_WIFI_SSID = String("wifiSsid");
4444
const String ObsConfig::PROPERTY_WIFI_PASSWORD = String("wifiPassword");
4545
const String ObsConfig::PROPERTY_PORTAL_URL = String("portalUrl");
4646
const String ObsConfig::PROPERTY_PORTAL_TOKEN = String("portalToken");
47-
const String ObsConfig::PROPERTY_GPS_FIX = String("gpsFix");
4847
const String ObsConfig::PROPERTY_DISPLAY_CONFIG = String("displayConfig");
4948
const String ObsConfig::PROPERTY_CONFIRMATION_TIME_SECONDS = String("confirmationTimeSeconds");
5049
const String ObsConfig::PROPERTY_PRIVACY_CONFIG = String("privacyConfig");
@@ -148,7 +147,6 @@ void ObsConfig::makeSureSystemDefaultsAreSet() {
148147
setProperty(0, PROPERTY_PORTAL_TOKEN, "");
149148
}
150149
ensureSet(data, PROPERTY_PORTAL_TOKEN, "");
151-
ensureSet(data, PROPERTY_GPS_FIX, (int) Gps::WaitFor::FIX_POS);
152150
ensureSet(data, PROPERTY_DISPLAY_CONFIG, DisplaySimple);
153151
if (getProperty<int>(PROPERTY_DISPLAY_CONFIG) == 0) {
154152
data[PROPERTY_DISPLAY_CONFIG] = DisplaySimple;
@@ -399,17 +397,6 @@ void ObsConfig::parseOldJsonDocument(DynamicJsonDocument &doc) {
399397
setProperty(0, PROPERTY_WIFI_PASSWORD, doc["password"] | String("Freifunk"));
400398
setProperty(0, PROPERTY_PORTAL_TOKEN, doc["obsUserID"] | String("5e8f2f43e7e3b3668ca13151"));
401399
setProperty(0, PROPERTY_DISPLAY_CONFIG, doc["displayConfig"] | DisplaySimple);
402-
403-
uint16_t gpsConfig = doc["GPSConfig"];
404-
if (gpsConfig & GPSOptions::ValidTime) {
405-
setProperty(0, PROPERTY_GPS_FIX, (int) Gps::WaitFor::FIX_TIME);
406-
} else if (gpsConfig & GPSOptions::ValidLocation) {
407-
setProperty(0, PROPERTY_GPS_FIX, (int) Gps::WaitFor::FIX_POS);
408-
} else if (gpsConfig & GPSOptions::NumberSatellites) {
409-
setProperty(0, PROPERTY_GPS_FIX, doc["satsForFix"] | 4);
410-
} else {
411-
setProperty(0, PROPERTY_GPS_FIX, (int) Gps::WaitFor::FIX_NO_WAIT);
412-
}
413400
setProperty(0, PROPERTY_CONFIRMATION_TIME_SECONDS, doc["confirmationTimeWindow"] | 5);
414401
setProperty(0, PROPERTY_PRIVACY_CONFIG, doc["privacyConfig"] | AbsolutePrivacy);
415402
setProperty(0, PROPERTY_BLUETOOTH, doc["bluetooth"] | false);

src/config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class ObsConfig {
132132
static const String PROPERTY_WIFI_PASSWORD;
133133
static const String PROPERTY_PORTAL_TOKEN;
134134
static const String PROPERTY_PORTAL_URL;
135-
static const String PROPERTY_GPS_FIX;
136135
static const String PROPERTY_DISPLAY_CONFIG;
137136
static const String PROPERTY_CONFIRMATION_TIME_SECONDS;
138137
static const String PROPERTY_PRIVACY_CONFIG;

src/configServer.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
#include <HTTPURLEncodedBodyParser.hpp>
3333
#include <esp_ota_ops.h>
3434
#include <esp_partition.h>
35-
#include <utils/https.h>
3635
#include <DNSServer.h>
3736
#include "SPIFFS.h"
3837
#include "HTTPMultipartBodyParser.hpp"
3938
#include "Firmware.h"
39+
#include "utils/https.h"
40+
#include "utils/timeutils.h"
4041

4142
using namespace httpsserver;
4243

@@ -311,14 +312,6 @@ static const char* const configIndex =
311312
"<hr>"
312313
"Swap Sensors (Left &#8660; Right)<input type='checkbox' name='displaySwapSensors' {displaySwapSensors}>"
313314
""
314-
"<h3>GPS</h3>"
315-
"<label for='gpsFix'>GPS to wait for</label> "
316-
"<select id='gpsFix' name='gpsFix'>"
317-
"<option value='-2' {fixPos}>position</option>"
318-
"<option value='-1' {fixTime}>time only</option>"
319-
"<option value='0' {fixNoWait}>no wait</option>"
320-
"</select>"
321-
""
322315
"<h3>Generic Display</h3>"
323316
"Invert<br>(black &#8660; white)<input type='checkbox' name='displayInvert' {displayInvert}>"
324317
"<hr>"
@@ -711,7 +704,7 @@ void startServer(ObsConfig *obsConfig) {
711704

712705
MDNS.begin("obs");
713706

714-
ObsUtils::setClockByNtp(WiFi.gatewayIP().toString().c_str());
707+
TimeUtils::setClockByNtp(WiFi.gatewayIP().toString().c_str());
715708
if (!voltageMeter) {
716709
voltageMeter = new VoltageMeter();
717710
}
@@ -857,13 +850,13 @@ static void handleAbout(HTTPRequest *req, HTTPResponse * res) {
857850
files += " ";
858851
files += ObsUtils::toScaledByteString(file.size());
859852
files += " ";
860-
files += ObsUtils::dateTimeToString(file.getLastWrite());
853+
files += TimeUtils::dateTimeToString(file.getLastWrite());
861854
file.close();
862855
file = dir.openNextFile();
863856
}
864857
dir.close();
865858
page += keyValue("SPIFFS files", files);
866-
page += keyValue("System date time", ObsUtils::dateTimeToString(file.getLastWrite()));
859+
page += keyValue("System date time", TimeUtils::dateTimeToString(file.getLastWrite()));
867860
page += keyValue("System millis", String(millis()));
868861

869862
if (voltageMeter) {
@@ -1095,9 +1088,6 @@ static void handleConfigSave(HTTPRequest * req, HTTPResponse * res) {
10951088
offsets.push_back(atoi(getParameter(params, "offsetS1").c_str()));
10961089
theObsConfig->setOffsets(0, offsets);
10971090

1098-
theObsConfig->setProperty(0, ObsConfig::PROPERTY_GPS_FIX,
1099-
atoi(getParameter(params, "gpsFix").c_str()));
1100-
11011091
// TODO: cleanup
11021092
const String privacyOptions = getParameter(params, "privacyOptions");
11031093
const String overridePrivacy = getParameter(params, "overridePrivacy");
@@ -1161,11 +1151,6 @@ static void handleConfig(HTTPRequest *, HTTPResponse * res) {
11611151
html = replaceHtml(html, "{simRaMode}",
11621152
theObsConfig->getProperty<bool>(ObsConfig::PROPERTY_SIM_RA) ? "checked" : "");
11631153

1164-
int gpsFix = theObsConfig->getProperty<int>(ObsConfig::PROPERTY_GPS_FIX);
1165-
html = replaceHtml(html, "{fixPos}", gpsFix == (int) Gps::WaitFor::FIX_POS || gpsFix > 0 ? "selected" : "");
1166-
html = replaceHtml(html, "{fixTime}", gpsFix == (int) Gps::WaitFor::FIX_TIME ? "selected" : "");
1167-
html = replaceHtml(html, "{fixNoWait}", gpsFix == (int) Gps::WaitFor::FIX_NO_WAIT ? "selected" : "");
1168-
11691154
const uint privacyConfig = (uint) theObsConfig->getProperty<int>(
11701155
ObsConfig::PROPERTY_PRIVACY_CONFIG);
11711156
const bool absolutePrivacy = privacyConfig & AbsolutePrivacy;
@@ -1584,7 +1569,7 @@ static void handleSd(HTTPRequest *req, HTTPResponse *res) {
15841569

15851570
auto fileName = String(child.name());
15861571
auto fileTip = ObsUtils::encodeForXmlAttribute(
1587-
ObsUtils::dateTimeToString(child.getLastWrite())
1572+
TimeUtils::dateTimeToString(child.getLastWrite())
15881573
+ " - " + ObsUtils::toScaledByteString(child.size()));
15891574

15901575
fileName = fileName.substring(int(fileName.lastIndexOf("/") + 1));

0 commit comments

Comments
 (0)