Add sending SMS
This commit is contained in:
parent
1ca3a3acc4
commit
325d707685
@ -48,6 +48,23 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
||||
self.read_response()
|
||||
}
|
||||
|
||||
pub fn raw_two_part_command(&mut self, command: String, additional: String) -> String {
|
||||
self.flush_rx();
|
||||
|
||||
self.uart.flush().unwrap();
|
||||
self.delay.delay_millis(250);
|
||||
self.uart.write_str(&(command.clone() + "\r")).unwrap();
|
||||
self.uart.flush().unwrap();
|
||||
self.delay.delay_millis(500);
|
||||
log::info!("Wrote command {}", command);
|
||||
log::info!("{}", self.flush_rx());
|
||||
|
||||
self.uart.write_str(&(additional.clone() + "\x1A")).unwrap();
|
||||
self.uart.flush().unwrap();
|
||||
|
||||
self.read_response()
|
||||
}
|
||||
|
||||
fn read_response(&mut self) -> String {
|
||||
let mut buffer = [0u8; 1024];
|
||||
|
||||
@ -55,17 +72,20 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
||||
|
||||
while {
|
||||
let parts: Vec<&str> = contents.split("\r\n").collect();
|
||||
!RESPONSES.iter().any(|r| parts.contains(r))
|
||||
!RESPONSES
|
||||
.iter()
|
||||
.any(|r| parts.iter().any(|p| p.contains(r)))
|
||||
} {
|
||||
let length = self.uart.read(&mut buffer).unwrap();
|
||||
contents += str::from_utf8(&buffer[..length]).unwrap();
|
||||
log::info!("Contents so far: {}", contents);
|
||||
}
|
||||
|
||||
let parts: Vec<&str> = contents.split("\r\n").collect();
|
||||
let (idx, _) = parts
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, part)| RESPONSES.contains(part))
|
||||
.find(|(_, part)| RESPONSES.iter().any(|r| part.contains(r)))
|
||||
.unwrap();
|
||||
parts
|
||||
.into_iter()
|
||||
@ -74,7 +94,7 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn flush_rx(&mut self) -> String {
|
||||
pub fn flush_rx(&mut self) -> String {
|
||||
let mut buffer = [0u8; 1024];
|
||||
|
||||
let mut contents = String::new();
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@ -135,8 +135,21 @@ fn main() -> ! {
|
||||
delay: Delay::new(),
|
||||
};
|
||||
|
||||
at_commands.init();
|
||||
log::info!("{}", at_commands.raw_command("ATI".to_owned()));
|
||||
// at_commands.init();
|
||||
// log::info!("{}", at_commands.raw_command("ATI".to_owned()));
|
||||
// log::info!("{}", at_commands.raw_command("AT+CMGF?".to_owned()));
|
||||
// log::info!("{}", at_commands.raw_command("AT+CPIN=1234".to_owned()));
|
||||
// log::info!("{}", at_commands.raw_command("AT+CPIN?".to_owned()));
|
||||
// log::info!("{}", at_commands.raw_command("AT+CMGF=1".to_owned()));
|
||||
// log::info!("{}", at_commands.raw_command("AT+CSCS=?".to_owned()));
|
||||
|
||||
// log::info!(
|
||||
// "{}",
|
||||
// at_commands.raw_two_part_command(
|
||||
// "AT+CMGS=\"number\"".to_owned(),
|
||||
// "hello".to_owned()
|
||||
// )
|
||||
// );
|
||||
|
||||
loop {
|
||||
let delay_start = Instant::now();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user