Skip to content

Commit

Permalink
Disconnect callback
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Sep 10, 2024
1 parent 01ae840 commit 49800a8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/point_cloud_demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/rayon_demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 13 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion xcp_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
16 changes: 10 additions & 6 deletions xcplib/src/xcpLite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion xcplib/src/xcpLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions xcplib/xcpAppl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 49800a8

Please sign in to comment.