-
Notifications
You must be signed in to change notification settings - Fork 0
Safe usbtmc network #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1-implement-usb-tmc
Are you sure you want to change the base?
Conversation
3af4648 to
1e48003
Compare
| 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}"))?; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
| fn send(&mut self, request: &str) -> Result<()> { | ||
| let mut request_with_newline = String::from(request); | ||
| request_with_newline.push('\n'); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
No description provided.