Skip to content

Commit

Permalink
Split f-xoss crate into two crates
Browse files Browse the repository at this point in the history
  • Loading branch information
DCNick3 committed Jun 9, 2023
1 parent bcf10cd commit 3ee8815
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 75 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 5 additions & 58 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,62 +1,9 @@
[package]
name = "f-xoss"
version = "0.1.0"
edition = "2021"
repository = "https://github.com/DCNick3/f-xoss.git"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
btleplug = "0.10.5"
uuid = "1.3.2"
itertools = "0.10.5"

hex = "0.4.3"
binrw = "0.11.1"
num_enum = "0.6.1"
thiserror = "1.0.40"
humansize = "2.1.3"
indicatif = "0.17.3"
directories = "5.0.1"
clap = { version = "4.2.7", features = ["derive"] }
clap_complete = "4.2.3"
prettytable-rs = "0.10.0"
dialoguer = "0.10.4"
console = "0.15.7"
owo-colors = "3.5.0"
similar = "2.2.1"

crc16 = "0.4.0"
once_cell = "1.17.1"
chrono = "0.4.24"
camino = "1.1.4"

serde = "1.0.163"
serde_repr = "0.1"
serde_tuple = "0.5.0"
serde_json = "1.0.96"
toml = "0.7.3"

tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread", "io-util", "fs"] }
tokio-stream = "0.1.14"
tokio-util = { version = "0.7.8", features = ["io"] }
futures-util = "0.3.28"
bytes = "1.4.0"
async-stream = "0.3.5"
async-trait = "0.1.68"
surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls", "middleware-logger"] }

anyhow = "1.0.71"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-futures = { version = "0.2.5", features = ["futures-03"] }
tracing-indicatif = "0.3.4"

[target.'cfg(target_os = "windows")'.dependencies]
ansi_term = "0.12.1"

[target.'cfg(target_os = "linux")'.dependencies]
dbus = { version = "0.9.7", features = ["vendored"] }
[workspace]
members = [
"crates/f-xoss",
"crates/f-xoss-util",
]

# The profile that 'cargo dist' will build with
[profile.dist]
Expand Down
60 changes: 60 additions & 0 deletions crates/f-xoss-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "f-xoss-util"
version = "0.1.0"
edition = "2021"
repository = "https://github.com/DCNick3/f-xoss.git"


[dependencies]
f-xoss = { path = "../f-xoss" }

btleplug = "0.10.5"
uuid = "1.3.2"
itertools = "0.10.5"

hex = "0.4.3"
binrw = "0.11.1"
num_enum = "0.6.1"
thiserror = "1.0.40"
humansize = "2.1.3"
indicatif = "0.17.3"
directories = "5.0.1"
clap = { version = "4.2.7", features = ["derive"] }
clap_complete = "4.2.3"
prettytable-rs = "0.10.0"
dialoguer = "0.10.4"
console = "0.15.7"
owo-colors = "3.5.0"
similar = "2.2.1"

crc16 = "0.4.0"
once_cell = "1.17.1"
chrono = "0.4.24"
camino = "1.1.4"

serde = "1.0.163"
serde_repr = "0.1"
serde_tuple = "0.5.0"
serde_json = "1.0.96"
toml = "0.7.3"

tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread", "io-util", "fs"] }
tokio-stream = "0.1.14"
tokio-util = { version = "0.7.8", features = ["io"] }
futures-util = "0.3.28"
bytes = "1.4.0"
async-stream = "0.3.5"
async-trait = "0.1.68"
surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls", "middleware-logger"] }

anyhow = "1.0.71"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-futures = { version = "0.2.5", features = ["futures-03"] }
tracing-indicatif = "0.3.4"

[target.'cfg(target_os = "windows")'.dependencies]
ansi_term = "0.12.1"

