Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Oct 8, 2024
1 parent 14dfb41 commit e4732a8
Show file tree
Hide file tree
Showing 22 changed files with 211 additions and 202 deletions.
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ path = "examples/protobuf_demo/src/main.rs"
xcp_server = []

# Feature json enables dependency to serde and serde_json
json = ["dep:serde","dep:serde_json"]
# json = ["dep:serde","dep:serde_json"]
json = []

# Feature a2l_gen to enable automatic registry entries for calibration page structs
auto_reg = ["dep:xcp_type_description_derive","dep:xcp_type_description"]
Expand All @@ -83,7 +84,8 @@ auto_reg = ["dep:xcp_type_description_derive","dep:xcp_type_description"]
# Also needed to build the xcp_client demo application
a2l_reader = ["dep:a2lfile"]

default = ["json","auto_reg","xcp_server"]
#default = ["json","auto_reg","xcp_server"]
default = ["auto_reg","xcp_server"]


[dependencies]
Expand All @@ -109,9 +111,10 @@ env_logger = "0.11.3"
# build-info = "0.0.36"

# A generic serialization/deserialization framework
# Used to handle json parameter files
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
# Used to handle json parameter files (optional)
# Used in point_cloud_demo
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }

# Binary serialization strategies for transforming structs into bytes
# bincode = "1.3.3"
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# xcp_lite
# xcp-lite
XCP for Rust - based on XCPlite

Disclaimer:
This code is in experimental state. There is no release yet.
This is no implementation of XCP in Rust, it is an API for measurement and calibration, which uses the ASAM XCP protocol for communication with a measurement and calibration tool like CANape and ASAM A2L for data description.
Disclaimer: This code is in experimental state. There is no release yet.

xcp-lite is a Rust API for measurement and calibration, which uses the ASAM XCP protocol for communication with a measurement and calibration tool like CANape and ASAM A2L for data description.

This is no complete implementation of XCP in Rust, parts of it are still C/C++ from XCPlite.

Main purpose was to experiment with Rust and to demonstrate some more advanced features of measurement and calibration with CANape:
- Automatic A2L and IDL generation with proc-macros
Expand Down Expand Up @@ -113,7 +115,8 @@ The registration of objects has to be completed, before the A2L file is generate
// Calibration parameter segment
// Each calibration parameter struct defines a MEMORY_SEGMENT in A2L and CANape
// The A2L serializer will create an A2L CHARACTERISTIC for each field.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage {

#[type_description(comment = "Amplitude")]
Expand Down Expand Up @@ -299,18 +302,21 @@ The EPK version string in the A2L file can be set by the application. It resides
- Add sub groups of measurements for event instances
- Improve the pointer provenance checks in XcpEvent
- Add support to describe the application clock domain in rust
- Provide a no-std version and create a embassy example
- Provide a no-std version and create an embassy example
Suggested changes to the XCP standard
- Add GET_ID type to upload (from ECU) binary schemas (.ZIP, .desc), referenced in A2L file
Suggested simplifications and optimizations for the XCP on ETH standard
- Support 64 Bit addresses in SHORT_UPLOAD, SHORT_DONWLOAD and SET_MTA
- Support more than (256-4)/(128-4) ODTs (ODT number as u16), avoid event based queue overload indication
- Add an option for 64 bit transport layer packet alignment
- Add an option to require a 1:1 association from event to daq list to simplify data structures and reduce event runtime
- Support variable length ODT entries for serialized data types
- Support segmented DTOs larger than segment size
- Support 64 Bit addresses
- Support more than (256-4)/(128-4) ODTs to avoid event based queue overload indication
- Add the option to require a 1:1 association from event to daq list to simplify data structures and reduce event runtime
- Make GET_DAQ_CLOCK obsolete (when PTP TAI time is provided), by supporting 64 Bit DAQ timestamps
- Add GET_ID type to upload (from ECU) binary schemas (.ZIP, .desc), referenced in A2L file
- Make GET_DAQ_CLOCK obsolete (when PTP TAI time is provided), by supporting 64 Bit DAQ timestamps
- Remove clock properties legacy mode
Expand Down
4 changes: 2 additions & 2 deletions benches/xcp_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::{
time::Duration,
};

use serde::{Deserialize, Serialize};
use xcp::*;
use xcp_client::xcp_client::*;
use xcp_type_description::prelude::*;
Expand All @@ -28,7 +27,8 @@ use criterion::{criterion_group, criterion_main, Criterion};
//-----------------------------------------------------------------------------
// Calibration parameters

#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage {
#[type_description(comment = "Amplitude value")]
#[type_description(min = "0")]
Expand Down
4 changes: 2 additions & 2 deletions examples/hello_xcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
use log::{debug, error, info, trace, warn};
use std::{fmt::Debug, thread, time::Duration};

use serde::{Deserialize, Serialize};
use xcp::*;
use xcp_type_description::prelude::*;

//-----------------------------------------------------------------------------
// Calibration parameters

#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage {
#[type_description(comment = "Max counter value")]
#[type_description(min = "0")]
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_thread_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{
time::{Duration, Instant},
};

use serde::{Deserialize, Serialize};
use xcp::*;
use xcp_type_description::prelude::*;

