Skip to content

Commit

Permalink
Fix LOG_DEBUG messages when no DEBUG_PORT. (#2485)
Browse files Browse the repository at this point in the history
* Fix LOG_DEBUG messages when no DEBUG_PORT.

* Fix LOG_DEBUG messages when no DEBUG_PORT.

* Fix LOG_DEBUG messages when no DEBUG_PORT.

* Fix LOG_DEBUG messages when no DEBUG_PORT.
  • Loading branch information
IhorNehrutsa authored May 13, 2023
1 parent cf07d2d commit 9c683f4
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/DebugConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define DEBUG_PORT (*console) // Serial debug port

#ifdef USE_SEGGER
#define DEBUG_PORT
#define LOG_DEBUG(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define LOG_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define LOG_WARN(...) SEGGER_RTT_printf(0, __VA_ARGS__)
Expand Down
3 changes: 2 additions & 1 deletion src/GPSStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class GPSStatus : public Status
LOG_DEBUG("New GPS pos@%x:3 lat=%f, lon=%f, alt=%d, pdop=%.2f, track=%.2f, speed=%.2f, sats=%d\n", 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
} else {
LOG_DEBUG("No GPS lock\n");
}
onNewStatus.notifyObservers(this);
}
return 0;
Expand Down
9 changes: 6 additions & 3 deletions src/concurrency/NotifiedWorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ IRAM_ATTR bool NotifiedWorkerThread::notifyCommon(uint32_t v, bool overwrite)
runASAP = true;

notification = v;
if (debugNotification)
if (debugNotification) {
LOG_DEBUG("setting notification %d\n", v);
}
return true;
} else {
if (debugNotification)
if (debugNotification) {
LOG_DEBUG("dropping notification %d\n", v);
}
return false;
}
}
Expand Down Expand Up @@ -64,8 +66,9 @@ bool NotifiedWorkerThread::notifyLater(uint32_t delay, uint32_t v, bool overwrit

if (didIt) { // If we didn't already have something queued, override the delay to be larger
setIntervalFromNow(delay); // a new version of setInterval relative to the current time
if (debugNotification)
if (debugNotification) {
LOG_DEBUG("delaying notification %u\n", delay);
}
}

return didIt;
Expand Down
9 changes: 6 additions & 3 deletions src/concurrency/OSThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ bool OSThread::shouldRun(unsigned long time)
{
bool r = Thread::shouldRun(time);

if (showRun && r)
if (showRun && r) {
LOG_DEBUG("Thread %s: run\n", ThreadName.c_str());
}

if (showWaiting && enabled && !r)
if (showWaiting && enabled && !r) {
LOG_DEBUG("Thread %s: wait %lu\n", ThreadName.c_str(), interval);
}

if (showDisabled && !enabled)
if (showDisabled && !enabled) {
LOG_DEBUG("Thread %s: disabled\n", ThreadName.c_str());
}

return r;
}
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,10 @@ void Screen::setFrames()

moduleFrames = MeshModule::GetMeshModulesWithUIFrames();
LOG_DEBUG("Showing %d module frames\n", moduleFrames.size());
#ifdef DEBUG_PORT
int totalFrameCount = MAX_NUM_NODES + NUM_EXTRA_FRAMES + moduleFrames.size();
LOG_DEBUG("Total frame count: %d\n", totalFrameCount);
#endif

// We don't show the node info our our node (if we have it yet - we should)
size_t numnodes = nodeDB.getNumNodes();
Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,11 @@ void setup()

gps = createGps();

if (gps)
if (gps) {
gpsStatus->observe(&gps->newStatus);
else
} else {
LOG_WARN("No GPS found - running without GPS\n");
}

nodeStatus->observe(&nodeDB.newStatus);

Expand Down
3 changes: 2 additions & 1 deletion src/mesh/Channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ CryptoKey Channels::getKey(ChannelIndex chIndex)
if (ch.role == meshtastic_Channel_Role_SECONDARY) {
LOG_DEBUG("Unset PSK for secondary channel %s. using primary key\n", ch.settings.name);
k = getKey(primaryIndex);
} else
} else {
LOG_WARN("User disabled encryption\n");
}
} else if (k.length == 1) {
// Convert the short single byte variants of psk into variant that can be used more generally

Expand Down
3 changes: 2 additions & 1 deletion src/mesh/MeshModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ void MeshModule::callPlugins(const meshtastic_MeshPacket &mp, RxSource src)
}
}

