ntrip

package
v0.0.0-...-3bbae6e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

README

ntrip client

with functions for

  • parsing the caster sourcetable
  • checking if caster is alive
  • ...

Connecting to the caster is done by HTTP only, i.e. no UDP, RTSP etc.

Examples

package main

import (
	"log"

	"github.com/de-bkg/gognss/ntrip"
)

func main() {
    casterAddr := "http://www.igs-ip.net:2101"
    c, err := ntrip.NewClient(casterAddr, Options{})
	if err != nil {
		log.Fatal(err)
	}
    defer c.CloseIdleConnections()

    if !c.IsCasterAlive() {
        log.Printf("caster %s seems to be down", casterAddr)
    }
    
    st, err := c.ParseSourcetable()
    if err != nil {
		log.Printf(err)
    }

}

Documentation

Overview

Package ntrip provides functions for the Ntrip protocol

The HTTP-based NtripClient to NtripCaster communication is fully compatible to HTTP 1.1, but in this context Ntrip uses only non-persistent connections.

A loss of the TCP connection between communicating system-components (NtripClient to NtripCaster, NtripServer to NtripCaster) will be automatically recognized by the TCPsockets. This effect can be used to trigger software events such as an automated reconnection.

The chunked transfer encoding is used to transfer a series of chunks, each with its own size information. This allows the transfer of streaming data together with information to verify the completeness of transfer. Every NTRIP 2.0 component must be able to handle this transfer encoding. The basic idea is to send the size of the following data block before the block itself as hexadecimal number.

The net/http package automatically uses chunked encoding for request bodies when the content length is not known and the application did not explicitly set the transfer encoding to "identity".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caster

type Caster struct {
	Host         string  // host name or IP address
	Port         int     // numeric port number
	Identifier   string  // Name of Caster or Caster provider
	Operator     string  // Name of institution or company operating the caster
	Nmea         bool    // Caster accepts NMEA input (1, true) or not (0)
	Country      string  // 3 char ISO 3166 country code
	Lat, Lon     float32 // Position, Latitude and Longitude in degree
	FallbackHost string  // Fallback Caster Internet address
	FallbackPort int     // Fallback Caster Port number
	Misc         string  // Miscellaneous information
}

Caster specifies a sourcetable record for a caster. See http://software.rtcm-ntrip.org/wiki/CAS.

type CasterConn

type CasterConn struct {
	MP           string
	Type         string
	ID           int
	UserAgent    string
	IP           string
	User         string
	ConnectedFor time.Duration
}

CasterConn defines a clients connection to the caster.

type CasterListener

type CasterListener struct {
	Host         string        `json:"host"`
	IP           string        `json:"ip"`
	User         string        `json:"username"`
	MP           string        `json:"mountpoint"`
	ID           int           `json:"id"`
	ConnectedFor time.Duration `json:"connected_for"`
	BytesWritten int           `json:"bytes_written"`
	Errors       int           `json:"errors"`
	UserAgent    string        `json:"user_agent"`
	Type         string        `json:"type"`
}

CasterListener contains the information about an connected listener/client like IP, user agent etc.

type CasterSource

type CasterSource struct {
	Host, IP                  string
	MP                        string
	ID                        int
	Agent                     string
	ConnectedFor              time.Duration
	ConnectionTime            time.Time
	Clients                   int
	ClientConnections         int
	KBytesRead, KBytesWritten int
}

CasterSource contains information about an active data stream.

type CasterStats

type CasterStats struct {
	Admins     int           `json:"admins"`
	Sources    int           `json:"sources"`
	Listeners  int           `json:"listeners"`
	Uptime     time.Duration `json:"uptime"`
	LastResync time.Time     `json:"last_resync"`

	// Following fields since last resync
	KBytesRead    int `json:"KBytes_recv"`
	KBytesWritten int `json:"KBytes_sent"`
}

CasterStats contains general statistics like number of clients, sources etc.

type Client

type Client struct {
	*http.Client
	URL       *url.URL // // URL specifies the URL to access, for client requests.
	Username  string
	Password  string
	Useragent string
	// contains filtered or unexported fields
}

Client is a caster client for http connections. The http.Client's Transport typically has internal state (cached TCP connections), so Clients should be reused instead of created as needed. Clients are safe for concurrent use by multiple goroutines.

func NewClient

func NewClient(addr string, opts Options) (*Client, error)

NewClient returns a new Ntrip Client with the given caster address and additional options. The caster addr should have the form "http://host:port". It uses HTTP proxies as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy) environment variables.

func (*Client) GetConnections

