make user presses ask other nodes for their latest status

see related bug
https://github.com/meshtastic/Meshtastic-esp32/issues/59
1.2-legacy
geeksville 2020-03-25 13:09:12 -07:00
rodzic 45babab8c4
commit 50d724780a
4 zmienionych plików z 18 dodań i 11 usunięć

Wyświetl plik

@ -71,10 +71,11 @@ void MeshService::init()
// sendOwnerPeriod(); // sendOwnerPeriod();
} }
void MeshService::sendOurOwner(NodeNum dest) void MeshService::sendOurOwner(NodeNum dest, bool wantReplies)
{ {
MeshPacket *p = allocForSending(); MeshPacket *p = allocForSending();
p->to = dest; p->to = dest;
p->payload.want_response = wantReplies;
p->payload.which_variant = SubPacket_user_tag; p->payload.which_variant = SubPacket_user_tag;
User &u = p->payload.variant.user; User &u = p->payload.variant.user;
u = owner; u = owner;
@ -257,9 +258,10 @@ void MeshService::sendToMesh(MeshPacket *p)
// nodes shouldn't trust it anyways) Note: for now, we allow a device with a local GPS to include the time, so that gpsless // 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. // devices can get time.
if (p->has_payload && p->payload.which_variant == SubPacket_position_tag) { if (p->has_payload && p->payload.which_variant == SubPacket_position_tag) {
if (!myNodeInfo.has_gps) if (!myNodeInfo.has_gps) {
DEBUG_MSG("Stripping time %u from position send\n", p->payload.variant.position.time);
p->payload.variant.position.time = 0; p->payload.variant.position.time = 0;
else } else
DEBUG_MSG("Providing time to mesh %u\n", p->payload.variant.position.time); DEBUG_MSG("Providing time to mesh %u\n", p->payload.variant.position.time);
} }
@ -285,18 +287,19 @@ MeshPacket *MeshService::allocForSending()
return p; return p;
} }
void MeshService::sendNetworkPing(NodeNum dest) void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies)
{ {
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
assert(node); assert(node);
DEBUG_MSG("Sending network ping to 0x%x, with position=%d, wantReplies=%d\n", dest, node->has_position, wantReplies);
if (node->has_position) if (node->has_position)
sendOurPosition(dest); sendOurPosition(dest, wantReplies);
else else
sendOurOwner(dest); sendOurOwner(dest, wantReplies);
} }
void MeshService::sendOurPosition(NodeNum dest) void MeshService::sendOurPosition(NodeNum dest, bool wantReplies)
{ {
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
assert(node); assert(node);
@ -307,6 +310,7 @@ void MeshService::sendOurPosition(NodeNum dest)
p->to = dest; p->to = dest;
p->payload.which_variant = SubPacket_position_tag; p->payload.which_variant = SubPacket_position_tag;
p->payload.variant.position = node->position; p->payload.variant.position = node->position;
p->payload.want_response = wantReplies;
p->payload.variant.position.time = p->payload.variant.position.time =
gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid. gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid.
sendToMesh(p); sendToMesh(p);

Wyświetl plik

@ -61,14 +61,14 @@ class MeshService : private Observer
/// Called when the user wakes up our GUI, normally sends our latest location to the mesh (if we have it), otherwise at least /// Called when the user wakes up our GUI, normally sends our latest location to the mesh (if we have it), otherwise at least
/// sends our owner /// sends our owner
void sendNetworkPing(NodeNum dest = NODENUM_BROADCAST); void sendNetworkPing(NodeNum dest, bool wantReplies = false);
/// Send our owner info to a particular node /// Send our owner info to a particular node
void sendOurOwner(NodeNum dest = NODENUM_BROADCAST); void sendOurOwner(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
private: private:
/// Broadcasts our last known position /// Broadcasts our last known position
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST); void sendOurPosition(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
/// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after /// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after
/// sending. This is the ONLY function you should use for sending messages into the mesh, because it also updates the nodedb /// sending. This is the ONLY function you should use for sending messages into the mesh, because it also updates the nodedb

Wyświetl plik

@ -121,7 +121,7 @@ static void onEnter()
uint32_t now = millis(); uint32_t now = millis();
if (now - lastPingMs > 60 * 1000) { // if more than a minute since our last press, ask other nodes to update their state if (now - lastPingMs > 60 * 1000) { // if more than a minute since our last press, ask other nodes to update their state
service.sendNetworkPing(); service.sendNetworkPing(NODENUM_BROADCAST, true);
lastPingMs = now; lastPingMs = now;
} }
} }

Wyświetl plik

@ -344,6 +344,9 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
float bearingToOther = bearing(p.latitude, p.longitude, op.latitude, op.longitude); float bearingToOther = bearing(p.latitude, p.longitude, op.latitude, op.longitude);
float myHeading = estimatedHeading(p.latitude, p.longitude); float myHeading = estimatedHeading(p.latitude, p.longitude);
headingRadian = bearingToOther - myHeading; headingRadian = bearingToOther - myHeading;
} else {
// Debug info for gps lock errors
// DEBUG_MSG("ourNode %d, ourPos %d, theirPos %d\n", !!ourNode, ourNode && hasPosition(ourNode), hasPosition(node));
} }
const char *fields[] = {username, distStr, signalStr, lastStr, NULL}; const char *fields[] = {username, distStr, signalStr, lastStr, NULL};