pub fn read_status_response(&mut self) -> Result<Response<ReadBuffer, WriteBuffer>, ReadError> {
		let deadline = Instant::now() + self.read_timeout;
		let stuffed_message_len = loop {
			if Instant::now() > deadline {
				trace!("timeout reading status response, data in buffer: {:02X?}", &self.read_buffer.as_ref()[..self.read_len]);
				return Err(std::io::ErrorKind::TimedOut.into());
			}

			// Try to read more data into the buffer.
			let new_data = self.serial_port.read(&mut self.read_buffer.as_mut()[self.read_len..])?;
			if new_data == 0 {
				continue;
			}

			self.read_len += new_data;
			self.remove_garbage();

			let read_buffer = &self.read_buffer.as_mut()[..self.read_len];
			if !read_buffer.starts_with(&HEADER_PREFIX) {
				continue;
			}

			if self.read_len < STATUS_HEADER_SIZE {
				continue;
			}

			let body_len = read_buffer[5] as usize + read_buffer[6] as usize * 256;
			let body_len = body_len - 2; // Length includes instruction and error fields, which is already included in STATUS_HEADER_SIZE too.

			if self.read_len >= STATUS_HEADER_SIZE + body_len {
				break STATUS_HEADER_SIZE + body_len;
			}
		};

		let buffer = self.read_buffer.as_mut();
		let parameters_end = stuffed_message_len - 2;
		trace!("read packet: {:02X?}", &buffer[..parameters_end]);

		let checksum_message = read_u16_le(&buffer[parameters_end..]);
		let checksum_computed = calculate_checksum(0, &buffer[..parameters_end]);
		if checksum_message != checksum_computed {
			self.consume_read_bytes(stuffed_message_len);
			return Err(crate::InvalidChecksum {
				message: checksum_message,
				computed: checksum_computed,
			}
			.into());
		}

		// Remove byte-stuffing from the parameters.
		let parameter_count = bytestuff::unstuff_inplace(&mut buffer[STATUS_HEADER_SIZE..parameters_end]);

		// Creating the response struct here means that the data gets purged from the buffer even if we return early using the try operator.
		let response = Response {
			bus: self,
			stuffed_message_len,
			parameter_count,
		};

		crate::InvalidInstruction::check(response.instruction_id(), crate::instructions::instruction_id::STATUS)?;
		crate::MotorError::check(response.error())?;
		Ok(response)
	}
/// Read a raw status response from the bus.
Read a raw status response from the bus.
Read a raw status response from the bus .
pub fn read_status_response(&mut self) -> Result<Response<ReadBuffer, WriteBuffer>, ReadError> {
		let deadline = Instant::now() + self.read_timeout;
		let stuffed_message_len = loop {
			if Instant::now() > deadline {
				trace!("timeout reading status response, data in buffer: {:02X?}", &self.read_buffer.as_ref()[..self.read_len]);
				return Err(std::io::ErrorKind::TimedOut.into());
			}
			// Try to read more data into the buffer.
			let new_data = self.serial_port.read(&mut self.read_buffer.as_mut()[self.read_len..])?;
			if new_data == 0 {
				continue;
			}
			self.read_len += new_data;
			self.remove_garbage();
			let read_buffer = &self.read_buffer.as_mut()[..self.read_len];
			if !read_buffer.starts_with(&HEADER_PREFIX) {
				continue;
			}
			if self.read_len < STATUS_HEADER_SIZE {
				continue;
			}
			let body_len = read_buffer[5] as usize + read_buffer[6] as usize * 256;
			let body_len = body_len - 2; // Length includes instruction and error fields, which is already included in STATUS_HEADER_SIZE too.
			if self.read_len >= STATUS_HEADER_SIZE + body_len {
				break STATUS_HEADER_SIZE + body_len;
			}
		};
		let buffer = self.read_buffer.as_mut();
		let parameters_end = stuffed_message_len - 2;
		trace!("read packet: {:02X?}", &buffer[..parameters_end]);
		let checksum_message = read_u16_le(&buffer[parameters_end..]);
		let checksum_computed = calculate_checksum(0, &buffer[..parameters_end]);
		if checksum_message != checksum_computed {
			self.consume_read_bytes(stuffed_message_len);
			return Err(crate::InvalidChecksum {
				message: checksum_message,
				computed: checksum_computed,
			}
			.into());
		}
		// Remove byte-stuffing from the parameters.
		let parameter_count = bytestuff::unstuff_inplace(&mut buffer[STATUS_HEADER_SIZE..parameters_end]);
		// Creating the response struct here means that the data gets purged from the buffer even if we return early using the try operator.
		let response = Response {
			bus: self,
			stuffed_message_len,
			parameter_count,
		};
		crate::InvalidInstruction::check(response.instruction_id(), crate::instructions::instruction_id::STATUS)?;
		crate::MotorError::check(response.error())?;
		Ok(response)
	}
pub fn read_status_response ( & mut self ) -> Result < Response < ReadBuffer , WriteBuffer > , ReadError > { let deadline = Instant :: now ( ) + self . read_timeout ; let stuffed_message_len = loop { if Instant :: now ( ) > deadline { trace ! ( " " self read_buffer as_ref ( ) [ self read_len ] ) ; return Err ( std :: io :: ErrorKind :: TimedOut . into ( ) ) ; } // Try to read more data into the buffer. let new_data = self . serial_port . read ( & mut self . read_buffer . as_mut ( ) [ self . read_len .. ] ) ? ; if new_data == 0 { continue ; } self . read_len += new_data ; self . remove_garbage ( ) ; let read_buffer = & self . read_buffer . as_mut ( ) [ .. self . read_len ] ; if ! read_buffer . starts_with ( & HEADER_PREFIX ) { continue ; } if self . read_len < STATUS_HEADER_SIZE { continue ; } let body_len = read_buffer [ 5 ] as usize + read_buffer [ 6 ] as usize * 256 ; let body_len = body_len - 2 ; // Length includes instruction and error fields, which is already included in STATUS_HEADER_SIZE too. if self . read_len >= STATUS_HEADER_SIZE + body_len { break STATUS_HEADER_SIZE + body_len ; } } ; let buffer = self . read_buffer . as_mut ( ) ; let parameters_end = stuffed_message_len - 2 ; trace ! ( " " buffer [ parameters_end ] ) ; let checksum_message = read_u16_le ( & buffer [ parameters_end .. ] ) ; let checksum_computed = calculate_checksum ( 0 , & buffer [ .. parameters_end ] ) ; if checksum_message != checksum_computed { self . consume_read_bytes ( stuffed_message_len ) ; return Err ( crate :: InvalidChecksum { message : checksum_message , computed : checksum_computed , } . into ( ) ) ; } // Remove byte-stuffing from the parameters. let parameter_count = bytestuff :: unstuff_inplace ( & mut buffer [ STATUS_HEADER_SIZE .. parameters_end ] ) ; // Creating the response struct here means that the data gets purged from the buffer even if we return early using the try operator. let response = Response { bus : self , stuffed_message_len , parameter_count , } ; crate :: InvalidInstruction :: check ( response . instruction_id ( ) , crate :: instructions :: instruction_id :: STATUS ) ? ; crate :: MotorError :: check ( response . error ( ) ) ? ; Ok ( response ) }
Read a raw status response from the bus.
Read a raw status response from the bus .
&mut self
&mut self