Added log and automatic reconnect.

This commit is contained in:
2025-08-12 11:59:10 +02:00
parent 0b55cdf8b8
commit 961e6cc34a
7 changed files with 193 additions and 84 deletions

View File

@@ -26,36 +26,17 @@ impl<E> From<HostErr<WireError>> for WorkbookError<E> {
}
}
trait FlattenErr {
type Good;
type Bad;
fn flatten(self) -> Result<Self::Good, WorkbookError<Self::Bad>>;
}
impl<T, E> FlattenErr for Result<T, E> {
type Good = T;
type Bad = E;
fn flatten(self) -> Result<Self::Good, WorkbookError<Self::Bad>> {
self.map_err(WorkbookError::Endpoint)
}
}
// ---
impl WorkbookClient {
pub fn new() -> Self {
let client = HostClient::new_raw_nusb(
pub fn new() -> Result<Self, String> {
let client = HostClient::try_new_raw_nusb(
|d| d.product_string() == Some("Bioz Amplifier"),
ERROR_PATH,
8,
VarSeqKind::Seq2,
);
Self { client }
}
pub fn new_serial(port: &str) -> Self {
let client = HostClient::new_serial_cobs(port, ERROR_PATH, 8, 9600, VarSeqKind::Seq2);
Self { client }
)?;
Ok(Self { client })
}
pub async fn wait_closed(&self) {
@@ -87,7 +68,6 @@ impl WorkbookClient {
self.client
.send_resp::<StartImpedanceEndpoint>(&StartImpedance { update_frequency: 60, sinus_frequency: frequency })
.await?;
Ok(())
}
@@ -96,13 +76,6 @@ impl WorkbookClient {
.client
.send_resp::<StopImpedanceEndpoint>(&())
.await?;
Ok(res)
}
}
impl Default for WorkbookClient {
fn default() -> Self {
Self::new()
}
}
}