mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-26 18:09:04 +00:00
Convert from inline to static class methods (#2883)
This commit is contained in:
parent
e39f129bd6
commit
092c6cac66
@ -335,7 +335,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus)
|
|||||||
// Used fixed position if configured regalrdless of GPS lock
|
// Used fixed position if configured regalrdless of GPS lock
|
||||||
if (config.position.fixed_position) {
|
if (config.position.fixed_position) {
|
||||||
LOG_WARN("Using fixed position\n");
|
LOG_WARN("Using fixed position\n");
|
||||||
pos = ConvertToPosition(node->position);
|
pos = TypeConversions::ConvertToPosition(node->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a fresh timestamp
|
// Add a fresh timestamp
|
||||||
|
@ -688,7 +688,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou
|
|||||||
p.longitude_i, p.altitude);
|
p.longitude_i, p.altitude);
|
||||||
|
|
||||||
setLocalPosition(p);
|
setLocalPosition(p);
|
||||||
info->position = ConvertToPositionLite(p);
|
info->position = TypeConversions::ConvertToPositionLite(p);
|
||||||
} else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.timestamp && !p.location_source) {
|
} else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.timestamp && !p.location_source) {
|
||||||
// FIXME SPECIAL TIME SETTING PACKET FROM EUD TO RADIO
|
// FIXME SPECIAL TIME SETTING PACKET FROM EUD TO RADIO
|
||||||
// (stop-gap fix for issue #900)
|
// (stop-gap fix for issue #900)
|
||||||
@ -706,7 +706,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou
|
|||||||
uint32_t tmp_time = info->position.time;
|
uint32_t tmp_time = info->position.time;
|
||||||
|
|
||||||
// Next, update atomically
|
// Next, update atomically
|
||||||
info->position = ConvertToPositionLite(p);
|
info->position = TypeConversions::ConvertToPositionLite(p);
|
||||||
|
|
||||||
// Last, restore any fields that may have been overwritten
|
// Last, restore any fields that may have been overwritten
|
||||||
if (!info->position.time)
|
if (!info->position.time)
|
||||||
|
@ -405,7 +405,7 @@ bool PhoneAPI::available()
|
|||||||
if (nodeInfoForPhone.num == 0) {
|
if (nodeInfoForPhone.num == 0) {
|
||||||
auto nextNode = nodeDB.readNextMeshNode(readIndex);
|
auto nextNode = nodeDB.readNextMeshNode(readIndex);
|
||||||
if (nextNode) {
|
if (nextNode) {
|
||||||
nodeInfoForPhone = ConvertToNodeInfo(nextNode);
|
nodeInfoForPhone = TypeConversions::ConvertToNodeInfo(nextNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true; // Always say we have something, because we might need to advance our state machine
|
return true; // Always say we have something, because we might need to advance our state machine
|
||||||
|
55
src/mesh/TypeConversions.cpp
Normal file
55
src/mesh/TypeConversions.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include "TypeConversions.h"
|
||||||
|
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
||||||
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
||||||
|
|
||||||
|
meshtastic_NodeInfo TypeConversions::ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite)
|
||||||
|
{
|
||||||
|
meshtastic_NodeInfo info = meshtastic_NodeInfo_init_default;
|
||||||
|
|
||||||
|
info.num = lite->num;
|
||||||
|
info.snr = lite->snr;
|
||||||
|
info.last_heard = lite->last_heard;
|
||||||
|
info.channel = lite->channel;
|
||||||
|
|
||||||
|
if (lite->has_position) {
|
||||||
|
info.has_position = true;
|
||||||
|
info.position.latitude_i = lite->position.latitude_i;
|
||||||
|
info.position.longitude_i = lite->position.longitude_i;
|
||||||
|
info.position.altitude = lite->position.altitude;
|
||||||
|
info.position.location_source = lite->position.location_source;
|
||||||
|
info.position.time = lite->position.time;
|
||||||
|
}
|
||||||
|
if (lite->has_user) {
|
||||||
|
info.has_user = true;
|
||||||
|
info.user = lite->user;
|
||||||
|
}
|
||||||
|
if (lite->has_device_metrics) {
|
||||||
|
info.has_device_metrics = true;
|
||||||
|
info.device_metrics = lite->device_metrics;
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
meshtastic_PositionLite TypeConversions::ConvertToPositionLite(meshtastic_Position position)
|
||||||
|
{
|
||||||
|
meshtastic_PositionLite lite = meshtastic_PositionLite_init_default;
|
||||||
|
lite.latitude_i = position.latitude_i;
|
||||||
|
lite.longitude_i = position.longitude_i;
|
||||||
|
lite.altitude = position.altitude;
|
||||||
|
lite.location_source = position.location_source;
|
||||||
|
lite.time = position.time;
|
||||||
|
|
||||||
|
return lite;
|
||||||
|
}
|
||||||
|
|
||||||
|
meshtastic_Position TypeConversions::ConvertToPosition(meshtastic_PositionLite lite)
|
||||||
|
{
|
||||||
|
meshtastic_Position position = meshtastic_Position_init_default;
|
||||||
|
position.latitude_i = lite.latitude_i;
|
||||||
|
position.longitude_i = lite.longitude_i;
|
||||||
|
position.altitude = lite.altitude;
|
||||||
|
position.location_source = lite.location_source;
|
||||||
|
position.time = lite.time;
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
@ -1,54 +1,13 @@
|
|||||||
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
||||||
#include "mesh/generated/meshtastic/mesh.pb.h"
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
||||||
|
|
||||||
inline static meshtastic_NodeInfo ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite)
|
#pragma once
|
||||||
|
#include "NodeDB.h"
|
||||||
|
|
||||||
|
class TypeConversions
|
||||||
{
|
{
|
||||||
meshtastic_NodeInfo info = meshtastic_NodeInfo_init_default;
|
public:
|
||||||
|
static meshtastic_NodeInfo ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite);
|
||||||
info.num = lite->num;
|
static meshtastic_PositionLite ConvertToPositionLite(meshtastic_Position position);
|
||||||
info.snr = lite->snr;
|
static meshtastic_Position ConvertToPosition(meshtastic_PositionLite lite);
|
||||||
info.last_heard = lite->last_heard;
|
};
|
||||||
info.channel = lite->channel;
|
|
||||||
|
|
||||||
if (lite->has_position) {
|
|
||||||
info.has_position = true;
|
|
||||||
info.position.latitude_i = lite->position.latitude_i;
|
|
||||||
info.position.longitude_i = lite->position.longitude_i;
|
|
||||||
info.position.altitude = lite->position.altitude;
|
|
||||||
info.position.location_source = lite->position.location_source;
|
|
||||||
info.position.time = lite->position.time;
|
|
||||||
}
|
|
||||||
if (lite->has_user) {
|
|
||||||
info.has_user = true;
|
|
||||||
info.user = lite->user;
|
|
||||||
}
|
|
||||||
if (lite->has_device_metrics) {
|
|
||||||
info.has_device_metrics = true;
|
|
||||||
info.device_metrics = lite->device_metrics;
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static meshtastic_PositionLite ConvertToPositionLite(meshtastic_Position position)
|
|
||||||
{
|
|
||||||
meshtastic_PositionLite lite = meshtastic_PositionLite_init_default;
|
|
||||||
lite.latitude_i = position.latitude_i;
|
|
||||||
lite.longitude_i = position.longitude_i;
|
|
||||||
lite.altitude = position.altitude;
|
|
||||||
lite.location_source = position.location_source;
|
|
||||||
lite.time = position.time;
|
|
||||||
|
|
||||||
return lite;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static meshtastic_Position ConvertToPosition(meshtastic_PositionLite lite)
|
|
||||||
{
|
|
||||||
meshtastic_Position position = meshtastic_Position_init_default;
|
|
||||||
position.latitude_i = lite.latitude_i;
|
|
||||||
position.longitude_i = lite.longitude_i;
|
|
||||||
position.altitude = lite.altitude;
|
|
||||||
position.location_source = lite.location_source;
|
|
||||||
position.time = lite.time;
|
|
||||||
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
@ -101,7 +101,7 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
|||||||
meshtastic_Position p = meshtastic_Position_init_default; // Start with an empty structure
|
meshtastic_Position p = meshtastic_Position_init_default; // Start with an empty structure
|
||||||
// if localPosition is totally empty, put our last saved position (lite) in there
|
// if localPosition is totally empty, put our last saved position (lite) in there
|
||||||
if (localPosition.latitude_i == 0 && localPosition.longitude_i == 0) {
|
if (localPosition.latitude_i == 0 && localPosition.longitude_i == 0) {
|
||||||
nodeDB.setLocalPosition(ConvertToPosition(node->position));
|
nodeDB.setLocalPosition(TypeConversions::ConvertToPosition(node->position));
|
||||||
}
|
}
|
||||||
localPosition.seq_number++;
|
localPosition.seq_number++;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user