From 10aed1b930414e95c81f82fa06c5992819cd74fa Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Sun, 26 May 2024 23:16:01 -0400 Subject: [PATCH] Pair with embedded-base 126 (#41) * test * bump * bump * bump * bump * remove format, bump submodule to yaml-restructure - also rerun generate command whenever embedded-base changes * bump yaml-restructure * bump * bump * bump * bump * bump * bump * bump * bump * bump * init bitstream io * bump * bump * bump endianness * cleanup * bump * bump last --- .vscode/settings.json | 6 --- Cargo.lock | 7 ++++ Cargo.toml | 3 +- Embedded-Base | 2 +- build.rs | 2 +- src/data.rs | 88 +------------------------------------------ 6 files changed, 12 insertions(+), 96 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e397228..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "editor.defaultFormatter": "rust-lang.rust-analyzer", - "rust-analyzer.linkedProjects": [ - "./Cargo.toml" - ] -} diff --git a/Cargo.lock b/Cargo.lock index c274e6f..3b51969 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,10 +52,17 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +[[package]] +name = "bitstream-io" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c12d1856e42f0d817a835fe55853957c85c8c8a470114029143d3f12671446e" + [[package]] name = "calypso" version = "0.1.0" dependencies = [ + "bitstream-io", "paho-mqtt", "protobuf", "protobuf-codegen", diff --git a/Cargo.toml b/Cargo.toml index 5fb2ade..e91bacf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ edition = "2021" socketcan = "1.7.0" paho-mqtt = "0.12.3" protobuf-codegen = "3.3.0" -protobuf = "3.3.0" \ No newline at end of file +protobuf = "3.3.0" +bitstream-io = "2.3.0" diff --git a/Embedded-Base b/Embedded-Base index ea4aed7..22b868d 160000 --- a/Embedded-Base +++ b/Embedded-Base @@ -1 +1 @@ -Subproject commit ea4aed794208c1b280f6ce805f7c2a7b805e0cec +Subproject commit 22b868d02c6697e49d91518b4d49a6556b63e803 diff --git a/build.rs b/build.rs index 588a383..3944752 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,7 @@ use std::process::Command; /* Prebuild script */ fn main() { - println!("cargo:rerun-if-env-changed=ALWAYS_RUN"); + println!("cargo:rerun-if-changed=Embedded-Base"); match Command::new("python3").arg("./calypsogen.py").status() { Ok(status) if status.success() => { diff --git a/src/data.rs b/src/data.rs index a63d84f..3c269e7 100644 --- a/src/data.rs +++ b/src/data.rs @@ -45,90 +45,4 @@ impl Data { pub fn to_json(&self) -> String { format!("{{\"value\": {:#?}, \"unit\": \"{}\"}}", self.value, self.unit) } -} - -/** - * Class to contain the data processing functions - */ -pub struct ProcessData {} - -impl ProcessData { - /** - * Computes the twos complement of the given value. - */ - pub fn twos_comp(val: u32, bits: usize) -> i64 { - if (val & (1 << (bits - 1))) != 0 { - (val as i64) - ((1 << bits) as i64) - } else { - val as i64 - } - } - - /** - * Transforms the given data bytes into a value in little endian. - * Little Endian byte order stores low order bytes first. - */ - pub fn little_endian(data_bytes: &[u8], bits: usize) -> u32 { - let mut result: u32 = 0; - for (i, byte) in data_bytes.iter().enumerate() { - result |= (*byte as u32) << (bits * i); - } - result - } - - /** - * Transforms the given data bytes into a value in big endian. - * Big Endian byte order stores low order bytes last. - */ - pub fn big_endian(bytes: &[u8], bits: usize) -> u32 { - let mut result: u32 = 0; - for (i, byte) in bytes.iter().enumerate() { - result |= (*byte as u32) << (bits * (bytes.len() - i - 1)); - } - result - } - - /** - * Decodes the given byte by taking the top four bits after shifting it by the given number of bits. - */ - pub fn half(byte: u8, bits: u8) -> u32 { - (byte >> bits & 15) as u32 - } -} - -/** - * Class to contain the data formatting functions - */ -pub struct FormatData {} - -impl FormatData { - /* Temperatures are divided by 10 for 1 decimal point precision in C */ - pub fn temperature(value: f32) -> f32 { - value / 10.0 - } - - /* Torque values are divided by 10 for one decimal point precision in N-m */ - pub fn torque(value: f32) -> f32 { - value / 10.0 - } - - /* Current values are divided by 10 for one decimal point precision in A */ - pub fn current(value: f32) -> f32 { - value / 10.0 - } - - /* Cell Voltages are recorded on a 10000x multiplier for V, must be divided by 10000 to get accurate number */ - pub fn cell_voltage(value: f32) -> f32 { - value / 10000.0 - } - - /* Acceleration values must be offset by 0.0029 according to datasheet */ - pub fn acceleration(value: f32) -> f32 { - value * 0.0029 - } - - /* High Voltage values are divided by 100 for one decimal point precision in V, high voltage is in regards to average voltage from the accumulator pack */ - pub fn high_voltage(value: f32) -> f32 { - value / 100.0 - } -} +} \ No newline at end of file