gpsutils

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package gpsutils contains GPS-related code shared between multiple components. This file describes data structures used to configure reading from NMEA devices.

Package gpsutils implements a GPS NMEA component. This file contains ways to read data from a PMTK device connected over the I2C bus.

Package gpsutils implements necessary functions to set and return NTRIP information here.

Package gpsutils contains code shared between multiple GPS implementations. This file is about how to interact with a PMTK device (a device which gets data from GPS satellites) connected by a serial port.

Package gpsutils implements necessary functions to set and return NTRIP information here.

Package gpsutils implements functions that are used in the gpsrtkserial and gpsrtkpmtk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasVRSStream added in v0.24.0

func HasVRSStream(sourceTable *Sourcetable, mountPoint string) (bool, error)

HasVRSStream returns the NMEA field associated with the given mountpoint and whether it is a Virtual Reference Station.

Types

type CachedData

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

CachedData allows the use of any MovementSensor chip via a DataReader.

func NewCachedData

func NewCachedData(dev DataReader, logger logging.Logger) *CachedData

NewCachedData creates a new CachedData object.

func (*CachedData) Accuracy

func (g *CachedData) Accuracy(
	ctx context.Context, extra map[string]interface{},
) (*movementsensor.Accuracy, error)

Accuracy returns the accuracy map, hDOP, vDOP, Fixquality and compass heading error.

func (*CachedData) AngularVelocity

func (g *CachedData) AngularVelocity(
	ctx context.Context, extra map[string]interface{},
) (spatialmath.AngularVelocity, error)

AngularVelocity returns the sensor's angular velocity.

func (*CachedData) Close

func (g *CachedData) Close(ctx context.Context) error

Close shuts down the DataReader feeding this struct.

func (*CachedData) CompassHeading

func (g *CachedData) CompassHeading(
	ctx context.Context, extra map[string]interface{},
) (float64, error)

CompassHeading returns the heading, from the range 0->360.

func (*CachedData) GGA added in v0.33.0

func (g *CachedData) GGA() (string, error)

GGA returns the GGA message of the sensor, or an error.

func (*CachedData) GetCommonReadings added in v0.34.0

func (g *CachedData) GetCommonReadings(ctx context.Context) *CommonReadings

GetCommonReadings returns a map including fix value, sats in view and sats in use.

func (*CachedData) LinearAcceleration

func (g *CachedData) LinearAcceleration(
	ctx context.Context, extra map[string]interface{},
) (r3.Vector, error)

LinearAcceleration returns the sensor's linear acceleration.

func (*CachedData) LinearVelocity

func (g *CachedData) LinearVelocity(
	ctx context.Context, extra map[string]interface{},
) (r3.Vector, error)

LinearVelocity returns the sensor's linear velocity. It requires having a compass heading, so we know which direction our speed is in. We assume all of this speed is horizontal, and not in gaining/losing altitude.

func (*CachedData) Orientation

func (g *CachedData) Orientation(
	ctx context.Context, extra map[string]interface{},
) (spatialmath.Orientation, error)

Orientation returns the sensor's orientation.

func (*CachedData) ParseAndUpdate

func (g *CachedData) ParseAndUpdate(line string) error

ParseAndUpdate passes the provided message into the inner NmeaParser object, which parses the NMEA message and updates its state to match.

func (*CachedData) Position

func (g *CachedData) Position(
	ctx context.Context, extra map[string]interface{},
) (*geo.Point, float64, error)

Position returns the position and altitide of the sensor, or an error.

func (*CachedData) Properties

func (g *CachedData) Properties(
	ctx context.Context, extra map[string]interface{},
) (*movementsensor.Properties, error)

Properties returns what movement sensor capabilities we have.

type CommonReadings added in v0.34.0

type CommonReadings struct {
	FixValue   int
	SatsInView int
	SatsInUse  int
}

CommonReadings struct contains the most common values we output in sensor reading.

type DataReader

type DataReader interface {
	Messages() chan string
	Close() error
}

DataReader represents a way to get data from a GPS NMEA device. We can read data from it using the channel in Messages, and we can close the device when we're done.

func NewI2cDataReader

func NewI2cDataReader(
	ctx context.Context,
	config I2CConfig,
	bus buses.I2C,
	logger logging.Logger,
) (DataReader, error)