if (!moduleFound)
if (!moduleFound) {
LOG_DEBUG("No modules interested in portnum=%d, src=%s\n", mp.decoded.portnum,
(src == RX_SRC_LOCAL) ? "LOCAL" : "REMOTE");
}
}

meshtastic_MeshPacket *MeshModule::allocReply()
Expand Down
14 changes: 9 additions & 5 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ void NodeDB::loadFromDisk()
}
}

if (loadProto(oemConfigFile, meshtastic_OEMStore_size, sizeof(meshtastic_OEMStore), &meshtastic_OEMStore_msg, &oemStore))
if (loadProto(oemConfigFile, meshtastic_OEMStore_size, sizeof(meshtastic_OEMStore), &meshtastic_OEMStore_msg, &oemStore)) {
LOG_INFO("Loaded OEMStore\n");
}
}

/** Save a protobuf from a file, return true for success */
Expand All @@ -494,10 +495,12 @@ bool NodeDB::saveProto(const char *filename, size_t protoSize, const pb_msgdesc_
f.close();

// brief window of risk here ;-)
if (FSCom.exists(filename) && !FSCom.remove(filename))
if (FSCom.exists(filename) && !FSCom.remove(filename)) {
LOG_WARN("Can't remove old pref file\n");
if (!renameFile(filenameTmp.c_str(), filename))
}
if (!renameFile(filenameTmp.c_str(), filename)) {
LOG_ERROR("Error: can't rename new pref file\n");
}
} else {
LOG_ERROR("Can't write prefs\n");
#ifdef ARCH_NRF52
Expand Down Expand Up @@ -802,10 +805,11 @@ void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, co
// Print error to screen and serial port
String lcd = String("Critical error ") + code + "!\n";
screen->print(lcd.c_str());
if (filename)
if (filename) {
LOG_ERROR("NOTE! Recording critical error %d at %s:%lu\n", code, filename, address);
else
} else {
LOG_ERROR("NOTE! Recording critical error %d, address=0x%lx\n", code, address);
}

// Record error to DB
myNodeInfo.error_code = code;
Expand Down
3 changes: 2 additions & 1 deletion src/mesh/PhoneAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ int PhoneAPI::onNotify(uint32_t newValue)
if (state == STATE_SEND_PACKETS) {
LOG_INFO("Telling client we have new packets %u\n", newValue);
onNowHasData(newValue);
} else
} else {
LOG_DEBUG("(Client not yet interested in packets)\n");
}

return 0;
}
2 changes: 2 additions & 0 deletions src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr)

void printPacket(const char *prefix, const meshtastic_MeshPacket *p)
{
#ifdef DEBUG_PORT
std::string out = DEBUG_PORT.mt_sprintf("%s (id=0x%08x fr=0x%02x to=0x%02x, WantAck=%d, HopLim=%d Ch=0x%x", prefix, p->id,
p->from & 0xff, p->to & 0xff, p->want_ack, p->hop_limit, p->channel);
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
Expand Down Expand Up @@ -283,6 +284,7 @@ void printPacket(const char *prefix, const meshtastic_MeshPacket *p)

out += ")";
LOG_DEBUG("%s\n", out.c_str());
#endif
}

RadioInterface::RadioInterface()
Expand Down
10 changes: 6 additions & 4 deletions src/mesh/RadioLibInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ bool RadioLibInterface::canSendImmediately()
bool busyRx = isReceiving && isActivelyReceiving();

if (busyTx || busyRx) {
if (busyTx)
if (busyTx) {
LOG_WARN("Can not send yet, busyTx\n");
}
// If we've been trying to send the same packet more than one minute and we haven't gotten a
// TX IRQ from the radio, the radio is probably broken.
if (busyTx && (millis() - lastTxStart > 60000)) {
Expand All @@ -88,8 +89,9 @@ bool RadioLibInterface::canSendImmediately()
// reboot in 5 seconds when this condition occurs.
rebootAtMsec = lastTxStart + 65000;
}
if (busyRx)
if (busyRx) {
LOG_WARN("Can not send yet, busyRx\n");
}
return false;
} else
return true;
Expand Down Expand Up @@ -164,9 +166,9 @@ meshtastic_QueueStatus RadioLibInterface::getQueueStatus()
bool RadioLibInterface::canSleep()
{
bool res = txQueue.empty();
if (!res) // only print debug messages if we are vetoing sleep
if (!res) { // only print debug messages if we are vetoing sleep
LOG_DEBUG("radio wait to sleep, txEmpty=%d\n", res);

}
return res;
}

