Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pair with embedded-base 126 #41

Merged
merged 23 commits into from
May 27, 2024
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

7 changes: 7 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ edition = "2021"
socketcan = "1.7.0"
paho-mqtt = "0.12.3"
protobuf-codegen = "3.3.0"
protobuf = "3.3.0"
protobuf = "3.3.0"
bitstream-io = "2.3.0"
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down
88 changes: 1 addition & 87 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Loading