Skip to content

Commit 5e8ba00

Browse files
committed
Feature renamed to a2l_reader
1 parent a6f9a01 commit 5e8ba00

File tree

10 files changed

+39
-51
lines changed

10 files changed

+39
-51
lines changed

Cargo.toml

+7-6
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ json = ["dep:serde","dep:serde_json"]
7979
# Feature a2l_gen to enable automatic registry entries for calibration page structs
8080
auto_reg = ["dep:xcp_type_description_derive","dep:xcp_type_description"]
8181

82-
# Feature a2l_gen to enable automatic registry entries for calibration page structs
83-
check_a2l = ["dep:a2lfile"]
82+
# Feature a2l_reader to enable automatic check of the generated A2L file
83+
# Also needed to build the xcp_client demo application
84+
a2l_reader = ["dep:a2lfile"]
8485

8586
default = ["json","auto_reg","xcp_server"]
8687

@@ -134,11 +135,13 @@ xcp_idl_generator_derive = { path = "./xcp_idl_generator/xcp_idl_generator_deri
134135
# A2L reader
135136
a2lfile = { version="2.2.0", optional = true}
136137

138+
139+
137140
[dev-dependencies]
138141

139-
# used to implement the integration test XCP client and A2L parser
142+
# XCP test client
140143
tokio = { version = "1.37.0", features = ["full"] }
141-
144+
a2lfile = "2.2.0"
142145
bytes = "1.6.0"
143146
xcp_client = { path = "xcp_client" }
144147

@@ -158,8 +161,6 @@ build-info-build = "0.0.36"
158161
# generate interface to XCPlite
159162
bindgen = "0.69.4"
160163

161-
# A2L reader
162-
a2lfile = "2.2.0"
163164

164165
[profile.dev.package."*"]
165166
debug = false

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ Run a specific example:
250250
251251
Tests may not run in parallel, as the XCP implementation is a singleton.
252252
Feature json and auto_reg must be enabled for testing. (Currently default)
253-
Feature check_a2l enabled automatic check of generated A2L file with crate a2lfile
253+
Feature a2l_reader enabled automatic check of generated A2L file with crate a2lfile
254254
255255
256256
```
257257

258-
cargo test --features=json --features=auto_reg --features=check_a2l -- --test-threads=1 --nocapture
259-
cargo test --features=json --features=auto_reg --features=check_a2l -- --test-threads=1 --nocapture --test test_tokio_multi_thread
258+
cargo test --features=json --features=auto_reg --features=a2l_reader -- --test-threads=1 --nocapture
259+
cargo test --features=json --features=auto_reg --features=a2l_reader -- --test-threads=1 --nocapture --test test_tokio_multi_thread
260260

261261
```
262262

src/cal.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ where
4848
{
4949
fn load_from_file(name: &str) -> Result<Self, std::io::Error>;
5050

51-
fn save_to_file(&self, name: &str);
51+
fn save_to_file(&self, name: &str) -> Result<(), std::io::Error>;
5252

5353
fn register_fields(&self, calseg_name: &'static str);
5454
}
@@ -79,12 +79,13 @@ where
7979
Ok(page)
8080
}
8181

82-
fn save_to_file(&self, name: &str) {
82+
fn save_to_file(&self, name: &str) -> Result<(), std::io::Error> {
8383
info!("Save parameter file {}", name);
84-
let file = std::fs::File::create(name).unwrap();
84+
let file = std::fs::File::create(name)?;
8585
let mut writer = std::io::BufWriter::new(file);
86-
let s = serde_json::to_string(self).unwrap();
87-
std::io::Write::write_all(&mut writer, s.as_ref()).unwrap();
86+
let s = serde_json::to_string(self).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("serde_json::to_string failed: {}", e)))?;
87+
std::io::Write::write_all(&mut writer, s.as_ref())?;
88+
Ok(())
8889
}
8990

9091
fn register_fields(&self, calseg_name: &'static str) {

src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ macro_rules! daq_register_static {
118118
}};
119119
}
120120

121-
//
122-
// ( $cell:ident.$field:ident ) => {{
123-
// let name = format!("{}.{}", stringify!($cell), stringify!($field));
124-
// let datatype = unsafe { $cell.$field.get_type() };
125-
// let addr = unsafe { &($cell.$field) as *const _ as u64 };
126-
// let c = RegistryCharacteristic::new(None, name.to_string(), datatype, "", datatype.get_min(), datatype.get_max(), "", 1, 1, addr);
127-
// Xcp::get().get_registry().lock().unwrap().add_characteristic(c);
128-
// }};
129-
130121
//-----------------------------------------------------------------------------
131122
// XCP println macro
132123

