Skip to content

Commit 49800a8

Browse files
committed
Disconnect callback
1 parent 01ae840 commit 49800a8

File tree

8 files changed

+32
-25
lines changed

8 files changed

+32
-25
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ xcp_client = { path = "xcp_client" }
138138
# dependencies for rayon demo example
139139
rayon = "1.10.0"
140140
num = "0.4.3"
141-
image = "0.13.0"
141+
image = "0.25.2"
142142

143143
# dependencies for protobuf demo example
144144
prost = "0.13.1"

examples/point_cloud_demo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ log = "0.4.21"
88
env_logger = "0.11.3"
99
rayon = "1.10.0"
1010
num = "0.4.3"
11-
image = "0.13.0"
11+
image = "0.25.2"
1212

1313
serde = { version = "1.0", features = ["derive"] }
1414
serde_json = "1.0"

examples/rayon_demo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ log = "0.4.21"
88
env_logger = "0.11.3"
99
rayon = "1.10.0"
1010
num = "0.4.3"
11-
image = "0.13.0"
11+
image = "0.25.2"
1212
serde = { version = "1.0", features = ["derive"] }
1313
serde_json = "1.0"
1414
lazy_static = "1.4.0"

src/main.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ fn main() {
422422
daq_register_static!(static_vars.test_f64, static_event, "Test static f64");
423423

424424
let mut current_session_status = xcp.get_session_status();
425+
426+
let mut idle_time = 0.0;
425427
while RUN.load(Ordering::Acquire) {
426428
// @@@@ Dev: Terminate mainloop for shutdown if calibration parameter run is false, for test automation
427429
if !calseg.run {
@@ -467,11 +469,17 @@ fn main() {
467469
current_session_status = session_status;
468470
}
469471

472+
// Log idle time
473+
if !xcp.is_connected() {
474+
idle_time += calseg.cycle_time_ms as f64 / 1000.0;
475+
} else {
476+
idle_time = 0.0;
477+
}
470478
// @@@@ Dev:
471479
// Finalize A2l after 2s delay
472-
// This is just for testing, to force immediate creation of A2L file
480+
// This is just for testing, to force creation of A2L file for inspection
473481
// Without this, the A2L file will be automatically written on XCP connect, to be available for download by CANape
474-
if !xcp.is_connected() && *mainloop_counter2 == (2000 / calseg.cycle_time_ms as u16) as u64 {
482+
if idle_time >= 2.0 {
475483
// Test A2L write
476484
xcp.write_a2l();
477485

@@ -483,20 +491,11 @@ fn main() {
483491
}
484492

485493
// Terminate after more than 10s disconnected to test shutdown behaviour
486-
487-
// This is just for testing, to force immediate creation of A2L file
488-
// Without this, the A2L file will be automatically written on XCP connect, to be available for download by CANape
489-
if !xcp.is_connected() {
490-
if *mainloop_counter2 % 200 == 0 {
491-
println!(".");
492-
}
493-
if mainloop_counter1 == (10000 / calseg.cycle_time_ms as u16) as u64 {
494-
// after 10s when disconnected
495-
thread::sleep(Duration::from_secs(2));
496-
break;
497-
}
494+
if idle_time >= 10.0 {
495+
break;
498496
}
499497
}
498+
500499
info!("Main task finished");
501500
RUN.store(false, Ordering::Relaxed);
502501

xcp_client/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ async fn main() {
234234
info!("Expected {} events/s, {} byte/s", 1_000_000 / 50 * 10, 90 * 1_000_000 / 50 * 10);
235235

236236
// Disconnect
237-
info!("XCP Disconnect");
238237
xcp_client.disconnect().await.unwrap();
239238
}
240239

xcplib/src/xcpLite.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,17 @@ void XcpDisconnect()
978978
{
979979
if (!isStarted()) return;
980980

981-
if (isDaqRunning()) {
982-
ApplXcpStopDaq();
983-
XcpStopAllDaq();
984-
XcpTlWaitForTransmitQueueEmpty(); // Wait until transmit queue empty
985-
}
981+
if (isConnected()) {
986982

987-
gXcp.SessionStatus &= ~SS_CONNECTED;
983+
if (isDaqRunning()) {
984+
ApplXcpStopDaq();
985+
XcpStopAllDaq();
986+
XcpTlWaitForTransmitQueueEmpty(); // Wait until transmit queue empty
987+
}
988+
989+
gXcp.SessionStatus &= ~SS_CONNECTED;
990+
ApplXcpDisconnect();
991+
}
988992
}
989993

990994
// Transmit command response

xcplib/src/xcpLite.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ extern tXcpEvent* XcpGetEvent(uint16_t event);
132132
// All callback functions supplied by the application
133133
// Must be thread save
134134

135-
/* Callbacks on connect, measurement prepare, start and stop */
135+
/* Callbacks on connect, disconnect, measurement prepare, start and stop */
136136
extern BOOL ApplXcpConnect();
137+
extern void ApplXcpDisconnect();
137138
#if XCP_PROTOCOL_LAYER_VERSION >= 0x0104
138139
extern BOOL ApplXcpPrepareDaq();
139140
#endif

xcplib/xcpAppl.c

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ BOOL ApplXcpConnect() {
9797
return TRUE;
9898
}
9999

100+
void ApplXcpDisconnect() {
101+
DBG_PRINT3("XCP disconnect\n");
102+
}
103+
100104
#if XCP_PROTOCOL_LAYER_VERSION >= 0x0104
101105
BOOL ApplXcpPrepareDaq() {
102106
DBG_PRINT3("XCP prepare DAQ\n");

0 commit comments

Comments
 (0)