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,45 +12,54 @@ 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);
} }
auto ti = reader.time; uint32_t now = millis();
auto d = reader.date; if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume
if (ti.isUpdated() && ti.isValid() && d.isValid()) { // serial chars at whatever rate)
/* Convert to unix time lastUpdateMsec = now;
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).
*/
struct tm t;
t.tm_sec = ti.second();
t.tm_min = ti.minute();
t.tm_hour = ti.hour();
t.tm_mday = d.day();
t.tm_mon = d.month() - 1;
t.tm_year = d.year() - 1900;
t.tm_isdst = false;
perhapsSetRTC(t);
}
if (reader.altitude.isUpdated() || reader.location.isUpdated()) { // probably get updated at the same time auto ti = reader.time;
if (reader.altitude.isValid()) auto d = reader.date;
altitude = reader.altitude.meters(); if (ti.isUpdated() && ti.isValid() && d.isValid()) {
/* 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
(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
*/
struct tm t;
t.tm_sec = ti.second();
t.tm_min = ti.minute();
t.tm_hour = ti.hour();
t.tm_mday = d.day();
t.tm_mon = d.month() - 1;
t.tm_year = d.year() - 1900;
t.tm_isdst = false;
perhapsSetRTC(t);
auto loc = reader.location; isConnected = true; // we seem to have a real GPS (but not necessarily a lock)
if (loc.isValid()) {
latitude = toDegInt(loc.rawLat());
longitude = toDegInt(loc.rawLng());
} }
// expect gps pos lat=37.520825, lon=-122.309162, alt=158 if (reader.location.isUpdated()) {
DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d\n", latitude * 1e-7, longitude * 1e-7, altitude); if (reader.altitude.isValid())
altitude = reader.altitude.meters();
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0 if (reader.location.isValid()) {
if (hasValidLocation) auto loc = reader.location.value();
notifyObservers(NULL); latitude = toDegInt(loc.lat);
longitude = toDegInt(loc.lng);
}
// expect gps pos lat=37.520825, lon=-122.309162, alt=158
DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d\n", latitude * 1e-7, longitude * 1e-7, altitude);
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
if (hasValidLocation)
notifyObservers(NULL);
}
} }
} }

View File

@ -13,6 +13,8 @@
class NEMAGPS : public GPS 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