src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ fn main() {
354354
// Initialize XCP driver singleton, the transport layer server and enable the A2L writer
355355
let xcp = XcpBuilder::new("xcp_lite")
356356
.set_log_level(log_level)
357-
// .set_segment_size(1500-20-8) // no jumbo frames
358357
// .set_epk(build_info::format!("{}", $.timestamp)); // Create new EPK from build info
359358
.set_epk("EPK_")
360359
.start_server(if args.tcp { XcpTransportLayer::Tcp } else { XcpTransportLayer::Udp }, args.bind, args.port)

src/reg/registry.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,8 @@ impl Registry {
735735
self.characteristic_list.iter().find(|c| c.name == name)
736736
}
737737

738-
#[cfg(feature = "check_a2l")]
739-
pub fn a2l_load(&mut self, filename: &str) -> Result<a2lfile::A2lFile, a2lfile::A2lError> {
738+
#[cfg(feature = "a2l_reader")]
739+
pub fn a2l_load(&mut self, filename: &str) -> Result<a2lfile::A2lFile, String> {
740740
trace!("Load A2L file {}", filename);
741741
let input_filename = &std::ffi::OsString::from(filename);
742742
let mut logmsgs = Vec::<a2lfile::A2lError>::new();
@@ -755,10 +755,7 @@ impl Registry {
755755
Ok(a2l_file)
756756
}
757757

758-
Err(e) => {
759-
error!("a2lfile::load failed: {:?}", e);
760-
Err(e)
761-
}
758+
Err(e) => Err(format!("a2lfile::load failed: {:?}", e)),
762759
}
763760
}
764761

@@ -784,10 +781,10 @@ impl Registry {
784781

785782
// @@@@ Dev
786783
// Check A2L file
787-
#[cfg(feature = "check_a2l")]
784+
#[cfg(feature = "a2l_reader")]
788785
{
789786
if let Err(e) = self.a2l_load(&a2l_path) {
790-
error!("a2lfile::load failed: {:?}", e);
787+
error!("A2l file check error: {}", e);
791788
} else {
792789
info!("A2L file check ok");
793790
}

src/reg/registry/a2l_writer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl GenerateA2l for RegistryMeasurement {
138138
// Dynamic object as CHARACTERISTIC ASCII string with IDL annotation
139139
if self.datatype == RegistryDataType::Blob {
140140
let buffer_size = self.x_dim;
141-
assert!(self.x_dim > 0 && self.y_dim == 1);
141+
assert!(self.x_dim > 0 && self.y_dim == 1, "Blob must have x_dim > 0 and y_dim == 1");
142142

143143
// BLOB (new in CANape 22 SP3: use a BLOB instead of a CHARACTERISTIC)
144144
// write!(,writer,
@@ -152,7 +152,7 @@ impl GenerateA2l for RegistryMeasurement {
152152
r#"/begin CHARACTERISTIC {name} "{comment}" ASCII 0x{addr:X} U8 0 NO_COMPU_METHOD 0 255 READ_ONLY NUMBER {buffer_size} ECU_ADDRESS_EXTENSION {ext} "#
153153
)?;
154154

155-
let annotation_object_descr = self.annotation.as_ref().unwrap();
155+
let annotation_object_descr = self.annotation.as_ref().expect("Blob type must have annotation");
156156
write!(
157157
writer,
158158
r#"
@@ -205,8 +205,8 @@ impl GenerateA2l for RegistryCharacteristic {
205205
let characteristic_type = self.get_type_str();
206206
let datatype = self.datatype.get_deposit_str();
207207
let (a2l_ext, a2l_addr) = if let Some(calseg_name) = self.calseg_name {
208-
// Segment relatice addressing
209-
assert!(self.addr_offset <= 0xFFFF);
208+
// Segment relative addressing
209+
assert!(self.addr_offset <= 0xFFFF, "Address offset must be 16 bit");
210210
Xcp::get_calseg_ext_addr(calseg_name, self.addr_offset as u16)
211211
} else {
212212
// Absolute addressing

tests/xcp_test_executor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ pub async fn xcp_test_executor(xcp: &Xcp, test_mode_cal: TestModeCal, test_mode_
225225
//-------------------------------------------------------------------------------------------------------------------------------------
226226
// Create xcp_client and connect the XCP server
227227
info!("XCP CONNECT");
228-
let dest_addr: Result<SocketAddr, _> = "127.0.0.1:5555".parse();
229-
let local_addr: Result<SocketAddr, _> = "0.0.0.0:0".parse();
230-
info!(" dest_addr: {:?}", dest_addr);
231-
info!(" local_addr: {:?}", local_addr);
232-
let mut xcp_client = XcpClient::new(dest_addr.unwrap(), local_addr.unwrap());
228+
let dest_addr = "127.0.0.1:5555".parse().unwrap();
229+
let local_addr = "0.0.0.0:0".parse().unwrap();
230+
info!(" dest_addr: {}", dest_addr);
231+
info!(" local_addr: {}", local_addr);
232+
let mut xcp_client = XcpClient::new(dest_addr, local_addr);
233233
let daq_decoder = Arc::new(Mutex::new(DaqDecoder::new()));
234234
let serv_text_decoder = ServTextDecoder::new();
235235
xcp_client.connect(Arc::clone(&daq_decoder), serv_text_decoder).await.unwrap();

xcp_client/src/main.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// xcp_client is a binary crate that uses the xcp_client library crate
33

44
use std::error::Error;
5-
use std::net::SocketAddr;
65
use std::sync::{Arc, Mutex};
76

87
mod xcp_client;
@@ -136,11 +135,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
136135
println!("Calibrate the task cycle time and counter_max");
137136

138137
// Create xcp_client
139-
let dest_addr: Result<SocketAddr, _> = args.dest_addr.parse();
140-
let local_addr: Result<SocketAddr, _> = args.bind_addr.parse();
141-
info!("dest_addr: {:?}", dest_addr);
142-
info!("local_addr: {:?}", local_addr);
143-
let mut xcp_client = XcpClient::new(dest_addr.unwrap(), local_addr.unwrap());
138+
let dest_addr = args.dest_addr.parse().map_err(|e| format!("{}", e))?;
139+
let local_addr = args.bind_addr.parse().map_err(|e| format!("{}", e))?;
140+
info!("dest_addr: {}", dest_addr);
141+
info!("local_addr: {}", local_addr);
142+
let mut xcp_client = XcpClient::new(dest_addr, local_addr);
144143

145144
// Connect to the XCP server
146145
info!("XCP Connect");

xcp_lite.a2l

+4-4
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@
191191
/begin GROUP mainloop "" ROOT /begin REF_MEASUREMENT mainloop_counter1 mainloop_counter2 /end REF_MEASUREMENT /end GROUP
192192
/begin GROUP task1 "" ROOT /begin REF_MEASUREMENT array1 counter counter_u16 counter_u32 counter_u64 counter_u8 /end REF_MEASUREMENT /end GROUP
193193
/begin GROUP task2_inst "" ROOT /begin REF_MEASUREMENT channel_1 channel_10 channel_2 channel_3 channel_4 channel_5 channel_6 channel_7 channel_8 channel_9 /end REF_MEASUREMENT /end GROUP
194-
/begin CHARACTERISTIC calpage00.task1_cycle_time_us "task1 cycle time" VALUE 0x21C00C U32 0 NO_COMPU_METHOD 0 4294967295 PHYS_UNIT "us" ECU_ADDRESS_EXTENSION 1 /end CHARACTERISTIC
195-
/begin CHARACTERISTIC calpage00.task2_cycle_time_us "task2 cycle time" VALUE 0x21C010 U32 0 NO_COMPU_METHOD 0 4294967295 PHYS_UNIT "us" ECU_ADDRESS_EXTENSION 1 /end CHARACTERISTIC
196-
/begin CHARACTERISTIC static_vars.test_f64 "Test static f64" VALUE 0x21C2AC F32 0 NO_COMPU_METHOD -1000000000000 1000000000000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end CHARACTERISTIC
197-
/begin CHARACTERISTIC static_vars.test_u32 "Test static u32" VALUE 0x21C2A8 U32 0 NO_COMPU_METHOD 0 4294967295 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end CHARACTERISTIC
194+
/begin CHARACTERISTIC calpage00.task1_cycle_time_us "task1 cycle time" VALUE 0x14800C U32 0 NO_COMPU_METHOD 0 4294967295 PHYS_UNIT "us" ECU_ADDRESS_EXTENSION 1 /end CHARACTERISTIC
195+
/begin CHARACTERISTIC calpage00.task2_cycle_time_us "task2 cycle time" VALUE 0x148010 U32 0 NO_COMPU_METHOD 0 4294967295 PHYS_UNIT "us" ECU_ADDRESS_EXTENSION 1 /end CHARACTERISTIC
196+
/begin CHARACTERISTIC static_vars.test_f64 "Test static f64" VALUE 0x14827C F32 0 NO_COMPU_METHOD -1000000000000 1000000000000 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end CHARACTERISTIC
197+
/begin CHARACTERISTIC static_vars.test_u32 "Test static u32" VALUE 0x148278 U32 0 NO_COMPU_METHOD 0 4294967295 ECU_ADDRESS_EXTENSION 1 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end CHARACTERISTIC
198198
/begin CHARACTERISTIC CalPage.cycle_time_ms "main task cycle time" VALUE 0x80010000 U32 0 NO_COMPU_METHOD 0 4294967295 PHYS_UNIT "ms" /end CHARACTERISTIC
199199
/begin CHARACTERISTIC CalPage.run "" VALUE 0x80010004 U8 0 NO_COMPU_METHOD 0 1 PHYS_UNIT "bool" /end CHARACTERISTIC
200200
/begin CHARACTERISTIC CalPage.run1 "" VALUE 0x80010005 U8 0 NO_COMPU_METHOD 0 1 PHYS_UNIT "bool" /end CHARACTERISTIC

0 commit comments

Comments
 (0)