Add some new AT commands
This commit is contained in:
parent
eb8e619aa1
commit
a8a52c8a22
@ -1,6 +1,6 @@
|
|||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
|
||||||
use alloc::{rc::Rc, string::String};
|
use alloc::{borrow::ToOwned, rc::Rc, string::String};
|
||||||
use critical_section::Mutex;
|
use critical_section::Mutex;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -17,6 +17,8 @@ pub enum ATCommand {
|
|||||||
CheckSMSFormat,
|
CheckSMSFormat,
|
||||||
/// AT+CSCS=?
|
/// AT+CSCS=?
|
||||||
ListTECharacterSets,
|
ListTECharacterSets,
|
||||||
|
SetTECharSet(Charset),
|
||||||
|
SendSMS(String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -25,6 +27,25 @@ pub enum SMSFormat {
|
|||||||
TextMode = 1,
|
TextMode = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum Charset {
|
||||||
|
IRA,
|
||||||
|
UCS2,
|
||||||
|
HEX,
|
||||||
|
GSM,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Charset {
|
||||||
|
pub fn into_str(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Charset::IRA => "IRA".to_owned(),
|
||||||
|
Charset::UCS2 => "UCS2".to_owned(),
|
||||||
|
Charset::HEX => "HEX".to_owned(),
|
||||||
|
Charset::GSM => "GSM".to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Button {
|
pub struct Button {
|
||||||
was_pressed: Rc<Mutex<RefCell<bool>>>,
|
was_pressed: Rc<Mutex<RefCell<bool>>>,
|
||||||
|
|||||||
@ -32,8 +32,7 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
|||||||
|
|
||||||
log::info!("ATCommands Ready!");
|
log::info!("ATCommands Ready!");
|
||||||
self.delay.delay_millis(1_000);
|
self.delay.delay_millis(1_000);
|
||||||
|
self.flush_rx();
|
||||||
log::info!("text: {}", self.flush_rx());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_command(&mut self, command: String) -> String {
|
pub fn raw_command(&mut self, command: String) -> String {
|
||||||
@ -99,7 +98,6 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
|||||||
self.uart.read_ready()
|
self.uart.read_ready()
|
||||||
} {
|
} {
|
||||||
let length = self.uart.read(&mut buffer).unwrap();
|
let length = self.uart.read(&mut buffer).unwrap();
|
||||||
log::info!("{:?}", &buffer[..length]);
|
|
||||||
contents += str::from_utf8(&buffer[..length]).unwrap();
|
contents += str::from_utf8(&buffer[..length]).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
src/main.rs
24
src/main.rs
@ -1,5 +1,6 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
#![feature(ascii_char)]
|
||||||
#![deny(
|
#![deny(
|
||||||
clippy::mem_forget,
|
clippy::mem_forget,
|
||||||
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
|
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
|
||||||
@ -7,24 +8,13 @@
|
|||||||
)]
|
)]
|
||||||
#![deny(clippy::large_stack_frames)]
|
#![deny(clippy::large_stack_frames)]
|
||||||
|
|
||||||
use core::{
|
use core::mem::MaybeUninit;
|
||||||
cell::{Cell, RefCell},
|
|
||||||
mem::MaybeUninit,
|
|
||||||
};
|
|
||||||
|
|
||||||
use alloc::{
|
use alloc::{boxed::Box, format, string::ToString};
|
||||||
borrow::ToOwned,
|
|
||||||
boxed::Box,
|
|
||||||
format,
|
|
||||||
string::{String, ToString},
|
|
||||||
sync::Arc,
|
|
||||||
vec::Vec,
|
|
||||||
};
|
|
||||||
use critical_section::Mutex;
|
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::CpuClock,
|
clock::CpuClock,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio::{Input, InputConfig, Level, Output, OutputConfig},
|
gpio::{InputConfig, Level, Output, OutputConfig},
|
||||||
interrupt::software::SoftwareInterruptControl,
|
interrupt::software::SoftwareInterruptControl,
|
||||||
main,
|
main,
|
||||||
spi::master::{Config, Spi},
|
spi::master::{Config, Spi},
|
||||||
@ -291,6 +281,12 @@ fn thread_2_main(async_io: AsyncIO, mut at_commands: ATCommands<'static, 'static
|
|||||||
async_io::ATCommand::ListTECharacterSets => {
|
async_io::ATCommand::ListTECharacterSets => {
|
||||||
at_commands.raw_command("AT+CSCS=?".to_string())
|
at_commands.raw_command("AT+CSCS=?".to_string())
|
||||||
}
|
}
|
||||||
|
async_io::ATCommand::SetTECharSet(charset) => {
|
||||||
|
at_commands.raw_command(format!("AT+CSCS=\"{}\"", charset.into_str()))
|
||||||
|
}
|
||||||
|
async_io::ATCommand::SendSMS(da, text) => {
|
||||||
|
at_commands.raw_two_part_command(format!("AT+CMGS={}", da), text)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
unsafe { async_io.set_at_response(response) };
|
unsafe { async_io.set_at_response(response) };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use alloc::{
|
|||||||
use esp_hal::time::{Duration, Instant};
|
use esp_hal::time::{Duration, Instant};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
async_io::{ATCommand, SMSFormat},
|
async_io::{ATCommand, Charset, SMSFormat},
|
||||||
display::{Position, Rgb565},
|
display::{Position, Rgb565},
|
||||||
font::{HorizontalAlignment, VerticalAlignment},
|
font::{HorizontalAlignment, VerticalAlignment},
|
||||||
state::{State, StateData, TextSettings},
|
state::{State, StateData, TextSettings},
|
||||||
@ -82,6 +82,13 @@ impl State for InitATState {
|
|||||||
self.message = "Selecting SMS\nformat".to_owned();
|
self.message = "Selecting SMS\nformat".to_owned();
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
5 => {
|
||||||
|
data.io
|
||||||
|
.send_at_command(ATCommand::SetTECharSet(Charset::IRA))
|
||||||
|
.unwrap();
|
||||||
|
self.message = "Selecting SMS\nformat".to_owned();
|
||||||
|
None
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
data.delay.delay_millis(1000);
|
data.delay.delay_millis(1000);
|
||||||
Some(Box::new(TextState {
|
Some(Box::new(TextState {
|
||||||
@ -90,7 +97,7 @@ impl State for InitATState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.inner_state = (self.inner_state + 1).min(7);
|
self.inner_state = (self.inner_state + 1).min(200);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user