mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
Merge branch 'dev' into gps-sleep-mode
# Conflicts: # docs/software/TODO.md # platformio.ini
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "GPS.h"
|
||||
#include "screen.h"
|
||||
#include "Periodic.h"
|
||||
#include "PowerFSM.h"
|
||||
|
||||
/*
|
||||
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
|
||||
@@ -123,10 +124,35 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
|
||||
return mp;
|
||||
}
|
||||
|
||||
void MeshService::handleIncomingPosition(MeshPacket *mp)
|
||||
{
|
||||
if (mp->has_payload && mp->payload.which_variant == SubPacket_position_tag)
|
||||
{
|
||||
DEBUG_MSG("handled incoming position time=%u\n", mp->payload.variant.position.time);
|
||||
|
||||
if (mp->payload.variant.position.time)
|
||||
{
|
||||
struct timeval tv;
|
||||
uint32_t secs = mp->payload.variant.position.time;
|
||||
|
||||
tv.tv_sec = secs;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
gps.perhapsSetRTC(&tv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MeshService::handleFromRadio(MeshPacket *mp)
|
||||
{
|
||||
powerFSM.trigger(EVENT_RECEIVED_PACKET); // Possibly keep the node from sleeping
|
||||
|
||||
mp->rx_time = gps.getValidTime(); // store the arrival timestamp for the phone
|
||||
|
||||
// If it is a position packet, perhaps set our clock (if we don't have a GPS of our own, otherwise wait for that to work)
|
||||
if (!myNodeInfo.has_gps)
|
||||
handleIncomingPosition(mp);
|
||||
|
||||
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag)
|
||||
{
|
||||
mp = handleFromRadioUser(mp);
|
||||
@@ -208,17 +234,7 @@ void MeshService::handleToRadio(std::string s)
|
||||
case ToRadio_packet_tag:
|
||||
{
|
||||
// If our phone is sending a position, see if we can use it to set our RTC
|
||||
if (r.variant.packet.has_payload && r.variant.packet.payload.which_variant == SubPacket_position_tag && r.variant.packet.payload.variant.position.time)
|
||||
{
|
||||
struct timeval tv;
|
||||
uint32_t secs = r.variant.packet.payload.variant.position.time;
|
||||
|
||||
// FIXME, this is a shit not right version of the standard def of unix time!!!
|
||||
tv.tv_sec = secs;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
gps.perhapsSetRTC(&tv);
|
||||
}
|
||||
handleIncomingPosition(&r.variant.packet); // If it is a position packet, perhaps set our clock
|
||||
|
||||
r.variant.packet.rx_time = gps.getValidTime(); // Record the time the packet arrived from the phone (so we update our nodedb for the local node)
|
||||
|
||||
@@ -246,8 +262,14 @@ void MeshService::sendToMesh(MeshPacket *p)
|
||||
nodeDB.updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...)
|
||||
|
||||
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other nodes shouldn't trust it anyways)
|
||||
// Note: for now, we allow a device with a local GPS to include the time, so that gpsless devices can get time.
|
||||
if (p->has_payload && p->payload.which_variant == SubPacket_position_tag)
|
||||
p->payload.variant.position.time = 0;
|
||||
{
|
||||
if (!myNodeInfo.has_gps)
|
||||
p->payload.variant.position.time = 0;
|
||||
else
|
||||
DEBUG_MSG("Providing time to mesh %u\n", p->payload.variant.position.time);
|
||||
}
|
||||
|
||||
// If the phone sent a packet just to us, don't send it out into the network
|
||||
if (p->to == nodeDB.getNodeNum())
|
||||
@@ -294,8 +316,7 @@ void MeshService::sendOurPosition(NodeNum dest)
|
||||
p->to = dest;
|
||||
p->payload.which_variant = SubPacket_position_tag;
|
||||
p->payload.variant.position = node->position;
|
||||
// FIXME - for now we are leaving this in the sent packets (for debugging)
|
||||
//p->payload.variant.position.time = 0; // No need to send time, other node won't trust it anyways
|
||||
p->payload.variant.position.time = gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid.
|
||||
sendToMesh(p);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user