mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-28 12:42:00 +00:00
Add list of text message packet IDs, and check for dupes
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "mesh-pb-constants.h"
|
#include "mesh-pb-constants.h"
|
||||||
#include "meshUtils.h"
|
#include "meshUtils.h"
|
||||||
|
#include "modules/TextMessageModule.h"
|
||||||
#if !MESHTASTIC_EXCLUDE_TRACEROUTE
|
#if !MESHTASTIC_EXCLUDE_TRACEROUTE
|
||||||
#include "modules/TraceRouteModule.h"
|
#include "modules/TraceRouteModule.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -35,6 +36,10 @@ bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
|
|||||||
return true; // we handled it, so stop processing
|
return true; // we handled it, so stop processing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!seenRecently && !wasUpgraded && textMessageModule) {
|
||||||
|
seenRecently = textMessageModule->recentlySeen(p->id);
|
||||||
|
}
|
||||||
|
|
||||||
if (seenRecently) {
|
if (seenRecently) {
|
||||||
printPacket("Ignore dupe incoming msg", p);
|
printPacket("Ignore dupe incoming msg", p);
|
||||||
rxDupe++;
|
rxDupe++;
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp
|
|||||||
auto &p = mp.decoded;
|
auto &p = mp.decoded;
|
||||||
LOG_INFO("Received text msg from=0x%0x, id=0x%x, msg=%.*s", mp.from, mp.id, p.payload.size, p.payload.bytes);
|
LOG_INFO("Received text msg from=0x%0x, id=0x%x, msg=%.*s", mp.from, mp.id, p.payload.size, p.payload.bytes);
|
||||||
#endif
|
#endif
|
||||||
|
// add packet ID to the rolling list of packets
|
||||||
|
textPacketList[textPacketListIndex] = mp.id;
|
||||||
|
textPacketListIndex = (textPacketListIndex + 1) % TEXT_PACKET_LIST_SIZE;
|
||||||
|
|
||||||
// We only store/display messages destined for us.
|
// We only store/display messages destined for us.
|
||||||
devicestate.rx_text_message = mp;
|
devicestate.rx_text_message = mp;
|
||||||
@@ -47,3 +50,13 @@ bool TextMessageModule::wantPacket(const meshtastic_MeshPacket *p)
|
|||||||
{
|
{
|
||||||
return MeshService::isTextPayload(p);
|
return MeshService::isTextPayload(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TextMessageModule::recentlySeen(uint32_t id)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < TEXT_PACKET_LIST_SIZE; i++) {
|
||||||
|
if (textPacketList[i] != 0 && textPacketList[i] == id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
#include "SinglePortModule.h"
|
#include "SinglePortModule.h"
|
||||||
|
#define TEXT_PACKET_LIST_SIZE 50
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text message handling for Meshtastic.
|
* Text message handling for Meshtastic.
|
||||||
@@ -19,6 +20,8 @@ class TextMessageModule : public SinglePortModule, public Observable<const mesht
|
|||||||
*/
|
*/
|
||||||
TextMessageModule() : SinglePortModule("text", meshtastic_PortNum_TEXT_MESSAGE_APP) {}
|
TextMessageModule() : SinglePortModule("text", meshtastic_PortNum_TEXT_MESSAGE_APP) {}
|
||||||
|
|
||||||
|
bool recentlySeen(uint32_t id);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Called to handle a particular incoming message
|
/** Called to handle a particular incoming message
|
||||||
*
|
*
|
||||||
@@ -27,6 +30,10 @@ class TextMessageModule : public SinglePortModule, public Observable<const mesht
|
|||||||
*/
|
*/
|
||||||
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
||||||
virtual bool wantPacket(const meshtastic_MeshPacket *p) override;
|
virtual bool wantPacket(const meshtastic_MeshPacket *p) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t textPacketList[TEXT_PACKET_LIST_SIZE] = {0};
|
||||||
|
size_t textPacketListIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TextMessageModule *textMessageModule;
|
extern TextMessageModule *textMessageModule;
|
||||||
Reference in New Issue
Block a user