Documentation ¶
Index ¶
- Constants
- func DecodeGPXRoutes(data []byte) ([]*navigator.Route, error)
- func DecodeGeoJSONRoutes(data []byte) ([]*navigator.Route, error)
- func DecodeRoutes(data []byte) ([]*navigator.Route, error)
- func DecodeSensors(data []byte) ([]*types.Sensor, error)
- func EncodeGPXRoutes(routes []*navigator.Route) ([]byte, error)
- func EncodeGeoJSONRoutes(routes []*navigator.Route) ([]byte, error)
- func EncodeRoutes(routes []*navigator.Route) ([]byte, error)
- func EncodeSensors(sensors []*types.Sensor) ([]byte, error)
- func EncodeTracker(t *Device) ([]byte, error)
- func PacketFromBytes(data []byte) (*pb.Packet, error)
- func RandomRoute(lon, lat float64, numTrack int, level int) *navigator.Route
- type Device
- func (d *Device) AddRoute(routes ...*navigator.Route) error
- func (d *Device) AddSensor(name string, min, max float64, amplitude int, mode types.SensorMode) (string, error)
- func (d *Device) Color() string
- func (d *Device) CurrentBearing() float64
- func (d *Device) CurrentDistance() float64
- func (d *Device) CurrentRoute() *navigator.Route
- func (d *Device) CurrentRouteDistance() float64
- func (d *Device) CurrentSegment() navigator.Segment
- func (d *Device) CurrentSegmentDistance() float64
- func (d *Device) CurrentTrack() *navigator.Track
- func (d *Device) CurrentTrackDistance() float64
- func (d *Device) Descr() string
- func (d *Device) DestinationTo(meters float64) bool
- func (d *Device) Distance() float64
- func (d *Device) Duration() float64
- func (d *Device) EachRoute(fn func(int, *navigator.Route) bool)
- func (d *Device) EachSensor(fn func(int, *types.Sensor) bool)
- func (d *Device) FromSnapshot(snap *pb.Snapshot)
- func (d *Device) ID() string
- func (d *Device) IsFinish() bool
- func (d *Device) IsOffline() bool
- func (d *Device) Location() geo.LatLonPoint
- func (d *Device) MarshalBinary() ([]byte, error)
- func (d *Device) Model() string
- func (d *Device) MoveToRoute(routeIndex int) bool
- func (d *Device) MoveToRouteByID(routeID string) bool
- func (d *Device) MoveToSegment(routeIndex int, trackIndex int, segmentIndex int) bool
- func (d *Device) MoveToTrack(routeIndex int, trackIndex int) bool
- func (d *Device) MoveToTrackByID(routeID string, trackID string) bool
- func (d *Device) Next(tick float64) bool
- func (d *Device) NumRoutes() int
- func (d *Device) NumSensors() int
- func (d *Device) RemoveRoute(routeID string) bool
- func (d *Device) RemoveSensor(sensorID string) (ok bool)
- func (d *Device) RemoveTrack(routeID, trackID string) bool
- func (d *Device) ResetNavigator()
- func (d *Device) ResetRoutes() bool
- func (d *Device) RouteAt(index int) *navigator.Route
- func (d *Device) RouteDistance() float64
- func (d *Device) RouteIndex() int
- func (d *Device) SegmentDistance() float64
- func (d *Device) SegmentIndex() int
- func (d *Device) SensorAt(i int) *types.Sensor
- func (d *Device) SensorByID(sensorID string) (*types.Sensor, bool)
- func (d *Device) SetColor(color colorful.Color) error
- func (d *Device) SetDescription(descr string)
- func (d *Device) SetModel(model string) error
- func (d *Device) SetUserID(id string) error
- func (d *Device) Snapshot() *pb.Snapshot
- func (d *Device) State() *pb.Device
- func (d *Device) Status() Status
- func (d *Device) ToNextRoute() bool
- func (d *Device) ToOffline()
- func (d *Device) ToPrevRoute() bool
- func (d *Device) TrackDistance() float64
- func (d *Device) TrackIndex() int
- func (d *Device) UnmarshalBinary(data []byte) error
- func (d *Device) Update()
- func (d *Device) UserID() string
- func (d *Device) Version() [3]int
- type DeviceOptions
- type Generator
- func (g *Generator) Attach(d *Device) error
- func (g *Generator) Close()
- func (g *Generator) Detach(deviceID string) error
- func (g *Generator) Lookup(deviceID string) (*Device, bool)
- func (g *Generator) NumDevices() int
- func (g *Generator) OnError(fn func(error))
- func (g *Generator) OnNext(fn func())
- func (g *Generator) OnPacket(fn func([]byte))
- func (g *Generator) Run()
- type Options
- type Status
Constants ¶
const ( RouteLevelXS = 1 RouteLevelS = 10 RouteLevelM = 60 RouteLevelL = 120 RouteLevelXL = 300 RouteLevelXXL = 600 )
Route level constants define different levels of route complexity.
Variables ¶
This section is empty.
Functions ¶
func DecodeGPXRoutes ¶ added in v0.2.0
DecodeGPXRoutes decodes GPX data into a slice of navigator routes.
func DecodeGeoJSONRoutes ¶ added in v0.2.0
DecodeGeoJSONRoutes decodes GeoJSON data into a slice of navigator routes.
func DecodeRoutes ¶ added in v0.2.0
DecodeRoutes decodes binary data into a slice of navigator routes.
func DecodeSensors ¶ added in v0.2.0
DecodeSensors decodes binary data into a slice of Sensor types.
func EncodeGPXRoutes ¶ added in v0.2.0
EncodeGPXRoutes encodes a slice of navigator routes into GPX format.
func EncodeGeoJSONRoutes ¶ added in v0.2.0
EncodeGeoJSONRoutes encodes a slice of navigator routes into GeoJSON format.
func EncodeRoutes ¶ added in v0.2.0
EncodeRoutes encodes a slice of navigator routes into binary data.
func EncodeSensors ¶ added in v0.2.0
EncodeSensors encodes a slice of Sensor types into binary data.
func EncodeTracker ¶ added in v0.2.0
EncodeTracker encodes a Device into a binary format.
func PacketFromBytes ¶
PacketFromBytes decodes a byte slice into a protobuf Packet. Returns the decoded Packet and an error if decoding fails.
func RandomRoute ¶
RandomRoute generates a random route with specified parameters. The function generates tracks within the route, using a specified number of tracks and complexity level. The generated route is centered around the provided latitude and longitude. Returns a random route with tracks, or nil if an error occurs during track creation.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents a GPS tracking device with various capabilities.
func DecodeTracker ¶ added in v0.2.0
DecodeTracker decodes binary data into a Device.
func NewBicycleTracker ¶
func NewBicycleTracker() *Device
NewBicycleTracker creates a new GPS tracking device.
func NewDevice ¶
func NewDevice(opts *DeviceOptions) (*Device, error)
NewDevice creates a new GPS tracking device with the provided options.
func NewDroneTracker ¶
func NewDroneTracker() *Device
NewDroneTracker creates a new GPS tracking device.
func NewKidsTracker ¶
func NewKidsTracker() *Device
NewKidsTracker creates a new GPS tracking device.
func (*Device) AddSensor ¶
func (d *Device) AddSensor( name string, min, max float64, amplitude int, mode types.SensorMode, ) (string, error)
AddSensor adds a sensor to the device with the specified parameters.
func (*Device) CurrentBearing ¶
CurrentBearing returns the current bearing direction of the device.
func (*Device) CurrentDistance ¶
CurrentDistance returns the distance traveled in the current segment.
func (*Device) CurrentRoute ¶
CurrentRoute returns the currently active route of the device.
func (*Device) CurrentRouteDistance ¶
CurrentRouteDistance returns the distance traveled in the current route.
func (*Device) CurrentSegment ¶
CurrentSegment returns the currently active segment of the device.
func (*Device) CurrentSegmentDistance ¶
CurrentSegmentDistance returns the distance traveled in the current segment.
func (*Device) CurrentTrack ¶
CurrentTrack returns the currently active track of the device.
func (*Device) CurrentTrackDistance ¶
CurrentTrackDistance returns the distance traveled in the current track.
func (*Device) DestinationTo ¶
DestinationTo updates the device's position to a specified distance along the current segment. It returns true on success, indicating the update was applied.
func (*Device) Duration ¶
Duration returns the duration of the device's current track segment in seconds. It returns the duration of the current track segment or 0 if no track is active.
func (*Device) EachRoute ¶
EachRoute iterates over each route in the device's navigator and applies a function.
func (*Device) EachSensor ¶
EachSensor iterates over each sensor in the device's navigator and applies a function.
func (*Device) FromSnapshot ¶
FromSnapshot updates the device's state using the provided snapshot data. It populates the device's state with the values from the snapshot, including device information, status, navigator, speed, battery, and sensors.
func (*Device) IsOffline ¶
IsOffline returns whether the device is currently offline based on the navigator's status.
func (*Device) Location ¶
func (d *Device) Location() geo.LatLonPoint
Location returns the current geographical location of the device.
func (*Device) MarshalBinary ¶
MarshalBinary converts the device's current state into a binary representation. It creates a snapshot of the device and serializes it using protobuf encoding. Returns the binary representation of the device's state and an error, if any.
func (*Device) MoveToRoute ¶
MoveToRoute updates the device's position to a specific route. It returns true on success, indicating the update was applied.
func (*Device) MoveToRouteByID ¶
MoveToRouteByID updates the device's position to a specific route, identified by its ID. It returns true on success, indicating the update was applied.
func (*Device) MoveToSegment ¶
MoveToSegment updates the device's position to a specific segment within a track and route. It returns true on success, indicating the update was applied.
func (*Device) MoveToTrack ¶
MoveToTrack updates the device's position to a specific track within a route. It returns true on success, indicating the update was applied.
func (*Device) MoveToTrackByID ¶
MoveToTrackByID updates the device's position to a specific track within a route, identified by IDs. It returns true on success, indicating the update was applied.
func (*Device) Next ¶
Next advances the device's state for the next time step. The tick parameter represents the time interval in seconds since the last update. It updates the device's position, speed, elevation, battery level, sensors, and state. Returns true if the state was successfully updated, and false if no routes are available or if the navigator has finished.
func (*Device) NumSensors ¶
NumSensors returns the number of sensors attached to the device.
func (*Device) RemoveRoute ¶
RemoveRoute removes a route from the device's navigator by its ID.
func (*Device) RemoveSensor ¶
RemoveSensor removes a sensor with the specified sensorID from the device's list of sensors. It returns true if the sensor was successfully removed, and false otherwise. If the provided sensorID is empty, the function returns false.
func (*Device) RemoveTrack ¶
RemoveTrack removes a track from a route in the device's navigator.
func (*Device) ResetNavigator ¶
func (d *Device) ResetNavigator()
ResetNavigator resets the navigator for the device. This method clears all navigation-related state and resets the device's position. It does not return a value.
func (*Device) ResetRoutes ¶
ResetRoutes resets the routes associated with the device in the navigator. It returns true on success and updates the device's internal routes.
func (*Device) RouteAt ¶
RouteAt returns the route at the specified index in the navigator. The index parameter is the index of the desired route. It returns the route at the given index or nil if the index is out of bounds.
func (*Device) RouteDistance ¶
RouteDistance returns the total distance of the active route.
func (*Device) RouteIndex ¶
RouteIndex returns the index of the currently active route in the navigator.
func (*Device) SegmentDistance ¶
SegmentDistance returns the total distance of the active segment.
func (*Device) SegmentIndex ¶
SegmentIndex returns the index of the current segment within the current track of the navigator.
func (*Device) SensorAt ¶
SensorAt returns the sensor at the specified index from the device's navigator.
func (*Device) SensorByID ¶
SensorByID returns the sensor with the given ID and a boolean indicating its existence.
func (*Device) SetDescription ¶
SetDescription sets the description of the device.
func (*Device) Snapshot ¶
Snapshot creates and returns a snapshot of the device's current state. The snapshot includes device information, status, duration, navigator, speed, battery, and sensors (if any).
func (*Device) ToNextRoute ¶
ToNextRoute updates the device's position to the next route in the navigator. It returns true on success, indicating the update was applied.
func (*Device) ToOffline ¶
func (d *Device) ToOffline()
ToOffline sets the device's status to offline in the navigator. This method does not return a value.
func (*Device) ToPrevRoute ¶
ToPrevRoute updates the device's position to the previous route in the navigator. It returns true on success, indicating the update was applied.
func (*Device) TrackDistance ¶
TrackDistance returns the total distance of the active track.
func (*Device) TrackIndex ¶
TrackIndex returns the index of the currently active track in the navigator.
func (*Device) UnmarshalBinary ¶
UnmarshalBinary populates the device's state using the provided binary data. It deserializes the binary data using protobuf decoding and updates the device's state accordingly. Returns an error if the binary data is invalid or if there's an issue during deserialization.
func (*Device) Update ¶
func (d *Device) Update()
Update updates the device's state and routes based on its current navigator state.
type DeviceOptions ¶
type DeviceOptions struct { ID string // ID of the device. Model string // Model of the device. Color string // Color of the device. UserID string // User ID associated with the device. Descr string // Description of the device. SkipOffline bool // Skip offline mode. Offline struct { Min int // Minimum duration for offline mode. Max int // Maximum duration for offline mode. } Elevation struct { Min float64 // Minimum elevation. Max float64 // Maximum elevation. Amplitude int // Amplitude for elevation changes. Mode types.SensorMode // Sensor mode for elevation changes. } } Battery struct { Min float64 // Minimum battery level. Max float64 // Maximum battery level. ChargeTime time.Duration // Charging time for the battery. } Speed struct { Min float64 // Minimum speed. Max float64 // Maximum speed. Amplitude int // Amplitude for speed changes. } }
DeviceOptions defines the options for creating a new device.
func BicycleTrackerOptions ¶
func BicycleTrackerOptions() *DeviceOptions
BicycleTrackerOptions returns DeviceOptions suitable for a bicycle tracker.
func DefaultTrackerOptions ¶
func DefaultTrackerOptions() *DeviceOptions
DefaultTrackerOptions returns DeviceOptions suitable for a default tracker.
func DogTrackerOptions ¶
func DogTrackerOptions() *DeviceOptions
DogTrackerOptions returns DeviceOptions suitable for a dog tracker.
func DroneTrackerOptions ¶
func DroneTrackerOptions() *DeviceOptions
DroneTrackerOptions returns DeviceOptions suitable for a drone tracker.
func KidsTrackerOptions ¶
func KidsTrackerOptions() *DeviceOptions
KidsTrackerOptions returns DeviceOptions suitable for a kids tracker.
func NewDeviceOptions ¶
func NewDeviceOptions() *DeviceOptions
NewDeviceOptions creates a new set of default DeviceOptions.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator represents the GPS data generator.
func (*Generator) Close ¶
func (g *Generator) Close()
Close stops the data generation process and closes the generator.
func (*Generator) Lookup ¶
Lookup searches for a device with the given ID and returns it along with a boolean indicating its existence.
func (*Generator) NumDevices ¶
NumDevices returns the number of devices attached to the generator.
func (*Generator) OnError ¶
OnError sets a callback function to handle errors during data generation.
func (*Generator) OnNext ¶
func (g *Generator) OnNext(fn func())
OnNext sets a callback function to be executed at each "next step" of data generation.
type Options ¶
type Options struct { // Interval determines the time interval between data generation iterations. Default one second. Interval time.Duration // PacketSize specifies the size of the data packet generated per iteration. Default 512. PacketSize int // NumWorkers sets the number of concurrent workers for data processing. Default numCPU. NumWorkers int }
Options defines the configuration options for the Generator.
func NewOptions ¶
func NewOptions() *Options
NewOptions creates a new Options instance with default values.