diff --git a/Cargo.toml b/Cargo.toml index 4791370..6e78f7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -138,7 +138,7 @@ xcp_client = { path = "xcp_client" } # dependencies for rayon demo example rayon = "1.10.0" num = "0.4.3" -image = "0.13.0" +image = "0.25.2" # dependencies for protobuf demo example prost = "0.13.1" diff --git a/examples/point_cloud_demo/Cargo.toml b/examples/point_cloud_demo/Cargo.toml index 7ddcefd..778e4e3 100644 --- a/examples/point_cloud_demo/Cargo.toml +++ b/examples/point_cloud_demo/Cargo.toml @@ -8,7 +8,7 @@ log = "0.4.21" env_logger = "0.11.3" rayon = "1.10.0" num = "0.4.3" -image = "0.13.0" +image = "0.25.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/examples/rayon_demo/Cargo.toml b/examples/rayon_demo/Cargo.toml index 75831c4..85c53a1 100644 --- a/examples/rayon_demo/Cargo.toml +++ b/examples/rayon_demo/Cargo.toml @@ -8,7 +8,7 @@ log = "0.4.21" env_logger = "0.11.3" rayon = "1.10.0" num = "0.4.3" -image = "0.13.0" +image = "0.25.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" lazy_static = "1.4.0" diff --git a/src/main.rs b/src/main.rs index 59757ed..9a038d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -422,6 +422,8 @@ fn main() { daq_register_static!(static_vars.test_f64, static_event, "Test static f64"); let mut current_session_status = xcp.get_session_status(); + + let mut idle_time = 0.0; while RUN.load(Ordering::Acquire) { // @@@@ Dev: Terminate mainloop for shutdown if calibration parameter run is false, for test automation if !calseg.run { @@ -467,11 +469,17 @@ fn main() { current_session_status = session_status; } + // Log idle time + if !xcp.is_connected() { + idle_time += calseg.cycle_time_ms as f64 / 1000.0; + } else { + idle_time = 0.0; + } // @@@@ Dev: // Finalize A2l after 2s delay - // This is just for testing, to force immediate creation of A2L file + // This is just for testing, to force creation of A2L file for inspection // Without this, the A2L file will be automatically written on XCP connect, to be available for download by CANape - if !xcp.is_connected() && *mainloop_counter2 == (2000 / calseg.cycle_time_ms as u16) as u64 { + if idle_time >= 2.0 { // Test A2L write xcp.write_a2l(); @@ -483,20 +491,11 @@ fn main() { } // Terminate after more than 10s disconnected to test shutdown behaviour - - // This is just for testing, to force immediate creation of A2L file - // Without this, the A2L file will be automatically written on XCP connect, to be available for download by CANape - if !xcp.is_connected() { - if *mainloop_counter2 % 200 == 0 { - println!("."); - } - if mainloop_counter1 == (10000 / calseg.cycle_time_ms as u16) as u64 { - // after 10s when disconnected - thread::sleep(Duration::from_secs(2)); - break; - } + if idle_time >= 10.0 { + break; } } + info!("Main task finished"); RUN.store(false, Ordering::Relaxed); diff --git a/xcp_client/src/main.rs b/xcp_client/src/main.rs index e35037a..cba8e54 100644 --- a/xcp_client/src/main.rs +++ b/xcp_client/src/main.rs @@ -234,7 +234,6 @@ async fn main() { info!("Expected {} events/s, {} byte/s", 1_000_000 / 50 * 10, 90 * 1_000_000 / 50 * 10); // Disconnect - info!("XCP Disconnect"); xcp_client.disconnect().await.unwrap(); } diff --git a/xcplib/src/xcpLite.c b/xcplib/src/xcpLite.c index d0cc673..99d8e16 100644 --- a/xcplib/src/xcpLite.c +++ b/xcplib/src/xcpLite.c @@ -978,13 +978,17 @@ void XcpDisconnect() { if (!isStarted()) return; - if (isDaqRunning()) { - ApplXcpStopDaq(); - XcpStopAllDaq(); - XcpTlWaitForTransmitQueueEmpty(); // Wait until transmit queue empty - } + if (isConnected()) { - gXcp.SessionStatus &= ~SS_CONNECTED; + if (isDaqRunning()) { + ApplXcpStopDaq(); + XcpStopAllDaq(); + XcpTlWaitForTransmitQueueEmpty(); // Wait until transmit queue empty + } + + gXcp.SessionStatus &= ~SS_CONNECTED; + ApplXcpDisconnect(); + } } // Transmit command response diff --git a/xcplib/src/xcpLite.h b/xcplib/src/xcpLite.h index c69c8d8..d60e998 100644 --- a/xcplib/src/xcpLite.h +++ b/xcplib/src/xcpLite.h @@ -132,8 +132,9 @@ extern tXcpEvent* XcpGetEvent(uint16_t event); // All callback functions supplied by the application // Must be thread save -/* Callbacks on connect, measurement prepare, start and stop */ +/* Callbacks on connect, disconnect, measurement prepare, start and stop */ extern BOOL ApplXcpConnect(); +extern void ApplXcpDisconnect(); #if XCP_PROTOCOL_LAYER_VERSION >= 0x0104 extern BOOL ApplXcpPrepareDaq(); #endif diff --git a/xcplib/xcpAppl.c b/xcplib/xcpAppl.c index ab0eb4a..1ab09ea 100644 --- a/xcplib/xcpAppl.c +++ b/xcplib/xcpAppl.c @@ -97,6 +97,10 @@ BOOL ApplXcpConnect() { return TRUE; } +void ApplXcpDisconnect() { + DBG_PRINT3("XCP disconnect\n"); +} + #if XCP_PROTOCOL_LAYER_VERSION >= 0x0104 BOOL ApplXcpPrepareDaq() { DBG_PRINT3("XCP prepare DAQ\n");