gpsd

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 7 Imported by: 13

README

go-gpsd

GPSD client for Go.

Go Reference

Installation

# go get github.com/stratoberry/go-gpsd

go-gpsd has no external dependencies.

Usage

go-gpsd is a streaming client for GPSD's JSON service and as such can be used only in async manner unlike clients for other languages which support both async and sync modes.

import ("github.com/stratoberry/go-gpsd")

func main() {
	gps := gpsd.Dial("localhost:2947")
}

After Dialing the server, you should install stream filters. Stream filters allow you to capture only certain types of GPSD reports.

gps.AddFilter("TPV", tpvFilter)

Filter functions have a type of gps.Filter and should receive one argument of type interface{}.

tpvFilter := func(r interface{}) {
	report := r.(*gpsd.TPVReport)
	fmt.Println("Location updated", report.Lat, report.Lon)
}

Due to the nature of GPSD reports your filter will manually have to cast the type of the argument it received to a proper *gpsd.Report struct pointer.

After installing all needed filters, call the Watch method to start observing reports. Please note that at this time installed filters can't be removed.

done := gps.Watch()
<-done
// ...some time later...
gps.Close()

Watch() spans a new goroutine in which all data processing will happen, done doesn't send anything.

Currently supported GPSD report types
  • VERSION (gpsd.VERSIONReport)
  • TPV (gpsd.TPVReport)
  • SKY (gpsd.SKYReport)
  • ATT (gpsd.ATTReport)
  • GST (gpsd.GSTReport)
  • PPS (gpsd.PPSReport)
  • TOFF (gpsd.TOFFReport)
  • DEVICES (gpsd.DEVICESReport)
  • DEVICE (gpsd.DEVICEReport)
  • ERROR (gpsd.ERRORReport)

Documentation

For complete library documentation visit Go Reference.

Documentation of GPSD's JSON protocol is available at https://gpsd.gitlab.io/gpsd/gpsd_json.html.

References

This library was originally developed as a part of a student project at FOI/University of Zagreb.

Documentation

Index

Constants

View Source
const DefaultAddress = "localhost:2947"

DefaultAddress of gpsd (localhost:2947)

Variables

This section is empty.

Functions

This section is empty.

Types

type ATTReport

type ATTReport struct {
	Class       string    `json:"class"`
	Tag         string    `json:"tag"`
	Device      string    `json:"device"`
	Time        time.Time `json:"time"`
	Heading     float64   `json:"heading"`
	MagSt       string    `json:"mag_st"`
	Pitch       float64   `json:"pitch"`
	PitchSt     string    `json:"pitch_st"`
	Yaw         float64   `json:"yaw"`
	YawSt       string    `json:"yaw_st"`
	Roll        float64   `json:"roll"`
	RollSt      string    `json:"roll_st"`
	Dip         float64   `json:"dip"`
	MagLen      float64   `json:"mag_len"`
	MagX        float64   `json:"mag_x"`
	MagY        float64   `json:"mag_y"`
	MagZ        float64   `json:"mag_z"`
	AccLen      float64   `json:"acc_len"`
	AccX        float64   `json:"acc_x"`
	AccY        float64   `json:"acc_y"`
	AccZ        float64   `json:"acc_z"`
	GyroX       float64   `json:"gyro_x"`
	GyroY       float64   `json:"gyro_y"`
	Depth       float64   `json:"depth"`
	Temperature float64   `json:"temperature"`
}

ATTReport reports vehicle-attitude from the digital compass or the gyroscope

type DEVICEReport

type DEVICEReport struct {
	Class     string  `json:"class"`
	Path      string  `json:"path"`
	Activated string  `json:"activated"`
	Flags     int     `json:"flags"`
	Driver    string  `json:"driver"`
	Subtype   string  `json:"subtype"`
	Bps       int     `json:"bps"`
	Parity    string  `json:"parity"`
	Stopbits  string  `json:"stopbits"`
	Native    int     `json:"native"`
	Cycle     float64 `json:"cycle"`
	Mincycle  float64 `json:"mincycle"`
}

DEVICEReport reports a state of a particular device

type DEVICESReport

type DEVICESReport struct {
	Class   string         `json:"class"`
	Devices []DEVICEReport `json:"devices"`
	Remote  string         `json:"remote"`
}

DEVICESReport lists all devices connected to the system

type ERRORReport

type ERRORReport struct {
	Class   string `json:"class"`
	Message string `json:"message"`
}

ERRORReport is an error response

type Filter

type Filter func(interface{})

Filter is a gpsd entry filter function

type GSTReport

type GSTReport struct {
	Class  string    `json:"class"`
	Tag    string    `json:"tag"`
	Device string    `json:"device"`
	Time   time.Time `json:"time"`
	Rms    float64   `json:"rms"`
	Major  float64   `json:"major"`
	Minor  float64   `json:"minor"`
	Orient float64   `json:"orient"`
	Lat    float64   `json:"lat"`
	Lon    float64   `json:"lon"`
	Alt    float64   `json:"alt"`
}

