use &[u8] instead of &str

This commit is contained in:
Vladan Popovic 2022-06-25 18:31:43 +02:00
parent a0a80a4d3e
commit bc495a7592

View file

@ -185,7 +185,7 @@ impl<UART: serial::Uart> Modem<UART> {
self.read_response(cmd.contains, cmd.timeout) self.read_response(cmd.contains, cmd.timeout)
} }
fn send_data(&mut self, payload: &str) -> Result<String> { fn send_data(&mut self, buf: &[u8]) -> Result<String> {
self.rx.clear(); self.rx.clear();
let _ = self.send_bytes("AT+CIPSEND".as_bytes(), '\r')?; let _ = self.send_bytes("AT+CIPSEND".as_bytes(), '\r')?;
let send_request: String = self.rx.reset(Duration::from_millis(3000)) let send_request: String = self.rx.reset(Duration::from_millis(3000))
@ -196,7 +196,7 @@ impl<UART: serial::Uart> Modem<UART> {
return Err(ModemError::SendDataError); return Err(ModemError::SendDataError);
} }
self.send_bytes(payload.as_bytes(), 26 as char)?; // 26_u8 = Ctrl+z - to end sending data self.send_bytes(buf, 26 as char)?; // 26_u8 = Ctrl+z - to end sending data
let _ = self.read_response(Some("DATA ACCEPT".to_string()), Duration::from_millis(3000)); let _ = self.read_response(Some("DATA ACCEPT".to_string()), Duration::from_millis(3000));
self.rx.clear(); self.rx.clear();
@ -263,8 +263,8 @@ impl<UART: serial::Uart> Modem<UART> {
Ok(()) Ok(())
} }
pub fn tcp_send(&mut self, payload: &str) -> Result<()> { pub fn tcp_send(&mut self, buf: &[u8]) -> Result<()> {
self.send_data(payload)?; self.send_data(buf)?;
Ok(()) Ok(())
} }