Skip to content

Commit

Permalink
Add support to clear device on Pica when host closes hal. (#48)
Browse files Browse the repository at this point in the history
* Add support to clear device on Pica when host closes hal.

* Also reset the country code when receiving DeviceResetCmd.
  • Loading branch information
bobwzy authored Dec 12, 2023
1 parent 85c0f4f commit 7f6fcf3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ impl Device {
let status = match reset_config {
ResetConfig::UwbsReset => StatusCode::UciStatusOk,
};

*self = Device::new(self.handle, self.tx.clone(), self.pica_tx.clone());
self.init();

DeviceResetRspBuilder { status }.build()
}
Expand Down Expand Up @@ -298,12 +298,19 @@ impl Device {
println!("[{}] Session deinit", self.handle);
println!(" session_id=0x{:x}", session_id);

let status = if self.sessions.remove(&session_id).is_some() {
StatusCode::UciStatusOk
} else {
StatusCode::UciStatusSessionNotExist
let status = match self.sessions.get_mut(&session_id) {
Some(session) => {
if session.state == SessionState::SessionStateActive {
self.n_active_sessions -= 1;
if self.n_active_sessions == 0 {
self.set_state(DeviceState::DeviceStateReady);
}
}
self.sessions.remove(&session_id);
StatusCode::UciStatusOk
}
None => StatusCode::UciStatusSessionNotExist,
};

SessionDeinitRspBuilder { status }.build()
}

Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl AppConfig {

pub struct Session {
/// cf. [UCI] 7.1
state: SessionState,
pub state: SessionState,
/// cf. [UCI] 7.2 Table 13: 4 octets unique random number generated by application
id: u32,
device_handle: usize,
Expand Down

0 comments on commit 7f6fcf3

Please sign in to comment.