func (c *Client) GetConnections() ([]CasterConn, error)

GetConnections fetches the current client connections.

func (*Client) GetListeners

func (c *Client) GetListeners() ([]CasterListener, error)

GetListeners fetches the currently connected listeners.

func (*Client) GetSources

func (c *Client) GetSources() ([]CasterSource, error)

GetSources fetches the current sources.

func (*Client) GetSourcetable

func (c *Client) GetSourcetable() (io.ReadCloser, error)

GetSourcetable downloads the sourcetable and returns the contents.

func (*Client) GetStats

func (c *Client) GetStats() (*CasterStats, error)

GetStats requests some general statistics from the caster like number of clients, connections etc.

func (*Client) GetStream

func (c *Client) GetStream(mp string) (io.ReadCloser, error)

GetStream requests a GNSS stream from the NtripCaster.

func (*Client) IsCasterAlive

func (c *Client) IsCasterAlive() bool

IsCasterAlive checks whether the caster is alive. This is done by checking if the caster responds with its sourcetable.

func (*Client) KickConnection

func (c *Client) KickConnection(id int) error

KickConnection stops an active client connection.

func (*Client) ParseSourcetable

func (c *Client) ParseSourcetable() (*Sourcetable, error)

ParseSourcetable downloads the sourcetable and parses its contents.

func (*Client) Reconnect

func (c *Client) Reconnect() (io.ReadCloser, error)

Reconnect tries to reconnect to the caster.

type Network

type Network struct {
	Identifier string //  Network Identifier
	Operator   string //  Name of institution or company operating the network
	Auth       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)
	WebNet     string // URL, Web address for network information
	WebStream  string // URL, Web address for stream information
	WebReg     string // URL or e-mail, Web or mail address for registration
	Misc       string // Miscellaneous information
}

Network specifies a sourcetable record for a network. See http://software.rtcm-ntrip.org/wiki/NET.

type Options

type Options struct {
	// Username is the Caster username
	Username string

	// Password is the Caster password
	Password string

	// UserAgent is the http User Agent, defaults to "InfluxDBClient".
	// For accessing the (BKG) casters websites (not sourcetable), it must not contain "NTRIP",
	// for accesing a stream, it MUST contain "NTRIP"
	UserAgent string

	// Timeout for GET requests in seconds. Defaults to 5 seconds.
	Timeout int

	// UnsafeSSL gets passed to the http client, if true, it will skip https certificate verification.
	// Defaults to false.
	UnsafeSSL bool

	// TLSConfig allows the user to set their own TLS config for the HTTP
	// Client. If set, this option overrides UnsafeSSL.
	TLSConfig *tls.Config
}

Options provides additional information for connecting to a Ntripcaster.

type Sourcetable

type Sourcetable struct {
	Casters  []Caster
	Networks []Network
	Streams  []Stream
}

Sourcetable holds the streams from an NtripCasters' sourcetable.

func MergeSourcetables

func MergeSourcetables(stables ...*Sourcetable) (*Sourcetable, error)

MergeSourcetables merges several sourcetables to a single combined sourcetable where every stream record appears once.

func (*Sourcetable) HasStream

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

HasStream checks if the sourcetable contains the specified stream/mountpoint. The first returned value is the Stream, the second value is boolean typed and will be true if the mountpont was found and otherwise false.

func (*Sourcetable) Write

func (st *Sourcetable) Write(w io.Writer) error

Write writes a RTCM formated sourcetable to the specified writer.

type Stream

type Stream struct {
	MP            string   // datastream mountpoint name
	Identifier    string   // Source identifier (most time nearest city)
	Format        string   //  Data format (see http://software.rtcm-ntrip.org/wiki/STR)
	FormatDetails string   // Specifics of data format (see http://software.rtcm-ntrip.org/wiki/STR)
	Carrier       int      // Phase information (see http://software.rtcm-ntrip.org/wiki/STR)
	SatSystem     []string // satellite navigation system (see http://software.rtcm-ntrip.org/wiki/STR)
	Network       string   // network name (Network.Identifier)
	Country       string   // 3 char ISO 3166 country code
	Lat, Lon      float32  // Position, Latitude and Longitude in degree
	Nmea          bool     // Caster accepts NMEA input (1, true) or not (0)
	Solution      int      // Generated by single base (0) or network (1)
	Generator     string   // Generating soft- or hardware
	Compression   string   // Compression algorithm
	Auth          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 specifies a sourcetable record for a stream. See http://software.rtcm-ntrip.org/wiki/STR.

Jump to

Keyboard shortcuts

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