use std::time::Duration;
use tracing::Instrument;
use crate::app::{Listener, RetryStrategy};
use crate::link::LinkErrorMode;
use crate::master::task::MasterTask;
use crate::master::*;
use crate::serial::{PortState, SerialSettings};
use crate::util::session::{Enabled, Session};
pub fn spawn_master_serial(
config: MasterChannelConfig,
path: &str,
serial_settings: SerialSettings,
retry_delay: Duration,
listener: Box<dyn Listener<PortState>>,
) -> MasterChannel {
let log_path = path.to_owned();
let (tx, rx) = crate::util::channel::request_channel();
let task = MasterTask::new(Enabled::No, LinkErrorMode::Discard, config, rx);
let mut serial = super::task::SerialTask::new(
path,
serial_settings,
Session::master(task),
RetryStrategy::new(retry_delay, retry_delay),
listener,
);
let future = async move {
serial
.run()
.instrument(tracing::info_span!("dnp3-master-serial", "port" = ?log_path))
.await;
};
tokio::spawn(future);
MasterChannel::new(tx)
}