Expand Down
7 changes: 4 additions & 3 deletions src/mesh/ReliableRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ void ReliableRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas

if (p->to == ourNode) { // ignore ack/nak/want_ack packets that are not address to us (we only handle 0 hop reliability)
if (p->want_ack) {
if (MeshModule::currentReply)
if (MeshModule::currentReply) {
LOG_DEBUG("Some other module has replied to this message, no need for a 2nd ack\n");
else if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag)
} else if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
sendAckNak(meshtastic_Routing_Error_NONE, getFrom(p), p->id, p->channel);
else
} else {
// Send a 'NO_CHANNEL' error on the primary channel if want_ack packet destined for us cannot be decoded
sendAckNak(meshtastic_Routing_Error_NO_CHANNEL, getFrom(p), p->id, channels.getPrimaryIndex());
}
}

// We consider an ack to be either a !routing packet with a request ID or a routing packet with !error
Expand Down
6 changes: 4 additions & 2 deletions src/mesh/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
if (!config.lora.override_duty_cycle && myRegion->dutyCycle < 100) {
float hourlyTxPercent = airTime->utilizationTXPercent();
if (hourlyTxPercent > myRegion->dutyCycle) {
#ifdef DEBUG_PORT
uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle);
LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes);
#endif
meshtastic_Routing_Error err = meshtastic_Routing_Error_DUTY_CYCLE_LIMIT;
if (getFrom(p) == nodeDB.getNodeNum()) { // only send NAK to API, not to the mesh
abortSendAndNak(err, p);
Expand Down Expand Up @@ -479,9 +481,9 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p)
// assert(radioConfig.has_preferences);
bool ignore = is_in_repeated(config.lora.ignore_incoming, p->from);

if (ignore)
if (ignore) {
LOG_DEBUG("Ignoring incoming message, 0x%x is in our ignore list\n", p->from);
else if (ignore |= shouldFilterReceived(p)) {
} else if (ignore |= shouldFilterReceived(p)) {
LOG_DEBUG("Incoming message was filtered 0x%x\n", p->from);
}

Expand Down
3 changes: 2 additions & 1 deletion src/mesh/SX126xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ template <typename T> void SX126xInterface<T>::setStandby()

int err = lora.standby();

if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
LOG_DEBUG("SX126x standby failed with error %d\n", err);
}

assert(err == RADIOLIB_ERR_NONE);

Expand Down
3 changes: 2 additions & 1 deletion src/mesh/SX128xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ template <typename T> void SX128xInterface<T>::setStandby()

int err = lora.standby();

if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("SX128x standby failed with error %d\n", err);
}

assert(err == RADIOLIB_ERR_NONE);

Expand Down
3 changes: 2 additions & 1 deletion src/modules/PositionModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ meshtastic_MeshPacket *PositionModule::allocReply()
if (getRTCQuality() < RTCQualityDevice) {
LOG_INFO("Stripping time %u from position send\n", p.time);
p.time = 0;
} else
} else {
LOG_INFO("Providing time to mesh %u\n", p.time);
}

LOG_INFO("Position reply: time=%i, latI=%i, lonI=-%i\n", p.time, p.latitude_i, p.longitude_i);

