diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 8436c3f60..91efbdf0d 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -3,6 +3,7 @@ #include "RTC.h" #include "configuration.h" #include "sleep.h" +#include "ubx.h" #ifdef ARCH_PORTDUINO #include "meshUtils.h" @@ -32,13 +33,6 @@ static bool didSerialInit; struct uBloxGnssModelInfo info; uint8_t uBloxProtocolVersion; -const uint8_t GPS::_message_PMREQ[] PROGMEM = { - 0x00, 0x00, // 4 bytes duration of request task - 0x00, 0x00, // (milliseconds) - 0x02, 0x00, // Task flag bitfield - 0x00, 0x00, // byte index 1 = sleep mode -}; - void GPS::UBXChecksum(uint8_t *message, size_t length) { uint8_t CK_A = 0, CK_B = 0; @@ -662,7 +656,24 @@ bool GPS::setupGPS() LOG_WARN("Unable to enable powersaving for GPS.\n"); } } else { - // use cfg-rxm + if (strncmp(info.hwVersion, "00040007", 8) == 0) { // This PSM mode has only been tested on this hardware + int msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_PSM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving mode for GPS.\n"); + } + msglen = makeUBXPacket(0x06, 0x3B, 44, _message_CFG_PM2); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x3B, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving details for GPS.\n"); + } + } else { + int msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_ECO); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving ECO mode for GPS.\n"); + } + } } // We need save configuration to flash to make our config changes persistent uint8_t _message_SAVE[21] = { diff --git a/src/gps/GPS.h b/src/gps/GPS.h index f6b4e95c8..f5254890d 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -63,7 +63,9 @@ class GPS : private concurrency::OSThread static HardwareSerial *_serial_gps; static const uint8_t _message_PMREQ[8]; - + static const uint8_t _message_CFG_RXM_PSM[2]; + static const uint8_t _message_CFG_RXM_ECO[2]; + static const uint8_t _message_CFG_PM2[44]; meshtastic_Position p = meshtastic_Position_init_default; GPS() : concurrency::OSThread("GPS") {} diff --git a/src/gps/ubx.h b/src/gps/ubx.h new file mode 100644 index 000000000..a81b52e80 --- /dev/null +++ b/src/gps/ubx.h @@ -0,0 +1,31 @@ +const uint8_t GPS::_message_PMREQ[] PROGMEM = { + 0x00, 0x00, // 4 bytes duration of request task + 0x00, 0x00, // (milliseconds) + 0x02, 0x00, // Task flag bitfield + 0x00, 0x00 // byte index 1 = sleep mode +}; + +const uint8_t GPS::_message_CFG_RXM_PSM[] PROGMEM = { + 0x08, // Reserved + 0x01 // Power save mode +}; + +const uint8_t GPS::_message_CFG_RXM_ECO[] PROGMEM = { + 0x08, // Reserved + 0x04 // eco mode +}; + +const uint8_t GPS::_message_CFG_PM2[] PROGMEM = { + 0x01, 0x06, 0x00, 0x00, // version, Reserved + 0x0e, 0x81, 0x42, 0x01, // flags + 0xE8, 0x03, 0x00, 0x00, // update period 1000 ms + 0x10, 0x27, 0x00, 0x00, // search period 10s + 0x00, 0x00, 0x00, 0x00, // Grod offset 0 + 0x01, 0x00, // onTime 1 second + 0x00, 0x00, // min search time 0 + 0x2C, 0x01, // reserved + 0x00, 0x00, 0x4F, 0xC1, // reserved + 0x03, 0x00, 0x87, 0x02, // reserved + 0x00, 0x00, 0xFF, 0x00, // reserved + 0x01, 0x00, 0xD6, 0x4D // reserved +}; \ No newline at end of file