mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-07-24 08:18:11 -07:00
move analysis into diag reader thread as well
This commit is contained in:
committed by
Cooper Quintin
parent
f9c8c4671e
commit
f41a8d38fe
@@ -197,6 +197,7 @@ async fn main() -> Result<(), RayhunterError> {
|
|||||||
diag_rx,
|
diag_rx,
|
||||||
ui_update_tx.clone(),
|
ui_update_tx.clone(),
|
||||||
qmdl_store_lock.clone(),
|
qmdl_store_lock.clone(),
|
||||||
|
analysis_tx.clone(),
|
||||||
config.enable_dummy_analyzer,
|
config.enable_dummy_analyzer,
|
||||||
);
|
);
|
||||||
info!("Starting UI");
|
info!("Starting UI");
|
||||||
|
|||||||
+18
-24
@@ -34,6 +34,7 @@ pub fn run_diag_read_thread(
|
|||||||
mut qmdl_file_rx: Receiver<DiagDeviceCtrlMessage>,
|
mut qmdl_file_rx: Receiver<DiagDeviceCtrlMessage>,
|
||||||
ui_update_sender: Sender<display::DisplayState>,
|
ui_update_sender: Sender<display::DisplayState>,
|
||||||
qmdl_store_lock: Arc<RwLock<RecordingStore>>,
|
qmdl_store_lock: Arc<RwLock<RecordingStore>>,
|
||||||
|
analysis_sender: Sender<AnalysisCtrlMessage>,
|
||||||
enable_dummy_analyzer: bool,
|
enable_dummy_analyzer: bool,
|
||||||
) {
|
) {
|
||||||
task_tracker.spawn(async move {
|
task_tracker.spawn(async move {
|
||||||
@@ -70,6 +71,23 @@ pub fn run_diag_read_thread(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(DiagDeviceCtrlMessage::StopRecording) => {
|
Some(DiagDeviceCtrlMessage::StopRecording) => {
|
||||||
|
let mut qmdl_store = qmdl_store_lock.write().await;
|
||||||
|
match qmdl_store.get_current_entry() {
|
||||||
|
Some((_, entry)) => {
|
||||||
|
if let Err(e) = analysis_sender
|
||||||
|
.send(AnalysisCtrlMessage::RecordingFinished(
|
||||||
|
entry.name.to_string(),
|
||||||
|
))
|
||||||
|
.await {
|
||||||
|
warn!("couldn't send analysis message: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => todo!(),
|
||||||
|
}
|
||||||
|
if let Err(e) = qmdl_store.close_current_entry().await {
|
||||||
|
error!("couldn't close current entry: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
maybe_qmdl_writer = None;
|
maybe_qmdl_writer = None;
|
||||||
if let Some(analysis_writer) = maybe_analysis_writer {
|
if let Some(analysis_writer) = maybe_analysis_writer {
|
||||||
analysis_writer.close().await.expect("failed to close analysis writer");
|
analysis_writer.close().await.expect("failed to close analysis writer");
|
||||||
@@ -165,30 +183,6 @@ pub async fn stop_recording(
|
|||||||
if state.debug_mode {
|
if state.debug_mode {
|
||||||
return Err((StatusCode::FORBIDDEN, "server is in debug mode".to_string()));
|
return Err((StatusCode::FORBIDDEN, "server is in debug mode".to_string()));
|
||||||
}
|
}
|
||||||
let mut qmdl_store = state.qmdl_store_lock.write().await;
|
|
||||||
match qmdl_store.get_current_entry() {
|
|
||||||
Some((_, entry)) => {
|
|
||||||
state
|
|
||||||
.analysis_sender
|
|
||||||
.send(AnalysisCtrlMessage::RecordingFinished(
|
|
||||||
entry.name.to_string(),
|
|
||||||
))
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("couldn't send AnalysisCtrlMessage: {}", e),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
None => todo!(),
|
|
||||||
}
|
|
||||||
qmdl_store.close_current_entry().await.map_err(|e| {
|
|
||||||
(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("couldn't close current qmdl entry: {}", e),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
state
|
state
|
||||||
.diag_device_ctrl_sender
|
.diag_device_ctrl_sender
|
||||||
.send(DiagDeviceCtrlMessage::StopRecording)
|
.send(DiagDeviceCtrlMessage::StopRecording)
|
||||||
|
|||||||
@@ -83,9 +83,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_parse_event_keydown_m7350_v5() {
|
fn test_parse_event_keydown_m7350_v5() {
|
||||||
let input = [
|
let input = [
|
||||||
0x57, 0x6c, 0x09, 0x00, 0x7c, 0xfb, 0x03, 0x00,
|
0x57, 0x6c, 0x09, 0x00, 0x7c, 0xfb, 0x03, 0x00, 0x01, 0x00, 0x74, 0x00, 0x01, 0x00,
|
||||||
0x01, 0x00, 0x74, 0x00, 0x01, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
];
|
];
|
||||||
assert!(matches!(parse_event(input), Event::KeyDown));
|
assert!(matches!(parse_event(input), Event::KeyDown));
|
||||||
}
|
}
|
||||||
@@ -93,9 +92,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_parse_event_keyup_m7350_v5() {
|
fn test_parse_event_keyup_m7350_v5() {
|
||||||
let input = [
|
let input = [
|
||||||
0x57, 0x6c, 0x09, 0x00, 0x1b, 0x15, 0x05, 0x00,
|
0x57, 0x6c, 0x09, 0x00, 0x1b, 0x15, 0x05, 0x00, 0x01, 0x00, 0x74, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
];
|
];
|
||||||
assert!(matches!(parse_event(input), Event::KeyUp));
|
assert!(matches!(parse_event(input), Event::KeyUp));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user