Skip to content

Commit 4dd0a6b

Browse files
authored
xcplib A2L generation improvements (#30)
* wrapper.h renamed to xcplib.h * Calibration segments with typedef instances * Bugfixes * A2L generator requires min max for all parameters * Auto groups * A2lSetSegmentAddrMode * A2lCreateLinearConversion * c_demo shared axis tested with CANape 24 release candidate
1 parent 2f9d3f1 commit 4dd0a6b

32 files changed

+4508
-2215
lines changed

.vscode/settings.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
{
22
"files.associations": {
33
"stdatomic.h": "c",
4-
"malloc.h": "c"
4+
"malloc.h": "c",
5+
"xcpethserver.h": "c",
6+
"xcplite.h": "c",
7+
"xcpqueue.h": "c",
8+
"xcp_cfg.h": "c",
9+
"stdlib.h": "c",
10+
"xcpethtl.h": "c",
11+
"a2l.h": "c",
12+
"stdint.h": "c",
13+
"platform.h": "c",
14+
"stdbool.h": "c",
15+
"xcplib.h": "c",
16+
"istream": "c",
17+
"locale": "c",
18+
"tuple": "c",
19+
"variant": "c",
20+
"ios": "c",
21+
"limits": "c",
22+
"ratio": "c",
23+
"algorithm": "c"
524
},
625
"cSpell.words": [
726
"ampl",

build.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
// Generate C code bindings for xcplib
1919
if is_posix {
2020
let bindings = bindgen::Builder::default()
21-
.header("xcplib/wrapper.h")
21+
.header("xcplib/xcplib.h")
2222
//
2323
//.clang_args(&["-target", "x86_64-pc-windows-msvc"])
2424
.clang_arg("-Ixcplib/src")
@@ -29,9 +29,8 @@ fn main() {
2929
// Protocol layer
3030
.allowlist_function("XcpInit")
3131
.allowlist_function("XcpDisconnect")
32-
// Transport layer
33-
.allowlist_function("XcpEthTlGetInfo")
3432
// Server
33+
.allowlist_function("XcpEthServerGetInfo")
3534
.allowlist_function("XcpEthServerInit")
3635
.allowlist_function("XcpEthServerShutdown")
3736
.allowlist_function("XcpEthServerStatus")
@@ -64,6 +63,7 @@ fn main() {
6463
.file("xcplib/src/xcpEthTl.c")
6564
.file("xcplib/src/xcpEthServer.c");
6665
if is_posix {
66+
//builder.define("_POSIX_C_SOURCE", "200112L");
6767
builder.flag("-std=c11");
6868
if is_release {
6969
builder.flag("-O2");
@@ -74,8 +74,7 @@ fn main() {
7474
builder.compile("xcplib");
7575

7676
// Tell cargo to invalidate the built crate whenever any of these files changed.
77-
println!("cargo:rerun-if-changed=xcplib/c_test.c");
78-
println!("cargo:rerun-if-changed=xcplib/wrapper.h");
77+
println!("cargo:rerun-if-changed=xcplib/xcplib.h");
7978
println!("cargo:rerun-if-changed=xcplib/src/main_cfg.h");
8079
println!("cargo:rerun-if-changed=xcplib/src/xcptl_cfg.h");
8180
println!("cargo:rerun-if-changed=xcplib/src/xcp_cfg.h");

src/xcp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl Xcp {
451451
if addr == [0, 0, 0, 0] {
452452
unsafe {
453453
// @@@@ UNSAFE - C library call
454-
xcplib::XcpEthTlGetInfo(std::ptr::null_mut(), std::ptr::null_mut(), &mut addr[0] as *mut u8, std::ptr::null_mut());
454+
xcplib::XcpEthServerGetInfo(std::ptr::null_mut(), std::ptr::null_mut(), &mut addr[0] as *mut u8, std::ptr::null_mut());
455455
}
456456
}
457457
let mut reg = registry::get_lock();

src/xcp/xcplib.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
/* automatically generated by rust-bindgen 0.71.1 */
22

33
unsafe extern "C" {
4-
#[doc = " Initialize the XCP on Ethernet server instance.\n @pre User has called XcpInit.\n @param address Address to bind to.\n @param port Port to bind to.\n @param use_tcp Use TCP if true, otherwise UDP.\n @param measurement_queue Optional external memory to place the measurement queue.\n Pass NULL if server should allocate it.\n @param measurement_queue_size Measurement queue size in bytes. Includes the bytes occupied by the queue header.\n @return True on success, otherwise false."]
4+
#[doc = " Initialize the XCP on Ethernet server singleton.\n @pre User has called XcpInit.\n @param address Address to bind to.\n @param port Port to bind to.\n @param use_tcp Use TCP if true, otherwise UDP.\n @param measurement_queue_size Measurement queue size in bytes. Includes the bytes occupied by the queue header and some space needed for alignment.\n @return true on success, otherwise false."]
55
pub fn XcpEthServerInit(address: *const u8, port: u16, use_tcp: bool, measurement_queue_size: u32) -> bool;
66
}
77
unsafe extern "C" {
8-
#[doc = " Shutdown the XCP on Ethernet server instance."]
8+
#[doc = " Shutdown the XCP on Ethernet server."]
99
pub fn XcpEthServerShutdown() -> bool;
1010
}
1111
unsafe extern "C" {
12-
#[doc = " Get the XCP on Ethernet server instance status.\n @return True if the server is running, otherwise false."]
12+
#[doc = " Get the XCP on Ethernet server instance status.\n @return true if the server is running, otherwise false."]
1313
pub fn XcpEthServerStatus() -> bool;
1414
}
1515
unsafe extern "C" {
16-
pub fn XcpEthTlGetInfo(isTCP: *mut bool, mac: *mut u8, addr: *mut u8, port: *mut u16);
16+
#[doc = " Get information about the XCP on Ethernet server instance address.\n @pre The server instance is running.\n @param out_is_tcp Optional out parameter to query if TCP or UDP is used.\n True if TCP, otherwise UDP.\n Pass NULL if not required.\n @param out_mac Optional out parameter to query the MAC address of the interface used in the server instance.\n Pass NULL if not required.\n @param out_address Optional out parameter to query the IP address used in the server instance.\n Pass NULL if not required.\n @param out_port Optional out parameter to query the port address used in the server instance.\n Pass NULL if not required."]
17+
pub fn XcpEthServerGetInfo(out_is_tcp: *mut bool, out_mac: *mut u8, out_address: *mut u8, out_port: *mut u16);
1718
}
19+
pub type tXcpEventId = u16;
1820
unsafe extern "C" {
19-
pub fn XcpInit();
21+
pub fn XcpEventExt(event: tXcpEventId, base: *const u8) -> u8;
2022
}
2123
unsafe extern "C" {
22-
pub fn XcpSetEpk(epk: *const ::std::os::raw::c_char);
24+
pub fn XcpSetLogLevel(level: u8);
2325
}
2426
unsafe extern "C" {
25-
pub fn XcpDisconnect();
27+
pub fn XcpInit();
2628
}
27-
pub type tXcpEventId = u16;
2829
unsafe extern "C" {
29-
pub fn XcpEventExt(event: tXcpEventId, base: *const u8) -> u8;
30+
pub fn ApplXcpSetA2lName(name: *const ::std::os::raw::c_char);
3031
}
3132
unsafe extern "C" {
32-
pub fn XcpEvent(event: tXcpEventId);
33+
pub fn XcpSetEpk(epk: *const ::std::os::raw::c_char);
3334
}
3435
unsafe extern "C" {
35-
pub fn XcpSendTerminateSessionEvent();
36+
pub fn XcpDisconnect();
3637
}
3738
unsafe extern "C" {
38-
pub fn XcpPrint(str_: *const ::std::os::raw::c_char);
39+
pub fn XcpSendTerminateSessionEvent();
3940
}
4041
unsafe extern "C" {
41-
pub fn XcpSetLogLevel(level: u8);
42+
pub fn XcpPrint(str_: *const ::std::os::raw::c_char);
4243
}
4344
unsafe extern "C" {
4445
pub fn ApplXcpGetClock64() -> u64;
@@ -59,6 +60,3 @@ unsafe extern "C" {
5960
cb_flush: ::std::option::Option<unsafe extern "C" fn() -> u8>,
6061
);
6162
}
62-
unsafe extern "C" {
63-
pub fn ApplXcpSetA2lName(name: *const ::std::os::raw::c_char);
64-
}

0 commit comments

Comments
 (0)