try to fix reading and fail at it :/

This commit is contained in:
Vladan Popovic 2023-02-07 17:15:08 +01:00
parent 31a6228669
commit 8308bdb9a0
2 changed files with 8 additions and 9 deletions

View file

@ -45,7 +45,6 @@ fn main() -> anyhow::Result<()> {
// threads.push(thread::spawn(move || gps::main(gps_rx, gps_tx, gps_uart, gps_sender))); // threads.push(thread::spawn(move || gps::main(gps_rx, gps_tx, gps_uart, gps_sender)));
//thread::sleep(Duration::from_millis(1000)); //thread::sleep(Duration::from_millis(1000));
threads.push(thread::spawn(move || accel::main(accel_sender))); threads.push(thread::spawn(move || accel::main(accel_sender)));
thread::sleep(Duration::from_millis(3000));
let _ = modem::main(modem_rx, modem_tx, modem_uart, modem_pwrkey, modem_rst, modem_power, receiver)?; let _ = modem::main(modem_rx, modem_tx, modem_uart, modem_pwrkey, modem_rst, modem_power, receiver)?;

View file

@ -125,12 +125,8 @@ impl<UART: serial::Uart> Modem<UART> {
println!("-----------------------------------------------------------"); println!("-----------------------------------------------------------");
println!("Sending {} ...", cmd.text); println!("Sending {} ...", cmd.text);
let _ = self.serial let _ = nb::block!(self.serial
.write_bytes(cmd.text.as_bytes()) .write_bytes(&[cmd.text.as_bytes(), &['\r' as u8]].concat()))
.map_err(|_| ModemError::SendDataError(format!("Error in send_command({})", cmd.text)))?;
let _ = self.serial
.write(&['\r' as u8])
.map_err(|_| ModemError::SendDataError(format!("Error in send_command({})", cmd.text)))?; .map_err(|_| ModemError::SendDataError(format!("Error in send_command({})", cmd.text)))?;
self.command_read_response(cmd.contains) self.command_read_response(cmd.contains)
@ -253,7 +249,7 @@ impl<UART: serial::Uart> Modem<UART> {
pub fn tcp_connect(&mut self, addr: &str, port: u16) -> Result<()> { pub fn tcp_connect(&mut self, addr: &str, port: u16) -> Result<()> {
let _ = self.send_command(Command::tcp_connect(addr, port))?; let _ = self.send_command(Command::tcp_connect(addr, port))?;
for _ in 0..3 { for _ in 0..3 {
if let Ok(reply) = self.command_read_response(Some("CONNECT_OK".to_string())) { if let Ok(reply) = self.command_read_response(Some("CONNECT OK".to_string())) {
println!("TCP connect replied with {}", reply); println!("TCP connect replied with {}", reply);
break break
} }
@ -532,7 +528,11 @@ pub fn main<T: Sync + Send>(
let _ = mdm.tcp_set_quick_mode(false); let _ = mdm.tcp_set_quick_mode(false);
let _ = mdm.tcp_set_manual_receive(true); let _ = mdm.tcp_set_manual_receive(true);
let _ = mdm.tcp_connect("51.158.66.64", 7887)?;
if let Err(_) = mdm.tcp_connect("51.158.66.64", 7887) {
continue;
}
thread::sleep(Duration::from_secs(1));
let _ = mdm.mqtt_connect(device_id)?; let _ = mdm.mqtt_connect(device_id)?;