Expand All @@ -21,7 +20,8 @@ lazy_static::lazy_static! {
//-----------------------------------------------------------------------------
// Demo calibration parameters

#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage1 {
#[type_description(comment = "Amplitude of the sine signal")]
#[type_description(unit = "Volt")]
Expand Down
9 changes: 4 additions & 5 deletions examples/point_cloud_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use std::{
time::{Duration, Instant},
};

use serde::{Deserialize, Serialize};

//-----------------------------------------------------------------------------
// Defaults

Expand Down Expand Up @@ -39,7 +37,8 @@ lazy_static::lazy_static! {
//-----------------------------------------------------------------------------
// Parameters

#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct Params {
#[type_description(unit = "s")]
#[type_description(min = "0.001")]
Expand Down Expand Up @@ -83,14 +82,14 @@ const PARAMS: Params = Params {

//---------------------------------------------------------------------------------------

#[derive(Debug, Serialize, IdlGenerator)]
#[derive(Debug, serde::Serialize, IdlGenerator)]
struct Point {
x: f32,
y: f32,
z: f32,
}

#[derive(Debug, Serialize, IdlGenerator)]
#[derive(Debug, serde::Serialize, IdlGenerator)]
struct PointCloud {
points: Vec<Point>,
}
Expand Down
5 changes: 2 additions & 3 deletions examples/rayon_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ use num::Complex;
use rayon::prelude::*;
use std::{thread, time::Duration};

use serde::{Deserialize, Serialize};
use xcp::*;

use xcp_type_description::prelude::*;

// Arrays measured may not exeed 2^15
const X_RES: usize = 1024 * 2;
const Y_RES: usize = 768 * 2;

#[derive(Debug, Copy, Clone, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, XcpTypeDescription)]
struct Mandelbrot {
x: f64,
y: f64,
Expand Down
4 changes: 2 additions & 2 deletions examples/scoped_threads/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
use log::{debug, error, info, trace, warn};
use std::{fmt::Debug, thread, time::Duration};

use serde::{Deserialize, Serialize};
use xcp::*;
use xcp_type_description::prelude::*;

//-----------------------------------------------------------------------------

#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage {
#[type_description(comment = "Max counter value")]
#[type_description(min = "0")]
Expand Down
4 changes: 2 additions & 2 deletions examples/single_thread_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use std::{
time::{Duration, Instant},
};

use serde::{Deserialize, Serialize};
use xcp::*;
use xcp_type_description::prelude::*;

//-----------------------------------------------------------------------------
// Demo calibration parameters

// Define a struct with calibration parameters
#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage {
#[type_description(comment = "Amplitude of the sine signal")]
#[type_description(unit = "Volt")]
Expand Down
4 changes: 2 additions & 2 deletions examples/tokio_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use log::{debug, error, info, trace, warn};

use core::f64::consts::PI;
use serde::{Deserialize, Serialize};
use std::error::Error;

use xcp::*;
Expand Down Expand Up @@ -42,7 +41,8 @@ static CAL_PAGE0: once_cell::sync::OnceCell<CalPage0> = once_cell::sync::OnceCel
// Creates a memory segment "CalPage1" with 2 pages, a default "FLASH" page and a mutable "RAM" page

// Define a struct with calibration parameters
#[derive(Debug, Clone, Copy, Serialize, Deserialize, XcpTypeDescription)]
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, XcpTypeDescription)]
struct CalPage1 {
#[type_description(comment = "Amplitude of the sine signal")]
#[type_description(unit = "Volt")]
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg(not(doctest))]
//#![warn(missing_docs)]

//-----------------------------------------------------------------------------
// Crate xcp
// Path: src/lib.rs
Expand Down Expand Up @@ -71,8 +74,6 @@
//!
//!

//#![warn(missing_docs)]

// This crate is a library
#![crate_type = "lib"]
// The library crate is named "xcp"
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static CAL_PAGE0: once_cell::sync::OnceCell<CalPage00> = once_cell::sync::OnceCe
// Each page defines a MEMORY_SEGMENT in A2L and CANape
// A2l addresses are relative to the segment start address, the segment numer is coded in the address

// Implement Serialize, Deserialize for json file persistency
// Implement Serialize, serde::Deserialize for json file persistency
// Implement XcpTypeDescription for auto registration of fields in the A2L registry

//---------------------------------------------------
Expand Down Expand Up @@ -250,7 +250,7 @@ fn task2(task_id: usize, calseg: CalSeg<CalPage>, calseg2: CalSeg<CalPage2>) {
// Create one static event for all instances of this thread, with 8 byte capture buffer
let mut event = daq_create_event!("task2_static", 8);

while RUN.load(Ordering::Acquire) {
while RUN.load(Ordering::Relaxed) {
// Stop task if calibration parameter run2 is false
if !calseg.run2 {
break;
Expand Down Expand Up @@ -308,7 +308,7 @@ fn task1(calseg: CalSeg<CalPage>, calseg1: CalSeg<CalPage1>) {
daq_register!(counter_u64, event, "wrapping counter: u64", "");
daq_register_array!(array1, event);

while RUN.load(Ordering::Acquire) {
while RUN.load(Ordering::Relaxed) {
// Stop task if calibration parameter run1 is false
if !calseg.run1 {
break;
Expand Down Expand Up @@ -428,7 +428,7 @@ fn main() {
xcp_println!("Main task starts");
let mut current_session_status = xcp.get_session_status();
let mut idle_time = 0.0;
while RUN.load(Ordering::Acquire) {
while RUN.load(Ordering::Relaxed) {
// @@@@ Dev: Terminate mainloop for shutdown if calibration parameter run is false, for test automation
if !calseg.run {
break;
Expand Down
Loading

0 comments on commit e4732a8

Please sign in to comment.