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
This commit is contained in:
Ben Meadors 2023-08-19 07:46:34 -05:00 committed by GitHub
parent 2dbdda204f
commit 5d78795065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 7 deletions

View File

@ -48,6 +48,14 @@ class MeshService
uint32_t oldFromNum = 0; uint32_t oldFromNum = 0;
public: 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 /// Called when some new packets have arrived from one of the radios
Observable<uint32_t> fromNumChanged; Observable<uint32_t> fromNumChanged;

View File

@ -5,7 +5,7 @@ class DetectionSensorModule : public SinglePortModule, private concurrency::OSTh
{ {
public: public:
DetectionSensorModule() DetectionSensorModule()
: SinglePortModule("detection", meshtastic_PortNum_TEXT_MESSAGE_APP), OSThread("DetectionSensorModule") : SinglePortModule("detection", meshtastic_PortNum_DETECTION_SENSOR_APP), OSThread("DetectionSensorModule")
{ {
} }

View File

@ -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. * Sets the external notification on for the specified index.
* *
@ -212,8 +217,8 @@ void ExternalNotificationModule::stopNow()
} }
ExternalNotificationModule::ExternalNotificationModule() ExternalNotificationModule::ExternalNotificationModule()
: SinglePortModule("ExternalNotificationModule", meshtastic_PortNum_TEXT_MESSAGE_APP), concurrency::OSThread( : SinglePortModule("ExternalNotificationModule", meshtastic_PortNum_TEXT_MESSAGE_APP),
"ExternalNotificationModule") concurrency::OSThread("ExternalNotificationModule")
{ {
/* /*
Uncomment the preferences below if you want to use the module Uncomment the preferences below if you want to use the module

View File

@ -52,6 +52,8 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency:
virtual int32_t runOnce() override; virtual int32_t runOnce() override;
virtual bool wantPacket(const meshtastic_MeshPacket *p) override;
bool isNagging = false; bool isNagging = false;
virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp, virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp,

View File

@ -120,7 +120,7 @@ Assumes that the neighborInfo packet has been allocated
*/ */
uint32_t NeighborInfoModule::collectNeighborInfo(meshtastic_NeighborInfo *neighborInfo) 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->node_id = my_node_id;
neighborInfo->last_sent_by_id = my_node_id; neighborInfo->last_sent_by_id = my_node_id;
neighborInfo->node_broadcast_interval_secs = moduleConfig.neighbor_info.update_interval; neighborInfo->node_broadcast_interval_secs = moduleConfig.neighbor_info.update_interval;

View File

@ -29,7 +29,7 @@ class RangeTestModuleRadio : public SinglePortModule
uint32_t lastRxID = 0; uint32_t lastRxID = 0;
public: 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 loopbackOk = true; // Allow locally generated messages to loop back to the client
} }

View File

@ -1,4 +1,5 @@
#include "TextMessageModule.h" #include "TextMessageModule.h"
#include "MeshService.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "configuration.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 return ProcessMessage::CONTINUE; // Let others look at this message also if they want
} }
bool TextMessageModule::wantPacket(const meshtastic_MeshPacket *p)
{
return MeshService::isTextPayload(p);
}

View File

@ -20,6 +20,7 @@ class TextMessageModule : public SinglePortModule, public Observable<const mesht
it it
*/ */
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override; virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
virtual bool wantPacket(const meshtastic_MeshPacket *p) override;
}; };
extern TextMessageModule *textMessageModule; extern TextMessageModule *textMessageModule;