2025-03-04 23:47:06 +08:00
|
|
|
#include <cstring> // Include for strstr
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2024-03-25 05:33:57 -06:00
|
|
|
#include "configuration.h"
|
|
|
|
|
#if !MESHTASTIC_EXCLUDE_GPS
|
2024-03-17 08:18:30 -05:00
|
|
|
#include "Default.h"
|
2024-03-25 05:33:57 -06:00
|
|
|
#include "GPS.h"
|
2024-08-22 10:15:23 -07:00
|
|
|
#include "GpioLogic.h"
|
2020-10-05 14:43:44 +08:00
|
|
|
#include "NodeDB.h"
|
2024-07-03 16:02:20 -07:00
|
|
|
#include "PowerMon.h"
|
2020-10-08 07:46:20 +08:00
|
|
|
#include "RTC.h"
|
2024-09-23 08:58:14 -05:00
|
|
|
#include "Throttle.h"
|
2024-10-17 22:40:18 -05:00
|
|
|
#include "buzz.h"
|
2025-04-07 12:46:22 +02:00
|
|
|
#include "concurrency/Periodic.h"
|
2024-09-25 13:50:00 -05:00
|
|
|
#include "meshUtils.h"
|
2024-03-25 05:33:57 -06:00
|
|
|
|
2023-09-23 23:45:35 -05:00
|
|
|
#include "main.h" // pmu_found
|
2020-10-01 09:11:54 -07:00
|
|
|
#include "sleep.h"
|
2024-04-16 16:03:51 +02:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
#include "GPSUpdateScheduling.h"
|
2024-04-16 16:03:51 +02:00
|
|
|
#include "cas.h"
|
2023-09-07 12:24:21 -05:00
|
|
|
#include "ubx.h"
|
2020-02-06 07:39:21 -08:00
|
|
|
|
2023-08-28 11:13:17 -05:00
|
|
|
#ifdef ARCH_PORTDUINO
|
2023-11-28 12:39:32 -06:00
|
|
|
#include "PortduinoGlue.h"
|
2023-08-28 11:13:17 -05:00
|
|
|
#include "meshUtils.h"
|
2024-10-27 19:21:57 -05:00
|
|
|
#include <algorithm>
|
2023-11-08 14:36:12 -06:00
|
|
|
#include <ctime>
|
2023-08-28 11:13:17 -05:00
|
|
|
#endif
|
|
|
|
|
|
2023-07-16 23:57:14 +02:00
|
|
|
#ifndef GPS_RESET_MODE
|
|
|
|
|
#define GPS_RESET_MODE HIGH
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-11-27 02:56:25 -08:00
|
|
|
// Not all platforms have std::size().
|
|
|
|
|
template <typename T, std::size_t N> std::size_t array_count(const T (&)[N])
|
|
|
|
|
{
|
|
|
|
|
return N;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-14 11:12:26 +01:00
|
|
|
#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(ARCH_PORTDUINO) || defined(ARCH_STM32WL)
|
|
|
|
|
#if defined(GPS_SERIAL_PORT)
|
|
|
|
|
HardwareSerial *GPS::_serial_gps = &GPS_SERIAL_PORT;
|
2025-01-10 09:20:38 +08:00
|
|
|
#else
|
2020-07-09 21:27:34 -07:00
|
|
|
HardwareSerial *GPS::_serial_gps = &Serial1;
|
2025-01-10 09:20:38 +08:00
|
|
|
#endif
|
2024-09-17 19:48:56 +08:00
|
|
|
#elif defined(ARCH_RP2040)
|
|
|
|
|
SerialUART *GPS::_serial_gps = &Serial1;
|
2020-04-14 20:22:27 -07:00
|
|
|
#else
|
2024-11-25 03:32:04 -08:00
|
|
|
HardwareSerial *GPS::_serial_gps = nullptr;
|
2020-04-14 20:22:27 -07:00
|
|
|
#endif
|
2020-02-19 20:02:57 -08:00
|
|
|
|
2023-10-03 13:37:46 +02:00
|
|
|
GPS *gps = nullptr;
|
2020-03-13 18:44:14 -07:00
|
|
|
|
2024-11-25 03:32:04 -08:00
|
|
|
static GPSUpdateScheduling scheduling;
|
2024-07-11 15:26:43 +12:00
|
|
|
|
2021-03-10 15:21:54 +08:00
|
|
|
/// Multiple GPS instances might use the same serial port (in sequence), but we can
|
2020-11-07 09:15:28 +08:00
|
|
|
/// only init that port once.
|
|
|
|
|
static bool didSerialInit;
|
|
|
|
|
|
2024-11-27 02:56:25 -08:00
|
|
|
static struct uBloxGnssModelInfo {
|
|
|
|
|
char swVersion[30];
|
|
|
|
|
char hwVersion[10];
|
|
|
|
|
uint8_t extensionNo;
|
|
|
|
|
char extension[10][30];
|
|
|
|
|
uint8_t protocol_version;
|
|
|
|
|
} ublox_info;
|
|
|
|
|
|
2023-09-16 23:10:10 -05:00
|
|
|
#define GPS_SOL_EXPIRY_MS 5000 // in millis. give 1 second time to combine different sentences. NMEA Frequency isn't higher anyway
|
|
|
|
|
#define NMEA_MSG_GXGSA "GNGSA" // GSA message (GPGSA, GNGSA etc)
|
2023-07-18 01:27:14 +00:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// For logging
|
2024-11-25 03:32:04 -08:00
|
|
|
static const char *getGPSPowerStateString(GPSPowerState state)
|
2024-07-11 15:26:43 +12:00
|
|
|
{
|
|
|
|
|
switch (state) {
|
|
|
|
|
case GPS_ACTIVE:
|
|
|
|
|
return "ACTIVE";
|
|
|
|
|
case GPS_IDLE:
|
|
|
|
|
return "IDLE";
|
|
|
|
|
case GPS_SOFTSLEEP:
|
|
|
|
|
return "SOFTSLEEP";
|
|
|
|
|
case GPS_HARDSLEEP:
|
|
|
|
|
return "HARDSLEEP";
|
|
|
|
|
case GPS_OFF:
|
|
|
|
|
return "OFF";
|
|
|
|
|
default:
|
2024-09-12 22:42:10 +02:00
|
|
|
assert(false); // Unhandled enum value..
|
|
|
|
|
return "FALSE"; // to make new ESP-IDF happy
|
2024-07-11 15:26:43 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-07 12:46:22 +02:00
|
|
|
#ifdef PIN_GPS_SWITCH
|
|
|
|
|
// If we have a hardware switch, define a periodic watcher outside of the GPS runOnce thread, since this can be sleeping
|
|
|
|
|
// idefinitely
|
|
|
|
|
|
|
|
|
|
int lastState = LOW;
|
|
|
|
|
bool firstrun = true;
|
|
|
|
|
|
|
|
|
|
static int32_t gpsSwitch()
|
|
|
|
|
{
|
|
|
|
|
if (gps) {
|
|
|
|
|
int currentState = digitalRead(PIN_GPS_SWITCH);
|
|
|
|
|
|
|
|
|
|
// if the switch is set to zero, disable the GPS Thread
|
|
|
|
|
if (firstrun)
|
|
|
|
|
if (currentState == LOW)
|
|
|
|
|
lastState = HIGH;
|
|
|
|
|
|
|
|
|
|
if (currentState != lastState) {
|
|
|
|
|
if (currentState == LOW) {
|
|
|
|
|
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED;
|
|
|
|
|
if (!firstrun)
|
|
|
|
|
playGPSDisableBeep();
|
|
|
|
|
gps->disable();
|
|
|
|
|
} else {
|
|
|
|
|
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED;
|
|
|
|
|
if (!firstrun)
|
|
|
|
|
playGPSEnableBeep();
|
|
|
|
|
gps->enable();
|
|
|
|
|
}
|
|
|
|
|
lastState = currentState;
|
|
|
|
|
}
|
|
|
|
|
firstrun = false;
|
|
|
|
|
}
|
|
|
|
|
return 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static concurrency::Periodic *gpsPeriodic;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-11-25 03:32:04 -08:00
|
|
|
static void UBXChecksum(uint8_t *message, size_t length)
|
2023-07-02 02:20:40 +02:00
|
|
|
{
|
|
|
|
|
uint8_t CK_A = 0, CK_B = 0;
|
|
|
|
|
|
|
|
|
|
// Calculate the checksum, starting from the CLASS field (which is message[2])
|
|
|
|
|
for (size_t i = 2; i < length - 2; i++) {
|
|
|
|
|
CK_A = (CK_A + message[i]) & 0xFF;
|
|
|
|
|
CK_B = (CK_B + CK_A) & 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Place the calculated checksum values in the message
|
|
|
|
|
message[length - 2] = CK_A;
|
|
|
|
|
message[length - 1] = CK_B;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 16:03:51 +02:00
|
|
|
// Calculate the checksum for a CAS packet
|
2024-11-25 03:32:04 -08:00
|
|
|
static void CASChecksum(uint8_t *message, size_t length)
|
2024-04-16 16:03:51 +02:00
|
|
|
{
|
|
|
|
|
uint32_t cksum = ((uint32_t)message[5] << 24); // Message ID
|
|
|
|
|
cksum += ((uint32_t)message[4]) << 16; // Class
|
|
|
|
|
cksum += message[2]; // Payload Len
|
|
|
|
|
|
|
|
|
|
// Iterate over the payload as a series of uint32_t's and
|
|
|
|
|
// accumulate the cksum
|
|
|
|
|
for (size_t i = 0; i < (length - 10) / 4; i++) {
|
2024-10-01 00:56:29 +02:00
|
|
|
uint32_t pl = 0;
|
|
|
|
|
memcpy(&pl, (message + 6) + (i * sizeof(uint32_t)), sizeof(uint32_t)); // avoid pointer dereference
|
2024-05-03 15:10:57 +02:00
|
|
|
cksum += pl;
|
2024-04-16 16:03:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Place the checksum values in the message
|
|
|
|
|
message[length - 4] = (cksum & 0xFF);
|
|
|
|
|
message[length - 3] = (cksum & (0xFF << 8)) >> 8;
|
|
|
|
|
message[length - 2] = (cksum & (0xFF << 16)) >> 16;
|
|
|
|
|
message[length - 1] = (cksum & (0xFF << 24)) >> 24;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 00:26:42 -04:00
|
|
|
// Function to create a ublox packet for editing in memory
|
|
|
|
|
uint8_t GPS::makeUBXPacket(uint8_t class_id, uint8_t msg_id, uint8_t payload_size, const uint8_t *msg)
|
|
|
|
|
{
|
|
|
|
|
// Construct the UBX packet
|
|
|
|
|
UBXscratch[0] = 0xB5; // header
|
|
|
|
|
UBXscratch[1] = 0x62; // header
|
|
|
|
|
UBXscratch[2] = class_id; // class
|
|
|
|
|
UBXscratch[3] = msg_id; // id
|
|
|
|
|
UBXscratch[4] = payload_size; // length
|
|
|
|
|
UBXscratch[5] = 0x00;
|
|
|
|
|
|
|
|
|
|
UBXscratch[6 + payload_size] = 0x00; // CK_A
|
|
|
|
|
UBXscratch[7 + payload_size] = 0x00; // CK_B
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < payload_size; i++) {
|
|
|
|
|
UBXscratch[6 + i] = pgm_read_byte(&msg[i]);
|
|
|
|
|
}
|
|
|
|
|
UBXChecksum(UBXscratch, (payload_size + 8));
|
|
|
|
|
return (payload_size + 8);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 16:03:51 +02:00
|
|
|
// Function to create a CAS packet for editing in memory
|
|
|
|
|
uint8_t GPS::makeCASPacket(uint8_t class_id, uint8_t msg_id, uint8_t payload_size, const uint8_t *msg)
|
|
|
|
|
{
|
|
|
|
|
// General CAS structure
|
|
|
|
|
// | H1 | H2 | payload_len | cls | msg | Payload ... | Checksum |
|
|
|
|
|
// Size: | 1 | 1 | 2 | 1 | 1 | payload_len | 4 |
|
|
|
|
|
// Pos: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 ... | 6 + payload_len ... |
|
|
|
|
|
// |------|------|-------------|------|------|------|--------------|---------------------------|
|
|
|
|
|
// | 0xBA | 0xCE | 0xXX | 0xXX | 0xXX | 0xXX | 0xXX | 0xXX ... | 0xXX | 0xXX | 0xXX | 0xXX |
|
|
|
|
|
|
|
|
|
|
// Construct the CAS packet
|
|
|
|
|
UBXscratch[0] = 0xBA; // header 1 (0xBA)
|
|
|
|
|
UBXscratch[1] = 0xCE; // header 2 (0xCE)
|
|
|
|
|
UBXscratch[2] = payload_size; // length 1
|
|
|
|
|
UBXscratch[3] = 0; // length 2
|
|
|
|
|
UBXscratch[4] = class_id; // class
|
|
|
|
|
UBXscratch[5] = msg_id; // id
|
|
|
|
|
|
|
|
|
|
UBXscratch[6 + payload_size] = 0x00; // Checksum
|
|
|
|
|
UBXscratch[7 + payload_size] = 0x00;
|
|
|
|
|
UBXscratch[8 + payload_size] = 0x00;
|
|
|
|
|
UBXscratch[9 + payload_size] = 0x00;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < payload_size; i++) {
|
|
|
|
|
UBXscratch[6 + i] = pgm_read_byte(&msg[i]);
|
|
|
|
|
}
|
|
|
|
|
CASChecksum(UBXscratch, (payload_size + 10));
|
|
|
|
|
|
|
|
|
|
#if defined(GPS_DEBUG) && defined(DEBUG_PORT)
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_DEBUG("CAS packet: ");
|
2024-04-16 16:03:51 +02:00
|
|
|
DEBUG_PORT.hexDump(MESHTASTIC_LOG_LEVEL_DEBUG, UBXscratch, payload_size + 10);
|
|
|
|
|
#endif
|
|
|
|
|
return (payload_size + 10);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 01:50:11 -05:00
|
|
|
GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
|
2023-09-01 11:55:46 -05:00
|
|
|
{
|
|
|
|
|
uint8_t buffer[768] = {0};
|
|
|
|
|
uint8_t b;
|
2023-09-01 16:23:52 -05:00
|
|
|
int bytesRead = 0;
|
2023-09-01 11:55:46 -05:00
|
|
|
uint32_t startTimeout = millis() + waitMillis;
|
2024-10-14 06:11:43 +02:00
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
std::string debugmsg = "";
|
|
|
|
|
#endif
|
2023-09-01 11:55:46 -05:00
|
|
|
while (millis() < startTimeout) {
|
2023-09-01 16:23:52 -05:00
|
|
|
if (_serial_gps->available()) {
|
2023-09-01 11:55:46 -05:00
|
|
|
b = _serial_gps->read();
|
2024-04-16 16:03:51 +02:00
|
|
|
|
2023-10-03 12:05:40 -05:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
debugmsg += vformat("%c", (b >= 32 && b <= 126) ? b : '.');
|
2023-10-03 12:05:40 -05:00
|
|
|
#endif
|
2023-09-01 11:55:46 -05:00
|
|
|
buffer[bytesRead] = b;
|
|
|
|
|
bytesRead++;
|
2023-09-02 20:35:38 -05:00
|
|
|
if ((bytesRead == 767) || (b == '\r')) {
|
2023-09-01 16:23:52 -05:00
|
|
|
if (strnstr((char *)buffer, message, bytesRead) != nullptr) {
|
2023-09-04 14:18:27 -05:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Found: %s", message); // Log the found message
|
2023-09-04 14:18:27 -05:00
|
|
|
#endif
|
2023-09-02 04:25:18 -05:00
|
|
|
return GNSS_RESPONSE_OK;
|
2023-09-01 16:23:52 -05:00
|
|
|
} else {
|
|
|
|
|
bytesRead = 0;
|
2024-09-12 08:30:29 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG(debugmsg.c_str());
|
2024-09-12 08:30:29 +08:00
|
|
|
#endif
|
2023-09-01 16:23:52 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-01 11:55:46 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-02 04:25:18 -05:00
|
|
|
return GNSS_RESPONSE_NONE;
|
2023-09-01 11:55:46 -05:00
|
|
|
}
|
|
|
|
|
|
2024-04-16 16:03:51 +02:00
|
|
|
GPS_RESPONSE GPS::getACKCas(uint8_t class_id, uint8_t msg_id, uint32_t waitMillis)
|
|
|
|
|
{
|
|
|
|
|
uint32_t startTime = millis();
|
|
|
|
|
uint8_t buffer[CAS_ACK_NACK_MSG_SIZE] = {0};
|
|
|
|
|
uint8_t bufferPos = 0;
|
|
|
|
|
|
|
|
|
|
// CAS-ACK-(N)ACK structure
|
|
|
|
|
// | H1 | H2 | Payload Len | cls | msg | Payload | Checksum (4) |
|
|
|
|
|
// | | | | | | Cls | Msg | Reserved | |
|
|
|
|
|
// |------|------|-------------|------|------|------|------|-------------|---------------------------|
|
|
|
|
|
// ACK-NACK| 0xBA | 0xCE | 0x04 | 0x00 | 0x05 | 0x00 | 0xXX | 0xXX | 0x00 | 0x00 | 0xXX | 0xXX | 0xXX | 0xXX |
|
|
|
|
|
// ACK-ACK | 0xBA | 0xCE | 0x04 | 0x00 | 0x05 | 0x01 | 0xXX | 0xXX | 0x00 | 0x00 | 0xXX | 0xXX | 0xXX | 0xXX |
|
|
|
|
|
|
2024-09-23 08:58:14 -05:00
|
|
|
while (Throttle::isWithinTimespanMs(startTime, waitMillis)) {
|
2024-04-16 16:03:51 +02:00
|
|
|
if (_serial_gps->available()) {
|
|
|
|
|
buffer[bufferPos++] = _serial_gps->read();
|
|
|
|
|
|
|
|
|
|
// keep looking at the first two bytes of buffer until
|
|
|
|
|
// we have found the CAS frame header (0xBA, 0xCE), if not
|
|
|
|
|
// keep reading bytes until we find a frame header or we run
|
|
|
|
|
// out of time.
|
|
|
|
|
if ((bufferPos == 2) && !(buffer[0] == 0xBA && buffer[1] == 0xCE)) {
|
|
|
|
|
buffer[0] = buffer[1];
|
|
|
|
|
buffer[1] = 0;
|
|
|
|
|
bufferPos = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we have read all the bytes required for the Ack/Nack (14-bytes)
|
|
|
|
|
// and we must have found a frame to get this far
|
|
|
|
|
if (bufferPos == sizeof(buffer) - 1) {
|
|
|
|
|
uint8_t msg_cls = buffer[4]; // message class should be 0x05
|
|
|
|
|
uint8_t msg_msg_id = buffer[5]; // message id should be 0x00 or 0x01
|
|
|
|
|
uint8_t payload_cls = buffer[6]; // payload class id
|
|
|
|
|
uint8_t payload_msg = buffer[7]; // payload message id
|
|
|
|
|
|
|
|
|
|
// Check for an ACK-ACK for the specified class and message id
|
|
|
|
|
if ((msg_cls == 0x05) && (msg_msg_id == 0x01) && payload_cls == class_id && payload_msg == msg_id) {
|
|
|
|
|
#ifdef GPS_DEBUG
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("Got ACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
|
2024-04-16 16:03:51 +02:00
|
|
|
#endif
|
|
|
|
|
return GNSS_RESPONSE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for an ACK-NACK for the specified class and message id
|
|
|
|
|
if ((msg_cls == 0x05) && (msg_msg_id == 0x00) && payload_cls == class_id && payload_msg == msg_id) {
|
|
|
|
|
#ifdef GPS_DEBUG
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("Got NACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
|
2024-04-16 16:03:51 +02:00
|
|
|
#endif
|
|
|
|
|
return GNSS_RESPONSE_NAK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This isn't the frame we are looking for, clear the buffer
|
|
|
|
|
// and try again until we run out of time.
|
|
|
|
|
memset(buffer, 0x0, sizeof(buffer));
|
|
|
|
|
bufferPos = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return GNSS_RESPONSE_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 01:50:11 -05:00
|
|
|
GPS_RESPONSE GPS::getACK(uint8_t class_id, uint8_t msg_id, uint32_t waitMillis)
|
2023-01-21 06:32:41 -05:00
|
|
|
{
|
|
|
|
|
uint8_t b;
|
|
|
|
|
uint8_t ack = 0;
|
2023-07-02 02:20:40 +02:00
|
|
|
const uint8_t ackP[2] = {class_id, msg_id};
|
2023-01-21 06:32:41 -05:00
|
|
|
uint8_t buf[10] = {0xB5, 0x62, 0x05, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00};
|
2023-09-03 01:50:11 -05:00
|
|
|
uint32_t startTime = millis();
|
2023-09-02 04:25:18 -05:00
|
|
|
const char frame_errors[] = "More than 100 frame errors";
|
|
|
|
|
int sCounter = 0;
|
2024-10-20 20:46:25 +11:00
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
std::string debugmsg = "";
|
|
|
|
|
#endif
|
2023-01-21 06:32:41 -05:00
|
|
|
|
2023-01-28 06:39:14 -06:00
|
|
|
for (int j = 2; j < 6; j++) {
|
2023-01-21 06:32:41 -05:00
|
|
|
buf[8] += buf[j];
|
|
|
|
|
buf[9] += buf[8];
|
2022-05-17 19:54:29 +02:00
|
|
|
}
|
2023-01-21 06:32:41 -05:00
|
|
|
|
2023-01-28 06:39:14 -06:00
|
|
|
for (int j = 0; j < 2; j++) {
|
2023-01-21 06:32:41 -05:00
|
|
|
buf[6 + j] = ackP[j];
|
|
|
|
|
buf[8] += buf[6 + j];
|
|
|
|
|
buf[9] += buf[8];
|
2022-05-17 19:54:29 +02:00
|
|
|
}
|
2023-01-21 06:32:41 -05:00
|
|
|
|
2024-09-23 08:58:14 -05:00
|
|
|
while (Throttle::isWithinTimespanMs(startTime, waitMillis)) {
|
2023-01-28 06:39:14 -06:00
|
|
|
if (ack > 9) {
|
2023-09-03 01:50:11 -05:00
|
|
|
#ifdef GPS_DEBUG
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("Got ACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
|
2023-09-03 01:50:11 -05:00
|
|
|
#endif
|
2023-09-02 04:25:18 -05:00
|
|
|
return GNSS_RESPONSE_OK; // ACK received
|
2023-01-21 06:32:41 -05:00
|
|
|
}
|
2023-01-28 06:39:14 -06:00
|
|
|
if (_serial_gps->available()) {
|
2023-01-21 06:32:41 -05:00
|
|
|
b = _serial_gps->read();
|
2023-09-02 04:25:18 -05:00
|
|
|
if (b == frame_errors[sCounter]) {
|
|
|
|
|
sCounter++;
|
|
|
|
|
if (sCounter == 26) {
|
2024-10-20 20:46:25 +11:00
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG(debugmsg.c_str());
|
|
|
|
|
#endif
|
2023-09-02 04:25:18 -05:00
|
|
|
return GNSS_RESPONSE_FRAME_ERRORS;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sCounter = 0;
|
|
|
|
|
}
|
2023-09-03 16:20:01 -05:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-20 20:46:25 +11:00
|
|
|
debugmsg += vformat("%02X", b);
|
2023-09-03 16:20:01 -05:00
|
|
|
#endif
|
2023-01-28 06:39:14 -06:00
|
|
|
if (b == buf[ack]) {
|
2023-01-21 06:32:41 -05:00
|
|
|
ack++;
|
2023-01-28 06:39:14 -06:00
|
|
|
} else {
|
2023-09-03 16:20:01 -05:00
|
|
|
if (ack == 3 && b == 0x00) { // UBX-ACK-NAK message
|
|
|
|
|
#ifdef GPS_DEBUG
|
2024-10-20 20:46:25 +11:00
|
|
|
LOG_DEBUG(debugmsg.c_str());
|
2023-09-03 16:20:01 -05:00
|
|
|
#endif
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_WARN("Got NAK for class %02X message %02X", class_id, msg_id);
|
2023-09-02 04:25:18 -05:00
|
|
|
return GNSS_RESPONSE_NAK; // NAK received
|
2023-07-02 02:20:40 +02:00
|
|
|
}
|
2023-09-03 16:20:01 -05:00
|
|
|
ack = 0; // Reset the acknowledgement counter
|
2023-01-21 06:32:41 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 19:54:29 +02:00
|
|
|
}
|
2023-09-03 16:20:01 -05:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-20 20:46:25 +11:00
|
|
|
LOG_DEBUG(debugmsg.c_str());
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_WARN("No response for class %02X message %02X", class_id, msg_id);
|
2023-09-03 16:20:01 -05:00
|
|
|
#endif
|
2023-09-02 04:25:18 -05:00
|
|
|
return GNSS_RESPONSE_NONE; // No response received within timeout
|
2022-05-17 19:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-16 02:43:04 +08:00
|
|
|
/**
|
2023-01-21 06:32:41 -05:00
|
|
|
* @brief
|
2022-09-16 02:43:04 +08:00
|
|
|
* @note New method, this method can wait for the specified class and message ID, and return the payload
|
|
|
|
|
* @param *buffer: The message buffer, if there is a response payload message, it will be returned through the buffer parameter
|
|
|
|
|
* @param size: size of buffer
|
|
|
|
|
* @param requestedClass: request class constant
|
|
|
|
|
* @param requestedID: request message ID constant
|
|
|
|
|
* @retval length of payload message
|
|
|
|
|
*/
|
2023-09-03 01:50:11 -05:00
|
|
|
int GPS::getACK(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedID, uint32_t waitMillis)
|
2022-09-16 02:43:04 +08:00
|
|
|
{
|
2023-01-21 06:32:41 -05:00
|
|
|
uint16_t ubxFrameCounter = 0;
|
|
|
|
|
uint32_t startTime = millis();
|
2024-09-12 22:42:10 +02:00
|
|
|
uint16_t needRead = 0;
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2024-09-23 08:58:14 -05:00
|
|
|
while (Throttle::isWithinTimespanMs(startTime, waitMillis)) {
|
2023-08-31 20:39:23 -05:00
|
|
|
if (_serial_gps->available()) {
|
2022-09-16 02:43:04 +08:00
|
|
|
int c = _serial_gps->read();
|
2023-01-28 06:39:14 -06:00
|
|
|
switch (ubxFrameCounter) {
|
2022-09-16 02:43:04 +08:00
|
|
|
case 0:
|
2023-01-21 06:32:41 -05:00
|
|
|
// ubxFrame 'μ'
|
2023-01-28 06:39:14 -06:00
|
|
|
if (c == 0xB5) {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2023-01-21 06:32:41 -05:00
|
|
|
// ubxFrame 'b'
|
2023-01-28 06:39:14 -06:00
|
|
|
if (c == 0x62) {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter++;
|
2023-01-28 06:39:14 -06:00
|
|
|
} else {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2023-01-21 06:32:41 -05:00
|
|
|
// Class
|
2023-01-28 06:39:14 -06:00
|
|
|
if (c == requestedClass) {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter++;
|
2023-01-28 06:39:14 -06:00
|
|
|
} else {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2023-01-21 06:32:41 -05:00
|
|
|
// Message ID
|
2023-01-28 06:39:14 -06:00
|
|
|
if (c == requestedID) {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter++;
|
2023-01-28 06:39:14 -06:00
|
|
|
} else {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2023-07-14 17:25:20 -04:00
|
|
|
// Payload length lsb
|
2022-09-16 02:43:04 +08:00
|
|
|
needRead = c;
|
|
|
|
|
ubxFrameCounter++;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2023-07-14 17:25:20 -04:00
|
|
|
// Payload length msb
|
2023-01-21 06:32:41 -05:00
|
|
|
needRead |= (c << 8);
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter++;
|
|
|
|
|
// Check for buffer overflow
|
2023-01-28 06:39:14 -06:00
|
|
|
if (needRead >= size) {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-01-28 06:39:14 -06:00
|
|
|
if (_serial_gps->readBytes(buffer, needRead) != needRead) {
|
2022-09-16 02:43:04 +08:00
|
|
|
ubxFrameCounter = 0;
|
2023-01-28 06:39:14 -06:00
|
|
|
} else {
|
2023-07-14 17:25:20 -04:00
|
|
|
// return payload length
|
2023-09-03 01:50:11 -05:00
|
|
|
#ifdef GPS_DEBUG
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("Got ACK for class %02X message %02X in %dms", requestedClass, requestedID, millis() - startTime);
|
2023-09-03 01:50:11 -05:00
|
|
|
#endif
|
2022-09-16 02:43:04 +08:00
|
|
|
return needRead;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 02:56:25 -08:00
|
|
|
#if GPS_BAUDRATE_FIXED
|
|
|
|
|
// if GPS_BAUDRATE is specified in variant, only try that.
|
|
|
|
|
static const int serialSpeeds[1] = {GPS_BAUDRATE};
|
|
|
|
|
static const int rareSerialSpeeds[1] = {GPS_BAUDRATE};
|
|
|
|
|
#else
|
|
|
|
|
static const int serialSpeeds[3] = {9600, 115200, 38400};
|
|
|
|
|
static const int rareSerialSpeeds[3] = {4800, 57600, GPS_BAUDRATE};
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-02-20 21:48:37 +08:00
|
|
|
#ifndef GPS_PROBETRIES
|
|
|
|
|
#define GPS_PROBETRIES 2
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-11-02 20:51:12 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Setup the GPS based on the model detected.
|
|
|
|
|
* We detect the GPS by cycling through a set of baud rates, first common then rare.
|
|
|
|
|
* For each baud rate, we run GPS::Probe to send commands and match the responses
|
|
|
|
|
* to known GPS responses.
|
|
|
|
|
* @retval Whether setup reached the end of its potential to configure the GPS.
|
|
|
|
|
*/
|
2023-09-10 22:21:14 -05:00
|
|
|
bool GPS::setup()
|
2020-10-25 17:07:54 +08:00
|
|
|
{
|
2023-09-20 19:34:45 -05:00
|
|
|
if (!didSerialInit) {
|
2024-09-26 02:09:06 +02:00
|
|
|
int msglen = 0;
|
2024-07-25 20:05:03 +02:00
|
|
|
if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) {
|
2025-02-07 16:02:56 +08:00
|
|
|
#ifdef TRACKER_T1000_E
|
|
|
|
|
// add power up/down strategy, improve ag3335 detection success
|
|
|
|
|
digitalWrite(PIN_GPS_EN, LOW);
|
|
|
|
|
delay(500);
|
|
|
|
|
digitalWrite(GPS_VRTC_EN, LOW);
|
|
|
|
|
delay(1000);
|
|
|
|
|
digitalWrite(GPS_VRTC_EN, HIGH);
|
|
|
|
|
delay(500);
|
|
|
|
|
digitalWrite(PIN_GPS_EN, HIGH);
|
|
|
|
|
delay(1000);
|
|
|
|
|
#endif
|
2025-02-20 21:48:37 +08:00
|
|
|
if (probeTries < GPS_PROBETRIES) {
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("Probe for GPS at %d", serialSpeeds[speedSelect]);
|
2024-11-02 20:51:12 +08:00
|
|
|
gnssModel = probe(serialSpeeds[speedSelect]);
|
|
|
|
|
if (gnssModel == GNSS_MODEL_UNKNOWN) {
|
2024-11-27 02:56:25 -08:00
|
|
|
if (++speedSelect == array_count(serialSpeeds)) {
|
2024-11-02 20:51:12 +08:00
|
|
|
speedSelect = 0;
|
|
|
|
|
++probeTries;
|
|
|
|
|
}
|
|
|
|
|
}
|
Cleanup GPS, add UC6580 autodetect (#4319)
* Cleanup GPS, add UC6580 autodetect
Our GPS code autodetects devices by default. Previously UC6580 was
statically assigned, and had its own baudrate configuration inside
the GPS code.
This change adds autodetect functionality for the UC6580 and moves
any 'special' GPS baud rate requirements for a variant out into the
variant configuration. Thereby cleaning up core GPS code a little,
saving the whales, and curing global warming.
New Functionality:
* If GPS_BAUDRATE is defined in variant.h, GPS autodetection will
try that baudrate first.
* UC6580 GPS chips are now automatically detected
* Only run speedSelect skip the first time
* Cleanup GPS, add UC6580 autodetect
Our GPS code autodetects devices by default. Previously UC6580 was
statically assigned, and had its own baudrate configuration inside
the GPS code.
This change adds autodetect functionality for the UC6580 and moves
any 'special' GPS baud rate requirements for a variant out into the
variant configuration. Thereby cleaning up core GPS code a little,
saving the whales, and curing global warming.
New Functionality:
* If GPS_BAUDRATE is defined in variant.h, GPS autodetection will
try that baudrate first.
* UC6580 GPS chips are now automatically detected
* Cleanup GPS, add UC6580 autodetect
Our GPS code autodetects devices by default. Previously UC6580 was
statically assigned, and had its own baudrate configuration inside
the GPS code.
This change adds autodetect functionality for the UC6580 and moves
any 'special' GPS baud rate requirements for a variant out into the
variant configuration. Thereby cleaning up core GPS code a little,
saving the whales, and curing global warming.
New Functionality:
* If GPS_BAUDRATE is defined in variant.h, GPS autodetection will
try that baudrate first.
* UC6580 GPS chips are now automatically detected
* Remove Airoha baud rate code
It's no longer needed.
2024-07-23 19:18:27 +08:00
|
|
|
}
|
2024-11-02 20:51:12 +08:00
|
|
|
// Rare Serial Speeds
|
2025-02-20 21:48:37 +08:00
|
|
|
if (probeTries == GPS_PROBETRIES) {
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("Probe for GPS at %d", rareSerialSpeeds[speedSelect]);
|
2024-11-02 20:51:12 +08:00
|
|
|
gnssModel = probe(rareSerialSpeeds[speedSelect]);
|
|
|
|
|
if (gnssModel == GNSS_MODEL_UNKNOWN) {
|
2024-11-27 02:56:25 -08:00
|
|
|
if (++speedSelect == array_count(rareSerialSpeeds)) {
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_WARN("Give up on GPS probe and set to %d", GPS_BAUDRATE);
|
2023-09-16 23:10:10 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2023-09-10 22:21:14 -05:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 20:19:15 +08:00
|
|
|
}
|
2024-11-02 20:51:12 +08:00
|
|
|
|
2024-11-03 20:19:15 +08:00
|
|
|
if (gnssModel != GNSS_MODEL_UNKNOWN) {
|
|
|
|
|
setConnected();
|
2023-09-16 23:10:10 -05:00
|
|
|
} else {
|
2024-11-03 20:19:15 +08:00
|
|
|
return false;
|
2023-09-10 22:21:14 -05:00
|
|
|
}
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2023-01-28 06:39:14 -06:00
|
|
|
if (gnssModel == GNSS_MODEL_MTK) {
|
2022-09-16 02:43:04 +08:00
|
|
|
/*
|
2023-01-21 06:32:41 -05:00
|
|
|
* t-beam-s3-core uses the same L76K GNSS module as t-echo.
|
|
|
|
|
* Unlike t-echo, L76K uses 9600 baud rate for communication by default.
|
|
|
|
|
* */
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2023-08-06 06:28:37 -07:00
|
|
|
// Initialize the L76K Chip, use GPS + GLONASS + BEIDOU
|
|
|
|
|
_serial_gps->write("$PCAS04,7*1E\r\n");
|
2022-09-16 02:43:04 +08:00
|
|
|
delay(250);
|
|
|
|
|
// only ask for RMC and GGA
|
|
|
|
|
_serial_gps->write("$PCAS03,1,0,0,0,1,0,0,0,0,0,,,0,0*02\r\n");
|
|
|
|
|
delay(250);
|
|
|
|
|
// Switch to Vehicle Mode, since SoftRF enables Aviation < 2g
|
|
|
|
|
_serial_gps->write("$PCAS11,3*1E\r\n");
|
|
|
|
|
delay(250);
|
2024-03-14 16:18:33 +01:00
|
|
|
} else if (gnssModel == GNSS_MODEL_MTK_L76B) {
|
|
|
|
|
// Waveshare Pico-GPS hat uses the L76B with 9600 baud
|
|
|
|
|
// Initialize the L76B Chip, use GPS + GLONASS
|
|
|
|
|
// See note in L76_Series_GNSS_Protocol_Specification, chapter 3.29
|
|
|
|
|
_serial_gps->write("$PMTK353,1,1,0,0,0*2B\r\n");
|
|
|
|
|
// Above command will reset the GPS and takes longer before it will accept new commands
|
|
|
|
|
delay(1000);
|
|
|
|
|
// only ask for RMC and GGA (GNRMC and GNGGA)
|
|
|
|
|
// See note in L76_Series_GNSS_Protocol_Specification, chapter 2.1
|
|
|
|
|
_serial_gps->write("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");
|
|
|
|
|
delay(250);
|
|
|
|
|
// Enable SBAS
|
|
|
|
|
_serial_gps->write("$PMTK301,2*2E\r\n");
|
|
|
|
|
delay(250);
|
|
|
|
|
// Enable PPS for 2D/3D fix only
|
|
|
|
|
_serial_gps->write("$PMTK285,3,100*3F\r\n");
|
|
|
|
|
delay(250);
|
|
|
|
|
// Switch to Fitness Mode, for running and walking purpose with low speed (<5 m/s)
|
|
|
|
|
_serial_gps->write("$PMTK886,1*29\r\n");
|
|
|
|
|
delay(250);
|
2025-05-02 03:11:09 +01:00
|
|
|
} else if (gnssModel == GNSS_MODEL_MTK_PA1010D) {
|
|
|
|
|
// PA1010D is used in the Pimoroni GPS board.
|
|
|
|
|
|
|
|
|
|
// Enable all constellations.
|
|
|
|
|
_serial_gps->write("$PMTK353,1,1,1,1,1*2A\r\n");
|
|
|
|
|
// Above command will reset the GPS and takes longer before it will accept new commands
|
|
|
|
|
delay(1000);
|
|
|
|
|
// Only ask for RMC and GGA (GNRMC and GNGGA)
|
|
|
|
|
_serial_gps->write("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");
|
|
|
|
|
delay(250);
|
|
|
|
|
// Enable SBAS / WAAS
|
|
|
|
|
_serial_gps->write("$PMTK301,2*2E\r\n");
|
|
|
|
|
delay(250);
|
2024-10-29 01:34:01 -07:00
|
|
|
} else if (gnssModel == GNSS_MODEL_MTK_PA1616S) {
|
|
|
|
|
// PA1616S is used in some GPS breakout boards from Adafruit
|
|
|
|
|
// PA1616S does not have GLONASS capability. PA1616D does, but is not implemented here.
|
|
|
|
|
_serial_gps->write("$PMTK353,1,0,0,0,0*2A\r\n");
|
|
|
|
|
// Above command will reset the GPS and takes longer before it will accept new commands
|
|
|
|
|
delay(1000);
|
|
|
|
|
// Only ask for RMC and GGA (GNRMC and GNGGA)
|
|
|
|
|
_serial_gps->write("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");
|
|
|
|
|
delay(250);
|
|
|
|
|
// Enable SBAS / WAAS
|
|
|
|
|
_serial_gps->write("$PMTK301,2*2E\r\n");
|
|
|
|
|
delay(250);
|
2024-04-16 16:03:51 +02:00
|
|
|
} else if (gnssModel == GNSS_MODEL_ATGM336H) {
|
|
|
|
|
// Set the intial configuration of the device - these _should_ work for most AT6558 devices
|
|
|
|
|
msglen = makeCASPacket(0x06, 0x07, sizeof(_message_CAS_CFG_NAVX_CONF), _message_CAS_CFG_NAVX_CONF);
|
|
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
|
|
|
|
if (getACKCas(0x06, 0x07, 250) != GNSS_RESPONSE_OK) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("ATGM336H: Could not set Config");
|
2024-04-16 16:03:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the update frequence to 1Hz
|
|
|
|
|
msglen = makeCASPacket(0x06, 0x04, sizeof(_message_CAS_CFG_RATE_1HZ), _message_CAS_CFG_RATE_1HZ);
|
|
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
|
|
|
|
if (getACKCas(0x06, 0x04, 250) != GNSS_RESPONSE_OK) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("ATGM336H: Could not set Update Frequency");
|
2024-04-16 16:03:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the NEMA output messages
|
|
|
|
|
// Ask for only RMC and GGA
|
|
|
|
|
uint8_t fields[] = {CAS_NEMA_RMC, CAS_NEMA_GGA};
|
2024-05-03 22:49:22 +02:00
|
|
|
for (unsigned int i = 0; i < sizeof(fields); i++) {
|
2024-04-16 16:03:51 +02:00
|
|
|
// Construct a CAS-CFG-MSG packet
|
|
|
|
|
uint8_t cas_cfg_msg_packet[] = {0x4e, fields[i], 0x01, 0x00};
|
|
|
|
|
msglen = makeCASPacket(0x06, 0x01, sizeof(cas_cfg_msg_packet), cas_cfg_msg_packet);
|
|
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
|
|
|
|
if (getACKCas(0x06, 0x01, 250) != GNSS_RESPONSE_OK) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("ATGM336H: Could not enable NMEA MSG: %d", fields[i]);
|
2024-04-16 16:03:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-04 11:35:26 -07:00
|
|
|
} else if (gnssModel == GNSS_MODEL_UC6580) {
|
2023-12-08 13:51:50 -07:00
|
|
|
// The Unicore UC6580 can use a lot of sat systems, enable it to
|
2024-10-10 17:56:32 +08:00
|
|
|
// use GPS L1 & L5 + BDS B1I & B2a + GLONASS L1 + GALILEO E1 & E5a + SBAS + QZSS
|
2023-12-08 13:51:50 -07:00
|
|
|
// This will reset the receiver, so wait a bit afterwards
|
|
|
|
|
// The paranoid will wait for the OK*04 confirmation response after each command.
|
2024-10-10 17:56:32 +08:00
|
|
|
_serial_gps->write("$CFGSYS,h35155\r\n");
|
2023-12-08 13:51:50 -07:00
|
|
|
delay(750);
|
|
|
|
|
// Must be done after the CFGSYS command
|
|
|
|
|
// Turn off GSV messages, we don't really care about which and where the sats are, maybe someday.
|
|
|
|
|
_serial_gps->write("$CFGMSG,0,3,0\r\n");
|
|
|
|
|
delay(250);
|
2024-05-15 11:12:46 -06:00
|
|
|
// Turn off GSA messages, TinyGPS++ doesn't use this message.
|
|
|
|
|
_serial_gps->write("$CFGMSG,0,2,0\r\n");
|
|
|
|
|
delay(250);
|
2023-12-08 13:51:50 -07:00
|
|
|
// Turn off NOTICE __TXT messages, these may provide Unicore some info but we don't care.
|
|
|
|
|
_serial_gps->write("$CFGMSG,6,0,0\r\n");
|
2023-07-16 23:57:14 +02:00
|
|
|
delay(250);
|
2023-12-08 13:51:50 -07:00
|
|
|
_serial_gps->write("$CFGMSG,6,1,0\r\n");
|
|
|
|
|
delay(250);
|
2024-09-25 13:50:00 -05:00
|
|
|
} else if (IS_ONE_OF(gnssModel, GNSS_MODEL_AG3335, GNSS_MODEL_AG3352)) {
|
2024-08-09 09:18:18 +08:00
|
|
|
|
2024-09-06 08:45:57 +08:00
|
|
|
_serial_gps->write("$PAIR066,1,0,1,0,0,1*3B\r\n"); // Enable GPS+GALILEO+NAVIC
|
2024-08-09 09:18:18 +08:00
|
|
|
|
|
|
|
|
// Configure NMEA (sentences will output once per fix)
|
2024-09-08 09:09:01 +08:00
|
|
|
_serial_gps->write("$PAIR062,0,1*3F\r\n"); // GGA ON
|
2024-09-06 08:45:57 +08:00
|
|
|
_serial_gps->write("$PAIR062,1,0*3F\r\n"); // GLL OFF
|
2024-09-08 09:09:01 +08:00
|
|
|
_serial_gps->write("$PAIR062,2,0*3C\r\n"); // GSA OFF
|
2024-09-06 08:45:57 +08:00
|
|
|
_serial_gps->write("$PAIR062,3,0*3D\r\n"); // GSV OFF
|
2024-09-08 09:09:01 +08:00
|
|
|
_serial_gps->write("$PAIR062,4,1*3B\r\n"); // RMC ON
|
2024-09-06 08:45:57 +08:00
|
|
|
_serial_gps->write("$PAIR062,5,0*3B\r\n"); // VTG OFF
|
2024-09-08 09:09:01 +08:00
|
|
|
_serial_gps->write("$PAIR062,6,0*38\r\n"); // ZDA ON
|
2024-08-09 09:18:18 +08:00
|
|
|
|
|
|
|
|
delay(250);
|
2024-09-06 08:45:57 +08:00
|
|
|
_serial_gps->write("$PAIR513*3D\r\n"); // save configuration
|
2024-09-22 23:00:32 +08:00
|
|
|
} else if (gnssModel == GNSS_MODEL_UBLOX6) {
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x02, _message_DISABLE_TXT_INFO, "disable text info messages", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x39, _message_JAM_6_7, "enable interference resistance", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x23, _message_NAVX5, "configure NAVX5 settings", 500);
|
2024-09-22 23:00:32 +08:00
|
|
|
|
|
|
|
|
// Turn off unwanted NMEA messages, set update rate
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x08, _message_1HZ, "set GPS update rate", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GLL, "disable NMEA GLL", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GSA, "enable NMEA GSA", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GSV, "disable NMEA GSV", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_VTG, "disable NMEA VTG", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_RMC, "enable NMEA RMC", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GGA, "enable NMEA GGA", 500);
|
2024-08-09 09:18:18 +08:00
|
|
|
|
2024-09-22 23:00:32 +08:00
|
|
|
clearBuffer();
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x11, _message_CFG_RXM_ECO, "enable powersave ECO mode for Neo-6", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x3B, _message_CFG_PM2, "enable powersave details for GPS", 500);
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_AID, "disable UBX-AID", 500);
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2024-09-22 23:00:32 +08:00
|
|
|
msglen = makeUBXPacket(0x06, 0x09, sizeof(_message_SAVE), _message_SAVE);
|
|
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
|
|
|
|
if (getACK(0x06, 0x09, 2000) != GNSS_RESPONSE_OK) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("Unable to save GNSS module config");
|
2024-09-22 23:00:32 +08:00
|
|
|
} else {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("GNSS module config saved!");
|
2024-09-22 23:00:32 +08:00
|
|
|
}
|
2024-09-25 13:50:00 -05:00
|
|
|
} else if (IS_ONE_OF(gnssModel, GNSS_MODEL_UBLOX7, GNSS_MODEL_UBLOX8, GNSS_MODEL_UBLOX9)) {
|
2024-09-22 23:00:32 +08:00
|
|
|
if (gnssModel == GNSS_MODEL_UBLOX7) {
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_DEBUG("Set GPS+SBAS");
|
2024-09-22 23:00:32 +08:00
|
|
|
msglen = makeUBXPacket(0x06, 0x3e, sizeof(_message_GNSS_7), _message_GNSS_7);
|
2024-02-05 08:02:30 -07:00
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
2024-09-22 23:00:32 +08:00
|
|
|
} else { // 8,9
|
|
|
|
|
msglen = makeUBXPacket(0x06, 0x3e, sizeof(_message_GNSS_8), _message_GNSS_8);
|
2024-02-05 08:02:30 -07:00
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
2024-09-22 23:00:32 +08:00
|
|
|
}
|
2023-07-13 02:35:41 +02:00
|
|
|
|
2024-09-22 23:00:32 +08:00
|
|
|
if (getACK(0x06, 0x3e, 800) == GNSS_RESPONSE_NAK) {
|
|
|
|
|
// It's not critical if the module doesn't acknowledge this configuration.
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_DEBUG("reconfigure GNSS - defaults maintained. Is this module GPS-only?");
|
2024-09-22 23:00:32 +08:00
|
|
|
} else {
|
|
|
|
|
if (gnssModel == GNSS_MODEL_UBLOX7) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("GPS+SBAS configured");
|
2024-09-22 23:00:32 +08:00
|
|
|
} else { // 8,9
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("GPS+SBAS+GLONASS+Galileo configured");
|
2024-02-05 08:02:30 -07:00
|
|
|
}
|
2024-09-22 23:00:32 +08:00
|
|
|
// Documentation say, we need wait atleast 0.5s after reconfiguration of GNSS module, before sending next
|
|
|
|
|
// commands for the M8 it tends to be more... 1 sec should be enough ;>)
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
2024-01-30 16:38:31 -07:00
|
|
|
|
2024-09-22 23:00:32 +08:00
|
|
|
// Disable Text Info messages //6,7,8,9
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x02, _message_DISABLE_TXT_INFO, "disable text info messages", 500);
|
2024-02-14 06:06:38 -07:00
|
|
|
|
2024-09-22 23:00:32 +08:00
|
|
|
if (gnssModel == GNSS_MODEL_UBLOX8) { // 8
|
2024-02-14 06:06:38 -07:00
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x39, _message_JAM_8, "enable interference resistance", 500);
|
2024-09-22 23:00:32 +08:00
|
|
|
|
2024-02-14 06:06:38 -07:00
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x23, _message_NAVX5_8, "configure NAVX5_8 settings", 500);
|
2024-09-22 23:00:32 +08:00
|
|
|
} else { // 6,7,9
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x39, _message_JAM_6_7, "enable interference resistance", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x23, _message_NAVX5, "configure NAVX5 settings", 500);
|
2024-09-22 23:00:32 +08:00
|
|
|
}
|
|
|
|
|
// Turn off unwanted NMEA messages, set update rate
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x08, _message_1HZ, "set GPS update rate", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GLL, "disable NMEA GLL", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GSA, "enable NMEA GSA", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GSV, "disable NMEA GSV", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_VTG, "disable NMEA VTG", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_RMC, "enable NMEA RMC", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x01, _message_GGA, "enable NMEA GGA", 500);
|
2024-09-22 23:00:32 +08:00
|
|
|
|
2024-11-27 02:56:25 -08:00
|
|
|
if (ublox_info.protocol_version >= 18) {
|
2024-02-14 06:06:38 -07:00
|
|
|
clearBuffer();
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x86, _message_PMS, "enable powersave for GPS", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x3B, _message_CFG_PM2, "enable powersave details for GPS", 500);
|
2024-02-14 06:06:38 -07:00
|
|
|
|
2024-09-22 23:00:32 +08:00
|
|
|
// For M8 we want to enable NMEA vserion 4.10 so we can see the additional sats.
|
|
|
|
|
if (gnssModel == GNSS_MODEL_UBLOX8) {
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x17, _message_NMEA, "enable NMEA 4.10", 500);
|
2024-02-14 06:06:38 -07:00
|
|
|
}
|
2024-09-22 23:00:32 +08:00
|
|
|
} else {
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x11, _message_CFG_RXM_PSM, "enable powersave mode for GPS", 500);
|
|
|
|
|
SEND_UBX_PACKET(0x06, 0x3B, _message_CFG_PM2, "enable powersave details for GPS", 500);
|
2024-01-30 16:38:31 -07:00
|
|
|
}
|
2024-02-14 06:06:38 -07:00
|
|
|
|
2024-03-03 12:08:47 -07:00
|
|
|
msglen = makeUBXPacket(0x06, 0x09, sizeof(_message_SAVE), _message_SAVE);
|
|
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
|
|
|
|
if (getACK(0x06, 0x09, 2000) != GNSS_RESPONSE_OK) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("Unable to save GNSS module config");
|
2024-03-03 12:08:47 -07:00
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("GNSS module configuration saved!");
|
2024-03-03 12:08:47 -07:00
|
|
|
}
|
2024-09-22 23:00:32 +08:00
|
|
|
} else if (gnssModel == GNSS_MODEL_UBLOX10) {
|
|
|
|
|
delay(1000);
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_DISABLE_NMEA_RAM, "disable NMEA messages in M10 RAM", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_DISABLE_NMEA_BBR, "disable NMEA messages in M10 BBR", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_DISABLE_TXT_INFO_RAM, "disable Info messages for M10 GPS RAM", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
// Next disable Info txt messages in BBR layer
|
|
|
|
|
clearBuffer();
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_DISABLE_TXT_INFO_BBR, "disable Info messages for M10 GPS BBR", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
// Do M10 configuration for Power Management.
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_PM_RAM, "enable powersave for M10 GPS RAM", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_PM_BBR, "enable powersave for M10 GPS BBR", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_ITFM_RAM, "enable jam detection M10 GPS RAM", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
2024-11-04 19:15:59 -06:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_ITFM_BBR, "enable jam detection M10 GPS BBR", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
// Here is where the init commands should go to do further M10 initialization.
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_DISABLE_SBAS_RAM, "disable SBAS M10 GPS RAM", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750); // will cause a receiver restart so wait a bit
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_DISABLE_SBAS_BBR, "disable SBAS M10 GPS BBR", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750); // will cause a receiver restart so wait a bit
|
|
|
|
|
|
2024-11-02 20:51:12 +08:00
|
|
|
// Done with initialization, Now enable wanted NMEA messages in BBR layer so they will survive a periodic
|
|
|
|
|
// sleep.
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_ENABLE_NMEA_BBR, "enable messages for M10 GPS BBR", 300);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
// Next enable wanted NMEA messages in RAM layer
|
2024-10-01 15:38:36 -05:00
|
|
|
SEND_UBX_PACKET(0x06, 0x8A, _message_VALSET_ENABLE_NMEA_RAM, "enable messages for M10 GPS RAM", 500);
|
2024-09-22 23:00:32 +08:00
|
|
|
delay(750);
|
|
|
|
|
|
|
|
|
|
// As the M10 has no flash, the best we can do to preserve the config is to set it in RAM and BBR.
|
|
|
|
|
// BBR will survive a restart, and power off for a while, but modules with small backup
|
|
|
|
|
// batteries or super caps will not retain the config for a long power off time.
|
2024-09-24 18:50:03 +08:00
|
|
|
msglen = makeUBXPacket(0x06, 0x09, sizeof(_message_SAVE_10), _message_SAVE_10);
|
2024-03-03 12:08:47 -07:00
|
|
|
_serial_gps->write(UBXscratch, msglen);
|
|
|
|
|
if (getACK(0x06, 0x09, 2000) != GNSS_RESPONSE_OK) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("Unable to save GNSS module config");
|
2024-03-03 12:08:47 -07:00
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("GNSS module configuration saved!");
|
2024-03-03 12:08:47 -07:00
|
|
|
}
|
2022-09-16 02:43:04 +08:00
|
|
|
}
|
2023-09-10 22:21:14 -05:00
|
|
|
didSerialInit = true;
|
2020-10-25 17:07:54 +08:00
|
|
|
}
|
|
|
|
|
|
2023-09-10 22:21:14 -05:00
|
|
|
notifyDeepSleepObserver.observe(¬ifyDeepSleep);
|
2023-11-28 20:40:51 -06:00
|
|
|
|
2023-09-10 22:21:14 -05:00
|
|
|
return true;
|
2020-10-01 09:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-10 15:21:54 +08:00
|
|
|
GPS::~GPS()
|
|
|
|
|
{
|
|
|
|
|
// we really should unregister our sleep observer
|
2022-04-14 00:43:06 +02:00
|
|
|
notifyDeepSleepObserver.unobserve(¬ifyDeepSleep);
|
2021-03-10 15:21:54 +08:00
|
|
|
}
|
2024-11-25 03:32:04 -08:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Put the GPS hardware into a specified state
|
|
|
|
|
void GPS::setPowerState(GPSPowerState newState, uint32_t sleepTime)
|
2020-10-13 13:59:06 +08:00
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
// Update the stored GPSPowerstate, and create local copies
|
|
|
|
|
GPSPowerState oldState = powerState;
|
|
|
|
|
powerState = newState;
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_INFO("GPS power state move from %s to %s", getGPSPowerStateString(oldState), getGPSPowerStateString(newState));
|
2024-07-11 15:26:43 +12:00
|
|
|
|
|
|
|
|
switch (newState) {
|
2024-06-21 17:25:54 -05:00
|
|
|
case GPS_ACTIVE:
|
2024-07-11 15:26:43 +12:00
|
|
|
case GPS_IDLE:
|
|
|
|
|
if (oldState == GPS_ACTIVE || oldState == GPS_IDLE) // If hardware already awake, no changes needed
|
|
|
|
|
break;
|
|
|
|
|
if (oldState != GPS_ACTIVE && oldState != GPS_IDLE) // If hardware just waking now, clear buffer
|
|
|
|
|
clearBuffer();
|
|
|
|
|
powerMon->setState(meshtastic_PowerMon_State_GPS_Active); // Report change for power monitoring (during testing)
|
|
|
|
|
writePinEN(true); // Power (EN pin): on
|
|
|
|
|
setPowerPMU(true); // Power (PMU): on
|
|
|
|
|
writePinStandby(false); // Standby (pin): awake (not standby)
|
|
|
|
|
setPowerUBLOX(true); // Standby (UBLOX): awake
|
2025-02-07 16:02:56 +08:00
|
|
|
#ifdef GNSS_AIROHA
|
|
|
|
|
lastFixStartMsec = 0;
|
|
|
|
|
#endif
|
2024-07-11 15:26:43 +12:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GPS_SOFTSLEEP:
|
|
|
|
|
powerMon->clearState(meshtastic_PowerMon_State_GPS_Active); // Report change for power monitoring (during testing)
|
|
|
|
|
writePinEN(true); // Power (EN pin): on
|
|
|
|
|
setPowerPMU(true); // Power (PMU): on
|
|
|
|
|
writePinStandby(true); // Standby (pin): asleep (not awake)
|
|
|
|
|
setPowerUBLOX(false, sleepTime); // Standby (UBLOX): asleep, timed
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GPS_HARDSLEEP:
|
|
|
|
|
powerMon->clearState(meshtastic_PowerMon_State_GPS_Active); // Report change for power monitoring (during testing)
|
|
|
|
|
writePinEN(false); // Power (EN pin): off
|
|
|
|
|
setPowerPMU(false); // Power (PMU): off
|
|
|
|
|
writePinStandby(true); // Standby (pin): asleep (not awake)
|
|
|
|
|
setPowerUBLOX(false, sleepTime); // Standby (UBLOX): asleep, timed
|
2024-07-25 10:10:38 +08:00
|
|
|
#ifdef GNSS_AIROHA
|
2025-07-22 13:49:10 -05:00
|
|
|
if (config.position.broadcast_smart_minimum_interval_secs * 1000 >= GPS_FIX_HOLD_TIME * 2) {
|
2024-07-25 10:10:38 +08:00
|
|
|
digitalWrite(PIN_GPS_EN, LOW);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-07-11 15:26:43 +12:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GPS_OFF:
|
|
|
|
|
assert(sleepTime == 0); // This is an indefinite sleep
|
|
|
|
|
powerMon->clearState(meshtastic_PowerMon_State_GPS_Active); // Report change for power monitoring (during testing)
|
|
|
|
|
writePinEN(false); // Power (EN pin): off
|
|
|
|
|
setPowerPMU(false); // Power (PMU): off
|
|
|
|
|
writePinStandby(true); // Standby (pin): asleep
|
|
|
|
|
setPowerUBLOX(false, 0); // Standby (UBLOX): asleep, indefinitely
|
2024-07-25 10:10:38 +08:00
|
|
|
#ifdef GNSS_AIROHA
|
2025-07-22 13:49:10 -05:00
|
|
|
if (config.position.broadcast_smart_minimum_interval_secs * 1000 >= GPS_FIX_HOLD_TIME * 2) {
|
2024-07-25 10:10:38 +08:00
|
|
|
digitalWrite(PIN_GPS_EN, LOW);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-07-11 15:26:43 +12:00
|
|
|
break;
|
2024-07-22 15:30:36 +02:00
|
|
|
}
|
2024-06-21 17:25:54 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Set power with EN pin, if relevant
|
|
|
|
|
void GPS::writePinEN(bool on)
|
2020-10-13 13:59:06 +08:00
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
// Abort: if conflict with Canned Messages when using Wisblock(?)
|
2024-11-19 22:57:46 -06:00
|
|
|
if ((HW_VENDOR == meshtastic_HardwareModel_RAK4631 || HW_VENDOR == meshtastic_HardwareModel_WISMESH_TAP) &&
|
|
|
|
|
(rotaryEncoderInterruptImpl1 || upDownInterruptImpl1))
|
2023-09-23 23:45:35 -05:00
|
|
|
return;
|
2024-06-15 01:28:01 +12:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Write and log
|
2024-08-22 10:15:23 -07:00
|
|
|
enablePin->set(on);
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-11-07 23:19:31 +01:00
|
|
|
LOG_DEBUG("Pin EN %s", on == HIGH ? "HI" : "LOW");
|
2020-10-13 13:59:06 +08:00
|
|
|
#endif
|
2024-07-11 15:26:43 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the value of the STANDBY pin, if relevant
|
|
|
|
|
// true for standby state, false for awake
|
|
|
|
|
void GPS::writePinStandby(bool standby)
|
|
|
|
|
{
|
2024-03-14 16:18:33 +01:00
|
|
|
#ifdef PIN_GPS_STANDBY // Specifically the standby pin for L76B, L76K and clones
|
2024-07-11 15:26:43 +12:00
|
|
|
|
|
|
|
|
// Determine the new value for the pin
|
|
|
|
|
// Normally: active HIGH for awake
|
2024-07-22 15:30:36 +02:00
|
|
|
#ifdef PIN_GPS_STANDBY_INVERTED
|
2024-07-11 15:26:43 +12:00
|
|
|
bool val = standby;
|
2024-07-22 15:30:36 +02:00
|
|
|
#else
|
2024-07-11 15:26:43 +12:00
|
|
|
bool val = !standby;
|
Sync Wio lr1110 refresh with master (#4288)
* Fix protobuf structs handling (#4140)
* Fix protobuf structs handling
* Log instead of assert
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* BLE based logging (#4146)
* WIP log characteristic
* Bluetooth logging plumbing
* Characteristic
* Callback
* Check for nullptr
* Esp32 bluetooth impl
* Formatting
* Add thread name and log level
* Add settings guard
* Remove comments
* Field name
* Fixes esp32
* Open it up
* Whoops
* Move va_end past our logic
* Use `upload_protocol = esptool` as with the other heltec devices instead of `esp-builtin` (#4151)
* Standardize lat/lon position logs (#4156)
* Standardize lat/lon position logs
* Missed sone and condensed logs
* [create-pull-request] automated change (#4157)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Pause BLE logging during want_config flow (#4162)
* Update NimBLE to 1.4.2 (#4163)
* Implement replies for all telemetry types based on variant tag (#4164)
* Implement replies for all telemetry types based on variant tag
* Remove check for `ignoreRequest`: modules can set this, don't need to check
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Esptool is better
* Explicitly set characteristic
* fix INA3221 sensor (#4168)
- pass wire to begin()
- remove redundant setAddr() (already set in header)
* Show compass on waypoint frame; clear when waypoint deleted (#4116)
* Clear expired or deleted waypoint frame
* Return 0 to CallbackObserver
* Add a missing comment
* Draw compass for waypoint frame
* Display our own waypoints
* [create-pull-request] automated change (#4171)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Add semihosting support for nrf52 devices (#4137)
* Turn off vscode cmake prompt - we don't use cmake on meshtastic
* Add rak4631_dap variant for debugging with NanoDAP debug probe device.
* The rak device can also run freertos (which is underneath nrf52 arduino)
* Add semihosting support for nrf52840 devices
Initial platformio.ini file only supports rak4630
Default to non TCP for the semihosting log output for now...
Fixes https://github.com/meshtastic/firmware/issues/4135
* fix my botched merge - keep board_level = extra flag for rak3631_dbg
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* [create-pull-request] automated change (#4174)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Display alerts (#4170)
* Move static functions into Screen.h, show compass during calibration
* Move to _fontHeight macro to avoid collision
* Move some alert functions to new alert handler
* Catch missed reboot code
* ESP32 fixes
* Bump esp8266-oled-ssd1306
* Fixes for when a device has no screen
* Use new startAlert(char*) helper class
* Add EINK bits back to alert handling
* Add noop class for no-display devices
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Send file system manifest up on want_config (#4176)
* Send file system manifest up on want_config
* Platform specific methods
* Helps to actually make the change
* Clear
* tell vscode, if formatting, use whatever our trunk formatter wants (#4186)
without this flag if the user has set some other formatter (clang)
in their user level settings, it will be looking in the wrong directory
for the clang options (we want the options in .trunk/clang)
Note: formatOnSave is true in master, which means a bunch of our older
files are non compliant and if you edit them it will generate lots of
formatting related diffs. I guess I'll start letting that happen with
my future commits ;-).
* fix the build - would loop forever if there were no files to send (#4188)
* Show owner.short_name on boot (and E-Ink sleep screen) (#4134)
* Show owner.short_name on boot and sleep screen (on e-ink)
* Update Screen.cpp - new line for short_name
Boot screen short_name now below the region setting.
Looks better on small screens.
* Draw short_name on right
---------
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* nrf52 soft device will watchdog if you use ICE while BT on... (#4189)
so have debugger disable bluetooth.
* correct xiao_ble build preventing sx1262 init (#4191)
* Force a compile time failur if FromRadio or ToRadio get larger than (#4190)
a BLE packet size. We are actually very close to this threshold so
important to make sure we don't accidentally pass it.
* Clear vector after complete config state (#4194)
* Clear after complete config
* Don't collect . entries
* Log file name and size
* [create-pull-request] automated change (#4200)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Make the logs Colorful! (#4199)
* Squash needlessly static functions (#4183)
* Trim extra vprintf and filter for unprintable characters
* Deprecate Router Client role (and make it Client) (#4201)
* [create-pull-request] automated change (#4205)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Move waypoint (#4202)
* Move waypoint screen draw into the waypoint module
* Get the observer set up for the waypoint screen draw
* Static squashing: screen dimensions
Macros moved back to Screen.cpp, as a band-aid until we eventually move all those static functions into the Screen class.
* Move getCompassDiam into Screen class
(supress compiler warnings)
At this stage, the method is still static, because it's used by drawNodeInfo, which has no tidy reference to our screen instance.
This is probably just another band-aid until these static functions all move.
* Use new getCompassDiam function in AccelerometerThread
* Properly gate display code in WaypointModule
---------
Co-authored-by: Todd Herbert <herbert.todd@gmail.com>
* Fix flakey phone api transition from file manifest to complete (#4209)
* Try fix flakey phone api transition from file manifest to complete
* Skip
* enable colors in platformio serial monitor (#4217)
* When talking via serial, encapsulate log messages in protobufs if necessary (#4187)
* clean up RedirectablePrint::log so it doesn't have three very different implementations inline.
* remove NoopPrint - it is no longer needed
* when talking to API clients via serial, don't turn off log msgs instead encapsuate them
* fix the build - would loop forever if there were no files to send
* don't use Segger code if not talking to a Segger debugger
* when encapsulating logs, make sure the strings always has nul terminators
* nrf52 soft device will watchdog if you use ICE while BT on...
so have debugger disable bluetooth.
* Important to not print debug messages while writing to the toPhone scratch buffer
* don't include newlines if encapsulating log records as protobufs
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* [create-pull-request] automated change (#4218)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Fix SHT41 support (#4222)
* Add SHT41 Serial to I2c Detection Code
On the Seeed Wio-WM1110 Dev Kit board, the SHT41 chip was being
incorrectly detected as SHT31.
This patch adds the necessary serial number for the SHT41 chip to
be correctly detected.
fixes meshtastic/firmware#4221
* Add missing sensor read for SHT41
* Typo fix in logs - mhz - MHz (#4225)
As reported by karamo, a few different places in our logs had
incorrect capitalization of MHz.
fixes meshtastic/firmware#4126
* New new BLE logging characteristic with LogRecord protos (#4220)
* New UUID
* New log radio characteristic with LogRecord protobuf
* LogRecord
* Merge derp
* How did you get there
* Trunk
* Fix length
* Remove assert
* minor cleanup proposal (#4169)
* MESHTASTIC_EXCLUDE_WIFI and HAS_WIFI cleanup...
Our code was checking HAS_WIFI and the new MESHTASTIC_EXCLUDE_WIFI
flags in various places (even though EXCLUDE_WIFI forces HAS_WIFI
to 0). Instead just check HAS_WIFI, only use EXCLUDE_WIFI inside
configuration.h
* cleanup: use HAS_NETWORKING instead of HAS_WIFI || HAS_ETHERNET
We already had HAS_NETWORKING as flag in MQTT to mean 'we have
tcpip'. Generallize that and move it into configuration.h so that
we can use it elsewhere.
* Use #pragma once, because supported by gcc and all modern compilers
instead of #ifdef DOTHFILE_H etc...
---------
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Add PowerMon support (#4155)
* Turn off vscode cmake prompt - we don't use cmake on meshtastic
* Add rak4631_dap variant for debugging with NanoDAP debug probe device.
* The rak device can also run freertos (which is underneath nrf52 arduino)
* Add semihosting support for nrf52840 devices
Initial platformio.ini file only supports rak4630
Default to non TCP for the semihosting log output for now...
Fixes https://github.com/meshtastic/firmware/issues/4135
* powermon WIP (for https://github.com/meshtastic/firmware/issues/4136 )
* oops - mean't to mark the _dbg variant as an 'extra' board.
* powermon wip
* Make serial port on wio-sdk-wm1110 board work
By disabling the (inaccessible) adafruit USB
* Instrument (radiolib only for now) lora for powermon
per https://github.com/meshtastic/firmware/issues/4136
* powermon gps support
https://github.com/meshtastic/firmware/issues/4136
* Add CPU deep and light sleep powermon states
https://github.com/meshtastic/firmware/issues/4136
* Change the board/swversion bootstring so it is a new "structured" log msg.
* powermon wip
* add example script for getting esp S3 debugging working
Not yet used but I didn't want these nasty tricks to get lost yet.
* Add PowerMon reporting for screen and bluetooth pwr.
* make power.powermon_enables config setting work.
* update to latest protobufs
* fix bogus shellcheck warning
* make powermon optional (but default enabled because tiny and no runtime impact)
* tell vscode, if formatting, use whatever our trunk formatter wants
without this flag if the user has set some other formatter (clang)
in their user level settings, it will be looking in the wrong directory
for the clang options (we want the options in .trunk/clang)
Note: formatOnSave is true in master, which means a bunch of our older
files are non compliant and if you edit them it will generate lots of
formatting related diffs. I guess I'll start letting that happen with
my future commits ;-).
* add PowerStress module
* nrf52 arduino is built upon freertos, so let platformio debug it
* don't accidentally try to Segger ICE if we are using another ICE
* clean up RedirectablePrint::log so it doesn't have three very different implementations inline.
* remove NoopPrint - it is no longer needed
* when talking to API clients via serial, don't turn off log msgs instead encapsuate them
* fix the build - would loop forever if there were no files to send
* don't use Segger code if not talking to a Segger debugger
* when encapsulating logs, make sure the strings always has nul terminators
* nrf52 soft device will watchdog if you use ICE while BT on...
so have debugger disable bluetooth.
* Important to not print debug messages while writing to the toPhone scratch buffer
* don't include newlines if encapsulating log records as protobufs
* update to latest protobufs (needed for powermon goo)
* PowerStress WIP
* fix linter warning
* Cleanup buffer
* Merge hex for wm1110 target(s)
* Only sdk
* Sudo
* Fix exclude macros (#4233)
* fix MESHTASTIC_EXCLUDE_BLUETOOTH
* fix HAS_SCREEN=0
* fix MESHTASTIC_EXCLUDE_GPS
* fix typo in build-nrf52.sh (#4231)
chmod is the command, '+x' is the argument.
* Tidy Wireless Paper variant files (#4238)
* Quick tidy of pins_arduino.h
Matches requests made at https://github.com/meshtastic/firmware/pull/4226#discussion_r1664183480)
* Tidy variant.h
* Change deprecated ADC attenuation parameter
From 11dB to 12dB. Resolves compiler warning. Allegly, no impact on function: `This is deprecated, it behaves the same as `ADC_ATTEN_DB_12`
* Updated raspbian CI to update apt repository ahead of libbluetooth. (#4243)
* Fix BLE logging on nrf52 (#4244)
* allow ble logrecords to be fetched either by NOTIFY or INDICATE ble types
This allows 'lossless' log reading. If client has requested INDICATE
(rather than NOTIFY) each log record emitted via log() will have to fetched
by the client device before the meshtastic node can continue.
* Fix serious problem with nrf52 BLE logging.
When doing notifies of LogRecords it is important to use the
binary write routines - writing using the 'string' write won't work.
Because protobufs can contain \0 nuls inside of them which if being
parsed as a string will cause only a portion of the protobuf to be sent.
I noticed this because some log messages were not getting through.
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Fix build when HAS_NETWORKING is false on nrf52 (#4237)
(tested on a rak4631 by setting HAS_ETHERNET false when shrinking
image)
* If `toPhoneQueue` is full, still increment `fromNum` to avoid client never getting packets (#4246)
* Update to SoftDevice 7.3.0 for wio-sdk-wm1110 and wio-tracker-wm1110 (#4248)
* Update variant.h
* Update wio-tracker-wm1110.json
* Update wio-sdk-wm1110.json
* Update platformio.ini
* Update platformio.ini
* Add files via upload
* Add files via upload
* Update variant.h
* Cleanup NRF s140 Softdevice variants (#4252)
Note: This idea is originally from @caveman99 and should be
credited as such. Submitting as a separate PR so the work in
meshtastic/firmware#4148 can be a bit cleaner and Seeed boards
can build while that work is ongoing.
The nrf52 boards that depend on the v7 softdevice all use the same
code and linker files. Rather than duplicate the code, keep it
all together with the platform.
* Remove tracker variant specific soft device headers (#4255)
* [create-pull-request] automated change (#4247)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Add wio-sdk-wm1110 to build. (#4258)
The wio-sdk-wm1110 is distinct from the wio-tracker-wm1110, with
different platformio build options and pin config.
This change adds the wio-sdk-wm1110 to the CI matrix so firmware
is built as part of release.
* fix python warning in uf2conf (#4235)
the old regex worked but was technically incorrect. fixes:
Generating NRF52 uf2 file
/home/kevinh/development/meshtastic/firmware/bin/uf2conv.py:195: SyntaxWarning: invalid escape sequence '\s'
words = re.split('\s+', line)
Converting to uf2, output size: 1458688, start address: 0x26000
* Collect hex files and specifically wm1110 sdk
* Skip dfu file for sdk (for now)
* Helps if you remove the original clause
* Add Heltec new boards. (#4226)
* Add Heltec new boards
* Update variant.h
disable RTC by default
* Add Heltec New boards
* Add Heltec new boards
* Update Heltec Mesh Node definition.
* Update Heltec Vision Mater E290
* [create-pull-request] automated change (#4259)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Trunk fmt
* Fix macros
* Move e290 to board level extra while CI is broken
* Tell trunk to ignore bin folder
* Fix missing
* Update trunk.yaml, fix whitespace
* Update trunk.yaml
* Update build_raspbian_armv7l.yml --fix-missing
* [create-pull-request] automated change (#4263)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* GPS Power State tidy-up (#4161)
* Refactor GPSPowerState enum
Identifies a case where the GPS hardware is awake, but an update is not yet desired
* Change terminology
* Clear old lock-time prediction on triple press
* Use exponential smoothing to predict lock time
* Rename averageLockTime to predictedLockTime
* Attempt: Send PMREQ with duration 0 on MCU deep-sleep
* Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep
* Revert "Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep"
This reverts commit 8b697cd2a445355dcfab5b33e0ce7a3128cab151.
* Revert "Attempt: Send PMREQ with duration 0 on MCU deep-sleep"
This reverts commit 9d29ec7603a88056b9115796b29b5023165a93bb.
* Remove unused notifyGPSSleep Observable
Handled with notifyDeepSleep, and enable() / disable()
* WIP: simplify GPS power management
An initial attempt only.
* Honor #3e9e0fd
* No-op when moving between GPS_IDLE and GPS_ACTIVE
* Ensure U-blox GPS is awake to receive indefinite sleep command
* Longer pause when waking U-blox to send sleep command
* Actually implement soft and hard sleep..
* Dynamically estimate the threshold for GPS_HARDSLEEP
* Fallback to GPS_HARDSLEEP, if GPS_SOFTSLEEP unsupported
* Move "excessive search time" behavior to scheduler class
* Minor logging adjustments
* Promote log to warning
* Gratuitous buffer clearing on boot
* Fix inverted standby pin logic
Specifically the standby pin for L76B, L76K and clones
Discovered during T-Echo testing: totally broken function, probe method failing.
* Remove redundant pin init
Now handled by setPowerState
* Replace max() with if statements
Avoid those platform specific implementations..
* Trunk formatting
New round of settings.json changes keep catching me out, have to remember to re-enable my "clang-format" for windows workaround.
* Remove some asserts from setPowerState
Original aim was to prevent sending a 0 second PMREQ to U-blox hardware as part of a timed sleep (GPS_HARDSLEEP, GPS_SOFTSLEEP). I'm not sure this is super important, and it feels tidier to just allow the 0 second sleeptime here, rather than fudge the sleeptime further up.
* Fix an error determining whether GPS_SOFTSLEEP is supported
* Clarify a log entry
* Set PIN_STANDBY for MCU deep-sleep
Required to reach TTGO's advertised 0.25mA sleep current for T-Echo. Without this change: ~6mA.
* Optimize the shutdown current of RAK10701 to around 25uA (#4260)
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* INA3221 sensor: use for bus voltage & environment metrics (#4215)
* use INA3221 for bus voltage; fixes for telemetry variants
- add to sensors available for environment telemetry
(to report voltage/current)
- add vars to define channels to use for battery voltage
(for getBusVoltage) and environment metrics (default
to CH1 for both)
- write to the correct fields on the measurement struct
depending on the measurement variant, and DRY up the
sensor measurement collection code a bit
- this might be suitable for a common implementation for
the INA* sensors in a future PR...
* formatting
* derp
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* WM1110 SDK kit enter serial DFU and add deployment packages (#4266)
* Switch default upload protocol to nrfutil so that pio generates zip deploy packages
* Enter serial DFU on SDK board
* Remove guard for DFU zip from SDK build
* NRF_USE_SERIAL_DFU macro instead
* Show specific frame when updating screen (#4264)
* Updated setFrames in Screen.cpp
Added code to attempt to revert back to the same frame that user was on prior to setFrame reload.
* Space added Screen.cpp
* Update Screen.cpp
Make screen to revert to Frame 0 if the originally displayed frame is no longer there.
* Update Screen.cpp
Inserted boolean holdPosition into setFrames to indicate the requirement to stay on the same frame ( if =true) or else it will switch to new frame .
Only Screen::handleStatusUpdate calls with setFrame(true). ( For Node Updates)
All other types of updates call as before setFrame(), so it will change focus as needed.
* Hold position, even if number of frames increases
* Hold position, if handling an outgoing text message
* Update Screen.cpp
* Reverted chnages related to devicestate.has_rx_text_message
* Reset to master
* CannedMessages only handles routing packets when waiting for ACK
Previously, this was calling Screen::setFrames at unexpected times
* Gather position info about screen frames while regenerating
* Make admin module observable
Notify only when relevant. Currently: only to handle remove_nodenum.
* Optionally specify which frame to focus when setFrames runs
* UIFrameEvent uses enum instead of multiple booleans
* Allow modules to request their own frame to be focussed
This is done internally by calling MeshModule::requestFocus()
Easier this way, insteady of passing the info in the UIFrameEvent:
* Modules don't always know whether they should be focussed until after the UIFrameEvent has been raised, in dramFrame
* Don't have to pass reference to module instance as parameter though several methods
* E-Ink screensaver uses FOCUS_PRESERVE
Previously, it had its own basic implementation of this.
* Spelling: regional variant
* trunk
* Fix HAS_SCREEN guarding
* More HAS_SCREEN guarding
---------
Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: slash-bit <v-b2@live.com>
* Move up telemetry defaults to every 30 minutes (#4274)
* Don't send node info interrogation when ch. util is >25% (#4273)
* Moar LR1110 Targets
* update SD_FLASH_SIZE to 0x27000 (#4232)
The 7.3.0 softdevice needs the extra 1000 :)
* Fix spacing.
---------
Co-authored-by: Mike <mikhael.skvortsov@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Mike G <mkgin@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
Co-authored-by: Warren Guy <5602790+warrenguy@users.noreply.github.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Alexander <156134901+Dorn8010@users.noreply.github.com>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: quimnut <github@dopegoat.com>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>
Co-authored-by: Agent Blu, 006 <blu006@ucr.edu>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Aaron.Lee <32860565+Heltec-Aaron-Lee@users.noreply.github.com>
Co-authored-by: Daniel.Cao <144674500+DanielCao0@users.noreply.github.com>
Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com>
Co-authored-by: slash-bit <v-b2@live.com>
2024-07-14 09:38:19 +08:00
|
|
|
#endif
|
2024-07-11 15:26:43 +12:00
|
|
|
|
|
|
|
|
// Write and log
|
|
|
|
|
pinMode(PIN_GPS_STANDBY, OUTPUT);
|
|
|
|
|
digitalWrite(PIN_GPS_STANDBY, val);
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
LOG_DEBUG("Pin STANDBY %s", val == HIGH ? "HI" : "LOW");
|
2024-07-22 15:30:36 +02:00
|
|
|
#endif
|
Sync Wio lr1110 refresh with master (#4288)
* Fix protobuf structs handling (#4140)
* Fix protobuf structs handling
* Log instead of assert
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* BLE based logging (#4146)
* WIP log characteristic
* Bluetooth logging plumbing
* Characteristic
* Callback
* Check for nullptr
* Esp32 bluetooth impl
* Formatting
* Add thread name and log level
* Add settings guard
* Remove comments
* Field name
* Fixes esp32
* Open it up
* Whoops
* Move va_end past our logic
* Use `upload_protocol = esptool` as with the other heltec devices instead of `esp-builtin` (#4151)
* Standardize lat/lon position logs (#4156)
* Standardize lat/lon position logs
* Missed sone and condensed logs
* [create-pull-request] automated change (#4157)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Pause BLE logging during want_config flow (#4162)
* Update NimBLE to 1.4.2 (#4163)
* Implement replies for all telemetry types based on variant tag (#4164)
* Implement replies for all telemetry types based on variant tag
* Remove check for `ignoreRequest`: modules can set this, don't need to check
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Esptool is better
* Explicitly set characteristic
* fix INA3221 sensor (#4168)
- pass wire to begin()
- remove redundant setAddr() (already set in header)
* Show compass on waypoint frame; clear when waypoint deleted (#4116)
* Clear expired or deleted waypoint frame
* Return 0 to CallbackObserver
* Add a missing comment
* Draw compass for waypoint frame
* Display our own waypoints
* [create-pull-request] automated change (#4171)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Add semihosting support for nrf52 devices (#4137)
* Turn off vscode cmake prompt - we don't use cmake on meshtastic
* Add rak4631_dap variant for debugging with NanoDAP debug probe device.
* The rak device can also run freertos (which is underneath nrf52 arduino)
* Add semihosting support for nrf52840 devices
Initial platformio.ini file only supports rak4630
Default to non TCP for the semihosting log output for now...
Fixes https://github.com/meshtastic/firmware/issues/4135
* fix my botched merge - keep board_level = extra flag for rak3631_dbg
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* [create-pull-request] automated change (#4174)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Display alerts (#4170)
* Move static functions into Screen.h, show compass during calibration
* Move to _fontHeight macro to avoid collision
* Move some alert functions to new alert handler
* Catch missed reboot code
* ESP32 fixes
* Bump esp8266-oled-ssd1306
* Fixes for when a device has no screen
* Use new startAlert(char*) helper class
* Add EINK bits back to alert handling
* Add noop class for no-display devices
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Send file system manifest up on want_config (#4176)
* Send file system manifest up on want_config
* Platform specific methods
* Helps to actually make the change
* Clear
* tell vscode, if formatting, use whatever our trunk formatter wants (#4186)
without this flag if the user has set some other formatter (clang)
in their user level settings, it will be looking in the wrong directory
for the clang options (we want the options in .trunk/clang)
Note: formatOnSave is true in master, which means a bunch of our older
files are non compliant and if you edit them it will generate lots of
formatting related diffs. I guess I'll start letting that happen with
my future commits ;-).
* fix the build - would loop forever if there were no files to send (#4188)
* Show owner.short_name on boot (and E-Ink sleep screen) (#4134)
* Show owner.short_name on boot and sleep screen (on e-ink)
* Update Screen.cpp - new line for short_name
Boot screen short_name now below the region setting.
Looks better on small screens.
* Draw short_name on right
---------
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* nrf52 soft device will watchdog if you use ICE while BT on... (#4189)
so have debugger disable bluetooth.
* correct xiao_ble build preventing sx1262 init (#4191)
* Force a compile time failur if FromRadio or ToRadio get larger than (#4190)
a BLE packet size. We are actually very close to this threshold so
important to make sure we don't accidentally pass it.
* Clear vector after complete config state (#4194)
* Clear after complete config
* Don't collect . entries
* Log file name and size
* [create-pull-request] automated change (#4200)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Make the logs Colorful! (#4199)
* Squash needlessly static functions (#4183)
* Trim extra vprintf and filter for unprintable characters
* Deprecate Router Client role (and make it Client) (#4201)
* [create-pull-request] automated change (#4205)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Move waypoint (#4202)
* Move waypoint screen draw into the waypoint module
* Get the observer set up for the waypoint screen draw
* Static squashing: screen dimensions
Macros moved back to Screen.cpp, as a band-aid until we eventually move all those static functions into the Screen class.
* Move getCompassDiam into Screen class
(supress compiler warnings)
At this stage, the method is still static, because it's used by drawNodeInfo, which has no tidy reference to our screen instance.
This is probably just another band-aid until these static functions all move.
* Use new getCompassDiam function in AccelerometerThread
* Properly gate display code in WaypointModule
---------
Co-authored-by: Todd Herbert <herbert.todd@gmail.com>
* Fix flakey phone api transition from file manifest to complete (#4209)
* Try fix flakey phone api transition from file manifest to complete
* Skip
* enable colors in platformio serial monitor (#4217)
* When talking via serial, encapsulate log messages in protobufs if necessary (#4187)
* clean up RedirectablePrint::log so it doesn't have three very different implementations inline.
* remove NoopPrint - it is no longer needed
* when talking to API clients via serial, don't turn off log msgs instead encapsuate them
* fix the build - would loop forever if there were no files to send
* don't use Segger code if not talking to a Segger debugger
* when encapsulating logs, make sure the strings always has nul terminators
* nrf52 soft device will watchdog if you use ICE while BT on...
so have debugger disable bluetooth.
* Important to not print debug messages while writing to the toPhone scratch buffer
* don't include newlines if encapsulating log records as protobufs
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* [create-pull-request] automated change (#4218)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Fix SHT41 support (#4222)
* Add SHT41 Serial to I2c Detection Code
On the Seeed Wio-WM1110 Dev Kit board, the SHT41 chip was being
incorrectly detected as SHT31.
This patch adds the necessary serial number for the SHT41 chip to
be correctly detected.
fixes meshtastic/firmware#4221
* Add missing sensor read for SHT41
* Typo fix in logs - mhz - MHz (#4225)
As reported by karamo, a few different places in our logs had
incorrect capitalization of MHz.
fixes meshtastic/firmware#4126
* New new BLE logging characteristic with LogRecord protos (#4220)
* New UUID
* New log radio characteristic with LogRecord protobuf
* LogRecord
* Merge derp
* How did you get there
* Trunk
* Fix length
* Remove assert
* minor cleanup proposal (#4169)
* MESHTASTIC_EXCLUDE_WIFI and HAS_WIFI cleanup...
Our code was checking HAS_WIFI and the new MESHTASTIC_EXCLUDE_WIFI
flags in various places (even though EXCLUDE_WIFI forces HAS_WIFI
to 0). Instead just check HAS_WIFI, only use EXCLUDE_WIFI inside
configuration.h
* cleanup: use HAS_NETWORKING instead of HAS_WIFI || HAS_ETHERNET
We already had HAS_NETWORKING as flag in MQTT to mean 'we have
tcpip'. Generallize that and move it into configuration.h so that
we can use it elsewhere.
* Use #pragma once, because supported by gcc and all modern compilers
instead of #ifdef DOTHFILE_H etc...
---------
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Add PowerMon support (#4155)
* Turn off vscode cmake prompt - we don't use cmake on meshtastic
* Add rak4631_dap variant for debugging with NanoDAP debug probe device.
* The rak device can also run freertos (which is underneath nrf52 arduino)
* Add semihosting support for nrf52840 devices
Initial platformio.ini file only supports rak4630
Default to non TCP for the semihosting log output for now...
Fixes https://github.com/meshtastic/firmware/issues/4135
* powermon WIP (for https://github.com/meshtastic/firmware/issues/4136 )
* oops - mean't to mark the _dbg variant as an 'extra' board.
* powermon wip
* Make serial port on wio-sdk-wm1110 board work
By disabling the (inaccessible) adafruit USB
* Instrument (radiolib only for now) lora for powermon
per https://github.com/meshtastic/firmware/issues/4136
* powermon gps support
https://github.com/meshtastic/firmware/issues/4136
* Add CPU deep and light sleep powermon states
https://github.com/meshtastic/firmware/issues/4136
* Change the board/swversion bootstring so it is a new "structured" log msg.
* powermon wip
* add example script for getting esp S3 debugging working
Not yet used but I didn't want these nasty tricks to get lost yet.
* Add PowerMon reporting for screen and bluetooth pwr.
* make power.powermon_enables config setting work.
* update to latest protobufs
* fix bogus shellcheck warning
* make powermon optional (but default enabled because tiny and no runtime impact)
* tell vscode, if formatting, use whatever our trunk formatter wants
without this flag if the user has set some other formatter (clang)
in their user level settings, it will be looking in the wrong directory
for the clang options (we want the options in .trunk/clang)
Note: formatOnSave is true in master, which means a bunch of our older
files are non compliant and if you edit them it will generate lots of
formatting related diffs. I guess I'll start letting that happen with
my future commits ;-).
* add PowerStress module
* nrf52 arduino is built upon freertos, so let platformio debug it
* don't accidentally try to Segger ICE if we are using another ICE
* clean up RedirectablePrint::log so it doesn't have three very different implementations inline.
* remove NoopPrint - it is no longer needed
* when talking to API clients via serial, don't turn off log msgs instead encapsuate them
* fix the build - would loop forever if there were no files to send
* don't use Segger code if not talking to a Segger debugger
* when encapsulating logs, make sure the strings always has nul terminators
* nrf52 soft device will watchdog if you use ICE while BT on...
so have debugger disable bluetooth.
* Important to not print debug messages while writing to the toPhone scratch buffer
* don't include newlines if encapsulating log records as protobufs
* update to latest protobufs (needed for powermon goo)
* PowerStress WIP
* fix linter warning
* Cleanup buffer
* Merge hex for wm1110 target(s)
* Only sdk
* Sudo
* Fix exclude macros (#4233)
* fix MESHTASTIC_EXCLUDE_BLUETOOTH
* fix HAS_SCREEN=0
* fix MESHTASTIC_EXCLUDE_GPS
* fix typo in build-nrf52.sh (#4231)
chmod is the command, '+x' is the argument.
* Tidy Wireless Paper variant files (#4238)
* Quick tidy of pins_arduino.h
Matches requests made at https://github.com/meshtastic/firmware/pull/4226#discussion_r1664183480)
* Tidy variant.h
* Change deprecated ADC attenuation parameter
From 11dB to 12dB. Resolves compiler warning. Allegly, no impact on function: `This is deprecated, it behaves the same as `ADC_ATTEN_DB_12`
* Updated raspbian CI to update apt repository ahead of libbluetooth. (#4243)
* Fix BLE logging on nrf52 (#4244)
* allow ble logrecords to be fetched either by NOTIFY or INDICATE ble types
This allows 'lossless' log reading. If client has requested INDICATE
(rather than NOTIFY) each log record emitted via log() will have to fetched
by the client device before the meshtastic node can continue.
* Fix serious problem with nrf52 BLE logging.
When doing notifies of LogRecords it is important to use the
binary write routines - writing using the 'string' write won't work.
Because protobufs can contain \0 nuls inside of them which if being
parsed as a string will cause only a portion of the protobuf to be sent.
I noticed this because some log messages were not getting through.
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Fix build when HAS_NETWORKING is false on nrf52 (#4237)
(tested on a rak4631 by setting HAS_ETHERNET false when shrinking
image)
* If `toPhoneQueue` is full, still increment `fromNum` to avoid client never getting packets (#4246)
* Update to SoftDevice 7.3.0 for wio-sdk-wm1110 and wio-tracker-wm1110 (#4248)
* Update variant.h
* Update wio-tracker-wm1110.json
* Update wio-sdk-wm1110.json
* Update platformio.ini
* Update platformio.ini
* Add files via upload
* Add files via upload
* Update variant.h
* Cleanup NRF s140 Softdevice variants (#4252)
Note: This idea is originally from @caveman99 and should be
credited as such. Submitting as a separate PR so the work in
meshtastic/firmware#4148 can be a bit cleaner and Seeed boards
can build while that work is ongoing.
The nrf52 boards that depend on the v7 softdevice all use the same
code and linker files. Rather than duplicate the code, keep it
all together with the platform.
* Remove tracker variant specific soft device headers (#4255)
* [create-pull-request] automated change (#4247)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Add wio-sdk-wm1110 to build. (#4258)
The wio-sdk-wm1110 is distinct from the wio-tracker-wm1110, with
different platformio build options and pin config.
This change adds the wio-sdk-wm1110 to the CI matrix so firmware
is built as part of release.
* fix python warning in uf2conf (#4235)
the old regex worked but was technically incorrect. fixes:
Generating NRF52 uf2 file
/home/kevinh/development/meshtastic/firmware/bin/uf2conv.py:195: SyntaxWarning: invalid escape sequence '\s'
words = re.split('\s+', line)
Converting to uf2, output size: 1458688, start address: 0x26000
* Collect hex files and specifically wm1110 sdk
* Skip dfu file for sdk (for now)
* Helps if you remove the original clause
* Add Heltec new boards. (#4226)
* Add Heltec new boards
* Update variant.h
disable RTC by default
* Add Heltec New boards
* Add Heltec new boards
* Update Heltec Mesh Node definition.
* Update Heltec Vision Mater E290
* [create-pull-request] automated change (#4259)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Trunk fmt
* Fix macros
* Move e290 to board level extra while CI is broken
* Tell trunk to ignore bin folder
* Fix missing
* Update trunk.yaml, fix whitespace
* Update trunk.yaml
* Update build_raspbian_armv7l.yml --fix-missing
* [create-pull-request] automated change (#4263)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* GPS Power State tidy-up (#4161)
* Refactor GPSPowerState enum
Identifies a case where the GPS hardware is awake, but an update is not yet desired
* Change terminology
* Clear old lock-time prediction on triple press
* Use exponential smoothing to predict lock time
* Rename averageLockTime to predictedLockTime
* Attempt: Send PMREQ with duration 0 on MCU deep-sleep
* Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep
* Revert "Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep"
This reverts commit 8b697cd2a445355dcfab5b33e0ce7a3128cab151.
* Revert "Attempt: Send PMREQ with duration 0 on MCU deep-sleep"
This reverts commit 9d29ec7603a88056b9115796b29b5023165a93bb.
* Remove unused notifyGPSSleep Observable
Handled with notifyDeepSleep, and enable() / disable()
* WIP: simplify GPS power management
An initial attempt only.
* Honor #3e9e0fd
* No-op when moving between GPS_IDLE and GPS_ACTIVE
* Ensure U-blox GPS is awake to receive indefinite sleep command
* Longer pause when waking U-blox to send sleep command
* Actually implement soft and hard sleep..
* Dynamically estimate the threshold for GPS_HARDSLEEP
* Fallback to GPS_HARDSLEEP, if GPS_SOFTSLEEP unsupported
* Move "excessive search time" behavior to scheduler class
* Minor logging adjustments
* Promote log to warning
* Gratuitous buffer clearing on boot
* Fix inverted standby pin logic
Specifically the standby pin for L76B, L76K and clones
Discovered during T-Echo testing: totally broken function, probe method failing.
* Remove redundant pin init
Now handled by setPowerState
* Replace max() with if statements
Avoid those platform specific implementations..
* Trunk formatting
New round of settings.json changes keep catching me out, have to remember to re-enable my "clang-format" for windows workaround.
* Remove some asserts from setPowerState
Original aim was to prevent sending a 0 second PMREQ to U-blox hardware as part of a timed sleep (GPS_HARDSLEEP, GPS_SOFTSLEEP). I'm not sure this is super important, and it feels tidier to just allow the 0 second sleeptime here, rather than fudge the sleeptime further up.
* Fix an error determining whether GPS_SOFTSLEEP is supported
* Clarify a log entry
* Set PIN_STANDBY for MCU deep-sleep
Required to reach TTGO's advertised 0.25mA sleep current for T-Echo. Without this change: ~6mA.
* Optimize the shutdown current of RAK10701 to around 25uA (#4260)
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* INA3221 sensor: use for bus voltage & environment metrics (#4215)
* use INA3221 for bus voltage; fixes for telemetry variants
- add to sensors available for environment telemetry
(to report voltage/current)
- add vars to define channels to use for battery voltage
(for getBusVoltage) and environment metrics (default
to CH1 for both)
- write to the correct fields on the measurement struct
depending on the measurement variant, and DRY up the
sensor measurement collection code a bit
- this might be suitable for a common implementation for
the INA* sensors in a future PR...
* formatting
* derp
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* WM1110 SDK kit enter serial DFU and add deployment packages (#4266)
* Switch default upload protocol to nrfutil so that pio generates zip deploy packages
* Enter serial DFU on SDK board
* Remove guard for DFU zip from SDK build
* NRF_USE_SERIAL_DFU macro instead
* Show specific frame when updating screen (#4264)
* Updated setFrames in Screen.cpp
Added code to attempt to revert back to the same frame that user was on prior to setFrame reload.
* Space added Screen.cpp
* Update Screen.cpp
Make screen to revert to Frame 0 if the originally displayed frame is no longer there.
* Update Screen.cpp
Inserted boolean holdPosition into setFrames to indicate the requirement to stay on the same frame ( if =true) or else it will switch to new frame .
Only Screen::handleStatusUpdate calls with setFrame(true). ( For Node Updates)
All other types of updates call as before setFrame(), so it will change focus as needed.
* Hold position, even if number of frames increases
* Hold position, if handling an outgoing text message
* Update Screen.cpp
* Reverted chnages related to devicestate.has_rx_text_message
* Reset to master
* CannedMessages only handles routing packets when waiting for ACK
Previously, this was calling Screen::setFrames at unexpected times
* Gather position info about screen frames while regenerating
* Make admin module observable
Notify only when relevant. Currently: only to handle remove_nodenum.
* Optionally specify which frame to focus when setFrames runs
* UIFrameEvent uses enum instead of multiple booleans
* Allow modules to request their own frame to be focussed
This is done internally by calling MeshModule::requestFocus()
Easier this way, insteady of passing the info in the UIFrameEvent:
* Modules don't always know whether they should be focussed until after the UIFrameEvent has been raised, in dramFrame
* Don't have to pass reference to module instance as parameter though several methods
* E-Ink screensaver uses FOCUS_PRESERVE
Previously, it had its own basic implementation of this.
* Spelling: regional variant
* trunk
* Fix HAS_SCREEN guarding
* More HAS_SCREEN guarding
---------
Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: slash-bit <v-b2@live.com>
* Move up telemetry defaults to every 30 minutes (#4274)
* Don't send node info interrogation when ch. util is >25% (#4273)
* Moar LR1110 Targets
* update SD_FLASH_SIZE to 0x27000 (#4232)
The 7.3.0 softdevice needs the extra 1000 :)
* Fix spacing.
---------
Co-authored-by: Mike <mikhael.skvortsov@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Mike G <mkgin@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
Co-authored-by: Warren Guy <5602790+warrenguy@users.noreply.github.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Alexander <156134901+Dorn8010@users.noreply.github.com>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: quimnut <github@dopegoat.com>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>
Co-authored-by: Agent Blu, 006 <blu006@ucr.edu>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Aaron.Lee <32860565+Heltec-Aaron-Lee@users.noreply.github.com>
Co-authored-by: Daniel.Cao <144674500+DanielCao0@users.noreply.github.com>
Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com>
Co-authored-by: slash-bit <v-b2@live.com>
2024-07-14 09:38:19 +08:00
|
|
|
#endif
|
2020-10-13 13:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Enable / Disable GPS with PMU, if present
|
|
|
|
|
void GPS::setPowerPMU(bool on)
|
2020-10-10 09:20:38 +08:00
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
// We only have PMUs on the T-Beam, and that board has a tiny battery to save GPS ephemera,
|
|
|
|
|
// so treat as a standby.
|
|
|
|
|
#ifdef HAS_PMU
|
|
|
|
|
// Abort: if no PMU
|
|
|
|
|
if (!pmu_found)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Abort: if PMU not initialized
|
|
|
|
|
if (!PMU)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uint8_t model = PMU->getChipModel();
|
|
|
|
|
if (model == XPOWERS_AXP2101) {
|
|
|
|
|
if (HW_VENDOR == meshtastic_HardwareModel_TBEAM) {
|
|
|
|
|
// t-beam v1.2 GNSS power channel
|
|
|
|
|
on ? PMU->enablePowerOutput(XPOWERS_ALDO3) : PMU->disablePowerOutput(XPOWERS_ALDO3);
|
|
|
|
|
} else if (HW_VENDOR == meshtastic_HardwareModel_LILYGO_TBEAM_S3_CORE) {
|
|
|
|
|
// t-beam-s3-core GNSS power channel
|
|
|
|
|
on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4);
|
|
|
|
|
}
|
|
|
|
|
} else if (model == XPOWERS_AXP192) {
|
|
|
|
|
// t-beam v1.1 GNSS power channel
|
|
|
|
|
on ? PMU->enablePowerOutput(XPOWERS_LDO3) : PMU->disablePowerOutput(XPOWERS_LDO3);
|
2020-10-10 09:20:38 +08:00
|
|
|
}
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("PMU %s", on ? "on" : "off");
|
2024-07-11 15:26:43 +12:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2020-10-10 09:20:38 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Set UBLOX power, if relevant
|
|
|
|
|
void GPS::setPowerUBLOX(bool on, uint32_t sleepMs)
|
2020-09-28 17:04:19 -07:00
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
// Abort: if not UBLOX hardware
|
2024-09-25 13:50:00 -05:00
|
|
|
if (!IS_ONE_OF(gnssModel, GNSS_MODEL_UBLOX6, GNSS_MODEL_UBLOX7, GNSS_MODEL_UBLOX8, GNSS_MODEL_UBLOX9, GNSS_MODEL_UBLOX10))
|
2024-07-22 15:30:36 +02:00
|
|
|
return;
|
2024-06-08 02:41:46 +12:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// If waking
|
|
|
|
|
if (on) {
|
|
|
|
|
gps->_serial_gps->write(0xFF);
|
|
|
|
|
clearBuffer(); // This often returns old data, so drop it
|
2024-06-08 02:41:46 +12:00
|
|
|
}
|
2020-10-05 14:43:44 +08:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// If putting to sleep
|
|
|
|
|
else {
|
|
|
|
|
uint8_t msglen;
|
2020-10-06 06:27:46 +08:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// If we're being asked to sleep indefinitely, make *sure* we're awake first, to process the new sleep command
|
|
|
|
|
if (sleepMs == 0) {
|
|
|
|
|
setPowerUBLOX(true);
|
|
|
|
|
delay(500);
|
2024-07-22 15:30:36 +02:00
|
|
|
}
|
2023-01-21 06:32:41 -05:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Determine hardware version
|
2024-10-10 17:19:52 +08:00
|
|
|
if (gnssModel != GNSS_MODEL_UBLOX10) {
|
2024-07-11 15:26:43 +12:00
|
|
|
// Encode the sleep time in millis into the packet
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
2024-11-25 03:32:04 -08:00
|
|
|
_message_PMREQ[0 + i] = sleepMs >> (i * 8);
|
2024-06-15 01:28:01 +12:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Record the message length
|
2024-11-25 03:32:04 -08:00
|
|
|
msglen = gps->makeUBXPacket(0x02, 0x41, sizeof(_message_PMREQ), _message_PMREQ);
|
2024-07-11 15:26:43 +12:00
|
|
|
} else {
|
|
|
|
|
// Encode the sleep time in millis into the packet
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
2024-11-25 03:32:04 -08:00
|
|
|
_message_PMREQ_10[4 + i] = sleepMs >> (i * 8);
|
2024-07-22 15:30:36 +02:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Record the message length
|
2024-11-25 03:32:04 -08:00
|
|
|
msglen = gps->makeUBXPacket(0x02, 0x41, sizeof(_message_PMREQ_10), _message_PMREQ_10);
|
2024-07-22 15:30:36 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Send the UBX packet
|
|
|
|
|
gps->_serial_gps->write(gps->UBXscratch, msglen);
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("UBLOX: sleep for %dmS", sleepMs);
|
2024-07-22 15:30:36 +02:00
|
|
|
#endif
|
Sync Wio lr1110 refresh with master (#4288)
* Fix protobuf structs handling (#4140)
* Fix protobuf structs handling
* Log instead of assert
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* BLE based logging (#4146)
* WIP log characteristic
* Bluetooth logging plumbing
* Characteristic
* Callback
* Check for nullptr
* Esp32 bluetooth impl
* Formatting
* Add thread name and log level
* Add settings guard
* Remove comments
* Field name
* Fixes esp32
* Open it up
* Whoops
* Move va_end past our logic
* Use `upload_protocol = esptool` as with the other heltec devices instead of `esp-builtin` (#4151)
* Standardize lat/lon position logs (#4156)
* Standardize lat/lon position logs
* Missed sone and condensed logs
* [create-pull-request] automated change (#4157)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Pause BLE logging during want_config flow (#4162)
* Update NimBLE to 1.4.2 (#4163)
* Implement replies for all telemetry types based on variant tag (#4164)
* Implement replies for all telemetry types based on variant tag
* Remove check for `ignoreRequest`: modules can set this, don't need to check
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Esptool is better
* Explicitly set characteristic
* fix INA3221 sensor (#4168)
- pass wire to begin()
- remove redundant setAddr() (already set in header)
* Show compass on waypoint frame; clear when waypoint deleted (#4116)
* Clear expired or deleted waypoint frame
* Return 0 to CallbackObserver
* Add a missing comment
* Draw compass for waypoint frame
* Display our own waypoints
* [create-pull-request] automated change (#4171)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Add semihosting support for nrf52 devices (#4137)
* Turn off vscode cmake prompt - we don't use cmake on meshtastic
* Add rak4631_dap variant for debugging with NanoDAP debug probe device.
* The rak device can also run freertos (which is underneath nrf52 arduino)
* Add semihosting support for nrf52840 devices
Initial platformio.ini file only supports rak4630
Default to non TCP for the semihosting log output for now...
Fixes https://github.com/meshtastic/firmware/issues/4135
* fix my botched merge - keep board_level = extra flag for rak3631_dbg
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* [create-pull-request] automated change (#4174)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Display alerts (#4170)
* Move static functions into Screen.h, show compass during calibration
* Move to _fontHeight macro to avoid collision
* Move some alert functions to new alert handler
* Catch missed reboot code
* ESP32 fixes
* Bump esp8266-oled-ssd1306
* Fixes for when a device has no screen
* Use new startAlert(char*) helper class
* Add EINK bits back to alert handling
* Add noop class for no-display devices
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Send file system manifest up on want_config (#4176)
* Send file system manifest up on want_config
* Platform specific methods
* Helps to actually make the change
* Clear
* tell vscode, if formatting, use whatever our trunk formatter wants (#4186)
without this flag if the user has set some other formatter (clang)
in their user level settings, it will be looking in the wrong directory
for the clang options (we want the options in .trunk/clang)
Note: formatOnSave is true in master, which means a bunch of our older
files are non compliant and if you edit them it will generate lots of
formatting related diffs. I guess I'll start letting that happen with
my future commits ;-).
* fix the build - would loop forever if there were no files to send (#4188)
* Show owner.short_name on boot (and E-Ink sleep screen) (#4134)
* Show owner.short_name on boot and sleep screen (on e-ink)
* Update Screen.cpp - new line for short_name
Boot screen short_name now below the region setting.
Looks better on small screens.
* Draw short_name on right
---------
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* nrf52 soft device will watchdog if you use ICE while BT on... (#4189)
so have debugger disable bluetooth.
* correct xiao_ble build preventing sx1262 init (#4191)
* Force a compile time failur if FromRadio or ToRadio get larger than (#4190)
a BLE packet size. We are actually very close to this threshold so
important to make sure we don't accidentally pass it.
* Clear vector after complete config state (#4194)
* Clear after complete config
* Don't collect . entries
* Log file name and size
* [create-pull-request] automated change (#4200)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Make the logs Colorful! (#4199)
* Squash needlessly static functions (#4183)
* Trim extra vprintf and filter for unprintable characters
* Deprecate Router Client role (and make it Client) (#4201)
* [create-pull-request] automated change (#4205)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Move waypoint (#4202)
* Move waypoint screen draw into the waypoint module
* Get the observer set up for the waypoint screen draw
* Static squashing: screen dimensions
Macros moved back to Screen.cpp, as a band-aid until we eventually move all those static functions into the Screen class.
* Move getCompassDiam into Screen class
(supress compiler warnings)
At this stage, the method is still static, because it's used by drawNodeInfo, which has no tidy reference to our screen instance.
This is probably just another band-aid until these static functions all move.
* Use new getCompassDiam function in AccelerometerThread
* Properly gate display code in WaypointModule
---------
Co-authored-by: Todd Herbert <herbert.todd@gmail.com>
* Fix flakey phone api transition from file manifest to complete (#4209)
* Try fix flakey phone api transition from file manifest to complete
* Skip
* enable colors in platformio serial monitor (#4217)
* When talking via serial, encapsulate log messages in protobufs if necessary (#4187)
* clean up RedirectablePrint::log so it doesn't have three very different implementations inline.
* remove NoopPrint - it is no longer needed
* when talking to API clients via serial, don't turn off log msgs instead encapsuate them
* fix the build - would loop forever if there were no files to send
* don't use Segger code if not talking to a Segger debugger
* when encapsulating logs, make sure the strings always has nul terminators
* nrf52 soft device will watchdog if you use ICE while BT on...
so have debugger disable bluetooth.
* Important to not print debug messages while writing to the toPhone scratch buffer
* don't include newlines if encapsulating log records as protobufs
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* [create-pull-request] automated change (#4218)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Fix SHT41 support (#4222)
* Add SHT41 Serial to I2c Detection Code
On the Seeed Wio-WM1110 Dev Kit board, the SHT41 chip was being
incorrectly detected as SHT31.
This patch adds the necessary serial number for the SHT41 chip to
be correctly detected.
fixes meshtastic/firmware#4221
* Add missing sensor read for SHT41
* Typo fix in logs - mhz - MHz (#4225)
As reported by karamo, a few different places in our logs had
incorrect capitalization of MHz.
fixes meshtastic/firmware#4126
* New new BLE logging characteristic with LogRecord protos (#4220)
* New UUID
* New log radio characteristic with LogRecord protobuf
* LogRecord
* Merge derp
* How did you get there
* Trunk
* Fix length
* Remove assert
* minor cleanup proposal (#4169)
* MESHTASTIC_EXCLUDE_WIFI and HAS_WIFI cleanup...
Our code was checking HAS_WIFI and the new MESHTASTIC_EXCLUDE_WIFI
flags in various places (even though EXCLUDE_WIFI forces HAS_WIFI
to 0). Instead just check HAS_WIFI, only use EXCLUDE_WIFI inside
configuration.h
* cleanup: use HAS_NETWORKING instead of HAS_WIFI || HAS_ETHERNET
We already had HAS_NETWORKING as flag in MQTT to mean 'we have
tcpip'. Generallize that and move it into configuration.h so that
we can use it elsewhere.
* Use #pragma once, because supported by gcc and all modern compilers
instead of #ifdef DOTHFILE_H etc...
---------
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Add PowerMon support (#4155)
* Turn off vscode cmake prompt - we don't use cmake on meshtastic
* Add rak4631_dap variant for debugging with NanoDAP debug probe device.
* The rak device can also run freertos (which is underneath nrf52 arduino)
* Add semihosting support for nrf52840 devices
Initial platformio.ini file only supports rak4630
Default to non TCP for the semihosting log output for now...
Fixes https://github.com/meshtastic/firmware/issues/4135
* powermon WIP (for https://github.com/meshtastic/firmware/issues/4136 )
* oops - mean't to mark the _dbg variant as an 'extra' board.
* powermon wip
* Make serial port on wio-sdk-wm1110 board work
By disabling the (inaccessible) adafruit USB
* Instrument (radiolib only for now) lora for powermon
per https://github.com/meshtastic/firmware/issues/4136
* powermon gps support
https://github.com/meshtastic/firmware/issues/4136
* Add CPU deep and light sleep powermon states
https://github.com/meshtastic/firmware/issues/4136
* Change the board/swversion bootstring so it is a new "structured" log msg.
* powermon wip
* add example script for getting esp S3 debugging working
Not yet used but I didn't want these nasty tricks to get lost yet.
* Add PowerMon reporting for screen and bluetooth pwr.
* make power.powermon_enables config setting work.
* update to latest protobufs
* fix bogus shellcheck warning
* make powermon optional (but default enabled because tiny and no runtime impact)
* tell vscode, if formatting, use whatever our trunk formatter wants
without this flag if the user has set some other formatter (clang)
in their user level settings, it will be looking in the wrong directory
for the clang options (we want the options in .trunk/clang)
Note: formatOnSave is true in master, which means a bunch of our older
files are non compliant and if you edit them it will generate lots of
formatting related diffs. I guess I'll start letting that happen with
my future commits ;-).
* add PowerStress module
* nrf52 arduino is built upon freertos, so let platformio debug it
* don't accidentally try to Segger ICE if we are using another ICE
* clean up RedirectablePrint::log so it doesn't have three very different implementations inline.
* remove NoopPrint - it is no longer needed
* when talking to API clients via serial, don't turn off log msgs instead encapsuate them
* fix the build - would loop forever if there were no files to send
* don't use Segger code if not talking to a Segger debugger
* when encapsulating logs, make sure the strings always has nul terminators
* nrf52 soft device will watchdog if you use ICE while BT on...
so have debugger disable bluetooth.
* Important to not print debug messages while writing to the toPhone scratch buffer
* don't include newlines if encapsulating log records as protobufs
* update to latest protobufs (needed for powermon goo)
* PowerStress WIP
* fix linter warning
* Cleanup buffer
* Merge hex for wm1110 target(s)
* Only sdk
* Sudo
* Fix exclude macros (#4233)
* fix MESHTASTIC_EXCLUDE_BLUETOOTH
* fix HAS_SCREEN=0
* fix MESHTASTIC_EXCLUDE_GPS
* fix typo in build-nrf52.sh (#4231)
chmod is the command, '+x' is the argument.
* Tidy Wireless Paper variant files (#4238)
* Quick tidy of pins_arduino.h
Matches requests made at https://github.com/meshtastic/firmware/pull/4226#discussion_r1664183480)
* Tidy variant.h
* Change deprecated ADC attenuation parameter
From 11dB to 12dB. Resolves compiler warning. Allegly, no impact on function: `This is deprecated, it behaves the same as `ADC_ATTEN_DB_12`
* Updated raspbian CI to update apt repository ahead of libbluetooth. (#4243)
* Fix BLE logging on nrf52 (#4244)
* allow ble logrecords to be fetched either by NOTIFY or INDICATE ble types
This allows 'lossless' log reading. If client has requested INDICATE
(rather than NOTIFY) each log record emitted via log() will have to fetched
by the client device before the meshtastic node can continue.
* Fix serious problem with nrf52 BLE logging.
When doing notifies of LogRecords it is important to use the
binary write routines - writing using the 'string' write won't work.
Because protobufs can contain \0 nuls inside of them which if being
parsed as a string will cause only a portion of the protobuf to be sent.
I noticed this because some log messages were not getting through.
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Fix build when HAS_NETWORKING is false on nrf52 (#4237)
(tested on a rak4631 by setting HAS_ETHERNET false when shrinking
image)
* If `toPhoneQueue` is full, still increment `fromNum` to avoid client never getting packets (#4246)
* Update to SoftDevice 7.3.0 for wio-sdk-wm1110 and wio-tracker-wm1110 (#4248)
* Update variant.h
* Update wio-tracker-wm1110.json
* Update wio-sdk-wm1110.json
* Update platformio.ini
* Update platformio.ini
* Add files via upload
* Add files via upload
* Update variant.h
* Cleanup NRF s140 Softdevice variants (#4252)
Note: This idea is originally from @caveman99 and should be
credited as such. Submitting as a separate PR so the work in
meshtastic/firmware#4148 can be a bit cleaner and Seeed boards
can build while that work is ongoing.
The nrf52 boards that depend on the v7 softdevice all use the same
code and linker files. Rather than duplicate the code, keep it
all together with the platform.
* Remove tracker variant specific soft device headers (#4255)
* [create-pull-request] automated change (#4247)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Add wio-sdk-wm1110 to build. (#4258)
The wio-sdk-wm1110 is distinct from the wio-tracker-wm1110, with
different platformio build options and pin config.
This change adds the wio-sdk-wm1110 to the CI matrix so firmware
is built as part of release.
* fix python warning in uf2conf (#4235)
the old regex worked but was technically incorrect. fixes:
Generating NRF52 uf2 file
/home/kevinh/development/meshtastic/firmware/bin/uf2conv.py:195: SyntaxWarning: invalid escape sequence '\s'
words = re.split('\s+', line)
Converting to uf2, output size: 1458688, start address: 0x26000
* Collect hex files and specifically wm1110 sdk
* Skip dfu file for sdk (for now)
* Helps if you remove the original clause
* Add Heltec new boards. (#4226)
* Add Heltec new boards
* Update variant.h
disable RTC by default
* Add Heltec New boards
* Add Heltec new boards
* Update Heltec Mesh Node definition.
* Update Heltec Vision Mater E290
* [create-pull-request] automated change (#4259)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Trunk fmt
* Fix macros
* Move e290 to board level extra while CI is broken
* Tell trunk to ignore bin folder
* Fix missing
* Update trunk.yaml, fix whitespace
* Update trunk.yaml
* Update build_raspbian_armv7l.yml --fix-missing
* [create-pull-request] automated change (#4263)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* GPS Power State tidy-up (#4161)
* Refactor GPSPowerState enum
Identifies a case where the GPS hardware is awake, but an update is not yet desired
* Change terminology
* Clear old lock-time prediction on triple press
* Use exponential smoothing to predict lock time
* Rename averageLockTime to predictedLockTime
* Attempt: Send PMREQ with duration 0 on MCU deep-sleep
* Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep
* Revert "Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep"
This reverts commit 8b697cd2a445355dcfab5b33e0ce7a3128cab151.
* Revert "Attempt: Send PMREQ with duration 0 on MCU deep-sleep"
This reverts commit 9d29ec7603a88056b9115796b29b5023165a93bb.
* Remove unused notifyGPSSleep Observable
Handled with notifyDeepSleep, and enable() / disable()
* WIP: simplify GPS power management
An initial attempt only.
* Honor #3e9e0fd
* No-op when moving between GPS_IDLE and GPS_ACTIVE
* Ensure U-blox GPS is awake to receive indefinite sleep command
* Longer pause when waking U-blox to send sleep command
* Actually implement soft and hard sleep..
* Dynamically estimate the threshold for GPS_HARDSLEEP
* Fallback to GPS_HARDSLEEP, if GPS_SOFTSLEEP unsupported
* Move "excessive search time" behavior to scheduler class
* Minor logging adjustments
* Promote log to warning
* Gratuitous buffer clearing on boot
* Fix inverted standby pin logic
Specifically the standby pin for L76B, L76K and clones
Discovered during T-Echo testing: totally broken function, probe method failing.
* Remove redundant pin init
Now handled by setPowerState
* Replace max() with if statements
Avoid those platform specific implementations..
* Trunk formatting
New round of settings.json changes keep catching me out, have to remember to re-enable my "clang-format" for windows workaround.
* Remove some asserts from setPowerState
Original aim was to prevent sending a 0 second PMREQ to U-blox hardware as part of a timed sleep (GPS_HARDSLEEP, GPS_SOFTSLEEP). I'm not sure this is super important, and it feels tidier to just allow the 0 second sleeptime here, rather than fudge the sleeptime further up.
* Fix an error determining whether GPS_SOFTSLEEP is supported
* Clarify a log entry
* Set PIN_STANDBY for MCU deep-sleep
Required to reach TTGO's advertised 0.25mA sleep current for T-Echo. Without this change: ~6mA.
* Optimize the shutdown current of RAK10701 to around 25uA (#4260)
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* INA3221 sensor: use for bus voltage & environment metrics (#4215)
* use INA3221 for bus voltage; fixes for telemetry variants
- add to sensors available for environment telemetry
(to report voltage/current)
- add vars to define channels to use for battery voltage
(for getBusVoltage) and environment metrics (default
to CH1 for both)
- write to the correct fields on the measurement struct
depending on the measurement variant, and DRY up the
sensor measurement collection code a bit
- this might be suitable for a common implementation for
the INA* sensors in a future PR...
* formatting
* derp
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* WM1110 SDK kit enter serial DFU and add deployment packages (#4266)
* Switch default upload protocol to nrfutil so that pio generates zip deploy packages
* Enter serial DFU on SDK board
* Remove guard for DFU zip from SDK build
* NRF_USE_SERIAL_DFU macro instead
* Show specific frame when updating screen (#4264)
* Updated setFrames in Screen.cpp
Added code to attempt to revert back to the same frame that user was on prior to setFrame reload.
* Space added Screen.cpp
* Update Screen.cpp
Make screen to revert to Frame 0 if the originally displayed frame is no longer there.
* Update Screen.cpp
Inserted boolean holdPosition into setFrames to indicate the requirement to stay on the same frame ( if =true) or else it will switch to new frame .
Only Screen::handleStatusUpdate calls with setFrame(true). ( For Node Updates)
All other types of updates call as before setFrame(), so it will change focus as needed.
* Hold position, even if number of frames increases
* Hold position, if handling an outgoing text message
* Update Screen.cpp
* Reverted chnages related to devicestate.has_rx_text_message
* Reset to master
* CannedMessages only handles routing packets when waiting for ACK
Previously, this was calling Screen::setFrames at unexpected times
* Gather position info about screen frames while regenerating
* Make admin module observable
Notify only when relevant. Currently: only to handle remove_nodenum.
* Optionally specify which frame to focus when setFrames runs
* UIFrameEvent uses enum instead of multiple booleans
* Allow modules to request their own frame to be focussed
This is done internally by calling MeshModule::requestFocus()
Easier this way, insteady of passing the info in the UIFrameEvent:
* Modules don't always know whether they should be focussed until after the UIFrameEvent has been raised, in dramFrame
* Don't have to pass reference to module instance as parameter though several methods
* E-Ink screensaver uses FOCUS_PRESERVE
Previously, it had its own basic implementation of this.
* Spelling: regional variant
* trunk
* Fix HAS_SCREEN guarding
* More HAS_SCREEN guarding
---------
Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: slash-bit <v-b2@live.com>
* Move up telemetry defaults to every 30 minutes (#4274)
* Don't send node info interrogation when ch. util is >25% (#4273)
* Moar LR1110 Targets
* update SD_FLASH_SIZE to 0x27000 (#4232)
The 7.3.0 softdevice needs the extra 1000 :)
* Fix spacing.
---------
Co-authored-by: Mike <mikhael.skvortsov@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Mike G <mkgin@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
Co-authored-by: Warren Guy <5602790+warrenguy@users.noreply.github.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Alexander <156134901+Dorn8010@users.noreply.github.com>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: quimnut <github@dopegoat.com>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>
Co-authored-by: Agent Blu, 006 <blu006@ucr.edu>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Aaron.Lee <32860565+Heltec-Aaron-Lee@users.noreply.github.com>
Co-authored-by: Daniel.Cao <144674500+DanielCao0@users.noreply.github.com>
Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com>
Co-authored-by: slash-bit <v-b2@live.com>
2024-07-14 09:38:19 +08:00
|
|
|
}
|
2020-10-05 14:43:44 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
/// Record that we have a GPS
|
|
|
|
|
void GPS::setConnected()
|
2024-07-22 15:30:36 +02:00
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
if (!hasGPS) {
|
|
|
|
|
hasGPS = true;
|
|
|
|
|
shouldPublish = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-22 15:30:36 +02:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// We want a GPS lock. Wake the hardware
|
|
|
|
|
void GPS::up()
|
|
|
|
|
{
|
|
|
|
|
scheduling.informSearching();
|
|
|
|
|
setPowerState(GPS_ACTIVE);
|
2024-07-22 15:30:36 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// We've got a GPS lock. Enter a low power state, potentially.
|
|
|
|
|
void GPS::down()
|
2024-07-22 15:30:36 +02:00
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
scheduling.informGotLock();
|
|
|
|
|
uint32_t predictedSearchDuration = scheduling.predictedSearchDurationMs();
|
|
|
|
|
uint32_t sleepTime = scheduling.msUntilNextSearch();
|
2025-07-22 13:49:10 -05:00
|
|
|
uint32_t updateInterval = Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs);
|
2024-07-11 15:26:43 +12:00
|
|
|
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("%us until next search", sleepTime / 1000);
|
2024-07-11 15:26:43 +12:00
|
|
|
|
|
|
|
|
// If update interval less than 10 seconds, no attempt to sleep
|
2024-09-09 09:28:04 +08:00
|
|
|
if (updateInterval <= 10 * 1000UL || sleepTime == 0)
|
2024-07-11 15:26:43 +12:00
|
|
|
setPowerState(GPS_IDLE);
|
|
|
|
|
|
|
|
|
|
else {
|
2025-03-29 14:14:24 +01:00
|
|
|
// Check whether the GPS hardware is capable of GPS_SOFTSLEEP
|
|
|
|
|
// If not, fallback to GPS_HARDSLEEP instead
|
|
|
|
|
#ifdef PIN_GPS_STANDBY // L76B, L76K and clones have a standby pin
|
|
|
|
|
bool softsleepSupported = true;
|
|
|
|
|
#else
|
2024-07-11 15:26:43 +12:00
|
|
|
bool softsleepSupported = false;
|
2025-03-29 14:14:24 +01:00
|
|
|
#endif
|
2024-09-22 23:00:32 +08:00
|
|
|
// U-blox is supported via PMREQ
|
2024-09-25 13:50:00 -05:00
|
|
|
if (IS_ONE_OF(gnssModel, GNSS_MODEL_UBLOX6, GNSS_MODEL_UBLOX7, GNSS_MODEL_UBLOX8, GNSS_MODEL_UBLOX9, GNSS_MODEL_UBLOX10))
|
2024-07-11 15:26:43 +12:00
|
|
|
softsleepSupported = true;
|
2024-07-22 15:30:36 +02:00
|
|
|
|
2024-09-28 09:34:37 +02:00
|
|
|
if (softsleepSupported) {
|
2025-07-22 13:49:10 -05:00
|
|
|
// How long does broadcast_smart_minimum_interval_secs need to be, for GPS_HARDSLEEP to become more efficient than
|
2024-11-02 20:51:12 +08:00
|
|
|
// GPS_SOFTSLEEP? Heuristic equation. A compromise manually fitted to power observations from U-blox NEO-6M
|
|
|
|
|
// and M10050 https://www.desmos.com/calculator/6gvjghoumr This is not particularly accurate, but probably an
|
|
|
|
|
// improvement over a single, fixed threshold
|
2024-09-28 09:34:37 +02:00
|
|
|
uint32_t hardsleepThreshold = (2750 * pow(predictedSearchDuration / 1000, 1.22));
|
2025-07-22 13:49:10 -05:00
|
|
|
LOG_DEBUG("broadcast_smart_minimum_interval_secs >= %us needed to justify hardsleep", hardsleepThreshold / 1000);
|
2024-09-28 09:34:37 +02:00
|
|
|
|
|
|
|
|
// If update interval too short: softsleep (if supported by hardware)
|
|
|
|
|
if (updateInterval < hardsleepThreshold) {
|
|
|
|
|
setPowerState(GPS_SOFTSLEEP, sleepTime);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-11 15:26:43 +12:00
|
|
|
// If update interval long enough (or softsleep unsupported): hardsleep instead
|
2024-09-28 09:34:37 +02:00
|
|
|
setPowerState(GPS_HARDSLEEP, sleepTime);
|
2024-07-11 15:26:43 +12:00
|
|
|
}
|
2024-07-22 15:30:36 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-05 14:43:44 +08:00
|
|
|
void GPS::publishUpdate()
|
|
|
|
|
{
|
2023-01-28 06:39:14 -06:00
|
|
|
if (shouldPublish) {
|
2020-10-10 09:20:38 +08:00
|
|
|
shouldPublish = false;
|
|
|
|
|
|
2021-10-24 12:38:35 +00:00
|
|
|
// In debug logs, identify position by @timestamp:stage (stage 2 = publish)
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("Publish pos@%x:2, hasVal=%d, Sats=%d, GPSlock=%d", p.timestamp, hasValidLocation, p.sats_in_view, hasLock());
|
2020-10-05 14:43:44 +08:00
|
|
|
|
2020-10-10 09:20:38 +08:00
|
|
|
// Notify any status instances that are observing us
|
2022-12-13 17:23:58 -05:00
|
|
|
const meshtastic::GPSStatus status = meshtastic::GPSStatus(hasValidLocation, isConnected(), isPowerSaving(), p);
|
2020-10-10 09:20:38 +08:00
|
|
|
newStatus.notifyObservers(&status);
|
2024-02-01 15:24:39 -06:00
|
|
|
if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
|
2023-09-23 23:45:35 -05:00
|
|
|
positionModule->handleNewPosition();
|
2024-02-01 15:24:39 -06:00
|
|
|
}
|
2020-10-10 09:20:38 +08:00
|
|
|
}
|
2020-10-05 14:43:44 +08:00
|
|
|
}
|
|
|
|
|
|
2020-10-10 09:57:57 +08:00
|
|
|
int32_t GPS::runOnce()
|
2020-10-01 09:11:54 -07:00
|
|
|
{
|
2023-09-10 22:21:14 -05:00
|
|
|
if (!GPSInitFinished) {
|
2024-02-01 15:24:39 -06:00
|
|
|
if (!_serial_gps || config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) {
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_INFO("GPS set to not-present. Skip probe");
|
2023-09-20 19:34:45 -05:00
|
|
|
return disable();
|
2024-02-01 15:24:39 -06:00
|
|
|
}
|
2023-09-10 22:21:14 -05:00
|
|
|
if (!setup())
|
|
|
|
|
return 2000; // Setup failed, re-run in two seconds
|
|
|
|
|
|
|
|
|
|
// We have now loaded our saved preferences from flash
|
2024-02-01 15:24:39 -06:00
|
|
|
if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
|
2023-09-23 23:45:35 -05:00
|
|
|
return disable();
|
|
|
|
|
}
|
2023-09-10 22:21:14 -05:00
|
|
|
GPSInitFinished = true;
|
2024-11-03 20:19:15 +08:00
|
|
|
publishUpdate();
|
2023-09-10 22:21:14 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-28 06:38:13 -06:00
|
|
|
// Repeaters have no need for GPS
|
2023-09-23 23:45:35 -05:00
|
|
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) {
|
|
|
|
|
return disable();
|
|
|
|
|
}
|
2023-01-28 06:38:13 -06:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
if (whileActive()) {
|
2020-10-01 09:11:54 -07:00
|
|
|
// if we have received valid NMEA claim we are connected
|
2020-10-10 09:20:38 +08:00
|
|
|
setConnected();
|
2023-10-03 12:05:40 -05:00
|
|
|
}
|
2020-10-01 09:11:54 -07:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// If we're due for an update, wake the GPS
|
|
|
|
|
if (!config.position.fixed_position && powerState != GPS_ACTIVE && scheduling.isUpdateDue())
|
|
|
|
|
up();
|
2020-10-01 09:11:54 -07:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// If we've already set time from the GPS, no need to ask the GPS
|
|
|
|
|
bool gotTime = (getRTCQuality() >= RTCQualityGPS);
|
|
|
|
|
if (!gotTime && lookForTime()) { // Note: we count on this && short-circuiting and not resetting the RTC time
|
|
|
|
|
gotTime = true;
|
|
|
|
|
shouldPublish = true;
|
2020-10-01 09:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
bool gotLoc = lookForLocation();
|
|
|
|
|
if (gotLoc && !hasValidLocation) { // declare that we have location ASAP
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("hasValidLocation RISING EDGE");
|
2024-07-11 15:26:43 +12:00
|
|
|
hasValidLocation = true;
|
|
|
|
|
shouldPublish = true;
|
|
|
|
|
}
|
2024-07-22 15:30:36 +02:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
bool tooLong = scheduling.searchedTooLong();
|
|
|
|
|
if (tooLong)
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("Couldn't publish a valid location: didn't get a GPS lock in time");
|
2020-10-01 09:11:54 -07:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Once we get a location we no longer desperately want an update
|
|
|
|
|
if ((gotLoc && gotTime) || tooLong) {
|
2020-10-01 09:11:54 -07:00
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
if (tooLong) {
|
|
|
|
|
// we didn't get a location during this ack window, therefore declare loss of lock
|
|
|
|
|
if (hasValidLocation) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("hasValidLocation FALLING EDGE");
|
2020-10-05 14:43:44 +08:00
|
|
|
}
|
2024-07-11 15:26:43 +12:00
|
|
|
p = meshtastic_Position_init_default;
|
|
|
|
|
hasValidLocation = false;
|
2024-07-22 15:30:36 +02:00
|
|
|
}
|
2024-07-11 15:26:43 +12:00
|
|
|
|
|
|
|
|
down();
|
|
|
|
|
shouldPublish = true; // publish our update for this just finished acquisition window
|
2020-10-01 09:11:54 -07:00
|
|
|
}
|
2020-10-10 09:20:38 +08:00
|
|
|
|
|
|
|
|
// If state has changed do a publish
|
|
|
|
|
publishUpdate();
|
2023-09-23 23:45:35 -05:00
|
|
|
|
2023-10-09 18:33:04 -05:00
|
|
|
if (config.position.fixed_position == true && hasValidLocation)
|
|
|
|
|
return disable(); // This should trigger when we have a fixed position, and get that first position
|
2023-09-23 23:45:35 -05:00
|
|
|
|
2020-10-10 09:57:57 +08:00
|
|
|
// 9600bps is approx 1 byte per msec, so considering our buffer size we never need to wake more often than 200ms
|
|
|
|
|
// if not awake we can run super infrquently (once every 5 secs?) to see if we need to wake.
|
2024-06-15 01:28:01 +12:00
|
|
|
return (powerState == GPS_ACTIVE) ? GPS_THREAD_INTERVAL : 5000;
|
2020-10-01 09:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 14:15:35 +01:00
|
|
|
// clear the GPS rx/tx buffer as quickly as possible
|
2023-08-12 09:29:44 -05:00
|
|
|
void GPS::clearBuffer()
|
|
|
|
|
{
|
2025-03-15 14:15:35 +01:00
|
|
|
#ifdef ARCH_ESP32
|
|
|
|
|
_serial_gps->flush(false);
|
|
|
|
|
#else
|
2023-08-12 09:29:44 -05:00
|
|
|
int x = _serial_gps->available();
|
|
|
|
|
while (x--)
|
|
|
|
|
_serial_gps->read();
|
2025-03-15 14:15:35 +01:00
|
|
|
#endif
|
2023-08-12 09:29:44 -05:00
|
|
|
}
|
|
|
|
|
|
2020-10-30 17:05:32 +08:00
|
|
|
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
|
|
|
|
|
int GPS::prepareDeepSleep(void *unused)
|
|
|
|
|
{
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("GPS deep sleep!");
|
2024-07-11 15:26:43 +12:00
|
|
|
disable();
|
2020-10-30 17:05:32 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
2021-03-14 19:00:20 -07:00
|
|
|
|
2024-11-25 03:32:04 -08:00
|
|
|
static const char *PROBE_MESSAGE = "Trying %s (%s)...";
|
2025-03-04 23:47:06 +08:00
|
|
|
static const char *DETECTED_MESSAGE = "%s detected";
|
2024-10-01 15:38:36 -05:00
|
|
|
|
2024-09-07 11:59:45 +08:00
|
|
|
#define PROBE_SIMPLE(CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
|
2024-11-25 03:32:04 -08:00
|
|
|
do { \
|
|
|
|
|
LOG_DEBUG(PROBE_MESSAGE, TOWRITE, CHIP); \
|
|
|
|
|
clearBuffer(); \
|
|
|
|
|
_serial_gps->write(TOWRITE "\r\n"); \
|
|
|
|
|
if (getACK(RESPONSE, TIMEOUT) == GNSS_RESPONSE_OK) { \
|
2025-03-04 23:47:06 +08:00
|
|
|
LOG_INFO(DETECTED_MESSAGE, CHIP); \
|
2024-11-25 03:32:04 -08:00
|
|
|
return DRIVER; \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
2024-09-07 11:59:45 +08:00
|
|
|
|
2025-03-04 23:47:06 +08:00
|
|
|
#define PROBE_FAMILY(FAMILY_NAME, COMMAND, RESPONSE_MAP, TIMEOUT) \
|
|
|
|
|
do { \
|
|
|
|
|
LOG_DEBUG(PROBE_MESSAGE, COMMAND, FAMILY_NAME); \
|
|
|
|
|
clearBuffer(); \
|
|
|
|
|
_serial_gps->write(COMMAND "\r\n"); \
|
|
|
|
|
GnssModel_t detectedDriver = getProbeResponse(TIMEOUT, RESPONSE_MAP); \
|
|
|
|
|
if (detectedDriver != GNSS_MODEL_UNKNOWN) { \
|
|
|
|
|
return detectedDriver; \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
2023-08-28 11:13:17 -05:00
|
|
|
GnssModel_t GPS::probe(int serialSpeed)
|
2022-09-16 02:43:04 +08:00
|
|
|
{
|
2024-09-17 19:48:56 +08:00
|
|
|
#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_STM32WL)
|
2023-08-28 11:13:17 -05:00
|
|
|
_serial_gps->end();
|
|
|
|
|
_serial_gps->begin(serialSpeed);
|
2024-09-17 19:48:56 +08:00
|
|
|
#elif defined(ARCH_RP2040)
|
|
|
|
|
_serial_gps->end();
|
|
|
|
|
_serial_gps->setFIFOSize(256);
|
|
|
|
|
_serial_gps->begin(serialSpeed);
|
2022-10-05 14:59:07 +02:00
|
|
|
#else
|
2023-09-04 14:18:27 -05:00
|
|
|
if (_serial_gps->baudRate() != serialSpeed) {
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_DEBUG("Set Baud to %i", serialSpeed);
|
2023-09-04 14:18:27 -05:00
|
|
|
_serial_gps->updateBaudRate(serialSpeed);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-09-07 11:59:45 +08:00
|
|
|
|
2024-11-27 02:56:25 -08:00
|
|
|
memset(&ublox_info, 0, sizeof(ublox_info));
|
2023-08-31 20:39:23 -05:00
|
|
|
uint8_t buffer[768] = {0};
|
2023-09-02 20:35:38 -05:00
|
|
|
delay(100);
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2024-04-16 16:03:51 +02:00
|
|
|
// Close all NMEA sentences, valid for L76K, ATGM336H (and likely other AT6558 devices)
|
2022-09-16 02:43:04 +08:00
|
|
|
_serial_gps->write("$PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n");
|
|
|
|
|
delay(20);
|
2024-10-10 19:45:40 +08:00
|
|
|
// Close NMEA sequences on Ublox
|
|
|
|
|
_serial_gps->write("$PUBX,40,GLL,0,0,0,0,0,0*5C\r\n");
|
|
|
|
|
_serial_gps->write("$PUBX,40,GSV,0,0,0,0,0,0*59\r\n");
|
|
|
|
|
_serial_gps->write("$PUBX,40,VTG,0,0,0,0,0,0*5E\r\n");
|
|
|
|
|
delay(20);
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2024-09-07 11:59:45 +08:00
|
|
|
// Unicore UFirebirdII Series: UC6580, UM620, UM621, UM670A, UM680A, or UM681A
|
2025-03-04 23:47:06 +08:00
|
|
|
std::vector<ChipInfo> unicore = {{"UC6580", "UC6580", GNSS_MODEL_UC6580}, {"UM600", "UM600", GNSS_MODEL_UC6580}};
|
|
|
|
|
PROBE_FAMILY("Unicore Family", "$PDTINFO", unicore, 500);
|
|
|
|
|
|
|
|
|
|
std::vector<ChipInfo> atgm = {
|
|
|
|
|
{"ATGM336H", "$GPTXT,01,01,02,HW=ATGM336H", GNSS_MODEL_ATGM336H},
|
|
|
|
|
/* ATGM332D series (-11(GPS), -21(BDS), -31(GPS+BDS), -51(GPS+GLONASS), -71-0(GPS+BDS+GLONASS)) based on AT6558 */
|
|
|
|
|
{"ATGM332D", "$GPTXT,01,01,02,HW=ATGM332D", GNSS_MODEL_ATGM336H}};
|
|
|
|
|
PROBE_FAMILY("ATGM33xx Family", "$PCAS06,1*1A", atgm, 500);
|
2024-07-31 04:57:13 +08:00
|
|
|
|
2024-08-09 09:18:18 +08:00
|
|
|
/* Airoha (Mediatek) AG3335A/M/S, A3352Q, Quectel L89 2.0, SimCom SIM65M */
|
2024-09-08 09:09:01 +08:00
|
|
|
_serial_gps->write("$PAIR062,2,0*3C\r\n"); // GSA OFF to reduce volume
|
|
|
|
|
_serial_gps->write("$PAIR062,3,0*3D\r\n"); // GSV OFF to reduce volume
|
|
|
|
|
_serial_gps->write("$PAIR513*3D\r\n"); // save configuration
|
2025-03-04 23:47:06 +08:00
|
|
|
std::vector<ChipInfo> airoha = {{"AG3335", "$PAIR021,AG3335", GNSS_MODEL_AG3335},
|
|
|
|
|
{"AG3352", "$PAIR021,AG3352", GNSS_MODEL_AG3352},
|
|
|
|
|
{"RYS3520", "$PAIR021,REYAX_RYS3520_V2", GNSS_MODEL_AG3352}};
|
|
|
|
|
PROBE_FAMILY("Airoha Family", "$PAIR021*39", airoha, 1000);
|
2024-08-09 09:18:18 +08:00
|
|
|
|
2025-03-04 23:47:06 +08:00
|
|
|
PROBE_SIMPLE("LC86", "$PQTMVERNO*58", "$PQTMVERNO,LC86", GNSS_MODEL_AG3352, 500);
|
2024-09-07 11:59:45 +08:00
|
|
|
PROBE_SIMPLE("L76K", "$PCAS06,0*1B", "$GPTXT,01,01,02,SW=", GNSS_MODEL_MTK, 500);
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2025-03-21 21:58:52 +11:00
|
|
|
// Close all NMEA sentences, valid for MTK3333 and MTK3339 platforms
|
2024-03-14 16:18:33 +01:00
|
|
|
_serial_gps->write("$PMTK514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2E\r\n");
|
|
|
|
|
delay(20);
|
2025-05-15 19:26:41 +10:00
|
|
|
std::vector<ChipInfo> mtk = {{"L76B", "Quectel-L76B", GNSS_MODEL_MTK_L76B}, {"PA1010D", "1010D", GNSS_MODEL_MTK_PA1010D},
|
|
|
|
|
{"PA1616S", "1616S", GNSS_MODEL_MTK_PA1616S}, {"LS20031", "MC-1513", GNSS_MODEL_MTK_L76B},
|
|
|
|
|
{"L96", "Quectel-L96", GNSS_MODEL_MTK_L76B}, {"L80-R", "_3337_", GNSS_MODEL_MTK_L76B},
|
|
|
|
|
{"L80", "_3339_", GNSS_MODEL_MTK_L76B}};
|
2025-05-02 03:11:09 +01:00
|
|
|
|
2025-03-04 23:47:06 +08:00
|
|
|
PROBE_FAMILY("MTK Family", "$PMTK605*31", mtk, 500);
|
2025-01-03 18:00:39 -05:00
|
|
|
|
2023-08-28 03:09:16 -05:00
|
|
|
uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
|
UBXChecksum(cfg_rate, sizeof(cfg_rate));
|
2023-09-03 16:20:01 -05:00
|
|
|
clearBuffer();
|
2022-09-16 02:43:04 +08:00
|
|
|
_serial_gps->write(cfg_rate, sizeof(cfg_rate));
|
|
|
|
|
// Check that the returned response class and message ID are correct
|
2023-09-02 04:25:18 -05:00
|
|
|
GPS_RESPONSE response = getACK(0x06, 0x08, 750);
|
|
|
|
|
if (response == GNSS_RESPONSE_NONE) {
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_WARN("No GNSS Module (baudrate %d)", serialSpeed);
|
2023-07-08 16:30:52 -07:00
|
|
|
return GNSS_MODEL_UNKNOWN;
|
2023-09-02 04:25:18 -05:00
|
|
|
} else if (response == GNSS_RESPONSE_FRAME_ERRORS) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("UBlox Frame Errors (baudrate %d)", serialSpeed);
|
2023-09-01 11:55:46 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-18 01:27:14 +00:00
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2023-09-05 00:32:53 -04:00
|
|
|
uint8_t _message_MONVER[8] = {
|
2023-07-18 01:27:14 +00:00
|
|
|
0xB5, 0x62, // Sync message for UBX protocol
|
|
|
|
|
0x0A, 0x04, // Message class and ID (UBX-MON-VER)
|
|
|
|
|
0x00, 0x00, // Length of payload (we're asking for an answer, so no payload)
|
|
|
|
|
0x00, 0x00 // Checksum
|
|
|
|
|
};
|
2022-09-16 02:43:04 +08:00
|
|
|
// Get Ublox gnss module hardware and software info
|
2023-07-18 01:27:14 +00:00
|
|
|
UBXChecksum(_message_MONVER, sizeof(_message_MONVER));
|
2023-08-31 20:39:23 -05:00
|
|
|
clearBuffer();
|
2023-07-18 01:27:14 +00:00
|
|
|
_serial_gps->write(_message_MONVER, sizeof(_message_MONVER));
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2023-09-01 16:23:52 -05:00
|
|
|
uint16_t len = getACK(buffer, sizeof(buffer), 0x0A, 0x04, 1200);
|
2023-01-28 06:39:14 -06:00
|
|
|
if (len) {
|
2022-09-16 02:43:04 +08:00
|
|
|
uint16_t position = 0;
|
2023-01-28 06:39:14 -06:00
|
|
|
for (int i = 0; i < 30; i++) {
|
2024-11-27 02:56:25 -08:00
|
|
|
ublox_info.swVersion[i] = buffer[position];
|
2022-09-16 02:43:04 +08:00
|
|
|
position++;
|
|
|
|
|
}
|
2023-01-28 06:39:14 -06:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2024-11-27 02:56:25 -08:00
|
|
|
ublox_info.hwVersion[i] = buffer[position];
|
2022-09-16 02:43:04 +08:00
|
|
|
position++;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-28 06:39:14 -06:00
|
|
|
while (len >= position + 30) {
|
|
|
|
|
for (int i = 0; i < 30; i++) {
|
2024-11-27 02:56:25 -08:00
|
|
|
ublox_info.extension[ublox_info.extensionNo][i] = buffer[position];
|
2022-09-16 02:43:04 +08:00
|
|
|
position++;
|
|
|
|
|
}
|
2024-11-27 02:56:25 -08:00
|
|
|
ublox_info.extensionNo++;
|
|
|
|
|
if (ublox_info.extensionNo > 9)
|
2022-09-16 02:43:04 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Module Info : ");
|
2024-11-27 02:56:25 -08:00
|
|
|
LOG_DEBUG("Soft version: %s", ublox_info.swVersion);
|
|
|
|
|
LOG_DEBUG("Hard version: %s", ublox_info.hwVersion);
|
|
|
|
|
LOG_DEBUG("Extensions:%d", ublox_info.extensionNo);
|
|
|
|
|
for (int i = 0; i < ublox_info.extensionNo; i++) {
|
|
|
|
|
LOG_DEBUG(" %s", ublox_info.extension[i]);
|
2022-09-16 02:43:04 +08:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 06:32:41 -05:00
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2022-09-16 02:43:04 +08:00
|
|
|
|
2023-01-21 06:32:41 -05:00
|
|
|
// tips: extensionNo field is 0 on some 6M GNSS modules
|
2024-11-27 02:56:25 -08:00
|
|
|
for (int i = 0; i < ublox_info.extensionNo; ++i) {
|
|
|
|
|
if (!strncmp(ublox_info.extension[i], "MOD=", 4)) {
|
|
|
|
|
strncpy((char *)buffer, &(ublox_info.extension[i][4]), sizeof(buffer));
|
|
|
|
|
} else if (!strncmp(ublox_info.extension[i], "PROTVER", 7)) {
|
2023-07-18 01:27:14 +00:00
|
|
|
char *ptr = nullptr;
|
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2024-11-27 02:56:25 -08:00
|
|
|
strncpy((char *)buffer, &(ublox_info.extension[i][8]), sizeof(buffer));
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Protocol Version:%s", (char *)buffer);
|
2023-07-18 01:27:14 +00:00
|
|
|
if (strlen((char *)buffer)) {
|
2024-11-27 02:56:25 -08:00
|
|
|
ublox_info.protocol_version = strtoul((char *)buffer, &ptr, 10);
|
|
|
|
|
LOG_DEBUG("ProtVer=%d", ublox_info.protocol_version);
|
2023-07-18 01:27:14 +00:00
|
|
|
} else {
|
2024-11-27 02:56:25 -08:00
|
|
|
ublox_info.protocol_version = 0;
|
2023-07-18 01:27:14 +00:00
|
|
|
}
|
2022-09-16 02:43:04 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-27 02:56:25 -08:00
|
|
|
if (strncmp(ublox_info.hwVersion, "00040007", 8) == 0) {
|
2024-10-10 14:58:42 -05:00
|
|
|
LOG_INFO(DETECTED_MESSAGE, "U-blox 6", "6");
|
2024-09-22 23:00:32 +08:00
|
|
|
return GNSS_MODEL_UBLOX6;
|
2024-11-27 02:56:25 -08:00
|
|
|
} else if (strncmp(ublox_info.hwVersion, "00070000", 8) == 0) {
|
2024-10-10 14:58:42 -05:00
|
|
|
LOG_INFO(DETECTED_MESSAGE, "U-blox 7", "7");
|
2024-09-22 23:00:32 +08:00
|
|
|
return GNSS_MODEL_UBLOX7;
|
2024-11-27 02:56:25 -08:00
|
|
|
} else if (strncmp(ublox_info.hwVersion, "00080000", 8) == 0) {
|
2024-10-10 14:58:42 -05:00
|
|
|
LOG_INFO(DETECTED_MESSAGE, "U-blox 8", "8");
|
2024-09-22 23:00:32 +08:00
|
|
|
return GNSS_MODEL_UBLOX8;
|
2024-11-27 02:56:25 -08:00
|
|
|
} else if (strncmp(ublox_info.hwVersion, "00190000", 8) == 0) {
|
2024-10-10 14:58:42 -05:00
|
|
|
LOG_INFO(DETECTED_MESSAGE, "U-blox 9", "9");
|
2024-09-22 23:00:32 +08:00
|
|
|
return GNSS_MODEL_UBLOX9;
|
2024-11-27 02:56:25 -08:00
|
|
|
} else if (strncmp(ublox_info.hwVersion, "000A0000", 8) == 0) {
|
2024-10-10 14:58:42 -05:00
|
|
|
LOG_INFO(DETECTED_MESSAGE, "U-blox 10", "10");
|
2024-09-22 23:00:32 +08:00
|
|
|
return GNSS_MODEL_UBLOX10;
|
|
|
|
|
}
|
2022-09-16 02:43:04 +08:00
|
|
|
}
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_WARN("No GNSS Module (baudrate %d)", serialSpeed);
|
2024-09-22 23:00:32 +08:00
|
|
|
return GNSS_MODEL_UNKNOWN;
|
2022-09-16 02:43:04 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-04 23:47:06 +08:00
|
|
|
GnssModel_t GPS::getProbeResponse(unsigned long timeout, const std::vector<ChipInfo> &responseMap)
|
|
|
|
|
{
|
|
|
|
|
String response = "";
|
|
|
|
|
unsigned long start = millis();
|
|
|
|
|
while (millis() - start < timeout) {
|
|
|
|
|
if (_serial_gps->available()) {
|
|
|
|
|
response += (char)_serial_gps->read();
|
|
|
|
|
|
|
|
|
|
if (response.endsWith(",") || response.endsWith("\r\n")) {
|
|
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
LOG_DEBUG(response.c_str());
|
|
|
|
|
#endif
|
|
|
|
|
// check if we can see our chips
|
|
|
|
|
for (const auto &chipInfo : responseMap) {
|
|
|
|
|
if (strstr(response.c_str(), chipInfo.detectionString.c_str()) != nullptr) {
|
|
|
|
|
LOG_INFO("%s detected", chipInfo.chipName.c_str());
|
|
|
|
|
return chipInfo.driver;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (response.endsWith("\r\n")) {
|
|
|
|
|
response.trim();
|
|
|
|
|
response = ""; // Reset the response string for the next potential message
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
LOG_DEBUG(response.c_str());
|
|
|
|
|
#endif
|
|
|
|
|
return GNSS_MODEL_UNKNOWN; // Return empty string on timeout
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-16 23:10:10 -05:00
|
|
|
GPS *GPS::createGps()
|
|
|
|
|
{
|
|
|
|
|
int8_t _rx_gpio = config.position.rx_gpio;
|
|
|
|
|
int8_t _tx_gpio = config.position.tx_gpio;
|
2023-09-23 23:45:35 -05:00
|
|
|
int8_t _en_gpio = config.position.gps_en_gpio;
|
2024-02-01 15:24:39 -06:00
|
|
|
#if HAS_GPS && !defined(ARCH_ESP32)
|
2023-09-16 23:10:10 -05:00
|
|
|
_rx_gpio = 1; // We only specify GPS serial ports on ESP32. Otherwise, these are just flags.
|
|
|
|
|
_tx_gpio = 1;
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(GPS_RX_PIN)
|
|
|
|
|
if (!_rx_gpio)
|
|
|
|
|
_rx_gpio = GPS_RX_PIN;
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(GPS_TX_PIN)
|
|
|
|
|
if (!_tx_gpio)
|
|
|
|
|
_tx_gpio = GPS_TX_PIN;
|
2023-09-23 23:45:35 -05:00
|
|
|
#endif
|
|
|
|
|
#if defined(PIN_GPS_EN)
|
|
|
|
|
if (!_en_gpio)
|
|
|
|
|
_en_gpio = PIN_GPS_EN;
|
2023-11-28 12:39:32 -06:00
|
|
|
#endif
|
2024-01-12 02:00:31 -06:00
|
|
|
#ifdef ARCH_PORTDUINO
|
2023-11-28 12:39:32 -06:00
|
|
|
if (!settingsMap[has_gps])
|
|
|
|
|
return nullptr;
|
2021-03-14 19:00:20 -07:00
|
|
|
#endif
|
2023-09-20 19:34:45 -05:00
|
|
|
if (!_rx_gpio || !_serial_gps) // Configured to have no GPS at all
|
2023-09-16 23:10:10 -05:00
|
|
|
return nullptr;
|
2021-03-14 19:00:20 -07:00
|
|
|
|
2023-09-16 23:10:10 -05:00
|
|
|
GPS *new_gps = new GPS;
|
|
|
|
|
new_gps->rx_gpio = _rx_gpio;
|
|
|
|
|
new_gps->tx_gpio = _tx_gpio;
|
2024-08-22 10:15:23 -07:00
|
|
|
|
2024-08-28 09:59:42 -07:00
|
|
|
GpioVirtPin *virtPin = new GpioVirtPin();
|
|
|
|
|
new_gps->enablePin = virtPin; // Always at least populate a virtual pin
|
2024-08-22 10:15:23 -07:00
|
|
|
if (_en_gpio) {
|
|
|
|
|
GpioPin *p = new GpioHwPin(_en_gpio);
|
|
|
|
|
|
|
|
|
|
if (!GPS_EN_ACTIVE) { // Need to invert the pin before hardware
|
|
|
|
|
new GpioNotTransformer(
|
2024-11-02 20:51:12 +08:00
|
|
|
virtPin,
|
|
|
|
|
p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio
|
2024-08-28 09:59:42 -07:00
|
|
|
} else {
|
|
|
|
|
new GpioUnaryTransformer(
|
2024-11-02 20:51:12 +08:00
|
|
|
virtPin,
|
|
|
|
|
p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio
|
2024-08-22 10:15:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-23 23:45:35 -05:00
|
|
|
|
2023-09-12 16:46:46 -05:00
|
|
|
#ifdef PIN_GPS_PPS
|
|
|
|
|
// pulse per second
|
|
|
|
|
pinMode(PIN_GPS_PPS, INPUT);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-04-07 12:46:22 +02:00
|
|
|
#ifdef PIN_GPS_SWITCH
|
|
|
|
|
// toggle GPS via external GPIO switch
|
|
|
|
|
pinMode(PIN_GPS_SWITCH, INPUT);
|
|
|
|
|
gpsPeriodic = new concurrency::Periodic("GPSSwitch", gpsSwitch);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-09-12 16:46:46 -05:00
|
|
|
// Currently disabled per issue #525 (TinyGPS++ crash bug)
|
|
|
|
|
// when fixed upstream, can be un-disabled to enable 3D FixType and PDOP
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
// see NMEAGPS.h
|
|
|
|
|
gsafixtype.begin(reader, NMEA_MSG_GXGSA, 2);
|
|
|
|
|
gsapdop.begin(reader, NMEA_MSG_GXGSA, 15);
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_DEBUG("Use " NMEA_MSG_GXGSA " for 3DFIX and PDOP");
|
2023-09-12 16:46:46 -05:00
|
|
|
#endif
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
// Make sure the GPS is awake before performing any init.
|
|
|
|
|
new_gps->up();
|
2023-09-12 16:46:46 -05:00
|
|
|
|
|
|
|
|
#ifdef PIN_GPS_RESET
|
|
|
|
|
pinMode(PIN_GPS_RESET, OUTPUT);
|
2023-12-02 13:40:31 +00:00
|
|
|
digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms
|
2023-09-12 16:46:46 -05:00
|
|
|
delay(10);
|
|
|
|
|
digitalWrite(PIN_GPS_RESET, !GPS_RESET_MODE);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-09-16 23:10:10 -05:00
|
|
|
if (_serial_gps) {
|
2023-09-12 16:46:46 -05:00
|
|
|
#ifdef ARCH_ESP32
|
|
|
|
|
// In esp32 framework, setRxBufferSize needs to be initialized before Serial
|
2023-09-16 23:10:10 -05:00
|
|
|
_serial_gps->setRxBufferSize(SERIAL_BUFFER_SIZE); // the default is 256
|
2023-09-12 16:46:46 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// ESP32 has a special set of parameters vs other arduino ports
|
|
|
|
|
#if defined(ARCH_ESP32)
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_DEBUG("Use GPIO%d for GPS RX", new_gps->rx_gpio);
|
|
|
|
|
LOG_DEBUG("Use GPIO%d for GPS TX", new_gps->tx_gpio);
|
2023-09-16 23:10:10 -05:00
|
|
|
_serial_gps->begin(GPS_BAUDRATE, SERIAL_8N1, new_gps->rx_gpio, new_gps->tx_gpio);
|
2024-09-17 19:48:56 +08:00
|
|
|
#elif defined(ARCH_RP2040)
|
|
|
|
|
_serial_gps->setFIFOSize(256);
|
|
|
|
|
_serial_gps->begin(GPS_BAUDRATE);
|
2024-03-15 16:37:47 +01:00
|
|
|
#else
|
|
|
|
|
_serial_gps->begin(GPS_BAUDRATE);
|
2023-09-12 16:46:46 -05:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
return new_gps;
|
2023-09-16 23:10:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int32_t toDegInt(RawDegrees d)
|
|
|
|
|
{
|
|
|
|
|
int32_t degMult = 10000000; // 1e7
|
|
|
|
|
int32_t r = d.deg * degMult + d.billionths / 100;
|
|
|
|
|
if (d.negative)
|
|
|
|
|
r *= -1;
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any processing that should be done only while the GPS is awake and looking for a fix.
|
|
|
|
|
* Override this method to check for new locations
|
|
|
|
|
*
|
|
|
|
|
* @return true if we've acquired a new location
|
|
|
|
|
*/
|
|
|
|
|
bool GPS::lookForTime()
|
|
|
|
|
{
|
2024-07-25 10:10:38 +08:00
|
|
|
|
|
|
|
|
#ifdef GNSS_AIROHA
|
2024-06-20 16:26:04 +02:00
|
|
|
uint8_t fix = reader.fixQuality();
|
2024-07-25 10:10:38 +08:00
|
|
|
if (fix > 0) {
|
|
|
|
|
if (lastFixStartMsec > 0) {
|
2024-09-23 08:58:14 -05:00
|
|
|
if (Throttle::isWithinTimespanMs(lastFixStartMsec, GPS_FIX_HOLD_TIME)) {
|
2024-07-25 10:10:38 +08:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
clearBuffer();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-09-23 08:58:14 -05:00
|
|
|
lastFixStartMsec = millis();
|
2024-07-25 10:10:38 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-06-20 16:26:04 +02:00
|
|
|
#endif
|
2023-09-16 23:10:10 -05:00
|
|
|
auto ti = reader.time;
|
|
|
|
|
auto d = reader.date;
|
|
|
|
|
if (ti.isValid() && d.isValid()) { // Note: we don't check for updated, because we'll only be called if needed
|
|
|
|
|
/* Convert to unix time
|
2024-11-02 20:51:12 +08:00
|
|
|
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).
|
2023-09-16 23:10:10 -05:00
|
|
|
*/
|
|
|
|
|
struct tm t;
|
2024-09-14 07:44:40 -05:00
|
|
|
t.tm_sec = ti.second() + round(ti.age() / 1000);
|
2023-09-16 23:10:10 -05:00
|
|
|
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;
|
|
|
|
|
if (t.tm_mon > -1) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("NMEA GPS time %02d-%02d-%02d %02d:%02d:%02d age %d", d.year(), d.month(), t.tm_mday, t.tm_hour, t.tm_min,
|
2024-09-14 07:44:40 -05:00
|
|
|
t.tm_sec, ti.age());
|
2025-07-07 19:35:57 -05:00
|
|
|
if (perhapsSetRTC(RTCQualityGPS, t) == RTCSetResultInvalidTime) {
|
|
|
|
|
// Clear the GPS buffer if we got an invalid time
|
|
|
|
|
clearBuffer();
|
|
|
|
|
}
|
2023-09-16 23:10:10 -05:00
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any processing that should be done only while the GPS is awake and looking for a fix.
|
|
|
|
|
* Override this method to check for new locations
|
|
|
|
|
*
|
|
|
|
|
* @return true if we've acquired a new location
|
|
|
|
|
*/
|
|
|
|
|
bool GPS::lookForLocation()
|
|
|
|
|
{
|
2024-07-25 10:10:38 +08:00
|
|
|
#ifdef GNSS_AIROHA
|
2025-07-22 13:49:10 -05:00
|
|
|
if ((config.position.broadcast_smart_minimum_interval_secs * 1000) >= (GPS_FIX_HOLD_TIME * 2)) {
|
2024-06-20 16:26:04 +02:00
|
|
|
uint8_t fix = reader.fixQuality();
|
2024-07-25 10:10:38 +08:00
|
|
|
if (fix > 0) {
|
|
|
|
|
if (lastFixStartMsec > 0) {
|
2024-09-23 08:58:14 -05:00
|
|
|
if (Throttle::isWithinTimespanMs(lastFixStartMsec, GPS_FIX_HOLD_TIME)) {
|
2024-07-25 10:10:38 +08:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
clearBuffer();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-09-23 08:58:14 -05:00
|
|
|
lastFixStartMsec = millis();
|
2024-07-25 10:10:38 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-06-20 16:26:04 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
2023-09-16 23:10:10 -05:00
|
|
|
// By default, TinyGPS++ does not parse GPGSA lines, which give us
|
|
|
|
|
// the 2D/3D fixType (see NMEAGPS.h)
|
|
|
|
|
// At a minimum, use the fixQuality indicator in GPGGA (FIXME?)
|
|
|
|
|
fixQual = reader.fixQuality();
|
|
|
|
|
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_STATISTICS
|
|
|
|
|
if (reader.failedChecksum() > lastChecksumFailCount) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_WARN("%u new GPS checksum failures, for a total of %u", reader.failedChecksum() - lastChecksumFailCount,
|
2023-09-16 23:10:10 -05:00
|
|
|
reader.failedChecksum());
|
|
|
|
|
lastChecksumFailCount = reader.failedChecksum();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
fixType = atoi(gsafixtype.value()); // will set to zero if no data
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// check if GPS has an acceptable lock
|
|
|
|
|
if (!hasLock())
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("AGE: LOC=%d FIX=%d DATE=%d TIME=%d", reader.location.age(),
|
2023-09-16 23:10:10 -05:00
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
gsafixtype.age(),
|
|
|
|
|
#else
|
|
|
|
|
0,
|
|
|
|
|
#endif
|
|
|
|
|
reader.date.age(), reader.time.age());
|
2024-11-04 20:09:23 +08:00
|
|
|
#endif // GPS_DEBUG
|
2023-09-16 23:10:10 -05:00
|
|
|
|
2024-01-30 17:44:08 -06:00
|
|
|
// Is this a new point or are we re-reading the previous one?
|
2024-05-02 20:13:36 +08:00
|
|
|
if (!reader.location.isUpdated() && !reader.altitude.isUpdated())
|
2024-01-30 17:44:08 -06:00
|
|
|
return false;
|
|
|
|
|
|
2023-09-16 23:10:10 -05:00
|
|
|
// check if a complete GPS solution set is available for reading
|
|
|
|
|
// tinyGPSDatum::age() also includes isValid() test
|
|
|
|
|
// FIXME
|
|
|
|
|
if (!((reader.location.age() < GPS_SOL_EXPIRY_MS) &&
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
(gsafixtype.age() < GPS_SOL_EXPIRY_MS) &&
|
|
|
|
|
#endif
|
|
|
|
|
(reader.time.age() < GPS_SOL_EXPIRY_MS) && (reader.date.age() < GPS_SOL_EXPIRY_MS))) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_WARN("SOME data is TOO OLD: LOC %u, TIME %u, DATE %u", reader.location.age(), reader.time.age(), reader.date.age());
|
2023-09-16 23:10:10 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We know the solution is fresh and valid, so just read the data
|
|
|
|
|
auto loc = reader.location.value();
|
|
|
|
|
|
|
|
|
|
// Bail out EARLY to avoid overwriting previous good data (like #857)
|
|
|
|
|
if (toDegInt(loc.lat) > 900000000) {
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Bail out EARLY on LAT %i", toDegInt(loc.lat));
|
2023-09-16 23:10:10 -05:00
|
|
|
#endif
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (toDegInt(loc.lng) > 1800000000) {
|
2024-11-04 20:09:23 +08:00
|
|
|
#ifdef GPS_DEBUG
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Bail out EARLY on LNG %i", toDegInt(loc.lng));
|
2023-09-16 23:10:10 -05:00
|
|
|
#endif
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.location_source = meshtastic_Position_LocSource_LOC_INTERNAL;
|
|
|
|
|
|
|
|
|
|
// Dilution of precision (an accuracy metric) is reported in 10^2 units, so we need to scale down when we use it
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
p.HDOP = reader.hdop.value();
|
|
|
|
|
p.PDOP = TinyGPSPlus::parseDecimal(gsapdop.value());
|
|
|
|
|
#else
|
|
|
|
|
// FIXME! naive PDOP emulation (assumes VDOP==HDOP)
|
|
|
|
|
// correct formula is PDOP = SQRT(HDOP^2 + VDOP^2)
|
|
|
|
|
p.HDOP = reader.hdop.value();
|
|
|
|
|
p.PDOP = 1.41 * reader.hdop.value();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Discard incomplete or erroneous readings
|
|
|
|
|
if (reader.hdop.value() == 0) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_WARN("BOGUS hdop.value() REJECTED: %d", reader.hdop.value());
|
2023-09-16 23:10:10 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.latitude_i = toDegInt(loc.lat);
|
|
|
|
|
p.longitude_i = toDegInt(loc.lng);
|
|
|
|
|
|
|
|
|
|
p.altitude_geoidal_separation = reader.geoidHeight.meters();
|
|
|
|
|
p.altitude_hae = reader.altitude.meters() + p.altitude_geoidal_separation;
|
|
|
|
|
p.altitude = reader.altitude.meters();
|
|
|
|
|
|
|
|
|
|
p.fix_quality = fixQual;
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
p.fix_type = fixType;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// positional timestamp
|
|
|
|
|
struct tm t;
|
|
|
|
|
t.tm_sec = reader.time.second();
|
|
|
|
|
t.tm_min = reader.time.minute();
|
|
|
|
|
t.tm_hour = reader.time.hour();
|
|
|
|
|
t.tm_mday = reader.date.day();
|
|
|
|
|
t.tm_mon = reader.date.month() - 1;
|
|
|
|
|
t.tm_year = reader.date.year() - 1900;
|
|
|
|
|
t.tm_isdst = false;
|
2024-04-09 00:26:23 +02:00
|
|
|
p.timestamp = gm_mktime(&t);
|
2023-09-16 23:10:10 -05:00
|
|
|
|
|
|
|
|
// Nice to have, if available
|
|
|
|
|
if (reader.satellites.isUpdated()) {
|
|
|
|
|
p.sats_in_view = reader.satellites.value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reader.course.isUpdated() && reader.course.isValid()) {
|
|
|
|
|
if (reader.course.value() < 36000) { // sanity check
|
|
|
|
|
p.ground_track =
|
|
|
|
|
reader.course.value() * 1e3; // Scale the heading (in degrees * 10^-2) to match the expected degrees * 10^-5
|
|
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_WARN("BOGUS course.value() REJECTED: %d", reader.course.value());
|
2023-09-16 23:10:10 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reader.speed.isUpdated() && reader.speed.isValid()) {
|
|
|
|
|
p.ground_speed = reader.speed.kmph();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPS::hasLock()
|
|
|
|
|
{
|
|
|
|
|
// Using GPGGA fix quality indicator
|
|
|
|
|
if (fixQual >= 1 && fixQual <= 5) {
|
|
|
|
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
|
|
|
|
// Use GPGSA fix type 2D/3D (better) if available
|
|
|
|
|
if (fixType == 3 || fixType == 0) // zero means "no data received"
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPS::hasFlow()
|
|
|
|
|
{
|
|
|
|
|
return reader.passedChecksum() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 15:26:43 +12:00
|
|
|
bool GPS::whileActive()
|
2023-09-16 23:10:10 -05:00
|
|
|
{
|
2024-05-03 22:49:22 +02:00
|
|
|
unsigned int charsInBuf = 0;
|
2023-09-16 23:10:10 -05:00
|
|
|
bool isValid = false;
|
2024-10-20 20:46:25 +11:00
|
|
|
#ifdef GPS_DEBUG
|
|
|
|
|
std::string debugmsg = "";
|
|
|
|
|
#endif
|
2024-06-15 01:28:01 +12:00
|
|
|
if (powerState != GPS_ACTIVE) {
|
2023-09-23 23:45:35 -05:00
|
|
|
clearBuffer();
|
2024-07-11 15:26:43 +12:00
|
|
|
return false;
|
2023-09-23 23:45:35 -05:00
|
|
|
}
|
2023-09-16 23:10:10 -05:00
|
|
|
#ifdef SERIAL_BUFFER_SIZE
|
|
|
|
|
if (_serial_gps->available() >= SERIAL_BUFFER_SIZE - 1) {
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_WARN("GPS Buffer full with %u bytes waiting. Flush to avoid corruption", _serial_gps->available());
|
2023-09-16 23:10:10 -05:00
|
|
|
clearBuffer();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
// First consume any chars that have piled up at the receiver
|
|
|
|
|
while (_serial_gps->available() > 0) {
|
|
|
|
|
int c = _serial_gps->read();
|
2023-10-03 12:05:40 -05:00
|
|
|
UBXscratch[charsInBuf] = c;
|
|
|
|
|
#ifdef GPS_DEBUG
|
2024-10-20 20:46:25 +11:00
|
|
|
debugmsg += vformat("%c", (c >= 32 && c <= 126) ? c : '.');
|
2023-10-03 12:05:40 -05:00
|
|
|
#endif
|
2023-09-16 23:10:10 -05:00
|
|
|
isValid |= reader.encode(c);
|
2023-10-03 12:05:40 -05:00
|
|
|
if (charsInBuf > sizeof(UBXscratch) - 10 || c == '\r') {
|
|
|
|
|
if (strnstr((char *)UBXscratch, "$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50", charsInBuf)) {
|
|
|
|
|
rebootsSeen++;
|
|
|
|
|
}
|
|
|
|
|
charsInBuf = 0;
|
|
|
|
|
} else {
|
|
|
|
|
charsInBuf++;
|
|
|
|
|
}
|
2023-09-16 23:10:10 -05:00
|
|
|
}
|
2024-10-20 20:46:25 +11:00
|
|
|
#ifdef GPS_DEBUG
|
2024-11-02 20:51:12 +08:00
|
|
|
if (debugmsg != "") {
|
|
|
|
|
LOG_DEBUG(debugmsg.c_str());
|
|
|
|
|
}
|
2024-10-20 20:46:25 +11:00
|
|
|
#endif
|
2023-09-16 23:10:10 -05:00
|
|
|
return isValid;
|
|
|
|
|
}
|
2023-09-23 23:45:35 -05:00
|
|
|
void GPS::enable()
|
|
|
|
|
{
|
2024-07-11 15:26:43 +12:00
|
|
|
// Clear the old scheduling info (reset the lock-time prediction)
|
|
|
|
|
scheduling.reset();
|
2024-06-15 01:28:01 +12:00
|
|
|
|
2023-09-23 23:45:35 -05:00
|
|
|
enabled = true;
|
|
|
|
|
setInterval(GPS_THREAD_INTERVAL);
|
2024-07-11 15:26:43 +12:00
|
|
|
|
|
|
|
|
scheduling.informSearching();
|
|
|
|
|
setPowerState(GPS_ACTIVE);
|
2023-09-23 23:45:35 -05:00
|
|
|
}
|
2023-09-16 23:10:10 -05:00
|
|
|
|
2023-09-23 23:45:35 -05:00
|
|
|
int32_t GPS::disable()
|
2023-09-16 23:10:10 -05:00
|
|
|
{
|
2023-09-23 23:45:35 -05:00
|
|
|
enabled = false;
|
|
|
|
|
setInterval(INT32_MAX);
|
2024-07-11 15:26:43 +12:00
|
|
|
setPowerState(GPS_OFF);
|
2023-09-23 23:45:35 -05:00
|
|
|
|
|
|
|
|
return INT32_MAX;
|
2024-02-01 15:24:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPS::toggleGpsMode()
|
|
|
|
|
{
|
|
|
|
|
if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
|
|
|
|
|
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED;
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_INFO("User toggled GpsMode. Now DISABLED");
|
2024-10-17 22:40:18 -05:00
|
|
|
playGPSDisableBeep();
|
2024-07-25 10:10:38 +08:00
|
|
|
#ifdef GNSS_AIROHA
|
|
|
|
|
if (powerState == GPS_ACTIVE) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("User power Off GPS");
|
2024-07-25 10:10:38 +08:00
|
|
|
digitalWrite(PIN_GPS_EN, LOW);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-02-01 15:24:39 -06:00
|
|
|
disable();
|
|
|
|
|
} else if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) {
|
|
|
|
|
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED;
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("User toggled GpsMode. Now ENABLED");
|
2024-10-17 22:40:18 -05:00
|
|
|
playGPSEnableBeep();
|
2024-02-01 15:24:39 -06:00
|
|
|
enable();
|
|
|
|
|
}
|
2024-03-25 05:33:57 -06:00
|
|
|
}
|
2025-01-03 18:00:39 -05:00
|
|
|
#endif // Exclude GPS
|