stationcache

package
v0.13.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MaxTrailLen = 200

Variables

This section is empty.

Functions

This section is empty.

Types

type BBox

type BBox struct {
	SwLat, SwLon, NeLat, NeLon float64
}

type CacheEntry

type CacheEntry struct {
	Key       string
	IsObject  bool
	Killed    bool // object/item with Live==false → delete from cache
	Callsign  string
	Lat, Lon  float64
	HasPos    bool
	Alt       float64
	HasAlt    bool
	Speed     float64
	Course    int
	HasCourse bool
	Symbol    [2]byte
	Via       string
	Path      []string
	Hops      int
	Direction string
	Channel   uint32
	Comment   string
	Weather   *Weather
	Timestamp time.Time
}

CacheEntry is the output of ExtractEntry, ready for MemCache.Update().

func ExtractEntry

func ExtractEntry(decoded *aprs.DecodedAPRSPacket, source, dir string, ch uint32) []CacheEntry

ExtractEntry converts a decoded APRS packet into cache update(s). Most packets produce one entry; a packet carrying an object/item produces an entry for the object plus (if the originator has a position) an entry for the originating station. Returns nil if the packet has no useful station data.

type HistoryStore

type HistoryStore interface {
	WriteEntries(entries []CacheEntry) error
	LoadRecent(maxAge time.Duration, trailLimit int) (map[string]*Station, error)
	Prune(maxAge time.Duration) error
	Close() error
}

HistoryStore is the persistence interface consumed by PersistentCache. historydb.DB implements it; the interface lives here to avoid an import cycle.

type LatLon

type LatLon struct {
	Lat, Lon float64
}

type MemCache

type MemCache struct {
	// contains filtered or unexported fields
}

MemCache is an in-memory StationStore for RF-scale traffic. Safe for concurrent use.

func NewMemCache

func NewMemCache(maxAge time.Duration) *MemCache

func (*MemCache) Close

func (c *MemCache) Close()

Close signals the pruning goroutine to exit.

func (*MemCache) Gen

func (c *MemCache) Gen() uint64

Gen returns the current generation counter.

func (*MemCache) Hydrate

func (c *MemCache) Hydrate(stations map[string]*Station)

Hydrate bulk-loads stations into the cache, typically from a persistent store on startup. Existing entries are not overwritten.

func (*MemCache) Lookup

func (c *MemCache) Lookup(callsigns []string) map[string]LatLon

Lookup returns positions for the given callsigns regardless of bbox.

func (*MemCache) QueryBBox

func (c *MemCache) QueryBBox(bbox BBox, maxAge time.Duration) []Station

QueryBBox returns stations within the bounding box heard within maxAge.

func (*MemCache) Update

func (c *MemCache) Update(entries []CacheEntry)

Update applies cache entries produced by ExtractEntry.

type PersistentCache

type PersistentCache struct {
	// contains filtered or unexported fields
}

PersistentCache wraps a MemCache with optional SQLite persistence. When persistence is disabled, it behaves identically to a bare MemCache. Persistence can be toggled at runtime via Reconfigure.

func NewPersistentCache

func NewPersistentCache(logger *slog.Logger) *PersistentCache

NewPersistentCache creates a PersistentCache with persistence disabled. Call Reconfigure to enable it.

func (*PersistentCache) Close

func (p *PersistentCache) Close()

Close shuts down persistence and the in-memory cache.

func (*PersistentCache) Gen

func (p *PersistentCache) Gen() uint64

Gen returns the in-memory generation counter (ETag support).

func (*PersistentCache) Lookup

func (p *PersistentCache) Lookup(callsigns []string) map[string]LatLon

Lookup delegates to the in-memory cache.

func (*PersistentCache) QueryBBox

func (p *PersistentCache) QueryBBox(bbox BBox, maxAge time.Duration) []Station

QueryBBox delegates to the in-memory cache.

func (*PersistentCache) Reconfigure

func (p *PersistentCache) Reconfigure(hdb HistoryStore) error

Reconfigure enables, disables, or changes the persistence backend. Pass a non-nil HistoryStore to enable, or nil to disable.

func (*PersistentCache) Update

func (p *PersistentCache) Update(entries []CacheEntry)

Update applies entries to the in-memory cache and, if persistence is enabled, writes them to the history database.

type Position

type Position struct {
	Lat       float64
	Lon       float64
	Alt       float64
	HasAlt    bool
	Speed     float64 // knots
	Course    int
	HasCourse bool
	Via       string
	Path      []string
	Hops      int
	Direction string
	Channel   uint32
	Comment   string
	Timestamp time.Time
}

Position is a single position fix with metadata. Per-position metadata (Via, Path, etc.) captures the packet context at the time this position was reported, enabling accurate historical trail display.

type Station

type Station struct {
	Key       string     // "stn:W1ABC-9" or "obj:SHELTER1"
	Callsign  string     // display name (callsign or object/item name)
	IsObject  bool       // true for APRS objects/items
	Positions []Position // newest first; cap at MaxTrailLen. Static stations have len 1.
	Symbol    [2]byte    // [table, code]
	Via       string     // "rf" or "is"
	Path      []string   // digi path from AX.25 header
	Hops      int        // count of H-bit digi addresses
	Direction string     // "RX", "TX", "IS"
	Channel   uint32
	Comment   string
	Weather   *Weather // nil if not a weather station
	LastHeard time.Time
}

Station is the last-known state of a single station or object. One entry per composite key. Position history is kept for moving stations only — static stations that beacon the same coordinates repeatedly don't accumulate trail points.

type StationStore

type StationStore interface {
	// QueryBBox returns stations within the bounding box heard within maxAge.
	// Returned slice is a snapshot — caller owns it.
	QueryBBox(bbox BBox, maxAge time.Duration) []Station

	// Lookup returns positions for the given callsigns regardless of bbox.
	// Used for server-side digi path resolution. Missing callsigns omitted.
	Lookup(callsigns []string) map[string]LatLon
}

StationStore is the read interface consumed by the API handler. MemCache implements it for RF-scale traffic; a future DB-backed implementation can serve full APRS-IS feeds behind this same interface.

type Weather

type Weather struct {
	Temp          float64
	HasTemp       bool
	WindSpeed     float64
	HasWindSpeed  bool
	WindDir       int
	HasWindDir    bool
	WindGust      float64
	HasWindGust   bool
	Humidity      int
	HasHumidity   bool
	Pressure      float64
	HasPressure   bool
	Rain1h        float64
	HasRain1h     bool
	Rain24h       float64
	HasRain24h    bool
	Snow24h       float64
	HasSnow24h    bool
	Luminosity    int
	HasLuminosity bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL