Skip to content

Commit

Permalink
Portnum promiscuity for text messages from other modules (#2732)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thebentern authored Aug 19, 2023
1 parent 2dbdda2 commit 5d78795
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/mesh/MeshService.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> fromNumChanged;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/DetectionSensorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
9 changes: 7 additions & 2 deletions src/modules/ExternalNotificationModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/modules/ExternalNotificationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ 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,
meshtastic_AdminMessage *request,
meshtastic_AdminMessage *response) override;
};

extern ExternalNotificationModule *externalNotificationModule;
extern ExternalNotificationModule *externalNotificationModule;
2 changes: 1 addition & 1 deletion src/modules/NeighborInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/RangeTestModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions src/modules/TextMessageModule.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "TextMessageModule.h"
#include "MeshService.h"
#include "NodeDB.h"
#include "PowerFSM.h"
#include "configuration.h"
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion src/modules/TextMessageModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TextMessageModule : public SinglePortModule, public Observable<const mesht
it
*/
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
virtual bool wantPacket(const meshtastic_MeshPacket *p) override;
};

extern TextMessageModule *textMessageModule;
extern TextMessageModule *textMessageModule;

0 comments on commit 5d78795

Please sign in to comment.