From 7d3e591aaed7aa78016613254184ef2638a3c597 Mon Sep 17 00:00:00 2001 From: Jason Playne Date: Thu, 30 Nov 2023 21:39:37 +0800 Subject: [PATCH] when aircraft send us @@@@@@@@ as their flight number/callsign - ignore them --- Makefile | 2 +- cmd/df_example_finder/main.go | 12 ++++++------ lib/tracker/mode_s/decode-bds.go | 2 +- lib/tracker/mode_s/decode.go | 6 ++++++ lib/tracker/mode_s/describe.go | 5 ++--- lib/tracker/mode_s/frame.go | 7 +++++++ lib/tracker/plane.go | 3 +++ 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index ee62295c..1e5890be 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ export GOBIN=$(shell pwd)/bin export GOAMD64=v3 - +export CGO_ENABLED=0 .PHONY: all all: tidy vet test build diff --git a/cmd/df_example_finder/main.go b/cmd/df_example_finder/main.go index bbdedc52..397d04d8 100644 --- a/cmd/df_example_finder/main.go +++ b/cmd/df_example_finder/main.go @@ -198,9 +198,9 @@ func showTypes(c *cli.Context) error { frame.IcaoStr(), frame.RawString(), frame.DownLinkFormat(), - frame.MessageTypeString(), + "", frame.FlightNumber(), - fmt.Sprint(frame.SquawkIdentity()), + frame.SquawkIdentityStr(), } case 17, 18, 19: fields = []string{ @@ -212,7 +212,7 @@ func showTypes(c *cli.Context) error { frame.DownLinkFormat(), frame.MessageTypeString(), frame.FlightNumber(), - fmt.Sprint(frame.SquawkIdentity()), + frame.SquawkIdentityStr(), } case 20, 21: fields = []string{ @@ -222,9 +222,9 @@ func showTypes(c *cli.Context) error { frame.IcaoStr(), frame.RawString(), frame.DownLinkFormat(), - frame.MessageTypeString(), + frame.DescribeBds(), frame.FlightNumber(), - fmt.Sprint(frame.SquawkIdentity()), + frame.SquawkIdentityStr(), } default: fields = []string{ @@ -236,7 +236,7 @@ func showTypes(c *cli.Context) error { frame.DownLinkFormat(), frame.MessageTypeString(), frame.FlightNumber(), - fmt.Sprint(frame.SquawkIdentity()), + frame.SquawkIdentityStr(), } } if !export { diff --git a/lib/tracker/mode_s/decode-bds.go b/lib/tracker/mode_s/decode-bds.go index c03f28de..a0668bda 100644 --- a/lib/tracker/mode_s/decode-bds.go +++ b/lib/tracker/mode_s/decode-bds.go @@ -139,7 +139,7 @@ func inferCommBMessageType(mb []byte) (byte, byte, error) { if mb[0] == 0b0010_0000 { // bits 9-56 are call sign, should not contain any ? chars from aisCharset callsign := string(decodeFlightNumber(mb[1:7])) - if !strings.Contains(callsign, "?") { + if callsign != "" && !strings.Contains(callsign, "?") { return 2, 0, nil } } diff --git a/lib/tracker/mode_s/decode.go b/lib/tracker/mode_s/decode.go index 87722d39..ffa94e6e 100644 --- a/lib/tracker/mode_s/decode.go +++ b/lib/tracker/mode_s/decode.go @@ -500,6 +500,12 @@ func decodeFlightNumber(b []byte) []byte { callsign[5] = aisCharset[((b[3]&3)<<4)|(b[4]>>4)] callsign[6] = aisCharset[((b[4]&15)<<2)|(b[5]>>6)] callsign[7] = aisCharset[b[5]&63] + + // because planes have sent us things like A90004A0200000000000007D8DB4 + // we need + if string(callsign) == "@@@@@@@@" { + callsign = nil + } return callsign } diff --git a/lib/tracker/mode_s/describe.go b/lib/tracker/mode_s/describe.go index a660cd24..b5092e4f 100644 --- a/lib/tracker/mode_s/describe.go +++ b/lib/tracker/mode_s/describe.go @@ -875,7 +875,7 @@ func (f *Frame) showAlert(output io.Writer) { f.showSpecial(output) } func (f *Frame) showSpecial(output io.Writer) { - if "" != f.special { + if f.special != "" { fprintf(output, " special : %s\n", f.special) } } @@ -884,9 +884,8 @@ func (f *Frame) showFlightNumber(output io.Writer) { fprintf(output, " flight Number : %s\n", f.FlightNumber()) } -// determines what type of mode S Message this frame is +// DownLinkFormat determines what type of mode S Message this frame is func (f *Frame) DownLinkFormat() string { - if description, ok := downlinkFormatTable[f.downLinkFormat]; ok { return description } diff --git a/lib/tracker/mode_s/frame.go b/lib/tracker/mode_s/frame.go index 1d8d9966..a0c259b6 100644 --- a/lib/tracker/mode_s/frame.go +++ b/lib/tracker/mode_s/frame.go @@ -749,6 +749,13 @@ func (f *Frame) SquawkIdentity() uint32 { return f.identity } +func (f *Frame) SquawkIdentityStr() string { + if nil == f || f.identity == 0 { + return "" + } + return fmt.Sprintf("%04d", f.identity) +} + func (f *Frame) OnGround() (bool, error) { if f.VerticalStatusValid() { return f.onGround, nil diff --git a/lib/tracker/plane.go b/lib/tracker/plane.go index 1cbfcb52..0fe77c69 100644 --- a/lib/tracker/plane.go +++ b/lib/tracker/plane.go @@ -493,6 +493,9 @@ func (p *Plane) Registration() *string { // setFlightNumber is the flights identifier/number func (p *Plane) setFlightNumber(flightIdentifier string) bool { + if flightIdentifier == "" { + return false + } p.rwLock.Lock() defer p.rwLock.Unlock() hasChanged := p.flight.identifier != flightIdentifier