Skip to content

Conversation

@MatzeS
Copy link
Owner

@MatzeS MatzeS commented Jul 29, 2025

No description provided.

@MatzeS MatzeS force-pushed the safe-usbtmc-network branch from 3af4648 to 1e48003 Compare July 29, 2025 21:35
let mut spd = self.spd.lock().await;
spd.measure(self.channel, quantity).await
pub fn measure(&self, quantity: Quantity) -> Result<f32> {
let mut spd = self.spd.lock().map_err(|e| anyhow!("{e}"))?;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that these have to be manually mapped to anyhow is somewhat strange,
but either way it should be explicitly handled as a case in our Error enum.

Unfortunately, this is currently blocked by the generics of the Spd3303x struct but should become applicable once the inner driver is boxed.

spd.measure(self.channel, quantity).await
pub fn measure(&self, quantity: Quantity) -> Result<f32> {
let mut spd = self.spd.lock().map_err(|e| anyhow!("{e}"))?;
spd.measure(self.channel, quantity)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mutex is moved down the stack and wraps the driver,
then most methods could take non-mut self.

Except for the instrument interface (which is not used anyway and still not safe), after one exchange it should be fine to

Might be worth refactoring.

Ok(e) => return Ok(Self::new(e)),
Err(_) => continue,
if let Ok(stream) = TcpStream::connect(addr) {
stream.set_read_timeout(Some(Duration::from_secs(2))).ok();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short comment why this timeout was chosen would be nice.

Ok(NetworkDriver::new(stream))
}

pub fn new(stream: TcpStream) -> Self {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reintroduce the new method with the new TcpStream type, this still can be present, no?

Comment on lines +91 to +93
fn send(&mut self, request: &str) -> Result<()> {
let mut request_with_newline = String::from(request);
request_with_newline.push('\n');
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

}

pub struct Spd3303x<D: Driver> {
pub driver: D,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not need to be pub if new has been added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants