use postcard_rpc::{ header::VarSeqKind, host_client::{HostClient, HostErr}, standard_icd::{WireError, ERROR_PATH}, }; use std::convert::Infallible; use bioz_icd_rs::{ BioImpedanceLeadMode, GetUniqueIdEndpoint, ImpedanceInitResult, SweepImpedanceInitResult, SweepImpedanceStartRequest, PingEndpoint, SetGreenLedEndpoint, SingleImpedanceStartRequest, StartSweepImpedanceEndpoint, StartSingleImpedanceEndpoint, StopImpedanceEndpoint }; use crate::icd::{IcdDftNum, MeasurementPointSet}; #[derive(Debug)] pub struct WorkbookClient { pub client: HostClient, } #[derive(Debug)] pub enum WorkbookError { Comms(HostErr), Endpoint(E), } impl From> for WorkbookError { fn from(value: HostErr) -> Self { Self::Comms(value) } } // --- impl WorkbookClient { pub fn new() -> Result { let client = HostClient::try_new_raw_nusb( |d| d.product_string() == Some("Bioz Amplifier"), ERROR_PATH, 8, VarSeqKind::Seq2, )?; Ok(Self { client }) } pub async fn wait_closed(&self) { self.client.wait_closed().await; } pub async fn ping(&self, id: u32) -> Result> { let val = self.client.send_resp::(&id).await?; Ok(val) } pub async fn get_id(&self) -> Result<[u8; 12], WorkbookError> { let id = self.client.send_resp::(&()).await?; Ok(id) } pub async fn set_green_led( &self, frequency: f32, ) -> Result<(), WorkbookError> { self.client.send_resp::(&frequency).await?; Ok(()) } pub async fn start_impedancemeter_single( &self, frequency: u32, lead_mode: BioImpedanceLeadMode, dft_number: IcdDftNum, ) -> Result> { let response = self.client .send_resp::(&SingleImpedanceStartRequest { update_frequency: 60, sinus_frequency: frequency, lead_mode, dft_number}) .await?; Ok(response) } pub async fn start_impedancemeter_sweep( &self, lead_mode: BioImpedanceLeadMode, points: MeasurementPointSet, ) -> Result> { let response = self.client .send_resp::(&SweepImpedanceStartRequest { lead_mode, points }) .await?; Ok(response) } pub async fn stop_impedancemeter(&self) -> Result> { let res = self .client .send_resp::(&()) .await?; Ok(res) } }