mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-01 02:09:57 +00:00
Rate limit position replies to three minutes (#5932)
This commit is contained in:
parent
fd56995764
commit
a14346bc4f
@ -160,7 +160,8 @@ bool PositionModule::hasGPS()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
meshtastic_MeshPacket *PositionModule::allocReply()
|
// Allocate a packet with our position data if we have one
|
||||||
|
meshtastic_MeshPacket *PositionModule::allocPositionPacket()
|
||||||
{
|
{
|
||||||
if (precision == 0) {
|
if (precision == 0) {
|
||||||
LOG_DEBUG("Skip location send because precision is set to 0!");
|
LOG_DEBUG("Skip location send because precision is set to 0!");
|
||||||
@ -262,7 +263,8 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
|||||||
p.has_ground_speed = true;
|
p.has_ground_speed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Position reply: time=%i lat=%i lon=%i", p.time, p.latitude_i, p.longitude_i);
|
LOG_INFO("Position packet: time=%i lat=%i lon=%i", p.time, p.latitude_i, p.longitude_i);
|
||||||
|
lastSentToMesh = millis();
|
||||||
|
|
||||||
// TAK Tracker devices should send their position in a TAK packet over the ATAK port
|
// TAK Tracker devices should send their position in a TAK packet over the ATAK port
|
||||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER)
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER)
|
||||||
@ -271,6 +273,16 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
|||||||
return allocDataProtobuf(p);
|
return allocDataProtobuf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meshtastic_MeshPacket *PositionModule::allocReply()
|
||||||
|
{
|
||||||
|
if (lastSentToMesh && Throttle::isWithinTimespanMs(lastSentToMesh, 3 * 60 * 1000)) {
|
||||||
|
LOG_DEBUG("Skip Position reply since we sent it <3min ago");
|
||||||
|
ignoreRequest = true; // Mark it as ignored for MeshModule
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return allocPositionPacket();
|
||||||
|
}
|
||||||
|
|
||||||
meshtastic_MeshPacket *PositionModule::allocAtakPli()
|
meshtastic_MeshPacket *PositionModule::allocAtakPli()
|
||||||
{
|
{
|
||||||
LOG_INFO("Send TAK PLI packet");
|
LOG_INFO("Send TAK PLI packet");
|
||||||
@ -333,9 +345,9 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha
|
|||||||
precision = 0;
|
precision = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocReply();
|
meshtastic_MeshPacket *p = allocPositionPacket();
|
||||||
if (p == nullptr) {
|
if (p == nullptr) {
|
||||||
LOG_DEBUG("allocReply returned a nullptr");
|
LOG_DEBUG("allocPositionPacket returned a nullptr");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
|||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
meshtastic_MeshPacket *allocPositionPacket();
|
||||||
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
||||||
meshtastic_MeshPacket *allocAtakPli();
|
meshtastic_MeshPacket *allocAtakPli();
|
||||||
void trySetRtc(meshtastic_Position p, bool isLocal, bool forceUpdate = false);
|
void trySetRtc(meshtastic_Position p, bool isLocal, bool forceUpdate = false);
|
||||||
@ -62,6 +63,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
|||||||
void sendLostAndFoundText();
|
void sendLostAndFoundText();
|
||||||
bool hasQualityTimesource();
|
bool hasQualityTimesource();
|
||||||
bool hasGPS();
|
bool hasGPS();
|
||||||
|
uint32_t lastSentToMesh = 0; // Last time we sent our position to the mesh
|
||||||
|
|
||||||
const uint32_t minimumTimeThreshold =
|
const uint32_t minimumTimeThreshold =
|
||||||
Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);
|
Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);
|
||||||
|
Loading…
Reference in New Issue
Block a user