From 304f26b909e6e9001918342369bc9f3ccfd26439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 19 Oct 2024 19:01:58 +0200 Subject: [PATCH 1/4] Revert "Permanently engage !CTRL" --- variants/rp2040-lora/variant.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variants/rp2040-lora/variant.h b/variants/rp2040-lora/variant.h index c93105f0ee..f1826605f5 100644 --- a/variants/rp2040-lora/variant.h +++ b/variants/rp2040-lora/variant.h @@ -54,7 +54,7 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_BUSY #define SX126X_RESET LORA_RESET -#define SX126X_DIO2_AS_RF_SWITCH // Antenna switch CTRL -#define SX126X_POWER_EN LORA_DIO4 // Antenna switch !CTRL via GPIO17 +#define SX126X_DIO2_AS_RF_SWITCH // Antenna switch CTRL +#define SX126X_RXEN LORA_DIO4 // Antenna switch !CTRL via GPIO17 // #define SX126X_DIO3_TCXO_VOLTAGE 1.8 -#endif +#endif \ No newline at end of file From 4575352d8cd71ab2adf7ba105ebd27d3ecc39c61 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 19 Oct 2024 12:48:00 -0500 Subject: [PATCH 2/4] Initial NODENUM_BROADCAST_NO_LORA implementation with NeighborInfo module (#5087) * Initial NODENUM_BROADCAST_NO_LORA implementation with NeighborInfo module * isBroadcast * Trunkt --- src/mesh/FloodingRouter.cpp | 2 +- src/mesh/MeshModule.cpp | 2 +- src/mesh/MeshTypes.h | 4 +++- src/mesh/NodeDB.cpp | 5 +++++ src/mesh/RadioLibInterface.cpp | 5 ++++- src/mesh/Router.cpp | 10 +++++----- src/modules/NeighborInfoModule.cpp | 2 +- src/modules/NodeInfoModule.cpp | 2 +- src/modules/RoutingModule.cpp | 5 ++--- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index 268fee2b05..6760d70ebf 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -44,7 +44,7 @@ bool FloodingRouter::isRebroadcaster() void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c) { bool isAckorReply = (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) && (p->decoded.request_id != 0); - if (isAckorReply && !isToUs(p) && p->to != NODENUM_BROADCAST) { + if (isAckorReply && !isToUs(p) && !isBroadcast(p->to)) { // do not flood direct message that is ACKed or replied to LOG_DEBUG("Rxd an ACK/reply not for me, cancel rebroadcast."); Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM diff --git a/src/mesh/MeshModule.cpp b/src/mesh/MeshModule.cpp index 48c3ee47d5..a8de540eb3 100644 --- a/src/mesh/MeshModule.cpp +++ b/src/mesh/MeshModule.cpp @@ -86,7 +86,7 @@ void MeshModule::callModules(meshtastic_MeshPacket &mp, RxSource src) // Was this message directed to us specifically? Will be false if we are sniffing someone elses packets auto ourNodeNum = nodeDB->getNodeNum(); - bool toUs = mp.to == NODENUM_BROADCAST || isToUs(&mp); + bool toUs = isBroadcast(mp.to) || isToUs(&mp); for (auto i = modules->begin(); i != modules->end(); ++i) { auto &pi = **i; diff --git a/src/mesh/MeshTypes.h b/src/mesh/MeshTypes.h index 27d100fbef..7a3d785dd5 100644 --- a/src/mesh/MeshTypes.h +++ b/src/mesh/MeshTypes.h @@ -57,4 +57,6 @@ bool isFromUs(const meshtastic_MeshPacket *p); bool isToUs(const meshtastic_MeshPacket *p); /* Some clients might not properly set priority, therefore we fix it here. */ -void fixPriority(meshtastic_MeshPacket *p); \ No newline at end of file +void fixPriority(meshtastic_MeshPacket *p); + +bool isBroadcast(uint32_t dest); \ No newline at end of file diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index ebe3debdb2..78ccdd85ad 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -222,6 +222,11 @@ bool isToUs(const meshtastic_MeshPacket *p) return p->to == nodeDB->getNodeNum(); } +bool isBroadcast(uint32_t dest) +{ + return dest == NODENUM_BROADCAST || dest == NODENUM_BROADCAST_NO_LORA; +} + bool NodeDB::resetRadioConfig(bool factory_reset) { bool didFactoryReset = false; diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 1ec3b90773..f44d50d363 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -467,7 +467,10 @@ void RadioLibInterface::setStandby() void RadioLibInterface::startSend(meshtastic_MeshPacket *txp) { printPacket("Starting low level send", txp); - if (disabled || !config.lora.tx_enabled) { + if (txp->to == NODENUM_BROADCAST_NO_LORA) { + LOG_DEBUG("Drop Tx packet because dest is broadcast no-lora"); + packetPool.release(txp); + } else if (disabled || !config.lora.tx_enabled) { LOG_WARN("Drop Tx packet because LoRa Tx disabled"); packetPool.release(txp); } else { diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index b7296f959b..84ae7bbb02 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -181,7 +181,7 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) } else { // If we are sending a broadcast, we also treat it as if we just received it ourself // this allows local apps (and PCs) to see broadcasts sourced locally - if (p->to == NODENUM_BROADCAST) { + if (isBroadcast(p->to)) { handleReceived(p, src); } @@ -240,7 +240,7 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) // assert // Never set the want_ack flag on broadcast packets sent over the air. - if (p->to == NODENUM_BROADCAST) + if (isBroadcast(p->to)) p->want_ack = false; // Up until this point we might have been using 0 for the from address (if it started with the phone), but when we send over @@ -328,7 +328,7 @@ bool perhapsDecode(meshtastic_MeshPacket *p) memcpy(ScratchEncrypted, p->encrypted.bytes, rawSize); #if !(MESHTASTIC_EXCLUDE_PKI) // Attempt PKI decryption first - if (p->channel == 0 && isToUs(p) && p->to > 0 && p->to != NODENUM_BROADCAST && nodeDB->getMeshNode(p->from) != nullptr && + if (p->channel == 0 && isToUs(p) && p->to > 0 && !isBroadcast(p->to) && nodeDB->getMeshNode(p->from) != nullptr && nodeDB->getMeshNode(p->from)->user.public_key.size > 0 && nodeDB->getMeshNode(p->to)->user.public_key.size > 0 && rawSize > MESHTASTIC_PKC_OVERHEAD) { LOG_DEBUG("Attempting PKI decryption"); @@ -493,7 +493,7 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) // Don't use PKC if it's not explicitly requested and a non-primary channel is requested !(p->pki_encrypted != true && p->channel > 0) && // Check for valid keys and single node destination - config.security.private_key.size == 32 && p->to != NODENUM_BROADCAST && node != nullptr && + config.security.private_key.size == 32 && !isBroadcast(p->to) && node != nullptr && // Check for a known public key for the destination (node->user.public_key.size == 32) && // Some portnums either make no sense to send with PKC @@ -615,7 +615,7 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) #if !MESHTASTIC_EXCLUDE_MQTT // Mark as pki_encrypted if it is not yet decoded and MQTT encryption is also enabled, hash matches and it's a DM not to // us (because we would be able to decrypt it) - if (!decoded && moduleConfig.mqtt.encryption_enabled && p->channel == 0x00 && p->to != NODENUM_BROADCAST && !isToUs(p)) + if (!decoded && moduleConfig.mqtt.encryption_enabled && p->channel == 0x00 && !isBroadcast(p->to) && !isToUs(p)) p_encrypted->pki_encrypted = true; // After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt) diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 85552a6bf4..cbf63e9af9 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -122,7 +122,7 @@ Will be used for broadcast. int32_t NeighborInfoModule::runOnce() { if (airTime->isTxAllowedChannelUtil(true) && airTime->isTxAllowedAirUtil()) { - sendNeighborInfo(NODENUM_BROADCAST, false); + sendNeighborInfo(NODENUM_BROADCAST_NO_LORA, false); } return Default::getConfiguredOrDefaultMs(moduleConfig.neighbor_info.update_interval, default_neighbor_info_broadcast_secs); } diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index 89f6ed3c45..843711807e 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -16,7 +16,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes bool hasChanged = nodeDB->updateUser(getFrom(&mp), p, mp.channel); - bool wasBroadcast = mp.to == NODENUM_BROADCAST; + bool wasBroadcast = isBroadcast(mp.to); // Show new nodes on LCD screen if (wasBroadcast) { diff --git a/src/modules/RoutingModule.cpp b/src/modules/RoutingModule.cpp index 3b7be1ab7c..f0d007d9d3 100644 --- a/src/modules/RoutingModule.cpp +++ b/src/modules/RoutingModule.cpp @@ -13,8 +13,7 @@ bool RoutingModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mesh printPacket("Routing sniffing", &mp); router->sniffReceived(&mp, r); - bool maybePKI = - mp.which_payload_variant == meshtastic_MeshPacket_encrypted_tag && mp.channel == 0 && mp.to != NODENUM_BROADCAST; + bool maybePKI = mp.which_payload_variant == meshtastic_MeshPacket_encrypted_tag && mp.channel == 0 && !isBroadcast(mp.to); // Beginning of logic whether to drop the packet based on Rebroadcast mode if (mp.which_payload_variant == meshtastic_MeshPacket_encrypted_tag && (config.device.rebroadcast_mode == meshtastic_Config_DeviceConfig_RebroadcastMode_LOCAL_ONLY || @@ -28,7 +27,7 @@ bool RoutingModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mesh // FIXME - move this to a non promsicious PhoneAPI module? // Note: we are careful not to send back packets that started with the phone back to the phone - if ((mp.to == NODENUM_BROADCAST || isToUs(&mp)) && (mp.from != 0)) { + if ((isBroadcast(mp.to) || isToUs(&mp)) && (mp.from != 0)) { printPacket("Delivering rx packet", &mp); service->handleFromRadio(&mp); } From 7e3931b05da532f0af24cd3d487ef0bf7be75b17 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 19 Oct 2024 20:05:52 -0500 Subject: [PATCH 3/4] Move 115200 baud GNSS probe earlier (#5101) * Move 115200 baud GNSS probe earlier * Even more optimized! --- src/gps/GPS.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gps/GPS.h b/src/gps/GPS.h index bc95613b35..8b1982cf74 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -75,7 +75,7 @@ class GPS : private concurrency::OSThread uint8_t fixType = 0; // fix type from GPGSA #endif private: - const int serialSpeeds[6] = {9600, 4800, 38400, 57600, 115200, 9600}; + const int serialSpeeds[6] = {9600, 115200, 38400, 4800, 57600, 9600}; uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0; uint32_t rx_gpio = 0; uint32_t tx_gpio = 0; From 2ba72c154ac6078c8884f705df594d776c254e6a Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Sun, 20 Oct 2024 20:46:25 +1100 Subject: [PATCH 4/4] Fix GPS_DEBUG output (#5100) After the recent change to move logging line breaks to a central location, GPS_DEBUG is now emitting one character per line, making the logs unusable. Patch uses local strings and appends to collate and then print in the right places. Fixes https://github.com/meshtastic/firmware/issues/5099 Co-authored-by: Ben Meadors --- src/gps/GPS.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index c33263326f..3a9516c842 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -267,6 +267,9 @@ GPS_RESPONSE GPS::getACK(uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) uint32_t startTime = millis(); const char frame_errors[] = "More than 100 frame errors"; int sCounter = 0; +#ifdef GPS_DEBUG + std::string debugmsg = ""; +#endif for (int j = 2; j < 6; j++) { buf[8] += buf[j]; @@ -292,20 +295,24 @@ GPS_RESPONSE GPS::getACK(uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) if (b == frame_errors[sCounter]) { sCounter++; if (sCounter == 26) { +#ifdef GPS_DEBUG + + LOG_DEBUG(debugmsg.c_str()); +#endif return GNSS_RESPONSE_FRAME_ERRORS; } } else { sCounter = 0; } #ifdef GPS_DEBUG - LOG_DEBUG("%02X", b); + debugmsg += vformat("%02X", b); #endif if (b == buf[ack]) { ack++; } else { if (ack == 3 && b == 0x00) { // UBX-ACK-NAK message #ifdef GPS_DEBUG - LOG_DEBUG(""); + LOG_DEBUG(debugmsg.c_str()); #endif LOG_WARN("Got NAK for class %02X message %02X", class_id, msg_id); return GNSS_RESPONSE_NAK; // NAK received @@ -315,7 +322,7 @@ GPS_RESPONSE GPS::getACK(uint8_t class_id, uint8_t msg_id, uint32_t waitMillis) } } #ifdef GPS_DEBUG - LOG_DEBUG(""); + LOG_DEBUG(debugmsg.c_str()); LOG_WARN("No response for class %02X message %02X", class_id, msg_id); #endif return GNSS_RESPONSE_NONE; // No response received within timeout @@ -1624,6 +1631,9 @@ bool GPS::whileActive() { unsigned int charsInBuf = 0; bool isValid = false; +#ifdef GPS_DEBUG + std::string debugmsg = ""; +#endif if (powerState != GPS_ACTIVE) { clearBuffer(); return false; @@ -1641,7 +1651,7 @@ bool GPS::whileActive() int c = _serial_gps->read(); UBXscratch[charsInBuf] = c; #ifdef GPS_DEBUG - LOG_DEBUG("%c", c); + debugmsg += vformat("%c", (c >= 32 && c <= 126) ? c : '.'); #endif isValid |= reader.encode(c); if (charsInBuf > sizeof(UBXscratch) - 10 || c == '\r') { @@ -1653,6 +1663,9 @@ bool GPS::whileActive() charsInBuf++; } } +#ifdef GPS_DEBUG + LOG_DEBUG(debugmsg.c_str()); +#endif return isValid; } void GPS::enable() @@ -1696,4 +1709,4 @@ void GPS::toggleGpsMode() enable(); } } -#endif // Exclude GPS +#endif // Exclude GPS \ No newline at end of file