Skip to content

Commit

Permalink
might switch to Binread
Browse files Browse the repository at this point in the history
  • Loading branch information
larsnaesbye committed Jan 5, 2024
1 parent abaab08 commit 6495fce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [] }
thiserror = "1.0"
15 changes: 2 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ pub fn main() -> Result<(), Error> {
.get_matches();
let filepath: String = matches.get_one::<String>("i").unwrap().to_string();
let rinexrec = sbf2rnxrec(filepath);
// write_rnx_file(rinexrec);
//write_rnx_file(rinexrec);
Ok(())
}

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);
Expand All @@ -46,18 +45,8 @@ fn sbf2rnxrec(filepath: String) -> Rinex {
panic!("{}", e);
}
}

rrecord
}

fn process_sbfdata(bytes: Vec<u8>) {
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.");
Expand Down
20 changes: 18 additions & 2 deletions src/sbf.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 ---
Expand Down Expand Up @@ -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<u8>) -> Rinex {
// let's find SBF blocks by using their sync bytes

let pattern: [u8; 2] = [SBF_SYNC1, SBF_SYNC2];
let result: Vec<Vec<u8>> = 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
}

0 comments on commit 6495fce

Please sign in to comment.