2020-11-28 05:51:51 +00:00
|
|
|
#include "PositionPlugin.h"
|
2020-12-03 08:48:44 +00:00
|
|
|
#include "MeshService.h"
|
2020-11-28 05:51:51 +00:00
|
|
|
#include "NodeDB.h"
|
2020-12-03 08:48:44 +00:00
|
|
|
#include "RTC.h"
|
|
|
|
#include "Router.h"
|
|
|
|
#include "configuration.h"
|
2020-11-28 05:51:51 +00:00
|
|
|
|
|
|
|
PositionPlugin positionPlugin;
|
|
|
|
|
2020-12-03 08:48:44 +00:00
|
|
|
bool PositionPlugin::handleReceivedProtobuf(const MeshPacket &mp, const Position &p)
|
2020-11-28 05:51:51 +00:00
|
|
|
{
|
2020-12-03 08:48:44 +00:00
|
|
|
// FIXME - we currently update position data in the DB only if the message was a broadcast or destined to us
|
|
|
|
// it would be better to update even if the message was destined to others.
|
|
|
|
|
2020-12-05 02:00:46 +00:00
|
|
|
if (p.time) {
|
|
|
|
struct timeval tv;
|
|
|
|
uint32_t secs = p.time;
|
|
|
|
|
|
|
|
tv.tv_sec = secs;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
perhapsSetRTC(RTCQualityFromNet, &tv);
|
|
|
|
}
|
|
|
|
|
2020-12-03 08:48:44 +00:00
|
|
|
nodeDB.updatePosition(mp.from, p);
|
2020-11-28 05:51:51 +00:00
|
|
|
|
|
|
|
return false; // Let others look at this message also if they want
|
|
|
|
}
|
2020-12-03 08:48:44 +00:00
|
|
|
|
2020-12-07 02:18:11 +00:00
|
|
|
MeshPacket *PositionPlugin::allocReply()
|
2020-12-03 08:48:44 +00:00
|
|
|
{
|
|
|
|
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
|
|
|
assert(node);
|
|
|
|
assert(node->has_position);
|
|
|
|
|
|
|
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
|
|
|
auto position = node->position;
|
|
|
|
position.time = getValidTime(RTCQualityGPS); // This nodedb timestamp might be stale, so update it if our clock is valid.
|
|
|
|
|
2020-12-07 02:18:11 +00:00
|
|
|
return allocDataProtobuf(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies)
|
|
|
|
{
|
|
|
|
MeshPacket *p = allocReply();
|
2020-12-03 08:48:44 +00:00
|
|
|
p->to = dest;
|
|
|
|
p->decoded.want_response = wantReplies;
|
|
|
|
|
|
|
|
service.sendToMesh(p);
|
|
|
|
}
|
2020-12-05 03:15:06 +00:00
|
|
|
|