gps

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gps reads a position from gpsd and turns it into a Maidenhead grid square.

gpsd (https://gpsd.io) owns the GPS receiver and shares it with any number of programs over a small TCP protocol: a client sends ?WATCH and receives one JSON object per line. hamstack only ever reads.

Index

Constants

View Source
const DefaultPort = 2948

DefaultPort is the port hamstack's own gpsd service listens on. gpsd's standard port is 2947; using a different one keeps hamstack from fighting a system-wide gpsd that may already be running there.

Variables

View Source
var ErrNoFix = errors.New("the GPS receiver has no fix yet")

ErrNoFix means gpsd answered but the receiver has no position yet.

Functions

func Addr

func Addr(s string) string

Addr completes an address typed by the user: "host" gets gpsd's standard port, ":2948" means this machine, and a bare IPv6 address is bracketed ("::1" becomes "[::1]:2947").

func Describe

func Describe(lat, lon float64) string

Describe is a one-line summary of a position, "46.73240 N, 117.00020 W".

func Grid

func Grid(lat, lon float64, chars int) (string, error)

Grid converts a position to a Maidenhead locator of 4, 6 or 8 characters (EM10, EM10dg, EM10dg54). The locator is truncated, not rounded: that is how grid squares are defined.

Types

type Status

type Status struct {
	Version  string   // gpsd's release
	Devices  []string // receivers gpsd has open (their paths)
	Mode     int      // 0 unknown, 1 no fix, 2 two-dimensional fix, 3 three-dimensional
	HasPos   bool     // Lat and Lon are valid
	Lat, Lon float64
	Alt      float64 // metres, with a 3D fix
	Time     string  // the receiver's UTC time of the fix
	SatsUsed int     // satellites in the solution
	SatsSeen int
	// contains filtered or unexported fields
}

Status is what gpsd reported.

func Query

func Query(ctx context.Context, addr string, needFix bool) (Status, error)

Query connects to gpsd at addr and watches until it has a position, or, when needFix is false, until it has also seen one position report and one satellite report. If the time runs out it returns what it saw so far; the error is ErrNoFix when gpsd was reachable but the receiver had no position.

func (Status) Fix

func (s Status) Fix() bool

Fix reports whether there is a position to use.

func (Status) ModeName

func (s Status) ModeName() string

ModeName describes Mode in words.

Jump to

Keyboard shortcuts

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