2020-12-05 10:00:46 +08:00
|
|
|
#pragma once
|
2024-04-21 07:42:36 -05:00
|
|
|
#include "Default.h"
|
2022-03-09 19:01:43 +11:00
|
|
|
#include "ProtobufModule.h"
|
2021-02-14 11:57:48 +08:00
|
|
|
#include "concurrency/OSThread.h"
|
2020-12-03 16:48:44 +08:00
|
|
|
|
|
|
|
|
/**
|
2022-02-27 00:29:05 -08:00
|
|
|
* Position module for sending/receiving positions into the mesh
|
2020-12-03 16:48:44 +08:00
|
|
|
*/
|
2023-01-21 18:22:19 +01:00
|
|
|
class PositionModule : public ProtobufModule<meshtastic_Position>, private concurrency::OSThread
|
2020-12-03 16:48:44 +08:00
|
|
|
{
|
2021-02-11 17:39:53 +08:00
|
|
|
/// The id of the last packet we sent, to allow us to cancel it if we make something fresher
|
|
|
|
|
PacketId prevPacketId = 0;
|
|
|
|
|
|
2021-02-14 11:57:48 +08:00
|
|
|
/// We limit our GPS broadcasts to a max rate
|
|
|
|
|
uint32_t lastGpsSend = 0;
|
|
|
|
|
|
2021-11-26 19:12:00 -08:00
|
|
|
// Store the latest good lat / long
|
2021-12-05 10:20:16 -08:00
|
|
|
int32_t lastGpsLatitude = 0;
|
|
|
|
|
int32_t lastGpsLongitude = 0;
|
2021-11-26 19:12:00 -08:00
|
|
|
|
2021-02-14 11:57:48 +08:00
|
|
|
/// We force a rebroadcast if the radio settings change
|
|
|
|
|
uint32_t currentGeneration = 0;
|
|
|
|
|
|
2020-12-03 16:48:44 +08:00
|
|
|
public:
|
|
|
|
|
/** Constructor
|
|
|
|
|
* name is for debugging output
|
|
|
|
|
*/
|
2022-02-27 02:21:02 -08:00
|
|
|
PositionModule();
|
2023-01-21 14:34:29 +01:00
|
|
|
|
2020-12-03 16:48:44 +08:00
|
|
|
/**
|
|
|
|
|
* Send our position into the mesh
|
|
|
|
|
*/
|
2024-04-21 07:42:36 -05:00
|
|
|
void sendOurPosition(NodeNum dest, bool wantReplies = false, uint8_t channel = 0);
|
|
|
|
|
void sendOurPosition();
|
2020-12-03 16:48:44 +08:00
|
|
|
|
2023-09-23 23:45:35 -05:00
|
|
|
void handleNewPosition();
|
|
|
|
|
|
2020-12-03 16:48:44 +08:00
|
|
|
protected:
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
|
|
|
|
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
|
|
|
|
*/
|
2023-01-21 18:22:19 +01:00
|
|
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Position *p) override;
|
2020-12-05 11:15:06 +08:00
|
|
|
|
|
|
|
|
/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
|
2020-12-07 10:18:11 +08:00
|
|
|
* so that subclasses can (optionally) send a response back to the original sender. */
|
2023-01-21 18:22:19 +01:00
|
|
|
virtual meshtastic_MeshPacket *allocReply() override;
|
2021-02-14 11:57:48 +08:00
|
|
|
|
|
|
|
|
/** Does our periodic broadcast */
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2023-09-27 10:32:35 -05:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
2024-02-16 20:04:21 -06:00
|
|
|
meshtastic_MeshPacket *allocAtakPli();
|
2024-04-21 14:40:47 -05:00
|
|
|
void trySetRtc(meshtastic_Position p, bool isLocal);
|
2024-02-22 12:32:01 -06:00
|
|
|
uint32_t precision;
|
2023-12-13 17:43:20 -06:00
|
|
|
void sendLostAndFoundText();
|
2024-04-21 07:42:36 -05:00
|
|
|
|
|
|
|
|
const uint32_t minimumTimeThreshold =
|
|
|
|
|
Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);
|
2023-09-27 10:32:35 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SmartPosition {
|
|
|
|
|
float distanceTraveled;
|
|
|
|
|
uint32_t distanceThreshold;
|
|
|
|
|
bool hasTraveledOverThreshold;
|
2020-12-03 16:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
2023-09-30 21:09:17 -05:00
|
|
|
extern PositionModule *positionModule;
|