Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Oct 16, 2024
1 parent f863db0 commit 8e766ac
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 62 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ cargo.lock
*.TMP
*.cnaxml
RecycleBin.ini
.DS_Store
~CANapeCurrentCfg.tmp
CANapeTmpMea.ini

# Artefacts generated by examples
xcp_test.a2l
xcp_client.a2l
test_single_thread.a2l
test_multi_thread.a2l
Expand All @@ -29,5 +29,3 @@ point_cloud.a2l
xcp_benchmark.a2l
rayon_demo.a2l
mandelbrot.png


1 change: 1 addition & 0 deletions examples/hello_xcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn main() -> Result<()> {
calseg.register_fields();

// Load calibration parameter mutable page from a file if it exists, otherwise initially save the defaults
#[allow(unexpected_cfgs)]
#[cfg(feature = "serde")]
if calseg.load("hello_xcp.json").is_err() {
calseg.save("hello_xcp.json").unwrap();
Expand Down
20 changes: 8 additions & 12 deletions examples/rayon_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn normalize(color: f32, factor: f32) -> u8 {
}

// Function converting intensity values to RGB
fn iterations_to_rgb(i: u32) -> Rgb<u8> {
fn wavelength_to_rgb(i: u32) -> Rgb<u8> {
let wave = i as f32;

let (r, g, b) = match i {
Expand All @@ -71,8 +71,8 @@ fn get_color_mag() -> Vec<Rgb<u8>> {
// Map iterations to colors
let mut color_map = Vec::with_capacity(256);
for i in 0..256 {
let rgb = iterations_to_rgb(785 - i * (800 - 350) / 255);
//let rgb = iterations_to_rgb(i);
let rgb = wavelength_to_rgb(379 + (i * (781 - 379)) / 255);

color_map.push(rgb);
}
color_map
Expand Down Expand Up @@ -134,7 +134,7 @@ fn pixel_to_point(pixel: (usize, usize), upper_left: Complex<f64>, lower_right:
}

/// Render a line of the Mandelbrot set into a buffer of pixels.
fn render(pixels: &mut [u8], row: usize, length: usize, upper_left: Complex<f64>, lower_right: Complex<f64>) {
fn render(pixels: &mut [u8], row: usize, upper_left: Complex<f64>, lower_right: Complex<f64>) {
// Create event for this worker thread and register variable index, which is the upper left corner of the rectangle
let event = daq_create_event_tli!("task");

Expand All @@ -143,18 +143,14 @@ fn render(pixels: &mut [u8], row: usize, length: usize, upper_left: Complex<f64>
event.trigger(); // measure line and timestamp of calculation start

// Render line
// @@@@
for column in 0..length {
for (column, pixel) in pixels.iter_mut().enumerate() {
let point = pixel_to_point((column, row), upper_left, lower_right);
pixels[column] = match mandelbrot(point, 255) {
None => 0,
Some(count) => 255 - count as u8,
};
*pixel = mandelbrot(point, 254).unwrap_or(255) as u8;
}

line = 0; // set to 0 to mark calculation end and measure again to get a timestamp for the end of the calculation
event.trigger();
_ = line; // prevent warning about unused variable
_ = line; // prevent warning about unused variable line
}

//---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -214,7 +210,7 @@ fn main() -> Result<()> {
lines.into_par_iter().for_each(|(y, band)| {
let band_upper_left = pixel_to_point((0, y), upper_left, lower_right);
let band_lower_right = pixel_to_point((X_RES, y + 1), upper_left, lower_right);
render(band, y, X_RES, band_upper_left, band_lower_right);
render(band, y, band_upper_left, band_lower_right);
});

elapsed_time = start_time.elapsed().as_secs_f64();
Expand Down
2 changes: 1 addition & 1 deletion examples/xcp_idl_generator_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ fn main() {
let measurement = Measurement::new();
let description = measurement.description();

let val = GeneratorCollection::generate(&IDL::CDR, &description).unwrap();
let val = GeneratorCollection::generate(&IDL::CDR, description).unwrap();
write_string_to_file("./gen.txt", &val);
}
4 changes: 2 additions & 2 deletions src/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod registry_tests {
let err = reg.write_a2l();
assert!(err.is_err());

std::fs::remove_file("test_registry_2.a2l").unwrap();
std::fs::remove_file("test_registry_2.a2l").ok();
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -241,6 +241,6 @@ mod registry_tests {
}
}

std::fs::remove_file("test_registry_1.a2l").unwrap();
std::fs::remove_file("test_registry_1.a2l").ok();
}
}
2 changes: 1 addition & 1 deletion src/xcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ pub mod xcp_test {
{
let mut r = xcp.registry.lock().unwrap();
r.clear();
r.set_name("xcp_lite");
r.set_name("xcp_test");
r.set_epk("TEST_EPK", Xcp::XCP_EPK_ADDR);
}
xcp.set_ecu_cal_page(XcpCalPage::Ram);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multi_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,5 @@ async fn test_multi_thread() {
info!("Stop XCP server");
xcp.stop_server();

std::fs::remove_file("test_multi_thread.a2l").unwrap();
std::fs::remove_file("test_multi_thread.a2l").ok();
}
2 changes: 1 addition & 1 deletion tests/test_single_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ async fn test_single_thread() {

xcp.stop_server();

std::fs::remove_file("test_single_thread.a2l").unwrap();
std::fs::remove_file("test_single_thread.a2l").ok();
}
}
2 changes: 1 addition & 1 deletion tests/test_tokio_multi_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,5 @@ async fn test_tokio_multi_thread() {
let _ = tokio::join!(t);
}

std::fs::remove_file("test_tokio_multi_thread.a2l").unwrap();
std::fs::remove_file("test_tokio_multi_thread.a2l").ok();
}
10 changes: 7 additions & 3 deletions tests/xcp_test_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,13 @@ pub async fn xcp_test_executor(xcp: &Xcp, test_mode_cal: TestModeCal, test_mode_
let t2 = xcp_client.get_daq_clock().await.unwrap();
let dt12 = (t2 - t1) / 1000;
let dt120 = t20.as_micros() as u64;
info!("t1 = {}ns, t2 = {}ns, dt={}us / elapsed={}us", t1, t2, dt12, dt120);
assert!(dt12 > dt120 - 100, "DAQ clock too slow");
assert!(dt12 < dt120 + 100, "DAQ clock too fast");
let diff = dt120 as i64 - dt12 as i64;
info!("t1 = {}ns, t2 = {}ns, dt={}us / elapsed={}us diff={}", t1, t2, dt12, dt120, diff);
if !(-100..=100).contains(&diff) {
warn!("DAQ clock too inaccurate");
}
assert!(dt12 > dt120 - 400, "DAQ clock too slow");
assert!(dt12 < dt120 + 400, "DAQ clock too fast");

info!("Start data acquisition test");

Expand Down
2 changes: 1 addition & 1 deletion xcp_client/src/xcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ impl XcpClient {
}
self.a2l_file = Some(a2l_file);
if upload {
std::fs::remove_file(file_name)?;
std::fs::remove_file(file_name).ok();
}
} else {
error!("Could not read A2L file {}", file_name.display());
Expand Down
Loading

0 comments on commit 8e766ac

Please sign in to comment.