From a8a52c8a22637071d9577d2714c99c37a391c8c2 Mon Sep 17 00:00:00 2001 From: Sofia Date: Thu, 28 May 2026 20:40:50 +0300 Subject: [PATCH] Add some new AT commands --- src/async_io.rs | 23 ++++++++++++++++++++++- src/at_commands.rs | 4 +--- src/main.rs | 24 ++++++++++-------------- src/states.rs | 11 +++++++++-- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/async_io.rs b/src/async_io.rs index 325948e..8a7007e 100644 --- a/src/async_io.rs +++ b/src/async_io.rs @@ -1,6 +1,6 @@ use core::cell::RefCell; -use alloc::{rc::Rc, string::String}; +use alloc::{borrow::ToOwned, rc::Rc, string::String}; use critical_section::Mutex; #[derive(Clone)] @@ -17,6 +17,8 @@ pub enum ATCommand { CheckSMSFormat, /// AT+CSCS=? ListTECharacterSets, + SetTECharSet(Charset), + SendSMS(String, String), } #[derive(Clone)] @@ -25,6 +27,25 @@ pub enum SMSFormat { 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)] pub struct Button { was_pressed: Rc>>, diff --git a/src/at_commands.rs b/src/at_commands.rs index b14c81f..ec4ca18 100644 --- a/src/at_commands.rs +++ b/src/at_commands.rs @@ -32,8 +32,7 @@ impl<'a, 'd> ATCommands<'a, 'd> { log::info!("ATCommands Ready!"); self.delay.delay_millis(1_000); - - log::info!("text: {}", self.flush_rx()); + self.flush_rx(); } pub fn raw_command(&mut self, command: String) -> String { @@ -99,7 +98,6 @@ impl<'a, 'd> ATCommands<'a, 'd> { self.uart.read_ready() } { let length = self.uart.read(&mut buffer).unwrap(); - log::info!("{:?}", &buffer[..length]); contents += str::from_utf8(&buffer[..length]).unwrap(); } diff --git a/src/main.rs b/src/main.rs index d9238da..17bd781 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![no_std] #![no_main] +#![feature(ascii_char)] #![deny( clippy::mem_forget, reason = "mem::forget is generally not safe to do with esp_hal types, especially those \ @@ -7,24 +8,13 @@ )] #![deny(clippy::large_stack_frames)] -use core::{ - cell::{Cell, RefCell}, - mem::MaybeUninit, -}; +use core::mem::MaybeUninit; -use alloc::{ - borrow::ToOwned, - boxed::Box, - format, - string::{String, ToString}, - sync::Arc, - vec::Vec, -}; -use critical_section::Mutex; +use alloc::{boxed::Box, format, string::ToString}; use esp_hal::{ clock::CpuClock, delay::Delay, - gpio::{Input, InputConfig, Level, Output, OutputConfig}, + gpio::{InputConfig, Level, Output, OutputConfig}, interrupt::software::SoftwareInterruptControl, main, 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 => { 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) }; } diff --git a/src/states.rs b/src/states.rs index 8d72233..1562a36 100644 --- a/src/states.rs +++ b/src/states.rs @@ -9,7 +9,7 @@ use alloc::{ use esp_hal::time::{Duration, Instant}; use crate::{ - async_io::{ATCommand, SMSFormat}, + async_io::{ATCommand, Charset, SMSFormat}, display::{Position, Rgb565}, font::{HorizontalAlignment, VerticalAlignment}, state::{State, StateData, TextSettings}, @@ -82,6 +82,13 @@ impl State for InitATState { self.message = "Selecting SMS\nformat".to_owned(); 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); 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 }