Skip to content

Commit f56fce9

Browse files
authored
Bugfixes (#16)
* Bugfixes * Cleaning code * Require 64 Bit platforms, 32 Bit queue t.b.d.
1 parent 1a2531f commit f56fce9

File tree

24 files changed

+402
-430
lines changed

24 files changed

+402
-430
lines changed

build.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,26 @@ fn main() {
2929
// Protocol layer
3030
.allowlist_function("XcpInit")
3131
.allowlist_function("XcpDisconnect")
32-
// ETH server mode
32+
// Transport layer
33+
.allowlist_function("XcpEthTlGetInfo")
34+
// Server
3335
.allowlist_function("XcpEthServerInit")
3436
.allowlist_function("XcpEthServerShutdown")
3537
.allowlist_function("XcpEthServerStatus")
36-
.allowlist_function("XcpEthTlGetInfo")
3738
// DAQ
38-
.allowlist_function("XcpTriggerDaqEventAt")
39-
//.allowlist_function("XcpEventAt")
4039
.allowlist_function("XcpEvent")
41-
//.allowlist_function("XcpEventExtAt")
4240
.allowlist_function("XcpEventExt")
41+
//.allowlist_function("XcpTriggerDaqEventAt")
42+
//.allowlist_function("XcpEventAt")
43+
//.allowlist_function("XcpEventExtAt")
4344
// Misc
45+
.allowlist_function("XcpSetLogLevel")
4446
.allowlist_function("XcpPrint")
4547
.allowlist_function("XcpSetEpk")
4648
.allowlist_function("XcpSendTerminateSessionEvent")
47-
.allowlist_function("ApplXcpSetLogLevel")
49+
//
50+
//.allowlist_function("ApplXcpGetAddr")
4851
.allowlist_function("ApplXcpSetA2lName")
49-
.allowlist_function("ApplXcpGetAddr")
5052
.allowlist_function("ApplXcpRegisterCallbacks")
5153
.allowlist_function("ApplXcpGetClock64")
5254
//
@@ -55,21 +57,15 @@ fn main() {
5557
bindings.write_to_file("src/xcp/xcplib.rs").expect("Couldn't write bindings!");
5658

5759
// Build xcplib
58-
5960
let mut builder = cc::Build::new();
6061
let builder = builder
61-
//
6262
.include("xcplib/src/")
63-
.include("xcplib/")
64-
//
65-
// xcplib source files
6663
.file("xcplib/src/xcpAppl.c")
6764
.file("xcplib/src/platform.c")
6865
.file("xcplib/src/xcpLite.c")
69-
.file("xcplib/src/xcpQueue.c")
66+
.file("xcplib/src/xcpQueue64.c")
7067
.file("xcplib/src/xcpEthTl.c")
7168
.file("xcplib/src/xcpEthServer.c")
72-
// Flags
7369
.flag("-std=c11");
7470

7571
if is_release {
@@ -93,7 +89,7 @@ fn main() {
9389
println!("cargo:rerun-if-changed=xcplib/src/platform.h");
9490
println!("cargo:rerun-if-changed=xcplib/src/platform.c");
9591
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue.h");
96-
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue.c");
92+
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue64.c");
9793
println!("cargo:rerun-if-changed=xcplib/src/xcpEthTl.h");
9894
println!("cargo:rerun-if-changed=xcplib/src/xcpEthTl.c");
9995
println!("cargo:rerun-if-changed=xcplib/src/xcpEthServer.h");

src/xcp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl Xcp {
387387
pub fn set_log_level(&self, level: u8) -> &'static Xcp {
388388
unsafe {
389389
// @@@@ UNSAFE - C library call
390-
xcplib::ApplXcpSetLogLevel(level);
390+
xcplib::XcpSetLogLevel(level);
391391
}
392392

393393
&XCP

src/xcp/xcplib.rs

Lines changed: 3 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,13 @@
11
/* automatically generated by rust-bindgen 0.71.1 */
22

3-
#[repr(C)]
4-
#[derive(Debug, Copy, Clone)]
5-
pub struct tQueueHandleType {
6-
_unused: [u8; 0],
7-
}
8-
pub type tQueueHandle = *mut tQueueHandleType;
9-
#[repr(C, packed)]
10-
#[derive(Debug, Copy, Clone)]
11-
pub struct tXcpOdt {
12-
pub first_odt_entry: u16,
13-
pub last_odt_entry: u16,
14-
pub size: u16,
15-
pub res: u16,
16-
}
17-
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
18-
const _: () = {
19-
["Size of tXcpOdt"][::std::mem::size_of::<tXcpOdt>() - 8usize];
20-
["Alignment of tXcpOdt"][::std::mem::align_of::<tXcpOdt>() - 1usize];
21-
["Offset of field: tXcpOdt::first_odt_entry"][::std::mem::offset_of!(tXcpOdt, first_odt_entry) - 0usize];
22-
["Offset of field: tXcpOdt::last_odt_entry"][::std::mem::offset_of!(tXcpOdt, last_odt_entry) - 2usize];
23-
["Offset of field: tXcpOdt::size"][::std::mem::offset_of!(tXcpOdt, size) - 4usize];
24-
["Offset of field: tXcpOdt::res"][::std::mem::offset_of!(tXcpOdt, res) - 6usize];
25-
};
26-
#[repr(C, packed)]
27-
#[derive(Debug, Copy, Clone)]
28-
pub struct tXcpDaqList {
29-
pub last_odt: u16,
30-
pub first_odt: u16,
31-
pub event_channel: u16,
32-
pub next: u16,
33-
pub mode: u8,
34-
pub state: u8,
35-
pub priority: u8,
36-
pub addr_ext: u8,
37-
}
38-
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
39-
const _: () = {
40-
["Size of tXcpDaqList"][::std::mem::size_of::<tXcpDaqList>() - 12usize];
41-
["Alignment of tXcpDaqList"][::std::mem::align_of::<tXcpDaqList>() - 1usize];
42-
["Offset of field: tXcpDaqList::last_odt"][::std::mem::offset_of!(tXcpDaqList, last_odt) - 0usize];
43-
["Offset of field: tXcpDaqList::first_odt"][::std::mem::offset_of!(tXcpDaqList, first_odt) - 2usize];
44-
["Offset of field: tXcpDaqList::event_channel"][::std::mem::offset_of!(tXcpDaqList, event_channel) - 4usize];
45-
["Offset of field: tXcpDaqList::next"][::std::mem::offset_of!(tXcpDaqList, next) - 6usize];
46-
["Offset of field: tXcpDaqList::mode"][::std::mem::offset_of!(tXcpDaqList, mode) - 8usize];
47-
["Offset of field: tXcpDaqList::state"][::std::mem::offset_of!(tXcpDaqList, state) - 9usize];
48-
["Offset of field: tXcpDaqList::priority"][::std::mem::offset_of!(tXcpDaqList, priority) - 10usize];
49-
["Offset of field: tXcpDaqList::addr_ext"][::std::mem::offset_of!(tXcpDaqList, addr_ext) - 11usize];
50-
};
51-
#[repr(C, packed)]
52-
#[derive(Copy, Clone)]
53-
pub struct tXcpDaqLists {
54-
pub odt_entry_count: u16,
55-
pub odt_count: u16,
56-
pub daq_count: u16,
57-
pub res: u16,
58-
pub config_id: u16,
59-
pub res1: u16,
60-
pub daq_first: [u16; 256usize],
61-
pub u: tXcpDaqLists__bindgen_ty_1,
62-
}
63-
#[repr(C, packed)]
64-
#[derive(Copy, Clone)]
65-
pub union tXcpDaqLists__bindgen_ty_1 {
66-
pub daq_list: [tXcpDaqList; 13653usize],
67-
pub odt: [tXcpOdt; 20480usize],
68-
pub odt_entry_addr: [u32; 40960usize],
69-
pub odt_entry_size: [u8; 163840usize],
70-
pub b: [u64; 20481usize],
71-
}
72-
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
73-
const _: () = {
74-
["Size of tXcpDaqLists__bindgen_ty_1"][::std::mem::size_of::<tXcpDaqLists__bindgen_ty_1>() - 163848usize];
75-
["Alignment of tXcpDaqLists__bindgen_ty_1"][::std::mem::align_of::<tXcpDaqLists__bindgen_ty_1>() - 1usize];
76-
["Offset of field: tXcpDaqLists__bindgen_ty_1::daq_list"][::std::mem::offset_of!(tXcpDaqLists__bindgen_ty_1, daq_list) - 0usize];
77-
["Offset of field: tXcpDaqLists__bindgen_ty_1::odt"][::std::mem::offset_of!(tXcpDaqLists__bindgen_ty_1, odt) - 0usize];
78-
["Offset of field: tXcpDaqLists__bindgen_ty_1::odt_entry_addr"][::std::mem::offset_of!(tXcpDaqLists__bindgen_ty_1, odt_entry_addr) - 0usize];
79-
["Offset of field: tXcpDaqLists__bindgen_ty_1::odt_entry_size"][::std::mem::offset_of!(tXcpDaqLists__bindgen_ty_1, odt_entry_size) - 0usize];
80-
["Offset of field: tXcpDaqLists__bindgen_ty_1::b"][::std::mem::offset_of!(tXcpDaqLists__bindgen_ty_1, b) - 0usize];
81-
};
82-
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
83-
const _: () = {
84-
["Size of tXcpDaqLists"][::std::mem::size_of::<tXcpDaqLists>() - 164372usize];
85-
["Alignment of tXcpDaqLists"][::std::mem::align_of::<tXcpDaqLists>() - 1usize];
86-
["Offset of field: tXcpDaqLists::odt_entry_count"][::std::mem::offset_of!(tXcpDaqLists, odt_entry_count) - 0usize];
87-
["Offset of field: tXcpDaqLists::odt_count"][::std::mem::offset_of!(tXcpDaqLists, odt_count) - 2usize];
88-
["Offset of field: tXcpDaqLists::daq_count"][::std::mem::offset_of!(tXcpDaqLists, daq_count) - 4usize];
89-
["Offset of field: tXcpDaqLists::res"][::std::mem::offset_of!(tXcpDaqLists, res) - 6usize];
90-
["Offset of field: tXcpDaqLists::config_id"][::std::mem::offset_of!(tXcpDaqLists, config_id) - 8usize];
91-
["Offset of field: tXcpDaqLists::res1"][::std::mem::offset_of!(tXcpDaqLists, res1) - 10usize];
92-
["Offset of field: tXcpDaqLists::daq_first"][::std::mem::offset_of!(tXcpDaqLists, daq_first) - 12usize];
93-
["Offset of field: tXcpDaqLists::u"][::std::mem::offset_of!(tXcpDaqLists, u) - 524usize];
94-
};
953
unsafe extern "C" {
964
pub fn XcpInit();
975
}
986
unsafe extern "C" {
99-
pub fn XcpDisconnect();
7+
pub fn XcpSetEpk(epk: *const ::std::os::raw::c_char);
1008
}
1019
unsafe extern "C" {
102-
pub fn XcpTriggerDaqEventAt(daq_lists: *const tXcpDaqLists, queueHandle: tQueueHandle, event: u16, base: *const u8, clock: u64);
10+
pub fn XcpDisconnect();
10311
}
10412
unsafe extern "C" {
10513
pub fn XcpEventExt(event: u16, base: *const u8) -> u8;
@@ -114,17 +22,11 @@ unsafe extern "C" {
11422
pub fn XcpPrint(str_: *const ::std::os::raw::c_char);
11523
}
11624
unsafe extern "C" {
117-
pub fn XcpSetEpk(epk: *const ::std::os::raw::c_char);
118-
}
119-
unsafe extern "C" {
120-
pub fn ApplXcpGetAddr(p: *const u8) -> u32;
25+
pub fn XcpSetLogLevel(level: u8);
12126
}
12227
unsafe extern "C" {
12328
pub fn ApplXcpGetClock64() -> u64;
12429
}
125-
unsafe extern "C" {
126-
pub fn ApplXcpSetLogLevel(level: u8);
127-
}
12830
unsafe extern "C" {
12931
pub fn ApplXcpRegisterCallbacks(
13032
cb_connect: ::std::option::Option<unsafe extern "C" fn() -> bool>,

xcplib/CMakeLists.txt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,48 @@
22

33
cmake_minimum_required(VERSION 3.5)
44

5-
set(MACOS TRUE) # Build for macOS Darwin ARM
6-
set(WINDOWS FALSE) # Build for Windows x64
7-
set(LINUX FALSE) # Build for Linus x64
5+
project(xcplib VERSION 6.0 LANGUAGES C)
6+
7+
8+
9+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
10+
message("Building for 64-bit platform")
11+
set(PLATFORM_64BIT TRUE)
12+
else()
13+
message("Building for 32-bit platform")
14+
set(PLATFORM_32BIT TRUE)
15+
endif()
16+
17+
18+
if(WIN32)
19+
message("Building for WINDOWS")
20+
set(WINDOWS FALSE) # Build for Windows
21+
elseif(APPLE)
22+
message("Building for APPLE")
23+
set(MACOS TRUE) # Build for macOS Darwin ARM
24+
elseif(UNIX)
25+
message("Building for UNIX")
26+
set(LINUX FALSE) # Build for Linus x64
27+
endif()
28+
29+
30+
831

932
set(CMAKE_C_COMPILER "gcc")
1033
set(CMAKE_CXX_COMPILER "g++")
1134
set(CMAKE_CXX_STANDARD 11)
1235
set(CMAKE_CXX_STANDARD_REQUIRED True)
1336

14-
project(xcplib VERSION 6.0 LANGUAGES C)
37+
1538

1639
# xcplib
17-
set(xcplib_SOURCES ./src/xcpAppl.c ./src/xcpLite.c ./src/xcpEthServer.c ./src/xcpEthTl.c ./src/xcpQueue.c ./src/a2l.c ./src/platform.c )
40+
if(PLATFORM_64BIT)
41+
set(xcplib_SOURCES ./src/xcpAppl.c ./src/xcpLite.c ./src/xcpEthServer.c ./src/xcpEthTl.c ./src/xcpQueue64.c ./src/a2l.c ./src/platform.c )
42+
else()
43+
set(xcplib_SOURCES ./src/xcpAppl.c ./src/xcpLite.c ./src/xcpEthServer.c ./src/xcpEthTl.c ./src/xcpQueue32.c ./src/a2l.c ./src/platform.c )
44+
endif()
45+
46+
1847
set_source_files_properties(${xcplib_SOURCES} PROPERTIES LANGUAGE C)
1948
add_library(xcplib ${xcplib_SOURCES})
2049
target_include_directories(xcplib PUBLIC "${PROJECT_SOURCE_DIR}/src" )

xcplib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
XCPlite is a lightweight pure C implementation of the ASAM XCP V1.4 standard protocol for measurement and calibration of electronic control units.
55
It supports XCP on TCP or UDP with jumboframes.
6-
Runs on POSIX based (LINUX, MACOS) or Windows Operating Systems.
6+
Runs on 64 Bit platforms with POSIX based (LINUX, MACOS) or Windows Operating Systems.
77
The A2L measurement and calibration object database is generated during runtime and uploaded by the XCP client on connect.
88

99
XCPlite is provided to test and demonstrate calibration tools such as CANape or any other XCP client implementation.

0 commit comments

Comments
 (0)