diff --git a/daemon/src/diag.rs b/daemon/src/diag.rs index 9406304..3db7492 100644 --- a/daemon/src/diag.rs +++ b/daemon/src/diag.rs @@ -10,6 +10,7 @@ use axum::http::header::CONTENT_TYPE; use axum::response::{IntoResponse, Response}; use futures::{StreamExt, TryStreamExt, future}; use log::{debug, error, info, warn}; +use rayhunter::Device; use tokio::fs::File; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::sync::mpsc::{Receiver, Sender}; @@ -370,7 +371,7 @@ impl DiagTask { #[allow(clippy::too_many_arguments)] pub fn run_diag_read_thread( task_tracker: &TaskTracker, - mut dev: DiagDevice, + device: Device, mut qmdl_file_rx: Receiver, qmdl_file_tx: Sender, ui_update_sender: Sender, @@ -382,8 +383,21 @@ pub fn run_diag_read_thread( min_space_to_continue_mb: u64, ) { task_tracker.spawn(async move { + info!("Using configuration for device: {0:?}", device); + let mut dev = DiagDevice::new(&device) + .await?; + dev.config_logs() + .await?; + let mut diag_stream = pin!(dev.as_stream().into_stream()); - let mut diag_task = DiagTask::new(ui_update_sender, analysis_sender, analyzer_config, notification_channel, min_space_to_start_mb, min_space_to_continue_mb); + let mut diag_task = DiagTask::new( + ui_update_sender, + analysis_sender, + analyzer_config, + notification_channel, + min_space_to_start_mb, + min_space_to_continue_mb + ); qmdl_file_tx .send(DiagDeviceCtrlMessage::StartRecording { response_tx: None }) .await diff --git a/daemon/src/error.rs b/daemon/src/error.rs index 0c9adb6..1f606f8 100644 --- a/daemon/src/error.rs +++ b/daemon/src/error.rs @@ -1,4 +1,3 @@ -use rayhunter::diag_device::DiagDeviceError; use thiserror::Error; use crate::qmdl_store::RecordingStoreError; @@ -7,8 +6,6 @@ use crate::qmdl_store::RecordingStoreError; pub enum RayhunterError { #[error("Config file parsing error: {0}")] ConfigFileParsingError(#[from] toml::de::Error), - #[error("Diag intialization error: {0}")] - DiagInitError(DiagDeviceError), #[error("Tokio error: {0}")] TokioError(#[from] tokio::io::Error), #[error("QmdlStore error: {0}")] diff --git a/daemon/src/main.rs b/daemon/src/main.rs index f829ebd..58a8d5c 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -42,7 +42,6 @@ use diag::{ use log::{error, info}; use qmdl_store::RecordingStoreError; use rayhunter::Device; -use rayhunter::diag_device::DiagDevice; use stats::get_log; use tokio::net::TcpListener; use tokio::select; @@ -214,18 +213,10 @@ async fn run_with_config( let notification_service = NotificationService::new(config.ntfy_url.clone()); if !config.debug_mode { - info!("Using configuration for device: {0:?}", config.device); - let mut dev = DiagDevice::new(&config.device) - .await - .map_err(RayhunterError::DiagInitError)?; - dev.config_logs() - .await - .map_err(RayhunterError::DiagInitError)?; - info!("Starting Diag Thread"); run_diag_read_thread( &task_tracker, - dev, + config.device.clone(), diag_rx, diag_tx.clone(), ui_update_tx.clone(),