GSTReport is pseudorange noise report

type Mode

type Mode byte

Mode describes status of a TPV report

const (
	// NoValueSeen indicates no data has been received yet
	NoValueSeen Mode = 0
	// NoFix indicates fix has not been required yet
	NoFix Mode = 1
	// Mode2D represents quality of the fix
	Mode2D Mode = 2
	// Mode3D represents quality of the fix
	Mode3D Mode = 3
)

type PPSReport

type PPSReport struct {
	Class      string  `json:"class"`
	Device     string  `json:"device"`
	RealSec    float64 `json:"real_sec"`
	RealMusec  float64 `json:"real_musec"`
	ClockSec   float64 `json:"clock_sec"`
	ClockMusec float64 `json:"clock_musec"`
}

PPSReport is triggered on each pulse-per-second strobe from a device

type SKYReport

type SKYReport struct {
	Class      string      `json:"class"`
	Tag        string      `json:"tag"`
	Device     string      `json:"device"`
	Time       time.Time   `json:"time"`
	Xdop       float64     `json:"xdop"`
	Ydop       float64     `json:"ydop"`
	Vdop       float64     `json:"vdop"`
	Tdop       float64     `json:"tdop"`
	Hdop       float64     `json:"hdop"`
	Pdop       float64     `json:"pdop"`
	Gdop       float64     `json:"gdop"`
	Satellites []Satellite `json:"satellites"`
}

SKYReport reports sky view of GPS satellites

type Satellite

type Satellite struct {
	PRN    float64 `json:"PRN"`
	Az     float64 `json:"az"`
	El     float64 `json:"el"`
	Ss     float64 `json:"ss"`
	Used   bool    `json:"used"`
	GnssId float64 `json:"gnssid"`
	SvId   float64 `json:"svid"`
	Health float64 `json:"health"`
}

Satellite describes a location of a GPS satellite

type Session

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

Session represents a connection to gpsd

func Dial

func Dial(address string) (*Session, error)

Dial opens a new connection to GPSD.

func DialTimeout

func DialTimeout(address string, to time.Duration) (*Session, error)

DialTimeout opens a new connection to GPSD with a timeout.

func (*Session) AddFilter

func (s *Session) AddFilter(class string, f Filter)

AddFilter attaches a function which will be called for all GPSD reports with the given class. Callback functions have type Filter.

Example:

gps := gpsd.Init(gpsd.DEFAULT_ADDRESS)
gps.AddFilter("TPV", func (r interface{}) {
  report := r.(*gpsd.TPVReport)
  fmt.Println(report.Time, report.Lat, report.Lon)
})
done := gps.Watch()
<- done

func (*Session) Close added in v1.1.0

func (s *Session) Close() error

Close closes the connection to GPSD

func (*Session) SendCommand

func (s *Session) SendCommand(command string)

SendCommand sends a command to GPSD

func (*Session) Watch

func (s *Session) Watch() (done chan bool)

Watch starts watching GPSD reports in a new goroutine.

Example:

gps := gpsd.Dial(gpsd.DEFAULT_ADDRESS)
done := gpsd.Watch()
<- done

type TOFFReport added in v1.1.0

type TOFFReport struct {
	Class     string  `json:"class"`
	Device    string  `json:"device"`
	RealSec   float64 `json:"real_sec"`
	RealNSec  float64 `json:"real_nsec"`
	ClockSec  float64 `json:"clock_sec"`
	ClockNSec float64 `json:"clock_nsec"`
}

TOFFReport is triggered on each PPS strobe from a device

type TPVReport

type TPVReport struct {
	Class  string    `json:"class"`
	Tag    string    `json:"tag"`
	Device string    `json:"device"`
	Mode   Mode      `json:"mode"`
	Time   time.Time `json:"time"`
	Ept    float64   `json:"ept"`
	Lat    float64   `json:"lat"`
	Lon    float64   `json:"lon"`
	Alt    float64   `json:"alt"`
	Epx    float64   `json:"epx"`
	Epy    float64   `json:"epy"`
	Epv    float64   `json:"epv"`
	Track  float64   `json:"track"`
	Speed  float64   `json:"speed"`
	Climb  float64   `json:"climb"`
	Epd    float64   `json:"epd"`
	Eps    float64   `json:"eps"`
	Epc    float64   `json:"epc"`
	Eph    float64   `json:"eph"`
}

TPVReport is a Time-Position-Velocity report

type VERSIONReport

type VERSIONReport struct {
	Class      string `json:"class"`
	Release    string `json:"release"`
	Rev        string `json:"rev"`
	ProtoMajor int    `json:"proto_major"`
	ProtoMinor int    `json:"proto_minor"`
	Remote     string `json:"remote"`
}

VERSIONReport returns version details of gpsd client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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