NewI2cDataReader constructs a new DataReader that gets its NMEA messages over an I2C bus.

func NewSerialDataReader

func NewSerialDataReader(
	ctx context.Context,
	config *SerialConfig,
	logger logging.Logger,
) (DataReader, error)

NewSerialDataReader constructs a new DataReader that gets its NMEA messages over a serial port.

type I2CConfig

type I2CConfig struct {
	I2CBus      string `json:"i2c_bus"`
	I2CAddr     int    `json:"i2c_addr"`
	I2CBaudRate int    `json:"i2c_baud_rate,omitempty"`
}

I2CConfig is used for converting Serial NMEA MovementSensor config attributes.

func (*I2CConfig) Validate

func (cfg *I2CConfig) Validate(path string) error

Validate ensures all parts of the config are valid.

type NmeaParser

type NmeaParser struct {
	Location   *geo.Point
	Alt        float64
	Speed      float64 // ground speed in m per sec
	VDOP       float64 // vertical accuracy
	HDOP       float64 // horizontal accuracy
	SatsInView int     // all satellites visible to the receiver, whether or not they are used for positioning.
	SatsInUse  int     // satellites actively used for positioning and measuring fix type

	FixQuality     int
	CompassHeading float64 // true compass heading in degree

	LastGGAMessage string
	SatsInViewArr  [7]int // this array keeps track of all the sats in view given by each constellation.
	SatsInUseArr   [7]int // this array keeps track of number of sats in use from different constellations.
	// contains filtered or unexported fields
}

NmeaParser struct combines various attributes related to GPS.

func (*NmeaParser) ParseAndUpdate

func (g *NmeaParser) ParseAndUpdate(line string) error

ParseAndUpdate will attempt to parse a line to an NMEA sentence, and if valid, will try to update the given struct with the values for that line. Nothing will be updated if there is not a valid gps fix.

func (*NmeaParser) TalkerToArrIndex added in v0.36.0

func (g *NmeaParser) TalkerToArrIndex(sentence nmea.BaseSentence) int

TalkerToArrIndex looks at the talker id of an NMEA message and converts it to array index. Talker id for constellations are: GPS - GP GL - GLONASS GA - Galileo GB/BG - BeiDou GI - NavIC GN - Multiple constellations GQ - QZSS.

type NtripConfig

type NtripConfig struct {
	NtripURL             string `json:"ntrip_url"`
	NtripConnectAttempts int    `json:"ntrip_connect_attempts,omitempty"`
	NtripMountpoint      string `json:"ntrip_mountpoint,omitempty"`
	NtripUser            string `json:"ntrip_username,omitempty"`
	NtripPass            string `json:"ntrip_password,omitempty"`
}

NtripConfig is used for converting attributes for a correction source.

type NtripInfo

type NtripInfo struct {
	MountPoint string
	// contains filtered or unexported fields
}

NtripInfo contains the information necessary to connect to a mountpoint.

func NewNtripInfo

func NewNtripInfo(cfg *NtripConfig, logger logging.Logger) (*NtripInfo, error)

NewNtripInfo function validates and sets NtripConfig arributes and returns NtripInfo.

func (*NtripInfo) Close added in v0.34.0

func (n *NtripInfo) Close(ctx context.Context) error

Close shuts down all connections to the NTRIP caster.

func (*NtripInfo) Connect

func (n *NtripInfo) Connect(ctx context.Context, logger logging.Logger) error

Connect attempts to initialize a new ntrip client. If we're unable to connect after multiple attempts, we return the last error.

func (*NtripInfo) GetStreamFromMountPoint added in v0.34.0

func (n *NtripInfo) GetStreamFromMountPoint(
	cancelCtx context.Context,
	logger logging.Logger,
) (io.ReadCloser, error)

GetStreamFromMountPoint attempts to connect to the NTRIP stream, store it in n.stream, and return it. We give up and return an error after n.maxConnectAttempts unsuccessful tries.

func (*NtripInfo) ParseSourcetable

func (n *NtripInfo) ParseSourcetable(logger logging.Logger) (*Sourcetable, error)

ParseSourcetable gets the sourcetable and parses it.

type PmtkI2cDataReader

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

PmtkI2cDataReader implements the DataReader interface for a PMTK device by communicating with it over an I2C bus.

