Skip to content

Commit

Permalink
when aircraft send us @@@@@@@@ as their flight number/callsign - igno…
Browse files Browse the repository at this point in the history
…re them
  • Loading branch information
bluntelk committed Nov 30, 2023
1 parent 57208fa commit 7d3e591
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export GOBIN=$(shell pwd)/bin
export GOAMD64=v3

export CGO_ENABLED=0
.PHONY: all

all: tidy vet test build
Expand Down
12 changes: 6 additions & 6 deletions cmd/df_example_finder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -236,7 +236,7 @@ func showTypes(c *cli.Context) error {
frame.DownLinkFormat(),
frame.MessageTypeString(),
frame.FlightNumber(),
fmt.Sprint(frame.SquawkIdentity()),
frame.SquawkIdentityStr(),
}
}
if !export {
Expand Down
2 changes: 1 addition & 1 deletion lib/tracker/mode_s/decode-bds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/tracker/mode_s/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions lib/tracker/mode_s/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions lib/tracker/mode_s/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/tracker/plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d3e591

Please sign in to comment.