gpsutils

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: AGPL-3.0 Imports: 25 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 functions that are used in the gpsrtkserial and gpsrtkpmtk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToVirtualBase

func ConnectToVirtualBase(ntripInfo *NtripInfo,
	logger logging.Logger,
) *bufio.ReadWriter

ConnectToVirtualBase is responsible for establishing a connection to a virtual base station using the NTRIP protocol.

func ContainsGGAMessage

func ContainsGGAMessage(data []byte) bool

ContainsGGAMessage returns true if data contains GGA message.

func GetGGAMessage

func GetGGAMessage(correctionWriter io.ReadWriteCloser, logger logging.Logger) ([]byte, error)

GetGGAMessage checks if a GGA message exists in the buffer and returns it.

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) 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.

func (*CachedData) ReadFix

func (g *CachedData) ReadFix(ctx context.Context) (int, error)

ReadFix returns Fix quality of MovementSensor measurements.

func (*CachedData) ReadSatsInView

func (g *CachedData) ReadSatsInView(ctx context.Context) (int, error)

ReadSatsInView returns the number of satellites in view.

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(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(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     // quantity satellites in view
	SatsInUse  int     // quantity satellites in view

	FixQuality     int
	CompassHeading float64 // true compass heading in degree
	// 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.

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 {
	URL string

	MountPoint         string
	Client             *ntrip.Client
	Stream             io.ReadCloser
	MaxConnectAttempts int
	// 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) 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) 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

Jump to

Keyboard shortcuts

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