ntrip_core/lib.rs
1//! # ntrip-core
2//!
3//! An async NTRIP client library for Rust.
4//!
5//! [NTRIP](https://en.wikipedia.org/wiki/Networked_Transport_of_RTCM_via_Internet_Protocol)
6//! (Networked Transport of RTCM via Internet Protocol) is a protocol for
7//! streaming GNSS correction data over the internet. This library provides
8//! a client implementation for receiving RTK corrections from NTRIP casters.
9//!
10//! ## Features
11//!
12//! - **Protocol Support**: NTRIP v1 (ICY) and v2 (HTTP/1.1 chunked)
13//! - **Security**: TLS/HTTPS via rustls (no OpenSSL dependency)
14//! - **Discovery**: Sourcetable retrieval and nearest mountpoint selection
15//! - **Async**: Built on Tokio for efficient async I/O
16//! - **Robust**: Read timeouts, automatic reconnection, and proper error handling
17//!
18//! ## Reconnection Behavior
19//!
20//! By default, [`NtripClient::read_chunk()`] will automatically attempt to reconnect
21//! on timeout or disconnect (up to 3 attempts with 1 second delay). This means the
22//! method may block for longer than the read timeout while reconnecting.
23//!
24//! To disable automatic reconnection, use [`NtripConfig::without_reconnect()`].
25//!
26//! ## TLS Support
27//!
28//! TLS/HTTPS capability is always compiled in via `tokio-rustls` (no OpenSSL dependency).
29//! TLS is **not** used by default - you must explicitly enable it per-connection:
30//!
31//! ```rust,no_run
32//! # use ntrip_core::NtripConfig;
33//! let config = NtripConfig::new("secure-caster.example.com", 443, "MOUNT")
34//! .with_tls(); // Enable TLS for this connection
35//! ```
36//!
37//! ## Quick Start
38//!
39//! ```rust,no_run
40//! use ntrip_core::{NtripClient, NtripConfig};
41//!
42//! #[tokio::main]
43//! async fn main() -> Result<(), ntrip_core::Error> {
44//! let config = NtripConfig::new("rtk2go.com", 2101, "MOUNTPOINT")
45//! .with_credentials("user@example.com", "none");
46//!
47//! let mut client = NtripClient::new(config)?;
48//! client.connect().await?;
49//!
50//! let mut buf = [0u8; 4096];
51//! let n = client.read_chunk(&mut buf).await?;
52//! println!("Received {} bytes of RTCM data", n);
53//! Ok(())
54//! }
55//! ```
56//!
57//! ## Sourcetable Discovery
58//!
59//! ```rust,no_run
60//! use ntrip_core::{NtripClient, NtripConfig};
61//!
62//! # async fn example() -> Result<(), ntrip_core::Error> {
63//! let config = NtripConfig::new("rtk2go.com", 2101, "");
64//! let table = NtripClient::get_sourcetable(&config).await?;
65//!
66//! // Find nearest mountpoint
67//! if let Some((stream, distance_km)) = table.nearest_rtcm_stream(-27.47, 153.02) {
68//! println!("Nearest: {} at {:.1} km", stream.mountpoint, distance_km);
69//! }
70//! # Ok(())
71//! # }
72//! ```
73
74mod client;
75mod config;
76mod error;
77mod gga;
78mod sourcetable;
79mod stream;
80
81// Re-export public API
82pub use client::NtripClient;
83pub use config::{ConnectionConfig, NtripConfig, NtripVersion};
84pub use error::Error;
85pub use gga::GgaSentence;
86pub use sourcetable::{CasterEntry, NetworkEntry, Sourcetable, StreamEntry};