protocol/aprs: extract position and symbol to frame
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user