~sungo/sbs-http

5787dccce24bb2c64dceb3de0a7e126988b925de — sungo 1 year, 7 months ago 42130ac
add distance and bearing to target
4 files changed, 38 insertions(+), 10 deletions(-)

M go.mod
M go.sum
M main.go
M pkg/models/main.go
M go.mod => go.mod +1 -1
@@ 3,7 3,7 @@ module git.sr.ht/~sungo/sbs-http
go 1.15

require (
	git.sr.ht/~sungo/go-sbs v0.0.0-20210208060320-5a6bdd976add
	git.sr.ht/~sungo/go-sbs v0.0.0-20210208062055-8759fc9f55e8
	github.com/davecgh/go-spew v1.1.1
	github.com/gorilla/handlers v1.5.1
	github.com/gorilla/mux v1.8.0

M go.sum => go.sum +2 -2
@@ 1,6 1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
git.sr.ht/~sungo/go-sbs v0.0.0-20210208060320-5a6bdd976add h1:Wlnf65T5zlLbjTbolc2LdnWL1Lp4MMxyCmjr+1hyOeM=
git.sr.ht/~sungo/go-sbs v0.0.0-20210208060320-5a6bdd976add/go.mod h1:wu7NVZK0dIY6RoQHgehb+1TmDisIEF9mj1iPfgtMlSQ=
git.sr.ht/~sungo/go-sbs v0.0.0-20210208062055-8759fc9f55e8 h1:Er4IvKeOO3VFa3A+KahhBmFzLsK5XqybDf+K3EnlOLE=
git.sr.ht/~sungo/go-sbs v0.0.0-20210208062055-8759fc9f55e8/go.mod h1:wu7NVZK0dIY6RoQHgehb+1TmDisIEF9mj1iPfgtMlSQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=

M main.go => main.go +30 -5
@@ 11,6 11,7 @@ import (
	"net"
	"net/http"
	"os"
	"strings"
	"sync"
	"sync/atomic"
	"time"


@@ 21,6 22,8 @@ import (
	"github.com/davecgh/go-spew/spew"
	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	"github.com/paulmach/orb"
	"github.com/paulmach/orb/geo"
)

const Version = "0.0.1"


@@ 132,7 135,11 @@ func talkToDump1090(url string) {
			}
			msg, err := sbs.Parse(str)
			if err != nil {
				ddp(err)
				fmt.Printf(
					"PARSE FAILURE: %s // --%s--\n",
					err,
					str,
				)
				continue
			}



@@ 154,13 161,13 @@ func talkToDump1090(url string) {
				a.LastSeen = now

				if msg.HexIdent != "" {
					a.Hex = msg.HexIdent
					a.Hex = strings.TrimSpace(msg.HexIdent)
				}
				if msg.Squawk != "" {
					a.Squawk = msg.Squawk
					a.Squawk = strings.TrimSpace(msg.Squawk)
				}
				if msg.CallSign != "" {
					a.Flight = msg.CallSign
					a.Flight = strings.TrimSpace(msg.CallSign)
				}

				if msg.TransmissionType == sbs.ESSurfacePosition {


@@ 254,6 261,18 @@ func talkToDump1090(url string) {
				}

				CurrentAircraft[aircraft.Hex] = aircraft
				a = aircraft
			}

			if Flags.ReceiverLat != 0 && Flags.ReceiverLon != 0 {
				if a.Lat != 0 && a.Lon != 0 {
					us := orb.Point{Flags.ReceiverLon, Flags.ReceiverLat}
					them := orb.Point{a.Lon, a.Lat}

					a.Distance = geo.Distance(us, them)
					a.Bearing = geo.Bearing(us, them)

				}
			}

			QueueMutex.Unlock()


@@ 286,7 305,13 @@ func dataExpiry() {
				delete(CurrentAircraft, k)
			}
		}
		fmt.Printf("[%s] Expired %d aircraft\n", time.Now().Local().Format("2006-01-02 15:04:05 -0700"), expired)
		//fmt.Printf("[%s] Expired %d aircraft\n", time.Now().Local().Format("2006-01-02 15:04:05 -0700"), expired)
		fmt.Printf(
			"[%s] %d visible aircraft\n",
			time.Now().Local().Format("2006-01-02 15:04:05 -0700"),
			len(CurrentAircraft),
		)
		// ddp(CurrentAircraft)
		QueueMutex.Unlock()
	}
}

M pkg/models/main.go => pkg/models/main.go +5 -2
@@ 24,8 24,11 @@ type Aircraft struct {
	GS           float64 `json:"gs"`
	VertRateGeom int     `json:"geom_rate"`

	LastSeen    time.Time `json:"last_seen"`
	LastPosSeen time.Time `json:"last_pos_seen"`
	LastSeen    time.Time `json:"-"`
	LastPosSeen time.Time `json:"-"`

	Distance float64 `json:"distance,omitempty"`
	Bearing  float64 `json:"bearing,omitempty"`
}

type OutputAircraft struct {