Expand Down
2 changes: 2 additions & 0 deletions src/modules/ReplyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
meshtastic_MeshPacket *ReplyModule::allocReply()
{
assert(currentRequest); // should always be !NULL
#ifdef DEBUG_PORT
auto req = *currentRequest;
auto &p = req.decoded;
// The incoming message is in p.payload
LOG_INFO("Received message from=0x%0x, id=%d, msg=%.*s\n", req.from, req.id, p.payload.size, p.payload.bytes);
#endif

screen->print("Sending reply\n");

Expand Down
3 changes: 2 additions & 1 deletion src/modules/Telemetry/AirQualityTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int32_t AirQualityTelemetryModule::runOnce()
bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
{
if (t->which_variant == meshtastic_Telemetry_air_quality_metrics_tag) {
#ifdef DEBUG_PORT
const char *sender = getSenderShortName(mp);

LOG_INFO("(Received from %s): pm10_standard=%i, pm25_standard=%i, pm100_standard=%i\n", sender,
Expand All @@ -68,7 +69,7 @@ bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPack
LOG_INFO(" | PM1.0(Environmental)=%i, PM2.5(Environmental)=%i, PM10.0(Environmental)=%i\n",
t->variant.air_quality_metrics.pm10_environmental, t->variant.air_quality_metrics.pm25_environmental,
t->variant.air_quality_metrics.pm100_environmental);

#endif
// release previous packet before occupying a new spot
if (lastMeasurementPacket != nullptr)
packetPool.release(lastMeasurementPacket);
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Telemetry/DeviceTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ int32_t DeviceTelemetryModule::runOnce()
bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
{
if (t->which_variant == meshtastic_Telemetry_device_metrics_tag) {
#ifdef DEBUG_PORT
const char *sender = getSenderShortName(mp);

LOG_INFO("(Received from %s): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n", sender,
t->variant.device_metrics.air_util_tx, t->variant.device_metrics.channel_utilization,
t->variant.device_metrics.battery_level, t->variant.device_metrics.voltage);

#endif
nodeDB.updateTelemetry(getFrom(&mp), *t, RX_SRC_RADIO);
}
return false; // Let others look at this message also if they want
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Telemetry/EnvironmentTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
{
if (t->which_variant == meshtastic_Telemetry_environment_metrics_tag) {
#ifdef DEBUG_PORT
const char *sender = getSenderShortName(mp);

LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, "
"temperature=%f, voltage=%f\n",
sender, t->variant.environment_metrics.barometric_pressure, t->variant.environment_metrics.current,
t->variant.environment_metrics.gas_resistance, t->variant.environment_metrics.relative_humidity,
t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage);

#endif
// release previous packet before occupying a new spot
if (lastMeasurementPacket != nullptr)
packetPool.release(lastMeasurementPacket);
Expand Down
6 changes: 4 additions & 2 deletions src/modules/Telemetry/Sensor/BME680Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ void BME680Sensor::updateState()
file.flush();
file.close();
// brief window of risk here ;-)
if (FSCom.exists(bsecConfigFileName) && !FSCom.remove(bsecConfigFileName))
if (FSCom.exists(bsecConfigFileName) && !FSCom.remove(bsecConfigFileName)) {
LOG_WARN("Can't remove old state file\n");
if (!renameFile(filenameTmp.c_str(), bsecConfigFileName))
}
if (!renameFile(filenameTmp.c_str(), bsecConfigFileName)) {
LOG_ERROR("Error: can't rename new state file\n");
}

} else {
LOG_INFO("Can't write %s state (File: %s).\n", sensorName, bsecConfigFileName);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/TextMessageModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ TextMessageModule *textMessageModule;

ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp)
{
#ifdef DEBUG_PORT
auto &p = mp.decoded;
LOG_INFO("Received text msg from=0x%0x, id=0x%x, msg=%.*s\n", mp.from, mp.id, p.payload.size, p.payload.bytes);
#endif

// We only store/display messages destined for us.
// Keep a copy of the most recent text message.
Expand Down
2 changes: 2 additions & 0 deletions src/modules/TraceRouteModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void TraceRouteModule::appendMyID(meshtastic_RouteDiscovery *updated)

void TraceRouteModule::printRoute(meshtastic_RouteDiscovery *r, uint32_t origin, uint32_t dest)
{
#ifdef DEBUG_PORT
LOG_INFO("Route traced:\n");
LOG_INFO("0x%x --> ", origin);
for (uint8_t i = 0; i < r->route_count; i++) {
Expand All @@ -56,6 +57,7 @@ void TraceRouteModule::printRoute(meshtastic_RouteDiscovery *r, uint32_t origin,
LOG_INFO("0x%x\n", dest);
else
LOG_INFO("...\n");
#endif
}

meshtastic_MeshPacket *TraceRouteModule::allocReply()
Expand Down
Loading

0 comments on commit 9c683f4

Please sign in to comment.