初步添加了标定支持,需要完善和测试
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::serial_core::calibration_session::CalibrationSession;
|
||||
use crate::serial_core::codecs::tactile_a::{
|
||||
export_recording_csv, TactileACodec, TactileACsvImporter, TactileAHandler,
|
||||
};
|
||||
@@ -23,7 +24,6 @@ const DEFAULT_TACTILE_REPLY_TIMEOUT_MS: u64 = 140;
|
||||
|
||||
type SharedTactileRecording = Arc<Mutex<TactileARecording>>;
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SerialConnectResponse {
|
||||
@@ -74,7 +74,8 @@ struct SerialSession {
|
||||
#[derive(Default)]
|
||||
pub struct SerialConnectionState {
|
||||
session: Mutex<Option<SerialSession>>,
|
||||
last_record: Mutex<Option<SharedTactileRecording>>
|
||||
last_record: Mutex<Option<SharedTactileRecording>>,
|
||||
pub calibration_session: Mutex<Option<CalibrationSession>>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -176,7 +177,7 @@ pub async fn serial_connect(
|
||||
port: port_name.clone(),
|
||||
cancel,
|
||||
task,
|
||||
current_record
|
||||
current_record,
|
||||
});
|
||||
|
||||
Ok(SerialConnectResponse {
|
||||
@@ -190,6 +191,24 @@ pub async fn serial_connect(
|
||||
pub async fn serial_disconnect(
|
||||
state: State<'_, SerialConnectionState>,
|
||||
) -> Result<SerialConnectResponse, SerialError> {
|
||||
let Some(port) = disconnect_active_session(state.inner()).await? else {
|
||||
return Ok(SerialConnectResponse {
|
||||
port: String::new(),
|
||||
connected: false,
|
||||
message: "already disconnected".to_string(),
|
||||
});
|
||||
};
|
||||
|
||||
Ok(SerialConnectResponse {
|
||||
port,
|
||||
connected: false,
|
||||
message: "disconnected".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn disconnect_active_session(
|
||||
state: &SerialConnectionState,
|
||||
) -> Result<Option<String>, SerialError> {
|
||||
let session = {
|
||||
let mut guard = state.session.lock().map_err(|_| SerialError::StateError)?;
|
||||
guard.take()
|
||||
@@ -202,18 +221,15 @@ pub async fn serial_disconnect(
|
||||
current_record,
|
||||
}) = session
|
||||
else {
|
||||
return Ok(SerialConnectResponse {
|
||||
port: String::new(),
|
||||
connected: false,
|
||||
message: "already disconnected".to_string(),
|
||||
});
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
cancel.cancel();
|
||||
let _ = task.await;
|
||||
let frame_count = current_record.lock().map(|record| {
|
||||
record.frames.len()
|
||||
}).unwrap_or(0);
|
||||
let frame_count = current_record
|
||||
.lock()
|
||||
.map(|record| record.frames.len())
|
||||
.unwrap_or(0);
|
||||
|
||||
info!("last_record has {} frames", frame_count);
|
||||
|
||||
@@ -221,12 +237,7 @@ pub async fn serial_disconnect(
|
||||
*last_record = Some(current_record);
|
||||
}
|
||||
|
||||
|
||||
Ok(SerialConnectResponse {
|
||||
port,
|
||||
connected: false,
|
||||
message: "disconnected".to_string(),
|
||||
})
|
||||
Ok(Some(port))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -290,7 +301,10 @@ pub fn serial_export_csv_to_path(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn serial_import_csv(file_name: String, csv_content: String) -> Result<SerialImportResponse, SerialError> {
|
||||
pub fn serial_import_csv(
|
||||
file_name: String,
|
||||
csv_content: String,
|
||||
) -> Result<SerialImportResponse, SerialError> {
|
||||
let mut importer = TactileACsvImporter::new(file_name.as_str());
|
||||
let packets = importer
|
||||
.load(Cursor::new(csv_content.into_bytes()))
|
||||
@@ -347,7 +361,10 @@ fn resolve_record_for_export(
|
||||
return Ok(recording);
|
||||
}
|
||||
|
||||
let last_record = state.last_record.lock().map_err(|_| SerialError::StateError)?;
|
||||
let last_record = state
|
||||
.last_record
|
||||
.lock()
|
||||
.map_err(|_| SerialError::StateError)?;
|
||||
last_record.clone().ok_or(SerialError::NoRecordedData)
|
||||
}
|
||||
|
||||
@@ -368,7 +385,10 @@ fn snapshot_record_frame_count(
|
||||
.map_err(|_| SerialError::StateError);
|
||||
}
|
||||
|
||||
let last_record = state.last_record.lock().map_err(|_| SerialError::StateError)?;
|
||||
let last_record = state
|
||||
.last_record
|
||||
.lock()
|
||||
.map_err(|_| SerialError::StateError)?;
|
||||
let Some(record) = last_record.as_ref() else {
|
||||
return Ok(0);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user