mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-01 19:46:42 +00:00
Merge branch 'master' into RCWL-9620
This commit is contained in:
commit
a957065fe8
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "mesh/compression/unishox2.h"
|
#include "mesh/compression/unishox2.h"
|
||||||
|
#include <Throttle.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
PositionModule *positionModule;
|
PositionModule *positionModule;
|
||||||
@ -63,7 +64,7 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log packet size and data fields
|
// Log packet size and data fields
|
||||||
LOG_INFO("POSITION node=%08x l=%d latI=%d lonI=%d msl=%d hae=%d geo=%d pdop=%d hdop=%d vdop=%d siv=%d fxq=%d fxt=%d pts=%d "
|
LOG_DEBUG("POSITION node=%08x l=%d latI=%d lonI=%d msl=%d hae=%d geo=%d pdop=%d hdop=%d vdop=%d siv=%d fxq=%d fxt=%d pts=%d "
|
||||||
"time=%d\n",
|
"time=%d\n",
|
||||||
getFrom(&mp), mp.decoded.payload.size, p.latitude_i, p.longitude_i, p.altitude, p.altitude_hae,
|
getFrom(&mp), mp.decoded.payload.size, p.latitude_i, p.longitude_i, p.altitude, p.altitude_hae,
|
||||||
p.altitude_geoidal_separation, p.PDOP, p.HDOP, p.VDOP, p.sats_in_view, p.fix_quality, p.fix_type, p.timestamp,
|
p.altitude_geoidal_separation, p.PDOP, p.HDOP, p.VDOP, p.sats_in_view, p.fix_quality, p.fix_type, p.timestamp,
|
||||||
@ -222,6 +223,16 @@ meshtastic_MeshPacket *PositionModule::allocAtakPli()
|
|||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PositionModule::sendOurPosition()
|
||||||
|
{
|
||||||
|
bool requestReplies = currentGeneration != radioGeneration;
|
||||||
|
currentGeneration = radioGeneration;
|
||||||
|
|
||||||
|
// If we changed channels, ask everyone else for their latest info
|
||||||
|
LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", localPosition.timestamp, requestReplies);
|
||||||
|
sendOurPosition(NODENUM_BROADCAST, requestReplies);
|
||||||
|
}
|
||||||
|
|
||||||
void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel)
|
void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel)
|
||||||
{
|
{
|
||||||
// cancel any not yet sent (now stale) position packets
|
// cancel any not yet sent (now stale) position packets
|
||||||
@ -299,12 +310,7 @@ int32_t PositionModule::runOnce()
|
|||||||
lastGpsLatitude = node->position.latitude_i;
|
lastGpsLatitude = node->position.latitude_i;
|
||||||
lastGpsLongitude = node->position.longitude_i;
|
lastGpsLongitude = node->position.longitude_i;
|
||||||
|
|
||||||
// If we changed channels, ask everyone else for their latest info
|
sendOurPosition();
|
||||||
bool requestReplies = currentGeneration != radioGeneration;
|
|
||||||
currentGeneration = radioGeneration;
|
|
||||||
|
|
||||||
LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", localPosition.timestamp, requestReplies);
|
|
||||||
sendOurPosition(NODENUM_BROADCAST, requestReplies);
|
|
||||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND) {
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND) {
|
||||||
sendLostAndFoundText();
|
sendLostAndFoundText();
|
||||||
}
|
}
|
||||||
@ -314,29 +320,23 @@ int32_t PositionModule::runOnce()
|
|||||||
|
|
||||||
if (hasValidPosition(node2)) {
|
if (hasValidPosition(node2)) {
|
||||||
// The minimum time (in seconds) that would pass before we are able to send a new position packet.
|
// The minimum time (in seconds) that would pass before we are able to send a new position packet.
|
||||||
const uint32_t minimumTimeThreshold =
|
|
||||||
Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);
|
|
||||||
|
|
||||||
auto smartPosition = getDistanceTraveledSinceLastSend(node->position);
|
auto smartPosition = getDistanceTraveledSinceLastSend(node->position);
|
||||||
|
uint32_t msSinceLastSend = now - lastGpsSend;
|
||||||
|
|
||||||
if (smartPosition.hasTraveledOverThreshold && msSinceLastSend >= minimumTimeThreshold) {
|
if (smartPosition.hasTraveledOverThreshold &&
|
||||||
bool requestReplies = currentGeneration != radioGeneration;
|
Throttle::execute(
|
||||||
currentGeneration = radioGeneration;
|
&lastGpsSend, minimumTimeThreshold, []() { positionModule->sendOurPosition(); },
|
||||||
|
[]() { LOG_DEBUG("Skipping send smart broadcast due to time throttling\n"); })) {
|
||||||
|
|
||||||
LOG_INFO("Sending smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims, "
|
LOG_DEBUG("Sent smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims, "
|
||||||
"minTimeInterval=%ims)\n",
|
"minTimeInterval=%ims)\n",
|
||||||
localPosition.timestamp, smartPosition.distanceTraveled, smartPosition.distanceThreshold,
|
localPosition.timestamp, smartPosition.distanceTraveled, smartPosition.distanceThreshold,
|
||||||
msSinceLastSend, minimumTimeThreshold);
|
msSinceLastSend, minimumTimeThreshold);
|
||||||
sendOurPosition(NODENUM_BROADCAST, requestReplies);
|
|
||||||
|
|
||||||
// Set the current coords as our last ones, after we've compared distance with current and decided to send
|
// Set the current coords as our last ones, after we've compared distance with current and decided to send
|
||||||
lastGpsLatitude = node->position.latitude_i;
|
lastGpsLatitude = node->position.latitude_i;
|
||||||
lastGpsLongitude = node->position.longitude_i;
|
lastGpsLongitude = node->position.longitude_i;
|
||||||
|
|
||||||
/* Update lastGpsSend to now. This means if the device is stationary, then
|
|
||||||
getPref_position_broadcast_secs will still apply.
|
|
||||||
*/
|
|
||||||
lastGpsSend = now;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,27 +396,21 @@ void PositionModule::handleNewPosition()
|
|||||||
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
||||||
const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position
|
const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position
|
||||||
// We limit our GPS broadcasts to a max rate
|
// We limit our GPS broadcasts to a max rate
|
||||||
uint32_t now = millis();
|
|
||||||
uint32_t msSinceLastSend = now - lastGpsSend;
|
|
||||||
|
|
||||||
if (hasValidPosition(node2)) {
|
if (hasValidPosition(node2)) {
|
||||||
auto smartPosition = getDistanceTraveledSinceLastSend(node->position);
|
auto smartPosition = getDistanceTraveledSinceLastSend(node->position);
|
||||||
if (smartPosition.hasTraveledOverThreshold) {
|
uint32_t msSinceLastSend = millis() - lastGpsSend;
|
||||||
bool requestReplies = currentGeneration != radioGeneration;
|
if (smartPosition.hasTraveledOverThreshold &&
|
||||||
currentGeneration = radioGeneration;
|
Throttle::execute(
|
||||||
|
&lastGpsSend, minimumTimeThreshold, []() { positionModule->sendOurPosition(); },
|
||||||
LOG_INFO("Sending smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims)\n",
|
[]() { LOG_DEBUG("Skipping send smart broadcast due to time throttling\n"); })) {
|
||||||
localPosition.timestamp, smartPosition.distanceTraveled, smartPosition.distanceThreshold, msSinceLastSend);
|
LOG_DEBUG("Sent smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims, "
|
||||||
sendOurPosition(NODENUM_BROADCAST, requestReplies);
|
"minTimeInterval=%ims)\n",
|
||||||
|
localPosition.timestamp, smartPosition.distanceTraveled, smartPosition.distanceThreshold, msSinceLastSend,
|
||||||
|
minimumTimeThreshold);
|
||||||
|
|
||||||
// Set the current coords as our last ones, after we've compared distance with current and decided to send
|
// Set the current coords as our last ones, after we've compared distance with current and decided to send
|
||||||
lastGpsLatitude = node->position.latitude_i;
|
lastGpsLatitude = node->position.latitude_i;
|
||||||
lastGpsLongitude = node->position.longitude_i;
|
lastGpsLongitude = node->position.longitude_i;
|
||||||
|
|
||||||
/* Update lastGpsSend to now. This means if the device is stationary, then
|
|
||||||
getPref_position_broadcast_secs will still apply.
|
|
||||||
*/
|
|
||||||
lastGpsSend = now;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Default.h"
|
||||||
#include "ProtobufModule.h"
|
#include "ProtobufModule.h"
|
||||||
#include "concurrency/OSThread.h"
|
#include "concurrency/OSThread.h"
|
||||||
|
|
||||||
@ -29,7 +30,8 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
|||||||
/**
|
/**
|
||||||
* Send our position into the mesh
|
* Send our position into the mesh
|
||||||
*/
|
*/
|
||||||
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false, uint8_t channel = 0);
|
void sendOurPosition(NodeNum dest, bool wantReplies = false, uint8_t channel = 0);
|
||||||
|
void sendOurPosition();
|
||||||
|
|
||||||
void handleNewPosition();
|
void handleNewPosition();
|
||||||
|
|
||||||
@ -52,6 +54,9 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
|||||||
meshtastic_MeshPacket *allocAtakPli();
|
meshtastic_MeshPacket *allocAtakPli();
|
||||||
uint32_t precision;
|
uint32_t precision;
|
||||||
void sendLostAndFoundText();
|
void sendLostAndFoundText();
|
||||||
|
|
||||||
|
const uint32_t minimumTimeThreshold =
|
||||||
|
Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SmartPosition {
|
struct SmartPosition {
|
||||||
|
Loading…
Reference in New Issue
Block a user