fix 124 - we now fallback to nema if we can't talk ublox protocol to

the GPS.  Though we are super power inefficient about it so TODO/FIXME
someday to decrease our power draw.
This commit is contained in:
geeksville 2020-05-04 20:02:43 -07:00
parent c2be6c4068
commit dcd1f7478a
5 changed files with 44 additions and 33 deletions

View File

@ -8,7 +8,6 @@ Minimum items needed to make sure hardware is good.
- use "variants" to get all gpio bindings - use "variants" to get all gpio bindings
- plug in correct variants for the real board - plug in correct variants for the real board
- Use the PMU driver on real hardware - Use the PMU driver on real hardware
- add a NEMA based GPS driver to test GPS
- Use new radio driver on real hardware - Use new radio driver on real hardware
- Use UC1701 LCD driver on real hardware. Still need to create at startup and probe on SPI - Use UC1701 LCD driver on real hardware. Still need to create at startup and probe on SPI
- test the LEDs - test the LEDs
@ -101,6 +100,7 @@ Nice ideas worth considering someday...
- DONE neg 7 error code from receive - DONE neg 7 error code from receive
- DONE remove unused sx1262 lib from github - DONE remove unused sx1262 lib from github
- at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug. - at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug.
- add a NEMA based GPS driver to test GPS
``` ```

View File

@ -61,7 +61,7 @@ void perhapsSetRTC(struct tm &t)
tv.tv_sec = res; tv.tv_sec = res;
tv.tv_usec = 0; // time.centisecond() * (10 / 1000); tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec); // DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec);
if (t.tm_year < 0 || t.tm_year >= 300) if (t.tm_year < 0 || t.tm_year >= 300)
DEBUG_MSG("Ignoring invalid GPS time\n"); DEBUG_MSG("Ignoring invalid GPS time\n");
else else

View File

@ -12,19 +12,25 @@ static int32_t toDegInt(RawDegrees d)
void NEMAGPS::loop() void NEMAGPS::loop()
{ {
while (_serial_gps.available() > 0) { while (_serial_gps.available() > 0) {
int c = _serial_gps.read(); int c = _serial_gps.read();
Serial.write(c); // Serial.write(c);
reader.encode(c); reader.encode(c);
} }
uint32_t now = millis();
if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume
// serial chars at whatever rate)
lastUpdateMsec = now;
auto ti = reader.time; auto ti = reader.time;
auto d = reader.date; auto d = reader.date;
if (ti.isUpdated() && ti.isValid() && d.isValid()) { if (ti.isUpdated() && ti.isValid() && d.isValid()) {
/* Convert to unix time /* Convert to unix time
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970
(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
*/ */
struct tm t; struct tm t;
t.tm_sec = ti.second(); t.tm_sec = ti.second();
t.tm_min = ti.minute(); t.tm_min = ti.minute();
@ -34,16 +40,18 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s
t.tm_year = d.year() - 1900; t.tm_year = d.year() - 1900;
t.tm_isdst = false; t.tm_isdst = false;
perhapsSetRTC(t); perhapsSetRTC(t);
isConnected = true; // we seem to have a real GPS (but not necessarily a lock)
} }
if (reader.altitude.isUpdated() || reader.location.isUpdated()) { // probably get updated at the same time if (reader.location.isUpdated()) {
if (reader.altitude.isValid()) if (reader.altitude.isValid())
altitude = reader.altitude.meters(); altitude = reader.altitude.meters();
auto loc = reader.location; if (reader.location.isValid()) {
if (loc.isValid()) { auto loc = reader.location.value();
latitude = toDegInt(loc.rawLat()); latitude = toDegInt(loc.lat);
longitude = toDegInt(loc.rawLng()); longitude = toDegInt(loc.lng);
} }
// expect gps pos lat=37.520825, lon=-122.309162, alt=158 // expect gps pos lat=37.520825, lon=-122.309162, alt=158
@ -53,4 +61,5 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s
if (hasValidLocation) if (hasValidLocation)
notifyObservers(NULL); notifyObservers(NULL);
} }
}
} }

View File

@ -14,6 +14,8 @@ class NEMAGPS : public GPS
{ {
TinyGPSPlus reader; TinyGPSPlus reader;
uint32_t lastUpdateMsec = 0;
public: public:
virtual void loop(); virtual void loop();
}; };

View File

@ -28,7 +28,7 @@ bool UBloxGPS::setup()
if (isConnected) { if (isConnected) {
DEBUG_MSG("Connected to UBLOX GPS successfully\n"); DEBUG_MSG("Connected to UBLOX GPS successfully\n");
bool factoryReset = true; bool factoryReset = false;
bool ok; bool ok;
if (factoryReset) { if (factoryReset) {
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have // It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have