sforkowany z mirror/meshtastic-firmware
fix #624 - update battery level and current time on mynodeinfo
rodzic
da8b1d41c7
commit
94a47dba7d
|
@ -199,11 +199,33 @@ void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies)
|
||||||
nodeInfoPlugin.sendOurNodeInfo(dest, wantReplies);
|
nodeInfoPlugin.sendOurNodeInfo(dest, wantReplies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NodeInfo *MeshService::refreshMyNodeInfo() {
|
||||||
|
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
||||||
|
assert(node);
|
||||||
|
|
||||||
|
// We might not have a position yet for our local node, in that case, at least try to send the time
|
||||||
|
if(!node->has_position) {
|
||||||
|
memset(&node->position, 0, sizeof(node->position));
|
||||||
|
node->has_position = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Position &position = node->position;
|
||||||
|
|
||||||
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||||
|
position.time = getValidTime(RTCQualityGPS); // This nodedb timestamp might be stale, so update it if our clock is valid.
|
||||||
|
|
||||||
|
position.battery_level = powerStatus->getBatteryChargePercent();
|
||||||
|
updateBatteryLevel(position.battery_level);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused)
|
int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused)
|
||||||
{
|
{
|
||||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||||
|
NodeInfo *node = refreshMyNodeInfo();
|
||||||
Position pos = Position_init_default;
|
Position pos = node->position;
|
||||||
|
|
||||||
if (gps->hasLock()) {
|
if (gps->hasLock()) {
|
||||||
if (gps->altitude != 0)
|
if (gps->altitude != 0)
|
||||||
|
@ -214,21 +236,16 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused)
|
||||||
else {
|
else {
|
||||||
// The GPS has lost lock, if we are fixed position we should just keep using
|
// The GPS has lost lock, if we are fixed position we should just keep using
|
||||||
// the old position
|
// the old position
|
||||||
if(radioConfig.preferences.fixed_position) {
|
if(!radioConfig.preferences.fixed_position) {
|
||||||
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
|
||||||
assert(node);
|
|
||||||
assert(node->has_position);
|
|
||||||
pos = node->position;
|
|
||||||
DEBUG_MSG("WARNING: Using fixed position\n");
|
DEBUG_MSG("WARNING: Using fixed position\n");
|
||||||
|
} else {
|
||||||
|
// throw away old position
|
||||||
|
pos.latitude_i = 0;
|
||||||
|
pos.longitude_i = 0;
|
||||||
|
pos.altitude = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pos.time = getValidTime(RTCQualityGPS);
|
|
||||||
|
|
||||||
// Include our current battery voltage in our position announcement
|
|
||||||
pos.battery_level = powerStatus->getBatteryChargePercent();
|
|
||||||
updateBatteryLevel(pos.battery_level);
|
|
||||||
|
|
||||||
DEBUG_MSG("got gps notify time=%u, lat=%d, bat=%d\n", pos.latitude_i, pos.time, pos.battery_level);
|
DEBUG_MSG("got gps notify time=%u, lat=%d, bat=%d\n", pos.latitude_i, pos.time, pos.battery_level);
|
||||||
|
|
||||||
// Update our current position in the local DB
|
// Update our current position in the local DB
|
||||||
|
|
|
@ -79,6 +79,9 @@ class MeshService
|
||||||
/// cache
|
/// cache
|
||||||
void sendToMesh(MeshPacket *p);
|
void sendToMesh(MeshPacket *p);
|
||||||
|
|
||||||
|
/// Pull the latest power and time info into my nodeinfo
|
||||||
|
NodeInfo *refreshMyNodeInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
|
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
|
||||||
|
|
|
@ -134,6 +134,8 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
||||||
fromRadioScratch.which_variant = FromRadio_my_info_tag;
|
fromRadioScratch.which_variant = FromRadio_my_info_tag;
|
||||||
fromRadioScratch.variant.my_info = myNodeInfo;
|
fromRadioScratch.variant.my_info = myNodeInfo;
|
||||||
state = STATE_SEND_RADIO;
|
state = STATE_SEND_RADIO;
|
||||||
|
|
||||||
|
service.refreshMyNodeInfo(); // Update my NodeInfo because the client will be asking for it soon.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_SEND_RADIO:
|
case STATE_SEND_RADIO:
|
||||||
|
|
|
@ -29,21 +29,10 @@ bool PositionPlugin::handleReceivedProtobuf(const MeshPacket &mp, const Position
|
||||||
|
|
||||||
MeshPacket *PositionPlugin::allocReply()
|
MeshPacket *PositionPlugin::allocReply()
|
||||||
{
|
{
|
||||||
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position
|
||||||
assert(node);
|
assert(node->has_position);
|
||||||
|
|
||||||
// We might not have a position yet for our local node, in that case, at least try to send the time
|
return allocDataProtobuf(node->position);
|
||||||
if(!node->has_position) {
|
|
||||||
memset(&node->position, 0, sizeof(node->position));
|
|
||||||
node->has_position = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Position &position = node->position;
|
|
||||||
|
|
||||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
|
||||||
position.time = getValidTime(RTCQualityGPS); // This nodedb timestamp might be stale, so update it if our clock is valid.
|
|
||||||
|
|
||||||
return allocDataProtobuf(position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies)
|
void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies)
|
||||||
|
|
Ładowanie…
Reference in New Issue