Coder Social home page Coder Social logo

mmadfox / go-gpsgen Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 482 KB

GPS data generator based on predefined routes

License: MIT License

Go 59.11% Makefile 0.08% TypeScript 14.90% JavaScript 25.91%
gps-tracker go-gps gps-faker gps-gen gps-spoofing

go-gpsgen's Introduction

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.WithSensorStartMode: Generation starts from the minimum value of 1 to 10
// types.WithSensorEndMode:   Generation ends at the minimum value from 10 to 1
// types.WithSensorRandomMode: Data generation follows a Bezier curve from 1 to 10

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

s1, err := gpsgen.NewSensor("s1", minValue, maxValue, amplitude, types.WithSensorStartMode|types.WithSensorRandomMode|types.WithSensorEndMode)
if err != nil {
	panic(err)
}

droneTracker.AddSensor(s1)
s2, err := gpsgen.NewSensor("s2", 10, 20, 16, types.WithSensorRandomMode|types.WithSensorEndMode)
if err != nil {
	panic(err)
}
droneTracker.AddSensor(s2)
s3, err := gpsgen.NewSensor("s3", 20, 30, 16, 0)
if err != nil {
	panic(err)
}
droneTracker.AddSensor(s3)
// ...

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

go-gpsgen's People

Contributors

mmadfox avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.