Categorygithub.com/mmadfox/go-gpsgen
modulepackage
0.2.0
Repository: https://github.com/mmadfox/go-gpsgen.git
Documentation: pkg.go.dev

# README

GPS data generator
GPSGen

GPS data generator based on predefined routes. Supports GPX and GeoJSON route formats.

This library can be used in testing and debugging applications or devices dependent on GPS/GLONASS/ETC, allowing you to simulate locations for checking their functionality without actual movement.


Coverage Status Docs Go Report Card Actions

Table of Contents

Installation

$ go get github.com/mmadfox/go-gpsgen

Example

package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/google/uuid"
	"github.com/mmadfox/go-gpsgen"
)

const (
	numTracksPerRoute = 3
	numTrackers       = 1000
	flushInterval     = 3 * time.Second
)

func main() {
	lon := 37.625616307117696
	lat := 55.75350460378772

	genOpts := gpsgen.NewOptions()
	genOpts.Interval = flushInterval
	gen := gpsgen.New(genOpts)

	// For network transmission
	gen.OnPacket(func(b []byte) {
		// udp.send(b)
	})

	gen.OnError(func(err error) {
		fmt.Println("[ERROR]", err)
	})

	gen.OnNext(func() {
		fmt.Println("tracker state changed successfully")
	})

    // Generate random routes
	for i := 0; i < numTrackers; i++ {
		tracker := gpsgen.NewTracker()
		tracker.SetUserID(uuid.NewString())
		route := gpsgen.RandomRoute(lon, lat, numTracksPerRoute, gpsgen.RouteLevelM)
		tracker.AddRoute(route)
		gen.Attach(tracker)
	}

	terminate(func() {
		gen.Close()
	})

	gen.Run()
}

func terminate(fn func()) {
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)
	go func() {
		<-sigChan
		fn()
	}()
}

Routes

GeoJSON

tracker := gpsgen.NewDroneTracker()

route, err := gpsgen.DecodeGeoJSONRoutes(geoJSONBytes)
if err != nil {
	panic(err)
}

tracker.AddRoute(route...)
// ...

GPX

tracker := gpsgen.NewDroneTracker()

route, err := gpsgen.DecodeGPXRoutes(GPXBytes)
if err != nil {
	panic(err)
}

tracker.AddRoute(route...)
// ...

Random

tracker := gpsgen.NewDroneTracker()

// lon, lat, numTracks, zoomLevel
lon := 28.31261399982
lat := 53.247483804819666
numTracks := 2

route := gpsgen.RandomRoute(lon, lat, numTracks, gpsgen.RouteLevelXL)

tracker.AddRoute(route...)
// ...

Sensors

A sensor provides a flexible and expandable way to represent and work with sensors. It enables the generation of different values for various tasks, making it suitable for diverse applications and use cases, including sensor data collection, modeling, or analysis.

// types.WithStart: Generation starts from the minimum value of 1 to 10
// types.WithEnd:   Generation ends at the minimum value from 10 to 1
// types.WithRandom: Data generation follows a Bezier curve from 1 to 10

minValue := 1
maxValue := 10
amplitude := 16 // 4 - 512

droneTracker.AddSensor("s1", minValue, maxValue, amplitude, types.WithStart|types.WithRandom|types.WithEnd)
droneTracker.AddSensor("s2", 10, 20, 16, types.WithRandom|types.WithEnd)
droneTracker.AddSensor("s3", 20, 30, 16, 0)

Generated Data

Device:
    id
    user_id
    tick
    duration
    model
    speed
    distance
    battery (charge, charge_time)
    routes (routes)
    location (lat, lon, elevation, bearing, lat_dms, lon_dms, utm)
    navigator (current_route_index, current_track_index, current_segment_index)
    sensors (id, name, val_x, val_y)
    description
    is_offline
    offline_duration
    color
    time_estimate
Device.Battery:
    charge
    charge_time
Device.Routes:
    routes (Route)
Device.Routes.Route:
    id
    tracks (Track)
    distance
    color
    props
    props_count
Device.Routes.Route.Track:
    distance
    num_segments
    color
    props
    props_count
Device.Sensor:
    id
    name
    val_x
    val_y
Device.Navigator:
    current_route_index
    current_track_index
    current_segment_index
Device.Distance:
    distance
    current_distance
    route_distance
    current_route_distance
    track_distance
    current_track_distance
    segment_distance
    current_segment_distance
Device.Location:
    lat
    lon
    elevation
    bearing
    lat_dms (degrees, minutes, seconds, direction)
    lon_dms (degrees, minutes, seconds, direction)
    utm (central_meridian, easting, northing, long_zone, lat_zone, hemisphere, srid)
Packet:
    devices (Device)
    timestamp

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

BicycleTrackerOptions returns DeviceOptions suitable for a bicycle tracker.
DecodeGeoJSONRoutes decodes GeoJSON data into a slice of navigator routes.
DecodeGPXRoutes decodes GPX data into a slice of navigator routes.
DecodeRoutes decodes binary data into a slice of navigator routes.
DecodeSensors decodes binary data into a slice of Sensor types.
DecodeTracker decodes binary data into a Device.
DefaultTrackerOptions returns DeviceOptions suitable for a default tracker.
DogTrackerOptions returns DeviceOptions suitable for a dog tracker.
DroneTrackerOptions returns DeviceOptions suitable for a drone tracker.
EncodeGeoJSONRoutes encodes a slice of navigator routes into GeoJSON format.
EncodeGPXRoutes encodes a slice of navigator routes into GPX format.
EncodeRoutes encodes a slice of navigator routes into binary data.
EncodeSensors encodes a slice of Sensor types into binary data.
EncodeTracker encodes a Device into a binary format.
KidsTrackerOptions returns DeviceOptions suitable for a kids tracker.
New creates a new GPS data generator with the provided options.
NewBicycleTracker creates a new GPS tracking device.
NewDevice creates a new GPS tracking device with the provided options.
NewDeviceOptions creates a new set of default DeviceOptions.
NewDogTracker creates a new GPS tracking device.
NewDroneTracker creates a new GPS tracking device.
NewKidsTracker creates a new GPS tracking device.
NewOptions creates a new Options instance with default values.
NewTracker creates a new GPS tracking device.
PacketFromBytes decodes a byte slice into a protobuf Packet.
RandomRoute generates a random route with specified parameters.

# Constants

Route level constants define different levels of route complexity.
Route level constants define different levels of route complexity.
Route level constants define different levels of route complexity.
Route level constants define different levels of route complexity.
Route level constants define different levels of route complexity.
Route level constants define different levels of route complexity.
Running and Stopped are the possible values for the Status type.
Running and Stopped are the possible values for the Status type.

# Structs

Device represents a GPS tracking device with various capabilities.
DeviceOptions defines the options for creating a new device.
Generator represents the GPS data generator.
Options defines the configuration options for the Generator.

# Type aliases

Status represents the status of a device.