read the TCP reply length and return a number

This commit is contained in:
Vladan Popovic 2022-06-22 14:37:55 +02:00
parent 327c86a504
commit 4842f18b34
2 changed files with 21 additions and 12 deletions

View file

@ -256,19 +256,26 @@ impl<UART: serial::Uart> Modem<UART> {
Ok(())
}
pub fn tcp_receive_query_len(&mut self) -> Result<()> {
self.send_command(Command::tcp_receive_query_len())?;
Ok(())
}
pub fn tcp_send(&mut self, payload: &str) -> Result<()> {
self.send_data(payload)?;
Ok(())
}
pub fn tcp_receive(&mut self, size: usize) -> Result<String> {
self.send_command(Command::tcp_receive(size))
pub fn tcp_receive_reply_len(&mut self) -> Result<usize> {
let reply = self.send_command(Command::tcp_receive_query_len())?;
reply.lines()
.filter(|line| line.contains("+CIPRXGET: 4"))
.next()
.ok_or(ModemError::CommandError("reply not found :/".to_string()))
.map(|line| {
line.split(',')
.into_iter()
.last()
.unwrap_or("x")
.parse::<usize>()
.map_err(|_| ModemError::CommandError(format!("response size should be a number, got {}", line)))
})
.unwrap_or(Err(ModemError::CommandError(format!("received 0 elements from parsing"))))
}
pub fn tcp_close_connection(&mut self) -> Result<String> {