mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-14 07:21:30 +10:00
* logging: gate LOG_TRACE behind MESHTASTIC_TRACE_LOGGING, drop redundant reclock logs LOG_TRACE now compiles out by default so trace-level diagnostics cost no flash; enable with -DMESHTASTIC_TRACE_LOGGING. Portduino keeps it on for the traceFilename packet-trace feature. Remove the 66 caller-side I2C reclock/restore log lines in the telemetry sensors: ReClockI2C::setClock/restoreClock already log both frequencies internally (now at trace level, since they fire every sensor read). Also unify near-duplicate literals (colon/case/punctuation variants) so linker string dedup applies, and drop an information-free bare 'done'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: demote chatty per-packet/per-poll DEBUG lines to trace level With LOG_TRACE compiled out by default, per-iteration chatter (packet bookkeeping, sensor poll values, e-ink refresh reasons, GPS pin states, UI runState traces) now costs no flash on device builds while remaining one -DMESHTASTIC_TRACE_LOGGING away. 108 lines demoted, 4 information- free lines removed; failure paths, drop reasons, and one-time init logs all stay at debug level. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: address CodeRabbit review on trace-gate PR - GPS: pass serial-derived buffers as %s args, never as format strings (untrusted bytes could contain % directives) - 0x%08x for packet id / NodeNum per convention (Router, CannedMessage, NeighborInfo); unsigned casts for size_t args; %u for uint32_t delta - EInk: async full-refresh begin/complete back to DEBUG (rare state transitions); per-frame SKIPPED lines stay trace Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: gate trace on the flag's value, not its presence -DMESHTASTIC_TRACE_LOGGING=0 previously *enabled* trace logging because the gate tested definedness. The flag now defaults per-platform (portduino 1, else 0) and both backends test the value, so =0 disables, =1 or a bare -D enables. Also cast tx_after-millis() to uint32_t for %u (millis() is unsigned long on native). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: clang-format rewrap after specifier widening Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * Even fewer bytes! * logging: keep compile-gated debug lines at debug level; fix native-suite-count Lines already inside default-off #ifdef blocks (GPS_DEBUG, DEBUG_LOOP_TIMING) cost no flash and should stay visible at debug level when their gate is enabled, rather than also requiring MESHTASTIC_TRACE_LOGGING. test/native-suite-count lags the two test_event_channel_* suites added by #11045 (develop's Native Suite Count check has the same mismatch); bump 46 -> 47. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * gps: route GPS_DEBUG diagnostics through a LOG_DEBUG_GPS() macro (#11414) Replaces 27 log-only #ifdef GPS_DEBUG blocks across GPS.cpp, PositionModule, MeshService, and GPSStatus.h with a single-line LOG_DEBUG_GPS() call (src/gps/GPSLog.h, modeled on LOG_MIGRATION: value-gated, ((void)0) when off). Blocks containing declarations, control flow, hexDump, or nested conditionals keep an explicit '#if GPS_DEBUG' guard. RTC.cpp's per-reading raw time dumps and per-candidate rejection chatter fold under the same gate; quality transitions and boot-time seeding stay at debug. Also fixes the '// define GPS_DEBUG' missing-# typo in two variant headers and updates all seven commented examples to the value form ('#define GPS_DEBUG 1') required by the value-based gate. Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 Co-authored-by: Claude <noreply@anthropic.com> * gps: declare RTC gmtime result as pointer to const (cppcheck) With the setTime debug dump gated behind GPS_DEBUG, all remaining uses of t are reads; cppcheck (constVariablePointer) now flags it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 --------- Co-authored-by: Claude <noreply@anthropic.com>
143 lines
4.6 KiB
C++
143 lines
4.6 KiB
C++
#pragma once
|
|
#include "NodeDB.h"
|
|
#include "Status.h"
|
|
#include "configuration.h"
|
|
#include "gps/GPSLog.h"
|
|
#include <Arduino.h>
|
|
|
|
namespace meshtastic
|
|
{
|
|
|
|
/// Describes the state of the GPS system.
|
|
class GPSStatus : public Status
|
|
{
|
|
|
|
private:
|
|
CallbackObserver<GPSStatus, const GPSStatus *> statusObserver =
|
|
CallbackObserver<GPSStatus, const GPSStatus *>(this, &GPSStatus::updateStatus);
|
|
|
|
bool hasLock = false; // default to false, until we complete our first read
|
|
bool isConnected = false; // Do we have a GPS we are talking to
|
|
bool hasTime = false; // GPS has decoded a valid time this acquisition, even without a position fix
|
|
|
|
bool isPowerSaving = false; // Are we in power saving state
|
|
|
|
meshtastic_Position p = meshtastic_Position_init_default;
|
|
|
|
/// Time of last valid GPS fix (millis since boot)
|
|
uint32_t lastFixMillis = 0;
|
|
|
|
public:
|
|
GPSStatus() { statusType = STATUS_TYPE_GPS; }
|
|
|
|
// preferred method
|
|
GPSStatus(bool hasLock, bool isConnected, bool isPowerSaving, const meshtastic_Position &pos, bool hasTime = false) : Status()
|
|
{
|
|
this->hasLock = hasLock;
|
|
this->isConnected = isConnected;
|
|
this->isPowerSaving = isPowerSaving;
|
|
this->hasTime = hasTime;
|
|
|
|
// all-in-one struct copy
|
|
this->p = pos;
|
|
}
|
|
|
|
GPSStatus(const GPSStatus &);
|
|
GPSStatus &operator=(const GPSStatus &);
|
|
|
|
void observe(Observable<const GPSStatus *> *source) { statusObserver.observe(source); }
|
|
|
|
bool getHasLock() const { return hasLock; }
|
|
|
|
bool getIsConnected() const { return isConnected; }
|
|
|
|
bool getIsPowerSaving() const { return isPowerSaving; }
|
|
|
|
bool getHasTime() const { return hasTime; }
|
|
|
|
int32_t getLatitude() const
|
|
{
|
|
if (config.position.fixed_position) {
|
|
return localPosition.latitude_i;
|
|
} else {
|
|
return p.latitude_i;
|
|
}
|
|
}
|
|
|
|
int32_t getLongitude() const
|
|
{
|
|
if (config.position.fixed_position) {
|
|
return localPosition.longitude_i;
|
|
} else {
|
|
return p.longitude_i;
|
|
}
|
|
}
|
|
|
|
int32_t getAltitude() const
|
|
{
|
|
if (config.position.fixed_position) {
|
|
return localPosition.altitude;
|
|
} else {
|
|
return p.altitude;
|
|
}
|
|
}
|
|
|
|
uint32_t getDOP() const { return p.PDOP; }
|
|
|
|
uint32_t getHeading() const { return p.ground_track; }
|
|
|
|
uint32_t getNumSatellites() const { return p.sats_in_view; }
|
|
|
|
/// Return millis() when the last GPS fix occurred (0 = never)
|
|
uint32_t getLastFixMillis() const { return lastFixMillis; }
|
|
|
|
bool matches(const GPSStatus *newStatus) const
|
|
{
|
|
LOG_DEBUG_GPS("GPSStatus.match() new pos@%x to old pos@%x", newStatus->p.timestamp, p.timestamp);
|
|
return (newStatus->hasLock != hasLock || newStatus->isConnected != isConnected || newStatus->hasTime != hasTime ||
|
|
newStatus->isPowerSaving != isPowerSaving || newStatus->p.latitude_i != p.latitude_i ||
|
|
newStatus->p.longitude_i != p.longitude_i || newStatus->p.altitude != p.altitude ||
|
|
newStatus->p.altitude_hae != p.altitude_hae || newStatus->p.PDOP != p.PDOP ||
|
|
newStatus->p.ground_track != p.ground_track || newStatus->p.ground_speed != p.ground_speed ||
|
|
newStatus->p.sats_in_view != p.sats_in_view);
|
|
}
|
|
|
|
int updateStatus(const GPSStatus *newStatus)
|
|
{
|
|
// Only update the status if values have actually changed
|
|
bool isDirty = matches(newStatus);
|
|
|
|
if (isDirty && p.timestamp && (newStatus->p.timestamp == p.timestamp)) {
|
|
// We can NEVER be in two locations at the same time! (also PR #886)
|
|
LOG_ERROR("BUG: Positional timestamp unchanged from prev solution");
|
|
}
|
|
|
|
initialized = true;
|
|
hasLock = newStatus->hasLock;
|
|
isConnected = newStatus->isConnected;
|
|
hasTime = newStatus->hasTime;
|
|
|
|
p = newStatus->p;
|
|
|
|
if (isDirty) {
|
|
if (hasLock) {
|
|
// Record time of last valid GPS fix
|
|
lastFixMillis = millis();
|
|
|
|
// In debug logs, identify position by @timestamp:stage (stage 3 = notify)
|
|
LOG_DEBUG("New GPS pos@%x:3 lat=%f lon=%f alt=%d pdop=%.2f track=%.2f speed=%.2f sats=%d", p.timestamp,
|
|
p.latitude_i * 1e-7, p.longitude_i * 1e-7, p.altitude, p.PDOP * 1e-2, p.ground_track * 1e-5,
|
|
p.ground_speed * 1e-2, p.sats_in_view);
|
|
} else {
|
|
LOG_DEBUG("No GPS lock");
|
|
}
|
|
onNewStatus.notifyObservers(this);
|
|
}
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
} // namespace meshtastic
|
|
|
|
extern meshtastic::GPSStatus *gpsStatus;
|