func (*PmtkI2cDataReader) Close

func (dr *PmtkI2cDataReader) Close() error

Close is part of the DataReader interface. It shuts everything down.

func (*PmtkI2cDataReader) Messages

func (dr *PmtkI2cDataReader) Messages() chan string

Messages returns the channel of complete NMEA sentences we have read off of the device. It's part of the DataReader interface.

type SerialConfig

type SerialConfig struct {
	SerialPath     string `json:"serial_path"`
	SerialBaudRate int    `json:"serial_baud_rate,omitempty"`

	// TestChan is a fake "serial" path for test use only
	TestChan chan []uint8 `json:"-"`
}

SerialConfig is used for converting Serial NMEA MovementSensor config attributes.

func (*SerialConfig) Validate

func (cfg *SerialConfig) Validate(path string) error

Validate ensures all parts of the config are valid.

type SerialDataReader

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

SerialDataReader implements the DataReader interface (defined in component.go) by interacting with the device over a serial port.

func (*SerialDataReader) Close

func (dr *SerialDataReader) Close() error

Close is part of the DataReader interface. It shuts everything down, including our connection to the serial port.

func (*SerialDataReader) Messages

func (dr *SerialDataReader) Messages() chan string

Messages returns the channel of complete NMEA sentences we have read off of the device. It's part of the DataReader interface.

type Sourcetable

type Sourcetable struct {
	Streams []Stream
}

Sourcetable struct contains the stream.

func (*Sourcetable) HasStream

func (st *Sourcetable) HasStream(mountpoint string) (Stream, bool)

HasStream checks if the sourcetable contains the given mountpoint in it's stream.

type Stream

type Stream struct {
	MP             string   // Datastream mountpoint
	Identifier     string   // Source identifier (most time nearest city)
	Format         string   // Data format of generic type (https://software.rtcm-ntrip.org/wiki/STR#DataFormats)
	FormatDetails  string   // Specifics of data format (https://software.rtcm-ntrip.org/wiki/STR#DataFormats)
	Carrier        int      // Phase information about GNSS correction (https://software.rtcm-ntrip.org/wiki/STR#Carrier)
	NavSystem      []string // Multiple navigation system (https://software.rtcm-ntrip.org/wiki/STR#NavigationSystem)
	Network        string   // Network record in sourcetable (https://software.rtcm-ntrip.org/wiki/NET)
	Country        string   // ISO 3166 country code (https://en.wikipedia.org/wiki/ISO_3166-1)
	Latitude       float32  // Position, Latitude in degree
	Longitude      float32  // Position, Longitude in degree
	Nmea           bool     // Caster requires NMEA input (1) or not (0)
	Solution       int      // Generated by single base (0) or network (1)
	Generator      string   // Generating soft- or hardware
	Compression    string   // Compression algorithm
	Authentication string   // Access protection for data streams None (N), Basic (B) or Digest (D)
	Fee            bool     // User fee for data access: yes (Y) or no (N)
	BitRate        int      // Datarate in bits per second
	Misc           string   // Miscellaneous information
}

Stream contrains a stream record in sourcetable. https://software.rtcm-ntrip.org/wiki/STR

type VRS added in v0.34.0

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

VRS contains the VRS.

func ConnectToVirtualBase

func ConnectToVirtualBase(ctx context.Context, ntripInfo *NtripInfo,
	getGGA func() (string, error), logger logging.Logger,
) (*VRS, error)

ConnectToVirtualBase is responsible for establishing a connection to a virtual base station using the NTRIP protocol with enhanced error handling and retries.

func (*VRS) Close added in v0.34.0

func (vrs *VRS) Close(ctx context.Context) error

Close closes the VRS connection and any other background threads.

func (*VRS) GetReaderWriter added in v0.34.0

func (vrs *VRS) GetReaderWriter() *bufio.ReadWriter

GetReaderWriter gets the readerWriter that wraps the tcp connection for the VRS.

func (*VRS) ReadLine added in v0.34.0

func (vrs *VRS) ReadLine() (string, error)

ReadLine reads a line from the vrs's readerWriter.

func (*VRS) WriteString added in v0.34.0

func (vrs *VRS) WriteString(line string) error

WriteString writes a string to the vrs's readerWriter.

Jump to

Keyboard shortcuts

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