[target.'cfg(target_os = "linux")'.dependencies]
dbus = { version = "0.9.7", features = ["vendored"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 3 additions & 11 deletions src/bin/f-xoss-util/mga/mod.rs → crates/f-xoss-util/src/mga.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod parse;

use crate::cli::MgaUpdateOptions;
use crate::config::MgaConfig;
use anyhow::{anyhow, Context, Result};
use chrono::NaiveDate;
use f_xoss::mga::{parse_mga_data, MgaData};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use surf::{StatusCode, Url};
Expand All @@ -14,12 +12,6 @@ fn mga_file_path() -> PathBuf {
crate::config::APP_DIRS.cache_dir().join("mgaoffline.ubx")
}

pub struct MgaData {
pub data: Vec<u8>,
pub valid_since: NaiveDate,
pub valid_until: NaiveDate,
}

#[derive(Serialize, Deserialize, Debug)]
struct ErrorResponse {
pub message: String,
Expand Down Expand Up @@ -102,7 +94,7 @@ async fn download_mga_data(config: &MgaConfig) -> Result<MgaData, Error> {
.map_err(|err| anyhow!(err))
.context("Failed to read MGA data")?;

Ok(parse::parse_mga_data(raw_data).context("Parsing downloaded MGA data")?)
Ok(parse_mga_data(raw_data).context("Parsing downloaded MGA data")?)
}

async fn get_current_mga_data() -> Result<Option<MgaData>> {
Expand All @@ -111,7 +103,7 @@ async fn get_current_mga_data() -> Result<Option<MgaData>> {
async {
match tokio::fs::read(&path).await {
Ok(data) => {
let data = parse::parse_mga_data(data).context("Parsing cached MGA data")?;
let data = parse_mga_data(data).context("Parsing cached MGA data")?;
Ok::<_, anyhow::Error>(Some(data))
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
Expand Down
40 changes: 40 additions & 0 deletions crates/f-xoss/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "f-xoss"
version = "0.1.0"
edition = "2021"
repository = "https://github.com/DCNick3/f-xoss.git"


[dependencies]
btleplug = "0.10.5"
uuid = "1.3.2"

hex = "0.4.3"
binrw = "0.11.1"
num_enum = "0.6.1"
thiserror = "1.0.40"
humansize = "2.1.3"
indicatif = "0.17.3"

crc16 = "0.4.0"
chrono = "0.4.24"

serde = "1.0.163"
serde_repr = "0.1"
serde_tuple = "0.5.0"
serde_json = "1.0.96"

tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread", "io-util", "fs"] }
tokio-stream = "0.1.14"
tokio-util = { version = "0.7.8", features = ["io"] }
futures-util = "0.3.28"
bytes = "1.4.0"
async-stream = "0.3.5"
async-trait = "0.1.68"
surf = { version = "2.3.2", default-features = false }

anyhow = "1.0.71"
tracing = "0.1.37"
#tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-futures = { version = "0.2.5", features = ["futures-03"] }
tracing-indicatif = "0.3.4"
File renamed without changes.
1 change: 1 addition & 0 deletions src/lib.rs → crates/f-xoss/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod device;
pub mod mga;
pub mod model;
pub mod transport;
16 changes: 10 additions & 6 deletions src/bin/f-xoss-util/mga/parse.rs → crates/f-xoss/src/mga.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use anyhow::Result;
use binrw::{BinRead, BinReaderExt};
use binrw::{BinRead, BinReaderExt, BinResult};
use chrono::NaiveDate;

use super::MgaData;
pub struct MgaData {
pub data: Vec<u8>,
pub valid_since: NaiveDate,
pub valid_until: NaiveDate,
}

#[derive(BinRead)]
#[br(magic = b"\xb5\x62\x13\x20\x4c\x00\x00\x00")]
Expand All @@ -20,15 +24,15 @@ struct UbxMgaAno {
}

impl UbxMgaAno {
pub fn date(&self) -> chrono::NaiveDate {
pub fn date(&self) -> NaiveDate {
let year = 2000 + self.year as i32;
let month = self.month as u32;
let day = self.day as u32;
chrono::NaiveDate::from_ymd_opt(year, month, day).unwrap()
NaiveDate::from_ymd_opt(year, month, day).unwrap()
}
}

pub fn parse_mga_data(data: Vec<u8>) -> Result<MgaData> {
pub fn parse_mga_data(data: Vec<u8>) -> BinResult<MgaData> {
let mut cursor = std::io::Cursor::new(&data);
let mut items = Vec::new();
while cursor.position() < cursor.get_ref().len() as u64 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3ee8815

Please sign in to comment.