pub enum Response {
Acknowledge,
Data {
address: Address,
value: u8,
},
Version {
product: String,
version: String,
},
Error(RolandError),
}Expand description
Response types from VR-6HD
Variants§
Acknowledge
Acknowledge (ack)
Data
Data response (DTH)
Version
Version information (VER)
Error(RolandError)
Error response (ERR)
Implementations§
Source§impl Response
impl Response
Sourcepub fn parse(response: &str) -> Result<Self, RolandError>
pub fn parse(response: &str) -> Result<Self, RolandError>
Parse response from string slice
Handles both Telnet (no STX) and RS-232 (with STX) formats.
Requires alloc for String allocation in Version response.
Examples found in repository?
examples/telnet_client.rs (line 122)
98 fn read_response(&mut self) -> Result<Response, TelnetError> {
99 let mut buf = [0u8; 1024];
100
101 // Read data
102 let n = self.stream.read(&mut buf)?;
103
104 if n == 0 {
105 return Err(TelnetError::ConnectionClosed);
106 }
107
108 // Append to buffer
109 self.buffer.extend_from_slice(&buf[..n]);
110
111 // Try to parse response
112 // Responses typically end with ';' or control characters
113 let response_str = String::from_utf8_lossy(&self.buffer);
114
115 // Look for complete response (ends with ';' or is a control character)
116 if response_str.ends_with(';') ||
117 response_str.contains('\x06') || // ACK
118 response_str.contains('\x11') || // XON
119 response_str.contains('\x13')
120 {
121 // XOFF
122 let response = Response::parse(&response_str)?;
123 self.buffer.clear();
124 Ok(response)
125 } else {
126 // Incomplete response, wait a bit and try again
127 std::thread::sleep(Duration::from_millis(100));
128 self.read_response()
129 }
130 }Trait Implementations§
impl Eq for Response
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more