Skip to content

Commit 053919e

Browse files
authored
xcp_client TCP support and improvement to test XCPlite GET_SEGMENT_INFO (#37)
* Update to XCPlite xcplib master * Updated xcplib (XCPlite) to VectorGrp master * GET_SEGMENT_INFO, GET_DAQ_EVENT_INFO * Read event and segment info from XCP server * Option --read_a2l * xcp_client TCP support
1 parent 4701244 commit 053919e

File tree

15 files changed

+2707
-2142
lines changed

15 files changed

+2707
-2142
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ regex = "1.11.1"
154154
tokio = { version = "1.37.0", features = ["full"] }
155155
xcp_client = { path = "xcp_client" }
156156

157+
#goblin = "0.8"
158+
#gimli = "0.28"
159+
160+
157161
# A2L checker (optional)
158162
a2lfile = { version="3.0.0", optional = false}
159163

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ Feature a2l_reader is needed for xcp_client based testing
170170
```
171171
cargo test --features=a2l_reader -- --test-threads=1 --nocapture
172172
cargo test --features=a2l_reader -- --test-threads=1 --nocapture --test test_multi_thread
173-
cargo test --features=shm_mode -- --test-threads=1 --nocapture --test test_performance
174173
```
175174

176175
Use --nocapture because the debug output from the XCPlite C library is via normal printf

build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ fn main() {
1818
// Generate C code bindings for xcplib
1919
if is_posix {
2020
let bindings = bindgen::Builder::default()
21-
.header("xcplib/src/xcplib.h")
21+
.header("xcplib/inc/xcplib.h")
2222
//
2323
//.clang_args(&["-target", "x86_64-pc-windows-msvc"])
2424
.clang_arg("-Ixcplib/src")
2525
.clang_arg("-Ixcplib")
26+
.clang_arg("-DXCPLIB_FOR_RUST")
2627
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
2728
//
2829
.blocklist_type("T_CLOCK_INFO")

src/registry/a2l/a2l_reader.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ fn registry_load_a2lfile(registry: &mut Registry, a2l_file: &a2lfile::A2lFile) -
326326
// Memory segments
327327

328328
// Add memory segments and EPK
329-
let mut index = 0;
330329
if let Some(mod_par) = &module.mod_par {
331330
// EPK
332331
if let Some(epk) = &mod_par.epk {
@@ -337,20 +336,23 @@ fn registry_load_a2lfile(registry: &mut Registry, a2l_file: &a2lfile::A2lFile) -
337336
}
338337

339338
// Memory segments
339+
let mut index = 0;
340+
let mut number: u8 = 0; // Number is part of the memory segment IF_DATA, not used here
340341
for m in mod_par.memory_segment.iter() {
341342
let name = m.get_name().to_string();
342343
let addr_ext = 0; // @@@@ xcp-lite address extensions hardcoded here, would be in IF_DATA
343344
let addr = m.address;
344345
let size = m.size;
345346
if vector_xcp_mode {
347+
// Get index from addr, in vector mode the high word of the segment address is the segment number
348+
let addr_index = ((addr >> 16) & 0x7FFF) as u16;
349+
assert!(number as u16 == addr_index);
350+
346351
if name == "epk" {
347-
// Predefined memory segment for EPK, just ignore
352+
// Predefined memory segment for EPK, just ignore, don't increment index
353+
number += 1;
348354
continue;
349355
}
350-
// Get index from addr
351-
index = ((addr >> 16) & 0x7FFF) as u16 - 1; // EPK segment is virtual, index starts with 0
352-
} else {
353-
index += 1; // Index starts with 1, 0 is predefined EPK segment
354356
}
355357

356358
let res = registry.cal_seg_list.add_a2l_cal_seg(name, index, addr_ext, addr, size);
@@ -360,6 +362,9 @@ fn registry_load_a2lfile(registry: &mut Registry, a2l_file: &a2lfile::A2lFile) -
360362
warn!("Failed to add calibration segment: {}", e);
361363
}
362364
}
365+
366+
index += 1;
367+
number += 1;
363368
}
364369
}
365370

src/registry/mc_support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl Default for McSupportData {
173173

174174
impl Clone for McSupportData {
175175
fn clone(&self) -> Self {
176-
log::debug!("Cloning McSupportData");
176+
log::trace!("Cloning McSupportData");
177177
McSupportData {
178178
object_type: self.object_type,
179179
qualifier: self.qualifier,

src/registry/mc_text.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl From<McText> for String {
8181
impl From<Option<&String>> for McText {
8282
fn from(s: Option<&String>) -> Self {
8383
if let Some(s) = s {
84-
log::debug!("From<String> to McText: Leak String '{s}' to &'static str");
84+
log::trace!("From<String> to McText: Leak String '{s}' to &'static str");
8585
let s = s.clone().into_boxed_str();
8686
let s = Box::leak(s);
8787

@@ -94,7 +94,7 @@ impl From<Option<&String>> for McText {
9494

9595
impl From<&String> for McText {
9696
fn from(s: &String) -> Self {
97-
log::debug!("From<String> to McText: Leak String '{s}' to &'static str");
97+
log::trace!("From<String> to McText: Leak String '{s}' to &'static str");
9898
let s = s.clone().into_boxed_str();
9999
let s = Box::leak(s);
100100

@@ -104,7 +104,7 @@ impl From<&String> for McText {
104104

105105
impl From<String> for McText {
106106
fn from(s: String) -> Self {
107-
log::debug!("From<String> to McText: Leak String '{s}' to &'static str");
107+
log::trace!("From<String> to McText: Leak String '{s}' to &'static str");
108108
let s = s.into_boxed_str();
109109
let s = Box::leak(s);
110110

@@ -228,7 +228,7 @@ fn check_identifier(s: &str) -> bool {
228228

229229
impl From<String> for McIdentifier {
230230
fn from(s: String) -> Self {
231-
log::debug!("From<String> to McIdentifier: Leak String '{s}' to &'static str");
231+
log::trace!("From<String> to McIdentifier: Leak String '{s}' to &'static str");
232232
let mut s = s.clone();
233233
to_identifier(&mut s);
234234
let s = s.into_boxed_str();

src/xcp/xcplib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ unsafe extern "C" {
1818
}
1919
pub type tXcpEventId = u16;
2020
unsafe extern "C" {
21-
#[doc = " Trigger the XCP event 'event' for stack relative or absolute addressing\n @param event Event id.\n Assumes XCP address extension XCP_ADDR_EXT_REL is used for stack relative addressing and XCP_ADDR_EXT_ABS for absolute addressing."]
21+
#[doc = " Trigger the XCP event 'event' for stack absolute addressing mode (XCP_ADDR_EXT_ABS)\n @param event Event id.\n Assumes XCP address extension XCP_ADDR_EXT_REL is used for stack relative addressing and XCP_ADDR_EXT_ABS for absolute addressing."]
2222
pub fn XcpEvent(event: tXcpEventId);
2323
}
2424
unsafe extern "C" {
25-
#[doc = " Trigger the XCP event 'event' for stack relative or absolute addressing and with explicitly given base address for relative addressing mode (DYN)\n @param event\n @param base address pointer for the relative (XCP_ADDR_EXT_DYN) addressing mode (from A2lSetRelativeAddrMode(base)).\n Assumes XCP_ADDR_EXT_REL is used for stack relative addressing and XCP_ADDR_EXT_ABS for absolute addressing."]
25+
#[doc = " Trigger the XCP event 'event' for relative or absolute addressing mode with explicitly given base address (XCP_ADDR_EXT_DYN)\n @param event\n @param base address pointer for the relative (XCP_ADDR_EXT_DYN) addressing mode"]
2626
pub fn XcpEventExt(event: tXcpEventId, base: *const u8);
2727
}
2828
unsafe extern "C" {

tests/xcp_test_executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub async fn test_setup(task_count: usize, load_a2l: bool, upload_a2l: bool) ->
631631
let local_addr = "0.0.0.0:0".parse().unwrap();
632632
info!(" dest_addr: {}", dest_addr);
633633
info!(" local_addr: {}", local_addr);
634-
let mut xcp_client = XcpClient::new(dest_addr, local_addr);
634+
let mut xcp_client = XcpClient::new(false, dest_addr, local_addr);
635635
let daq_decoder: Arc<parking_lot::lock_api::Mutex<parking_lot::RawMutex, DaqDecoder>> = Arc::new(Mutex::new(DaqDecoder::new(task_count)));
636636
let serv_text_decoder = ServTextDecoder::new();
637637
xcp_client.connect(Arc::clone(&daq_decoder), serv_text_decoder).await.unwrap();
@@ -679,7 +679,7 @@ pub async fn test_setup(task_count: usize, load_a2l: bool, upload_a2l: bool) ->
679679
if load_a2l {
680680
// Upload A2L file from XCP server
681681
if upload_a2l {
682-
xcp_client.a2l_loader().await.unwrap();
682+
xcp_client.a2l_loader("test").await.unwrap();
683683
}
684684
// Load the A2L file from file
685685
else {

xcp_client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ byteorder = "1.5.0"
2525
regex = "1.11.1"
2626
lazy_static = "1.4"
2727

28+
#goblin = "0.8"
29+
#gimli = "0.28"
30+
2831
a2lfile = { version="3.0.0" }
2932
xcp_lite = { path = "../", features = ["a2l_reader"] }
3033

xcp_client/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Options:
2424
Lists all measurement variables
2525
--list-cal
2626
Lists all calibration variables
27+
--cal `<NAME>` `<VALUE>`
28+
Set calibration variable to a value (format: "variable_name value")
2729
-m, --measurement-list <MEASUREMENT_LIST>...
2830
Specifies the variables names for DAQ measurement, 'all' or a list of names separated by space
2931
-a, --a2l-filename <A2L_FILENAME>
@@ -33,6 +35,27 @@ Options:
3335
-V, --version
3436
Print version
3537

38+
## Examples
39+
40+
### List calibration variables
41+
42+
```bash
43+
cargo run --example=xcp_client -- --list-cal ".*"
44+
```
45+
46+
### Set a calibration variable
47+
48+
```bash
49+
cargo run --example=xcp_client -- --cal variable_name 42.5
50+
```
51+
52+
### Measure variables
53+
54+
```bash
55+
cargo run --example=xcp_client -- -m ".*" -t 5000
56+
```
57+
58+
3659

3760

3861
``` rust
@@ -71,5 +94,4 @@ Options:
7194
// Disconnect
7295
xcp_client.disconnect().await?);
7396

74-
7597
```

0 commit comments

Comments
 (0)