mirror of
https://github.com/meshtastic/firmware.git
synced 2026-09-29 17:55:25 -04: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>
164 lines
5.4 KiB
C++
164 lines
5.4 KiB
C++
#include "RemoteHardwareModule.h"
|
|
#include "MeshService.h"
|
|
#include "NodeDB.h"
|
|
#include "Router.h"
|
|
#include "configuration.h"
|
|
#include "gps/RTC.h"
|
|
#include "main.h"
|
|
#include <Throttle.h>
|
|
|
|
#define NUM_GPIOS 64
|
|
|
|
// Because (FIXME) we currently don't tell API clients status on sent messages
|
|
// we need to throttle our sending, so that if a gpio is bouncing up and down we
|
|
// don't generate more messages than the net can send. So we limit watch messages to
|
|
// a max of one change per 30 seconds
|
|
#define WATCH_INTERVAL_MSEC (30 * 1000)
|
|
|
|
// Tests for access to read from or write to a specified GPIO pin
|
|
static bool pinAccessAllowed(uint64_t mask, uint8_t pin)
|
|
{
|
|
// If undefined pin access is allowed, don't check the pin and just return true
|
|
if (moduleConfig.remote_hardware.allow_undefined_pin_access) {
|
|
return true;
|
|
}
|
|
|
|
// Test to see if the pin is in the list of allowed pins and return true if found
|
|
if (mask & (1ULL << pin)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// Set pin modes for every set bit in a mask
|
|
static void pinModes(uint64_t mask, uint8_t mode, uint64_t maskAvailable)
|
|
{
|
|
for (uint64_t i = 0; i < NUM_GPIOS; i++) {
|
|
if (mask & (1ULL << i)) {
|
|
if (pinAccessAllowed(maskAvailable, i)) {
|
|
pinMode(i, mode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Read all the pins mentioned in a mask
|
|
static uint64_t digitalReads(uint64_t mask, uint64_t maskAvailable)
|
|
{
|
|
uint64_t res = 0;
|
|
|
|
pinModes(mask, INPUT_PULLUP, maskAvailable);
|
|
|
|
for (uint64_t i = 0; i < NUM_GPIOS; i++) {
|
|
uint64_t m = 1ULL << i;
|
|
if (mask & m && pinAccessAllowed(maskAvailable, i)) {
|
|
if (digitalRead(i)) {
|
|
res |= m;
|
|
}
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
RemoteHardwareModule::RemoteHardwareModule()
|
|
: ProtobufModule("remotehardware", meshtastic_PortNum_REMOTE_HARDWARE_APP, &meshtastic_HardwareMessage_msg),
|
|
concurrency::OSThread("RemoteHardware")
|
|
{
|
|
// restrict to the gpio channel for rx
|
|
boundChannel = Channels::gpioChannel;
|
|
|
|
// Pull available pin allowlist from config and build a bitmask out of it for fast comparisons later
|
|
for (uint8_t i = 0; i < 4; i++) {
|
|
availablePins += 1ULL << moduleConfig.remote_hardware.available_pins[i].gpio_pin;
|
|
}
|
|
}
|
|
|
|
bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &req, meshtastic_HardwareMessage *pptr)
|
|
{
|
|
if (moduleConfig.remote_hardware.enabled) {
|
|
auto p = *pptr;
|
|
LOG_INFO("Received RemoteHardware type=%d", p.type);
|
|
|
|
switch (p.type) {
|
|
case meshtastic_HardwareMessage_Type_WRITE_GPIOS: {
|
|
pinModes(p.gpio_mask, OUTPUT, availablePins);
|
|
for (uint8_t i = 0; i < NUM_GPIOS; i++) {
|
|
uint64_t mask = 1ULL << i;
|
|
if (p.gpio_mask & mask && pinAccessAllowed(availablePins, i)) {
|
|
digitalWrite(i, (p.gpio_value & mask) ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
case meshtastic_HardwareMessage_Type_READ_GPIOS: {
|
|
uint64_t res = digitalReads(p.gpio_mask, availablePins);
|
|
|
|
// Send the reply
|
|
meshtastic_HardwareMessage r = meshtastic_HardwareMessage_init_default;
|
|
r.type = meshtastic_HardwareMessage_Type_READ_GPIOS_REPLY;
|
|
r.gpio_value = res;
|
|
r.gpio_mask = p.gpio_mask;
|
|
meshtastic_MeshPacket *p2 = allocDataProtobuf(r);
|
|
if (p2) {
|
|
setReplyTo(p2, req);
|
|
myReply = p2;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case meshtastic_HardwareMessage_Type_WATCH_GPIOS: {
|
|
watchGpios = p.gpio_mask;
|
|
lastWatchMsec = 0; // Force a new publish soon
|
|
previousWatch =
|
|
~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish)
|
|
enabled = true; // Let our thread run at least once
|
|
setInterval(2000); // Set a new interval so we'll run soon
|
|
LOG_INFO("Now watching GPIOs 0x%llx", watchGpios);
|
|
break;
|
|
}
|
|
|
|
case meshtastic_HardwareMessage_Type_READ_GPIOS_REPLY:
|
|
case meshtastic_HardwareMessage_Type_GPIOS_CHANGED:
|
|
break; // Ignore - we might see our own replies
|
|
|
|
default:
|
|
LOG_ERROR("Hardware operation %d not yet implemented! FIXME", p.type);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
int32_t RemoteHardwareModule::runOnce()
|
|
{
|
|
if (moduleConfig.remote_hardware.enabled && watchGpios) {
|
|
|
|
if (!Throttle::isWithinTimespanMs(lastWatchMsec, WATCH_INTERVAL_MSEC)) {
|
|
uint64_t curVal = digitalReads(watchGpios, availablePins);
|
|
lastWatchMsec = millis();
|
|
|
|
if (curVal != previousWatch) {
|
|
previousWatch = curVal;
|
|
LOG_INFO("Broadcast GPIOS 0x%llx changed", curVal);
|
|
|
|
// Something changed! Tell the world with a broadcast message
|
|
meshtastic_HardwareMessage r = meshtastic_HardwareMessage_init_default;
|
|
r.type = meshtastic_HardwareMessage_Type_GPIOS_CHANGED;
|
|
r.gpio_value = curVal;
|
|
meshtastic_MeshPacket *p = allocDataProtobuf(r);
|
|
if (p)
|
|
service->sendToMesh(p);
|
|
}
|
|
}
|
|
} else {
|
|
// No longer watching anything - stop using CPU
|
|
return disable();
|
|
}
|
|
|
|
return 2000; // Poll our GPIOs every 2000ms
|
|
} |