mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-10 22:11:00 +10:00
* logging: strip redundant punctuation, level prefixes, and 'successfully' from log strings The logger already appends a newline and prints the level tag, so trailing '.', '!', '...', literal \n, and 'Error:'/'Warning:' prefixes inside format strings are wasted flash bytes. Same for 'successfully' (the affirmative form already implies it). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: tighten verbose log strings in modules, radio, platform, and system code Rewrite wordy log messages to terser equivalents - drop filler words (articles, 'attempting', 'due to', 'please'), use 'Can't X'/'X failed' phrasing, and abbreviate where the codebase already does (config, init, msg, BT). Format specifiers and argument lists are unchanged; distinctive greppable tokens are preserved. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: tighten verbose log strings in telemetry sensors and GPS Same terseness pass: drop filler, 'Can't X'/'X failed' phrasing, common abbreviations (temp, msg). Specifiers, arguments, and sensor-name prefixes unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: tighten verbose log strings in mesh core Same terseness pass over NodeDB, Router, MeshService, PhoneAPI, RadioInterface, NextHopRouter, and PacketHistory: 'X failed'/'Can't X' phrasing, imperative verbs, dropped filler. Specifiers and arguments unchanged; duplicate literals kept identical to preserve linker string dedup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: 'Unable to/Could not/Cannot' -> "Can't" in log strings Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: clang-format rewrap after string shortening Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: restore boot-logo trailing newline and progress-dot strings The terseness pass over-trimmed: the Meshtastic ASCII boot logo kept its blank line via a trailing \n, and three bare "." progress ticks were reduced to empty strings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * Update src/mesh/wifi/WiFiAPClient.cpp Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * logging: address review feedback on the terseness audit - Node/packet IDs use the repo's 0x%08x convention in NextHopRouter, NodeDB, AdminModule and CannedMessageModule. The sibling log in each if/else pair is converted too, so a pair isn't split across two formats. next_hop stays 0x%x - it's the last-byte relay hint, not a NodeNum. - RTC: the read-path and set-path "not found" warnings were byte-identical, so the linker deduped them and the log couldn't say which one fired. Split into "RTC read:" / "RTC set:". (The four sites live in mutually exclusive #ifdef branches, so the RTC family was never ambiguous.) - SCD4X getAmbientPressure()/setAmbientPressure() logged "altitude", and SCD30 getASC() logged "Can't send command" for a read. Both now name the operation they actually perform. - LOG_ERROR already carries the level: ". Error: %u" -> ", rc=%u" (matching the existing rc=%d house style) and "Error executing X()" -> "X() failed". - Typos and wording: "OTA partiton. (Reason" -> "OTA partition (reason", "CST3530 not response ~" -> "CST3530 no response", "Packet received with to: of 0" -> "to=0", HostMetrics "Error decoding" -> "Can't decode", and the dangling ": " on the NextHopRouter retransmission line. Printf specifier sequences are byte-identical on all 37 touched lines apart from the 6 deliberate %x/%u -> %08x node-ID widenings, all on uint32_t args. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
108 lines
2.5 KiB
C++
108 lines
2.5 KiB
C++
#include "SafeFile.h"
|
|
|
|
#ifdef FSCom
|
|
|
|
// Only way to work on both esp32 and nrf52
|
|
static File openFile(const char *filename, bool fullAtomic)
|
|
{
|
|
concurrency::LockGuard g(spiLock);
|
|
LOG_DEBUG("Opening %s, fullAtomic=%d", filename, fullAtomic);
|
|
if (!fullAtomic) {
|
|
FSCom.remove(filename); // Nuke the old file to make space (ignore if it !exists)
|
|
}
|
|
|
|
String filenameTmp = filename;
|
|
filenameTmp += ".tmp";
|
|
|
|
// FIXME: If we are doing a full atomic write, we may need to remove the old tmp file now
|
|
// if (fullAtomic) {
|
|
// FSCom.remove(filename);
|
|
// }
|
|
|
|
// clear any previous LFS errors
|
|
return FSCom.open(filenameTmp.c_str(), FILE_O_WRITE);
|
|
}
|
|
|
|
SafeFile::SafeFile(const char *_filename, bool fullAtomic)
|
|
: filename(_filename), f(openFile(_filename, fullAtomic)), fullAtomic(fullAtomic)
|
|
{
|
|
}
|
|
|
|
size_t SafeFile::write(uint8_t ch)
|
|
{
|
|
if (!f)
|
|
return 0;
|
|
|
|
hash ^= ch;
|
|
return f.write(ch);
|
|
}
|
|
|
|
size_t SafeFile::write(const uint8_t *buffer, size_t size)
|
|
{
|
|
if (!f)
|
|
return 0;
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
hash ^= buffer[i];
|
|
}
|
|
return f.write((uint8_t const *)buffer, size); // This nasty cast is _IMPORTANT_ otherwise the correct adafruit method does
|
|
// not get used (they made a mistake in their typing)
|
|
}
|
|
|
|
/**
|
|
* Atomically close the file (overwriting any old version) and readback the contents to confirm the hash matches
|
|
*
|
|
* @return false for failure
|
|
*/
|
|
bool SafeFile::close()
|
|
{
|
|
if (!f)
|
|
return false;
|
|
|
|
spiLock->lock();
|
|
f.close();
|
|
spiLock->unlock();
|
|
|
|
if (!testReadback())
|
|
return false;
|
|
|
|
// Rename or overwrite (atomic operation)
|
|
String filenameTmp = filename;
|
|
filenameTmp += ".tmp";
|
|
if (!renameFile(filenameTmp.c_str(), filename.c_str())) {
|
|
LOG_ERROR("Can't rename new pref file");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// Read our (closed) tempfile back in and compare the hash
|
|
bool SafeFile::testReadback()
|
|
{
|
|
concurrency::LockGuard g(spiLock);
|
|
|
|
String filenameTmp = filename;
|
|
filenameTmp += ".tmp";
|
|
auto f2 = FSCom.open(filenameTmp.c_str(), FILE_O_READ);
|
|
if (!f2) {
|
|
LOG_ERROR("Can't open tmp file for readback");
|
|
return false;
|
|
}
|
|
|
|
int c = 0;
|
|
uint8_t test_hash = 0;
|
|
while ((c = f2.read()) >= 0) {
|
|
test_hash ^= (uint8_t)c;
|
|
}
|
|
f2.close();
|
|
|
|
if (test_hash != hash) {
|
|
LOG_ERROR("Readback failed hash mismatch");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
#endif |