Skip to content

Commit

Permalink
Merge pull request #60 from afk11/map-time-usage
Browse files Browse the repository at this point in the history
tracker/map.go: use result of time.After instead of time.Since everywhere
  • Loading branch information
afk11 committed Dec 16, 2020
2 parents 22fa511 + 2cca979 commit 5165d8b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes BEAST message processing - call `TrackUpdateFromMessage` ASAP so our message
is updated with the processed information.
- Fixes deadlock in tracker/map.go:updateJSON. Release projMu ASAP since ProjectHistory
also needs it. Debugged using go-deadlock.
also needs it. Debugged using go-deadlock.
- BEAST Server configuration: default to 30005 if nothing provided
5 changes: 3 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ BEAST format messages are produced by dump1090 on port 30005 by default.
name: <string>
# Hostname or IP for server
host: <host>
# Port for connection (probably 30005)
port: <port>
# Port for connection (probably 30005). Optional, as defaults
# to 30005
[ port: <port> | default = 30005 ]
```

### `<airports_config>`
Expand Down
16 changes: 16 additions & 0 deletions docs/running-airtrack.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ projects:
- name: global
```
If you run a dump1090 or readsb instance, you can receive messages from its BEAST output port.
Add the following to your config file:
```yaml
beast:
- name: home
host: 10.10.10.92
# port: 30005 # port is optional, defaults to 30005
```

If you have an ADSB Exchange API key, you can configure that to receive information
about aircraft worldwide from the ADSB Exchange community feeders.
```yaml
adsbx:
apikey: 42424242-4242-4242-4242-424242424242
```
## Migrations
When setting up airtrack for the first time, we'll need to create a database.
Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/airtrack/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ func (l *Loader) Load(c *TrackCmd) error {
} else if bcfg.Host == "" {
return errors.Errorf("beast server '%s' is missing host field", bcfg.Name)
}
l.producers = append(l.producers, tracker.NewBeastProducer(l.msgs, bcfg.Host, bcfg.Port, bcfg.Name))
var port uint16 = 30005
if bcfg.Port != nil {
port = *bcfg.Port
}
l.producers = append(l.producers, tracker.NewBeastProducer(l.msgs, bcfg.Host, port, bcfg.Name))
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ type (
Name string `yaml:"name"`
// IP or hostname for beast server
Host string `yaml:"host"`
// Port for beast services (port 30005)
Port uint16 `yaml:"port"`
// Port for beast services (Optional, defaults to 30005)
Port *uint16 `yaml:"port"`
}

// Config - represents the yaml block in the main config file.
Expand Down
12 changes: 11 additions & 1 deletion pkg/readsb/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,20 @@ var navModeNames = map[NavModes]string{
NavModeTCAS: "tcas",
}

// AllNavModes contains a slice of all valid nav modes
var AllNavModes = []NavModes{
NavModeAutopilot,
NavModeVNAV,
NavModeAltHold,
NavModeApproach,
NavModeLNAV,
NavModeTCAS,
}

// NavModesList returns the names of enabled nav modes in a list
func (nm NavModes) NavModesList() []string {
var strs []string
for navMode := NavModes(1); navMode <= NavModeTCAS; navMode <<= 1 {
for _, navMode := range AllNavModes {
if (navMode & nm) != 0 {
strs = append(strs, navModeNames[navMode])
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/tracker/map.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tracker

import "C"
import (
"context"
"fmt"
Expand Down Expand Up @@ -553,16 +552,21 @@ func (m *AircraftMap) updateJSON(ctx context.Context) {
return
}

<-time.After(time.Second)
updateTime := <-time.After(time.Second)

// Update ac with duration since last msg, and duration since last position
m.acMu.RLock()
for _, ac := range m.ac {
ac.Lock()
ac.Seen = int64(time.Since(ac.lastMsgTime).Seconds())
ac.SeenPos = time.Since(ac.lastPosTime).Seconds()
ac.Unlock()
for i := range m.ac {
m.ac[i].Lock()
m.ac[i].Seen = int64(updateTime.Sub(m.ac[i].lastMsgTime).Seconds())
m.ac[i].SeenPos = updateTime.Sub(m.ac[i].lastPosTime).Seconds()
m.ac[i].Unlock()
}
m.acMu.RUnlock()
if firstRun || time.Since(lastHistoryUpdate) > m.historyInterval {

// If there are no history files, or historyInterval has passed since lastHistoryUpdate
// have each MapServices UpdateHistory for all projects
if firstRun || updateTime.Sub(lastHistoryUpdate) > m.historyInterval {
if firstRun {
firstRun = false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ func (t *Tracker) UpdateStateFromMessage(s *Sighting, msg *pb.Message, now time.
}
if msg.NavModes != 0 {
nm := readsb.NavModes(msg.NavModes)
for navMode := readsb.NavModes(0); navMode <= readsb.NavModeTCAS; navMode <<= 1 {
for _, navMode := range readsb.AllNavModes {
if (nm & navMode) != 0 {
s.State.NavModes |= uint32(navMode)
}
Expand Down

0 comments on commit 5165d8b

Please sign in to comment.