-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ntrip client [main branch] [CPP-952] (#1088)
Ports NTRIP client support to the main branch: #1033
- Loading branch information
1 parent
5fc0bb4
commit 1aebe7b
Showing
31 changed files
with
1,081 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
"console_backend/tests/data/*" filter=lfs diff=lfs merge=lfs -text | ||
installers/Windows/NSIS/*.zip filter=lfs diff=lfs merge=lfs -text | ||
binaries/** filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use crate::tabs::advanced_tab::ntrip_tab::OutputType; | ||
use crate::types::Result; | ||
use crate::utils::pythonhome_dir; | ||
use anyhow::Context; | ||
use crossbeam::channel::Receiver; | ||
use log::{error, info}; | ||
use std::io::Write; | ||
use std::process::{Command, Stdio}; | ||
use std::{io, thread}; | ||
|
||
pub struct MessageConverter { | ||
in_rx: Receiver<Vec<u8>>, | ||
output_type: OutputType, | ||
} | ||
|
||
impl MessageConverter { | ||
pub fn new(in_rx: Receiver<Vec<u8>>, output_type: OutputType) -> Self { | ||
Self { in_rx, output_type } | ||
} | ||
|
||
pub fn start<W: Write + Send + 'static>(&mut self, out: W) -> Result<()> { | ||
match self.output_type { | ||
OutputType::RTCM => self.output_rtcm(out), | ||
OutputType::SBP => self.output_sbp(out), | ||
} | ||
} | ||
|
||
/// Just redirects directly to writer | ||
fn output_rtcm<W: Write + Send + 'static>(&mut self, mut out: W) -> Result<()> { | ||
let in_rx = self.in_rx.clone(); | ||
thread::spawn(move || loop { | ||
if let Ok(data) = in_rx.recv() { | ||
if let Err(e) = out.write(&data) { | ||
error!("failed to write to device {e}"); | ||
} | ||
} | ||
}); | ||
Ok(()) | ||
} | ||
|
||
/// Runs rtcm3tosbp converter | ||
fn output_sbp<W: Write + Send + 'static>(&mut self, mut out: W) -> Result<()> { | ||
let mut child = if cfg!(target_os = "windows") { | ||
let mut cmd = Command::new("cmd"); | ||
let rtcm = pythonhome_dir()? | ||
.join("binaries") | ||
.join("windows") | ||
.join("rtcm3tosbp.exe") | ||
.to_string_lossy() | ||
.to_string(); | ||
info!("running rtcm3tosbp from \"{}\"", rtcm); | ||
cmd.args(["/C", &rtcm]); | ||
cmd | ||
} else if cfg!(target_os = "macos") { | ||
let mut cmd = Command::new("sh"); | ||
let rtcm = pythonhome_dir()? | ||
.join("binaries") | ||
.join("mac") | ||
.join("rtcm3tosbp") | ||
.to_string_lossy() | ||
.to_string(); | ||
info!("running rtcm3tosbp from \"{}\"", rtcm); | ||
cmd.args(["-c", &rtcm]); | ||
cmd | ||
} else { | ||
let mut cmd = Command::new("sh"); | ||
let rtcm = pythonhome_dir()? | ||
.join("binaries") | ||
.join("linux") | ||
.join("rtcm3tosbp") | ||
.to_string_lossy() | ||
.to_string(); | ||
info!("running rtcm3tosbp from \"{}\"", rtcm); | ||
cmd.args(["-c", &rtcm]); | ||
cmd | ||
}; | ||
let mut child = child | ||
.stdin(Stdio::piped()) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::null()) | ||
.spawn() | ||
.context("rtcm converter process failed")?; | ||
|
||
let mut child_in = child.stdin.take().context("rtcm3tosbp stdin missing")?; | ||
let mut child_out = child.stdout.take().context("rtcm3tosbp stdout missing")?; | ||
let in_rx = self.in_rx.clone(); | ||
|
||
thread::spawn(move || { | ||
if let Err(e) = io::copy(&mut child_out, &mut out) { | ||
error!("failed to write to device {e}"); | ||
} | ||
}); | ||
thread::spawn(move || { | ||
while let Ok(data) = in_rx.recv() { | ||
if let Err(e) = child_in.write_all(&data) { | ||
error!("failed to write to rtcm3tosbp {e}") | ||
} | ||
} | ||
}); | ||
thread::spawn(move || child.wait()); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.