pub struct NtripClient { /* private fields */ }Expand description
NTRIP Client, used to connect to an NTRIP (RTCM) service. When “mounted”, the NtripHandle allows real-time messaging through a Stream channel.
use tokio::select;
use tokio::sync; // broadcast channel
use futures::StreamExt; // real-time channel
use ntrip_client::{
NtripClient,
NtripConfig,
RtcmProvider,
NtripCredentials,
NtripClientError,
};
async fn basic_listener() -> Result<(), anyhow::Error> {
// this network does not require SSL
let config = NtripConfig::from_provider(RtcmProvider::Centipede);
// adapt your credentials to the network
let creds = NtripCredentials::default()
.with_username("centipede")
.with_password("password");
// client definition
let mut client = NtripClient::new(config, creds)
.await?;
// list available mountpoints
let mountpoints = client.list_mounts()
.await?;
for remote in mountpoints.services {
println!("{} - {}", remote.name, remote.details);
}
// subscribe to remote server
let mut handle = client.mount("VALDM").await?;
// listening
loop {
select! {
message = handle.next() => match message {
Some(msg) => {
println!("received RTCM message: {:?}", msg);
},
None => {
println!("End of stream!");
break;
},
},
}
}
Ok(())
}
basic_listener();Implementations§
Source§impl NtripClient
impl NtripClient
pub async fn new( config: NtripConfig, creds: NtripCredentials, ) -> Result<Self, NtripClientError>
Sourcepub async fn list_mounts(&mut self) -> Result<ServerInfo, NtripClientError>
pub async fn list_mounts(&mut self) -> Result<ServerInfo, NtripClientError>
List available mounts on the NTRIP server
Sourcepub async fn mount(
&mut self,
mount: impl ToString,
) -> Result<NtripHandle<UnboundedReceiver<(Message, Vec<u8>)>>, NtripClientError>
pub async fn mount( &mut self, mount: impl ToString, ) -> Result<NtripHandle<UnboundedReceiver<(Message, Vec<u8>)>>, NtripClientError>
‘Mount’ the NtripClient from remote $url/$mount service point. On success, you can then start listening to messages from the server.
§Input
- mount: readable remote mount point (server name)
- exit_tx: BroadcastSender is passed to allow graceful exit on errors
§Output
- NtripHandle which implements Stream to receive messages in real-time.
Sourcepub async fn mount_with_sink(
&mut self,
mount: impl ToString,
ntrip_tx: UnboundedSender<(Message, Vec<u8>)>,
) -> Result<NtripHandle<()>, NtripClientError>
pub async fn mount_with_sink( &mut self, mount: impl ToString, ntrip_tx: UnboundedSender<(Message, Vec<u8>)>, ) -> Result<NtripHandle<()>, NtripClientError>
‘Mount’ the NtripClient from remote $url/$mount service point. On success, you can then start listening to messages from the server.
§Input
- mount: readable remote mount point (server name)
- exit_tx: BroadcastSender is passed to allow graceful exit on errors
§Output
- [NtripHandle<()>] which will route received messages throught the provided channel
pub async fn handle_connection( config: &NtripConfig, creds: &NtripCredentials, mount: &str, ntrip_tx: UnboundedSender<(Message, Vec<u8>)>, exit_tx: BroadcastSender<()>, sock: impl AsyncRead + AsyncWrite + Unpin + Send + 'static, ) -> Result<JoinHandle<()>, NtripClientError>
Auto Trait Implementations§
impl Freeze for NtripClient
impl RefUnwindSafe for NtripClient
impl Send for NtripClient
impl Sync for NtripClient
impl Unpin for NtripClient
impl UnsafeUnpin for NtripClient
impl UnwindSafe for NtripClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more