INITIAL
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
// Package datapoint holds the position fix type shared by the macker client
|
||||
// and server.
|
||||
package datapoint
|
||||
|
||||
import "sync"
|
||||
|
||||
type Tri struct {
|
||||
Lat, Long, Alt float64
|
||||
}
|
||||
|
||||
// DataPoint is a single position fix extracted from a gpsd TPV report.
|
||||
// Timestamp is Unix time in milliseconds; zero means gpsd omitted the time.
|
||||
type DataPoint struct {
|
||||
Speed *float64 // Ground speed in metres per second; nil means unavailable.
|
||||
Timestamp uint64
|
||||
Lat, LatErr float64
|
||||
Long, LongErr float64
|
||||
Alt, AltErr float64
|
||||
}
|
||||
|
||||
func (dp DataPoint) getTri() Tri {
|
||||
return Tri{
|
||||
dp.Lat,
|
||||
dp.Long,
|
||||
dp.Alt,
|
||||
}
|
||||
}
|
||||
|
||||
type TrackBuffer struct {
|
||||
DataPoints []DataPoint
|
||||
Mtx *sync.Mutex
|
||||
}
|
||||
|
||||
func GenTrackBuff() TrackBuffer {
|
||||
|
||||
var sm sync.Mutex
|
||||
|
||||
return TrackBuffer{
|
||||
[]DataPoint{},
|
||||
&sm,
|
||||
}
|
||||
}
|
||||
|
||||
func (tb *TrackBuffer) Add(input DataPoint) {
|
||||
tb.Mtx.Lock()
|
||||
tb.DataPoints = append(tb.DataPoints, input)
|
||||
tb.Mtx.Unlock()
|
||||
}
|
||||
|
||||
func (tb *TrackBuffer) StartTBHandler() (chan DataPoint, *TrackBuffer) {
|
||||
|
||||
inchan := make(chan DataPoint)
|
||||
|
||||
go func() {
|
||||
for tmp := range inchan {
|
||||
tb.Add(tmp)
|
||||
}
|
||||
}()
|
||||
return inchan, tb
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module macker/datapoint
|
||||
|
||||
go 1.27.0
|
||||
Reference in New Issue
Block a user