protocol/aprs: refactored
Some checks failed
Run tests / test (1.25) (push) Failing after 1m37s
Run tests / test (stable) (push) Failing after 1m37s

This commit is contained in:
2026-03-02 22:28:17 +01:00
parent 452f521866
commit 63040a44b3
24 changed files with 3506 additions and 1533 deletions

50
protocol/aprs/query.go Normal file
View File

@@ -0,0 +1,50 @@
package aprs
import (
"strconv"
"strings"
)
type Query struct {
Type string `json:"type"`
Latitude float64
Longitude float64
Radius float64 // radius in meters
}
func (q Query) String() string {
return q.Type
}
type queryDecoder struct{}
func (queryDecoder) CanDecode(frame *Frame) bool {
return len(frame.Raw) >= 3 && frame.Raw.Type() == '?'
}
func (queryDecoder) Decode(frame *Frame) (data Data, err error) {
var (
kind = string(frame.Raw[1:])
args string
i int
)
if i = strings.IndexByte(kind, '?'); i == -1 {
return &Query{
Type: kind,
}, nil
} else {
kind, args = kind[:i], kind[i+1:]
}
query := &Query{Type: kind}
if part := strings.SplitN(strings.TrimSpace(args), ",", 3); len(part) == 3 {
var radius int
query.Latitude, _ = strconv.ParseFloat(part[0], 64)
query.Longitude, _ = strconv.ParseFloat(part[1], 64)
radius, _ = strconv.Atoi(part[2])
query.Radius = milesToMeters(float64(radius))
}
return query, nil
}