From 3e5f76a5ca8cd0345a6ef9f468a97e0c94654af6 Mon Sep 17 00:00:00 2001 From: root <165865819+brianshea2@users.noreply.github.com> Date: Sun, 18 Aug 2024 22:14:17 +0000 Subject: [PATCH] collect altitude from position and map report messages --- cmd/meshobserv/meshobserv.go | 16 +++++++++------- internal/meshtastic/node.go | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/meshobserv/meshobserv.go b/cmd/meshobserv/meshobserv.go index 51f9f4d..b77204c 100644 --- a/cmd/meshobserv/meshobserv.go +++ b/cmd/meshobserv/meshobserv.go @@ -20,8 +20,8 @@ import ( const ( NodeExpiration = 86400 // 1 day - NeighborExpiration = 7200 // 2 hr - MetricsExpiration = 7200 // 2 hr + NeighborExpiration = 7200 // 2 hr + MetricsExpiration = 7200 // 2 hr PruneWriteInterval = time.Minute ) @@ -44,8 +44,9 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload } latitude := position.GetLatitudeI() longitude := position.GetLongitudeI() + altitude := position.GetAltitude() precision := position.GetPrecisionBits() - log.Printf("[msg] %v (%v) %s: (%v, %v) %v/32", from, topic, portNum, latitude, longitude, precision) + log.Printf("[msg] %v (%v) %s: (%v, %v, %v) %v/32", from, topic, portNum, latitude, longitude, altitude, precision) if latitude == 0 && longitude == 0 { return } @@ -53,7 +54,7 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload if Nodes[from] == nil { Nodes[from] = meshtastic.NewNode(topic) } - Nodes[from].UpdatePosition(latitude, longitude, precision) + Nodes[from].UpdatePosition(latitude, longitude, altitude, precision) Nodes[from].UpdateSeenBy(topic) NodesMutex.Unlock() case generated.PortNum_NODEINFO_APP: @@ -147,12 +148,13 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload onlineLocalNodes := mapReport.GetNumOnlineLocalNodes() latitude := mapReport.GetLatitudeI() longitude := mapReport.GetLongitudeI() + altitude := mapReport.GetAltitude() precision := mapReport.GetPositionPrecision() log.Printf( - "[msg] %v (%v) %s: {\"%v\" \"%v\" %v %v %v %v %v %v %v} (%v, %v) %v/32", + "[msg] %v (%v) %s: {\"%v\" \"%v\" %v %v %v %v %v %v %v} (%v, %v, %v) %v/32", from, topic, portNum, longName, shortName, hwModel, role, fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes, - latitude, longitude, precision, + latitude, longitude, altitude, precision, ) if len(longName) == 0 { return @@ -166,7 +168,7 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload } Nodes[from].UpdateUser(longName, shortName, hwModel, role) Nodes[from].UpdateMapReport(fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes) - Nodes[from].UpdatePosition(latitude, longitude, precision) + Nodes[from].UpdatePosition(latitude, longitude, altitude, precision) Nodes[from].UpdateSeenBy(topic) NodesMutex.Unlock() default: diff --git a/internal/meshtastic/node.go b/internal/meshtastic/node.go index c08db75..5ff4a8d 100644 --- a/internal/meshtastic/node.go +++ b/internal/meshtastic/node.go @@ -33,6 +33,7 @@ type Node struct { // Position Latitude int32 `json:"latitude"` Longitude int32 `json:"longitude"` + Altitude int32 `json:"altitude,omitempty"` Precision uint32 `json:"precision,omitempty"` // DeviceMetrics BatteryLevel uint32 `json:"batteryLevel,omitempty"` @@ -157,9 +158,10 @@ func (node *Node) UpdateNeighborInfo(neighborNum uint32, snr float32) { } } -func (node *Node) UpdatePosition(latitude, longitude int32, precision uint32) { +func (node *Node) UpdatePosition(latitude, longitude, altitude int32, precision uint32) { node.Latitude = latitude node.Longitude = longitude + node.Altitude = altitude node.Precision = precision }