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 channem
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);
}
// this channel allows graceful exit
let (exit_tx, mut exit_rx) = sync::broadcast::channel(1);
// subscribe to remote server
let mut handle = client.mount("VALDM", exit_tx).await?;
// listening
loop {
select! {
message = handle.next() => match message {
Some(msg) => {
println!("received RTCM message: {:?}", msg);
},
None => {
println!("End of stream!");
break;
},
},
_ = exit_rx.recv() => {
println!("graceful exit");
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,
exit_tx: BroadcastSender<()>,
) -> Result<NtripHandle, NtripClientError>
pub async fn mount( &mut self, mount: impl ToString, exit_tx: BroadcastSender<()>, ) -> 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 implements Stream to receive messages in real-time.
pub async fn handle_connection( config: &NtripConfig, creds: &NtripCredentials, mount: &str, exit_tx: BroadcastSender<()>, sock: impl AsyncRead + AsyncWrite + Unpin + Send + 'static, ) -> Result<(JoinHandle<()>, UnboundedReceiver<Message>), 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 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