Skip to content

Commit

Permalink
Pair with embedded-base 126 (#41)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jr1221 committed Jun 17, 2024
1 parent 5bb7cae commit a4adc5f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 96 deletions.
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
}
}
}

0 comments on commit a4adc5f

Please sign in to comment.