2020-12-05 10:00:46 +08:00
|
|
|
#pragma once
|
2020-12-03 16:48:44 +08:00
|
|
|
#include "ProtobufPlugin.h"
|
2021-02-14 11:57:48 +08:00
|
|
|
#include "concurrency/OSThread.h"
|
2020-12-03 16:48:44 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Position plugin for sending/receiving positions into the mesh
|
|
|
|
|
*/
|
2021-02-14 11:57:48 +08:00
|
|
|
class PositionPlugin : public ProtobufPlugin<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
|
|
|
|
|
uint32_t lastGpsLatitude = 0;
|
|
|
|
|
uint32_t lastGpsLongitude = 0;
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2021-02-14 12:26:51 +08:00
|
|
|
PositionPlugin();
|
|
|
|
|
|
2020-12-03 16:48:44 +08:00
|
|
|
/**
|
|
|
|
|
* Send our position into the mesh
|
|
|
|
|
*/
|
|
|
|
|
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2021-08-01 11:20:38 -07:00
|
|
|
virtual bool handleReceivedProtobuf(const MeshPacket &mp, Position *p);
|
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. */
|
|
|
|
|
virtual MeshPacket *allocReply();
|
2021-02-14 11:57:48 +08:00
|
|
|
|
|
|
|
|
/** Does our periodic broadcast */
|
|
|
|
|
virtual int32_t runOnce();
|
2020-12-03 16:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
2021-01-08 13:15:49 +08:00
|
|
|
extern PositionPlugin *positionPlugin;
|