From d4a693365d898798b3ac541eb0b05415ae9641e9 Mon Sep 17 00:00:00 2001 From: maze Date: Mon, 2 Mar 2026 22:33:15 +0100 Subject: [PATCH] protocol/aprs: extract position and symbol to frame --- protocol/aprs/frame.go | 15 +++++++++++++-- protocol/aprs/mice.go | 25 +++++++++++++++---------- protocol/aprs/position.go | 5 +++++ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/protocol/aprs/frame.go b/protocol/aprs/frame.go index c00284a..984b4dd 100644 --- a/protocol/aprs/frame.go +++ b/protocol/aprs/frame.go @@ -13,11 +13,22 @@ var ( // Frame represents a single APRS frame. type Frame struct { + // Addressing Source Address `json:"source"` Destination Address `json:"destination"` Path Path `json:"path"` - Raw Raw `json:"raw"` - Data Data `json:"data,omitempty"` + + // Raw payload + Raw Raw `json:"raw"` + + // Data contained in the raw payload. + Data Data `json:"data,omitempty"` + + // Data extracted + Latitude float64 + Longitude float64 + Altitude float64 + Symbol string } func Parse(s string) (*Frame, error) { diff --git a/protocol/aprs/mice.go b/protocol/aprs/mice.go index a536a6c..a44c10d 100644 --- a/protocol/aprs/mice.go +++ b/protocol/aprs/mice.go @@ -79,31 +79,36 @@ func (d micEDecoder) Decode(frame *Frame) (data Data, err error) { } var ( - r = new(MicE) + report = new(MicE) north, west bool dest = frame.Destination.Call info = []byte(frame.Raw[1:]) ) - if r.Latitude, r.Type, r.Ambiguity, north, err = r.decodeLatitude(dest); err != nil { + if report.Latitude, report.Type, report.Ambiguity, north, err = report.decodeLatitude(dest); err != nil { return } - if r.Longitude, west, r.Velocity, r.Symbol, err = r.decodeMicELongitudeAndMotion(dest, info); err != nil { + if report.Longitude, west, report.Velocity, report.Symbol, err = report.decodeMicELongitudeAndMotion(dest, info); err != nil { return } if !north { - r.Latitude = -r.Latitude + report.Latitude = -report.Latitude } if west { - r.Longitude = -r.Longitude + report.Longitude = -report.Longitude } - r.parseExtensions(info[8:]) + report.parseExtensions(info[8:]) - return r, nil + frame.Latitude = report.Latitude + frame.Longitude = report.Longitude + frame.Altitude = report.Altitude + frame.Symbol = report.Symbol + + return report, nil } -func (r *MicE) decodeLatitude(dest string) ( +func (report *MicE) decodeLatitude(dest string) ( lat float64, msg MessageType, ambiguity int, @@ -161,7 +166,7 @@ func (r *MicE) decodeLatitude(dest string) ( lat = -lat } - return lat, r.interpretMessage(msgBits), ambiguity, north, nil + return lat, report.interpretMessage(msgBits), ambiguity, north, nil } func decodeDestChar(c byte) ( @@ -196,7 +201,7 @@ func maskAmbiguity(digits []int, ambiguity int) { } } -func (r *MicE) decodeMicELongitudeAndMotion(dest string, info []byte) (lon float64, west bool, velocity *Velocity, symbol string, err error) { +func (report *MicE) decodeMicELongitudeAndMotion(dest string, info []byte) (lon float64, west bool, velocity *Velocity, symbol string, err error) { if len(info) < 3 { err = errors.New("info too short for longitude") return diff --git a/protocol/aprs/position.go b/protocol/aprs/position.go index 94bf768..cb061e0 100644 --- a/protocol/aprs/position.go +++ b/protocol/aprs/position.go @@ -100,6 +100,11 @@ func (d positionDecoder) Decode(frame *Frame) (data Data, err error) { return } + frame.Latitude = pos.Latitude + frame.Longitude = pos.Longitude + frame.Altitude = pos.Altitude + frame.Symbol = pos.Symbol + return pos, nil }