From 5d78795065e51fde0ecbbd30a7e2193a50f7be0b Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 19 Aug 2023 07:46:34 -0500 Subject: [PATCH] Portnum promiscuity for text messages from other modules (#2732) * Add interested portnums to TextMessageModule * Send Detection Sensor Module messages on its own portnum * Add to Ext. Notification and consolidate logic * RANGE_TEST_APP portnum for RangeTestModule --- src/mesh/MeshService.h | 8 ++++++++ src/modules/DetectionSensorModule.h | 2 +- src/modules/ExternalNotificationModule.cpp | 9 +++++++-- src/modules/ExternalNotificationModule.h | 4 +++- src/modules/NeighborInfoModule.cpp | 2 +- src/modules/RangeTestModule.h | 2 +- src/modules/TextMessageModule.cpp | 6 ++++++ src/modules/TextMessageModule.h | 3 ++- 8 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index fa184b391..eb40b7712 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -48,6 +48,14 @@ class MeshService uint32_t oldFromNum = 0; public: + static bool isTextPayload(const meshtastic_MeshPacket *p) + { + if (moduleConfig.range_test.enabled && p->decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP) { + return true; + } + return p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP || + p->decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP; + } /// Called when some new packets have arrived from one of the radios Observable fromNumChanged; diff --git a/src/modules/DetectionSensorModule.h b/src/modules/DetectionSensorModule.h index bcc0b9419..ed6cddda5 100644 --- a/src/modules/DetectionSensorModule.h +++ b/src/modules/DetectionSensorModule.h @@ -5,7 +5,7 @@ class DetectionSensorModule : public SinglePortModule, private concurrency::OSTh { public: DetectionSensorModule() - : SinglePortModule("detection", meshtastic_PortNum_TEXT_MESSAGE_APP), OSThread("DetectionSensorModule") + : SinglePortModule("detection", meshtastic_PortNum_DETECTION_SENSOR_APP), OSThread("DetectionSensorModule") { } diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index cbcf4e452..20191e706 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -128,6 +128,11 @@ int32_t ExternalNotificationModule::runOnce() } } +bool ExternalNotificationModule::wantPacket(const meshtastic_MeshPacket *p) +{ + return MeshService::isTextPayload(p); +} + /** * Sets the external notification on for the specified index. * @@ -212,8 +217,8 @@ void ExternalNotificationModule::stopNow() } ExternalNotificationModule::ExternalNotificationModule() - : SinglePortModule("ExternalNotificationModule", meshtastic_PortNum_TEXT_MESSAGE_APP), concurrency::OSThread( - "ExternalNotificationModule") + : SinglePortModule("ExternalNotificationModule", meshtastic_PortNum_TEXT_MESSAGE_APP), + concurrency::OSThread("ExternalNotificationModule") { /* Uncomment the preferences below if you want to use the module diff --git a/src/modules/ExternalNotificationModule.h b/src/modules/ExternalNotificationModule.h index f8ec053dd..3331ec428 100644 --- a/src/modules/ExternalNotificationModule.h +++ b/src/modules/ExternalNotificationModule.h @@ -52,6 +52,8 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency: virtual int32_t runOnce() override; + virtual bool wantPacket(const meshtastic_MeshPacket *p) override; + bool isNagging = false; virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp, @@ -59,4 +61,4 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency: meshtastic_AdminMessage *response) override; }; -extern ExternalNotificationModule *externalNotificationModule; +extern ExternalNotificationModule *externalNotificationModule; \ No newline at end of file diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 706b1db58..804384cb6 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -120,7 +120,7 @@ Assumes that the neighborInfo packet has been allocated */ uint32_t NeighborInfoModule::collectNeighborInfo(meshtastic_NeighborInfo *neighborInfo) { - int my_node_id = nodeDB.getNodeNum(); + uint my_node_id = nodeDB.getNodeNum(); neighborInfo->node_id = my_node_id; neighborInfo->last_sent_by_id = my_node_id; neighborInfo->node_broadcast_interval_secs = moduleConfig.neighbor_info.update_interval; diff --git a/src/modules/RangeTestModule.h b/src/modules/RangeTestModule.h index ae2a8f182..b632d343e 100644 --- a/src/modules/RangeTestModule.h +++ b/src/modules/RangeTestModule.h @@ -29,7 +29,7 @@ class RangeTestModuleRadio : public SinglePortModule uint32_t lastRxID = 0; public: - RangeTestModuleRadio() : SinglePortModule("RangeTestModuleRadio", meshtastic_PortNum_TEXT_MESSAGE_APP) + RangeTestModuleRadio() : SinglePortModule("RangeTestModuleRadio", meshtastic_PortNum_RANGE_TEST_APP) { loopbackOk = true; // Allow locally generated messages to loop back to the client } diff --git a/src/modules/TextMessageModule.cpp b/src/modules/TextMessageModule.cpp index 8ff034fa9..0f86a6470 100644 --- a/src/modules/TextMessageModule.cpp +++ b/src/modules/TextMessageModule.cpp @@ -1,4 +1,5 @@ #include "TextMessageModule.h" +#include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" #include "configuration.h" @@ -22,3 +23,8 @@ ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp return ProcessMessage::CONTINUE; // Let others look at this message also if they want } + +bool TextMessageModule::wantPacket(const meshtastic_MeshPacket *p) +{ + return MeshService::isTextPayload(p); +} \ No newline at end of file diff --git a/src/modules/TextMessageModule.h b/src/modules/TextMessageModule.h index 93b1bfaa2..cc0b0f9d5 100644 --- a/src/modules/TextMessageModule.h +++ b/src/modules/TextMessageModule.h @@ -20,6 +20,7 @@ class TextMessageModule : public SinglePortModule, public Observable