use std::sync::Arc;
use deimos_shared::peripherals::PeripheralId;
use deimos_shared::states::{ByteStruct, OperatingMetrics};
use super::super::responder::{InstrumentProxy, InstrumentRunHandle, start_driver};
use super::driver::SiglentSdg2042XDriver;
use super::peripheral::{INPUT_SIZE, OUTPUT_SIZE, OperatingInput, OperatingOutput};
use crate::controller::context::ControllerCtx;
use crate::peripheral::Peripheral;
impl SiglentSdg2042XDriver {
pub fn run(&self, ctx: &ControllerCtx) -> Result<InstrumentRunHandle, String> {
let worker = self.shared_handle();
start_driver(
ctx,
format!("sdg2042x-{}", self.peripheral().serial_number),
"SDG2042X",
self.startup_timeout(),
Arc::new(self.shared_handle()),
move |stop, startup| worker.run_worker(stop, startup),
)
}
}
impl InstrumentProxy for SiglentSdg2042XDriver {
fn id(&self) -> PeripheralId {
self.peripheral().id()
}
fn input_size(&self) -> usize {
INPUT_SIZE
}
fn output_size(&self) -> usize {
OUTPUT_SIZE
}
fn process_request(&self, bytes: &[u8]) -> u64 {
let packet = OperatingInput::read_bytes(bytes);
self.submit(packet.state);
packet.id
}
fn write_response(&self, metrics: OperatingMetrics, bytes: &mut [u8]) -> Result<(), String> {
OperatingOutput {
metrics,
state: self.applied()?,
}
.write_bytes(bytes);
Ok(())
}
fn on_loss_of_contact(&self) {
self.request_safe_state();
}
fn error(&self) -> Option<String> {
self.latched_error()
}
}