ntrip_client

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 12 Imported by: ? 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.

README

NTRIP Client

A Go library for connecting to NTRIP (Networked Transport of RTCM via Internet Protocol) casters to stream RTCM correction data.

Features

  • Fetch sourcetables from NTRIP casters
  • Stream RTCM data from mountpoints with context-based cancellation
  • Automatic mountpoint selection based on geographic location
  • In-memory registry for managing casters and stations

Installation

go get github.com/bezineb5/ntrip-client

Usage

Fetch and register mountpoints from a caster
package main

import (
    "context"
    "fmt"

    ntrip_client "github.com/bezineb5/ntrip-client"
    "github.com/bezineb5/ntrip-client/input"
)

func main() {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

    registry := ntrip_client.NewInMemoryRegistry()
    client := input.NewNtripV2Client("http://caster.example.com:2101/")
    source := ntrip_client.NewSource(client)

    if err := source.RegisterMountPoints(ctx, registry); err != nil {
        fmt.Println("Error:", err)
        return
    }
}
Stream RTCM data from a mountpoint
package main

import (
    "context"
    "fmt"
    "io"

    "github.com/bezineb5/ntrip-client/input"
)

func main() {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

    client := input.NewNtripV2MountPointClient("http://caster.example.com:2101/MNT001")
    ch, err := client.Stream(ctx)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }

    for data := range ch {
        // Process RTCM data
        fmt.Printf("Received %d bytes\n", len(data))
    }
}
Automatic mountpoint selection based on location
package main

import (
    "context"
    "fmt"

    ntrip_client "github.com/bezineb5/ntrip-client"
    "github.com/bezineb5/ntrip-client/input"
)

func main() {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

    registry := ntrip_client.NewInMemoryRegistry()
    client := input.NewNtripV2Client("http://caster.example.com:2101/")
    source := ntrip_client.NewSource(client)

    if err := source.RegisterMountPoints(ctx, registry); err != nil {
        fmt.Println("Error:", err)
        return
    }

    selector := ntrip_client.NewRegistrySelector(registry, 0.01)

    // Set location (lat, lng in degrees)
    if err := selector.SetLocation(48.8566, 2.3522); err != nil {
        fmt.Println("Error:", err)
        return
    }

    // Stream from nearest mountpoint
    ch, err := selector.Stream(ctx)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }

    for data := range ch {
        fmt.Printf("Received %d bytes\n", len(data))
    }
}

Example

A complete working example is available in example/main.go.

License

MIT

Documentation

Index

Constants

View Source
const (
	MaximumDistanceToBaseInM = 100 * 1000
)
View Source
const (
	SIGNIFICANT_CHANGE = 0.01 // Number of degrees of latitude or longitude that is considered significant for a location change (so it does not trigger a new mountpoint selection)
)

Variables

This section is empty.

Functions

func Distance32

func Distance32(latA float32, lngA float32, latB float32, lngB float32) float32

DistanceTo computes the distance in meters between 2 points It uses the Haversine formula: https://www.movable-type.co.uk/scripts/latlong.html

func MetersToDegrees32

func MetersToDegrees32(lengthInM float32, radius float32) float32

func MetersToLatitudeAngle

func MetersToLatitudeAngle(lengthInM float32) float32

func MetersToLongitudeAngleAtLatitude

func MetersToLongitudeAngleAtLatitude(lengthInM float32, latitude float32) float32

Types

type CasterSource

type CasterSource interface {
	RegisterMountPoints(ctx context.Context, registry Registry) error
}

func NewSource

func NewSource(input input.SourceTableInput) CasterSource

type Registry

type Registry interface {
	RegisterCaster(url string, details ntrip.CasterEntry) error
	RegisterStation(url string, details ntrip.StreamEntry) error
	NearestStations(lat float32, lng float32) (distances []StationDistance, err error)
}

func NewInMemoryRegistry

func NewInMemoryRegistry() Registry

type Selector

type Selector interface {
	Stream(ctx context.Context) (<-chan []byte, error)
	SetLocation(lat float32, lng float32) error
	Invalidate() error
}

func NewRegistrySelector

func NewRegistrySelector(registry Registry, significantChange float32) Selector

type StationDistance

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

type StationsRegistry

type StationsRegistry interface {
	Register(source CasterSource, mountpoint string, lat float32, lng float32)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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