diff --git a/Cargo.toml b/Cargo.toml index e8da63d..dcf1744 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" description = "Converts SBF to RINEX" [dependencies] +binread = "2.2.0" +bstr = "1.9" +clap = { version = "4.4", features = [] } rinex = "0.15" -thiserror = "1.0" -clap = { version = "4.4.12", features = [] } \ No newline at end of file +thiserror = "1.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e4a2b75..e8073a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ pub fn main() -> Result<(), Error> { .get_matches(); let filepath: String = matches.get_one::("i").unwrap().to_string(); let rinexrec = sbf2rnxrec(filepath); - // write_rnx_file(rinexrec); + //write_rnx_file(rinexrec); Ok(()) } @@ -31,9 +31,8 @@ fn sbf2rnxrec(filepath: String) -> Rinex { //! Build RINEX records and output them as files // For now we read the entire file as bytes before conversion - this uses more memory! - let rrecord: Rinex = Rinex::default(); match std::fs::read(Path::new(&filepath).as_os_str()) { - Ok(bytes) => { process_sbfdata(bytes) } + Ok(bytes) => { sbf::process_sbfdata(bytes) } Err(e) => { if e.kind() == std::io::ErrorKind::NotFound { eprintln!("Please check path {}", &filepath); @@ -46,18 +45,8 @@ fn sbf2rnxrec(filepath: String) -> Rinex { panic!("{}", e); } } - - rrecord } -fn process_sbfdata(bytes: Vec) { - const SBF_SYNC1: u8 = 0x24; /* SBF message header sync field 1 (correspond to $) */ - const SBF_SYNC2: u8 = 0x40; /* SBF message header sync field 2 (correspond to @)*/ - // let's find SBF blocks by their sync bytes - for byte in bytes { - eprintln!("Read byte {}", byte); - } -} fn write_rnx_file(rinexrec: Rinex) { rinexrec.to_file("test.rnx").expect("Error: RINEX writeout failed."); diff --git a/src/sbf.rs b/src/sbf.rs index c1cb0ed..2f1d44e 100644 --- a/src/sbf.rs +++ b/src/sbf.rs @@ -1,4 +1,6 @@ //! Record holding the extracted information from an SBF file, arranged +use bstr::ByteSlice; +use rinex::Rinex; #[derive(Clone, Debug)] pub struct SbfBlockHeader { @@ -21,6 +23,9 @@ pub struct SbfBlock { timestamp: SbfBlockTimestamp, } +pub(crate) const SBF_SYNC1: u8 = 0x24; /* SBF message header sync field 1 (correspond to $) */ +pub(crate) const SBF_SYNC2: u8 = 0x40; /* SBF message header sync field 2 (correspond to @)*/ + // ====== SBF BLOCK DATA ====== // --- Measurement Blocks --- @@ -336,6 +341,17 @@ fn decode_galalm(galalmdata: u8) -> u8 { galalmdata // Placeholder } -fn decode_sbf(sbfdata: u8) -> u8 { - sbfdata // Placeholder +pub(crate) fn process_sbfdata(bytes: Vec) -> Rinex { + // let's find SBF blocks by using their sync bytes + + let pattern: [u8; 2] = [SBF_SYNC1, SBF_SYNC2]; + let result: Vec> = bytes.split_str(&pattern).map(|x| x.to_vec()).collect(); + // now we have a collection of SBF blocks + for block in result { + eprintln!("Read block {:?}", block); + // let crc = ((block[1] as u16) << 8) | block[2] as u16; + // eprintln!("CRC: {}", crc); + } + + Rinex::default() // Placeholder to output right type for now }