tests with embassy
This commit is contained in:
parent
dc5f90af49
commit
9e2dee4926
2 changed files with 48 additions and 56 deletions
76
src/main.rs
76
src/main.rs
|
@ -8,11 +8,12 @@ use esp_backtrace as _;
|
||||||
use esp_println::println;
|
use esp_println::println;
|
||||||
use hal::{
|
use hal::{
|
||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
|
Delay,
|
||||||
embassy::{self, executor::Executor},
|
embassy::{self, executor::Executor},
|
||||||
gpio::IO,
|
gpio::IO,
|
||||||
interrupt,
|
peripherals::{Peripherals, UART1},
|
||||||
peripherals::{Peripherals, Interrupt, UART1},
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
prelude::entry,
|
||||||
timer::TimerGroup,
|
timer::TimerGroup,
|
||||||
Uart,
|
Uart,
|
||||||
uart::{
|
uart::{
|
||||||
|
@ -27,8 +28,16 @@ use hal::{
|
||||||
};
|
};
|
||||||
use esp_hal_common::{UartRx, UartTx};
|
use esp_hal_common::{UartRx, UartTx};
|
||||||
|
|
||||||
use atat::{asynch::AtatClient, AtatIngress, Buffers, DefaultDigester, Ingress};
|
use atat::{
|
||||||
use heapless::Vec;
|
asynch::{
|
||||||
|
AtatClient,
|
||||||
|
Client,
|
||||||
|
},
|
||||||
|
AtatIngress,
|
||||||
|
Buffers,
|
||||||
|
DefaultDigester,
|
||||||
|
Ingress,
|
||||||
|
};
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
|
|
||||||
const READ_BUF_SIZE: usize = 64;
|
const READ_BUF_SIZE: usize = 64;
|
||||||
|
@ -37,27 +46,24 @@ const URC_CAPACITY: usize = 128;
|
||||||
const URC_SUBSCRIBERS: usize = 3;
|
const URC_SUBSCRIBERS: usize = 3;
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn reader(mut rx: UartRx<'static, UART1>) {
|
async fn ingress_task(
|
||||||
esp_println::println!("reading...");
|
mut ingress: Ingress<
|
||||||
// max message size to receive
|
'static,
|
||||||
// leave some extra space for AT-CMD characters
|
DefaultDigester<modem::Urc>,
|
||||||
const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16;
|
modem::Urc,
|
||||||
|
INGRESS_BUF_SIZE,
|
||||||
let mut rbuf: Vec<u8, MAX_BUFFER_SIZE> = Vec::new();
|
URC_CAPACITY,
|
||||||
let mut offset = 0;
|
URC_SUBSCRIBERS,
|
||||||
while let Ok(len) = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await {
|
>,
|
||||||
offset += len;
|
mut rx: UartRx<'static, UART1>) {
|
||||||
if offset == 0 {
|
println!("reading in ingress_task...");
|
||||||
rbuf.truncate(0);
|
ingress.read_from(&mut rx).await;
|
||||||
break;
|
|
||||||
}
|
|
||||||
// if set_at_cmd is used than stop reading
|
|
||||||
if len < READ_BUF_SIZE {
|
|
||||||
rbuf.truncate(offset);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn test_send(mut client: Client<'static, UartTx<'static, UART1>, INGRESS_BUF_SIZE>) {
|
||||||
|
println!("sending a single message (GetManufacturerId)");
|
||||||
|
client.send(&modem::GetManufacturerId).await.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
|
@ -65,6 +71,7 @@ fn main() -> ! {
|
||||||
let peripherals = Peripherals::take();
|
let peripherals = Peripherals::take();
|
||||||
let mut system = peripherals.DPORT.split();
|
let mut system = peripherals.DPORT.split();
|
||||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||||
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
let timer_group0 = TimerGroup::new(
|
let timer_group0 = TimerGroup::new(
|
||||||
peripherals.TIMG0,
|
peripherals.TIMG0,
|
||||||
|
@ -80,6 +87,11 @@ fn main() -> ! {
|
||||||
let mut power = io.pins.gpio4.into_push_pull_output();
|
let mut power = io.pins.gpio4.into_push_pull_output();
|
||||||
power.set_high().ok();
|
power.set_high().ok();
|
||||||
|
|
||||||
|
for i in 0..15 {
|
||||||
|
println!("waiting {} seconds ...", 15 - i);
|
||||||
|
delay.delay_ms(1000u32);
|
||||||
|
}
|
||||||
|
|
||||||
let modem_uart_pins = TxRxPins::new_tx_rx(
|
let modem_uart_pins = TxRxPins::new_tx_rx(
|
||||||
io.pins.gpio26.into_push_pull_output(),
|
io.pins.gpio26.into_push_pull_output(),
|
||||||
io.pins.gpio27.into_floating_input(),
|
io.pins.gpio27.into_floating_input(),
|
||||||
|
@ -107,18 +119,24 @@ fn main() -> ! {
|
||||||
static BUFFERS: Buffers<modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS> =
|
static BUFFERS: Buffers<modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS> =
|
||||||
Buffers::<modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>::new();
|
Buffers::<modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>::new();
|
||||||
|
|
||||||
|
let digester = DefaultDigester::<modem::Urc>::default()
|
||||||
|
.with_custom_success(|buf| {
|
||||||
|
println!("digested:\n{:?}", buf);
|
||||||
|
Ok((buf, buf.len()))
|
||||||
|
});
|
||||||
|
|
||||||
let (ingress, client) = BUFFERS.split(
|
let (ingress, client) = BUFFERS.split(
|
||||||
tx,
|
tx,
|
||||||
DefaultDigester::<modem::Urc>::default(),
|
digester,
|
||||||
atat::Config::default()
|
atat::Config::default()
|
||||||
);
|
);
|
||||||
|
|
||||||
interrupt::enable(Interrupt::UART1, interrupt::Priority::Priority1).unwrap();
|
|
||||||
|
|
||||||
println!("Starting embassy executor ...");
|
println!("Starting embassy executor ...");
|
||||||
let cell = StaticCell::new();
|
|
||||||
let executor: &'static mut Executor = cell.init(Executor::new());
|
static CELL: StaticCell<Executor> = StaticCell::new();
|
||||||
|
let executor = CELL.init(Executor::new());
|
||||||
executor.run(|spawner| {
|
executor.run(|spawner| {
|
||||||
spawner.spawn(reader(rx)).unwrap();
|
let _ = spawner.spawn(ingress_task(ingress, rx));
|
||||||
|
let _ = spawner.spawn(test_send(client));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,23 +11,6 @@ use heapless::String;
|
||||||
#[derive(Clone, AtatResp)]
|
#[derive(Clone, AtatResp)]
|
||||||
pub struct NoResponse;
|
pub struct NoResponse;
|
||||||
|
|
||||||
#[derive(Clone, AtatCmd)]
|
|
||||||
#[at_cmd("+CSGT", NoResponse)]
|
|
||||||
pub struct SetGreetingText<'a> {
|
|
||||||
#[at_arg(position = 0, len = 32)]
|
|
||||||
pub text: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, AtatCmd)]
|
|
||||||
#[at_cmd("AT", GreetingText)]
|
|
||||||
pub struct GetGreetingText;
|
|
||||||
|
|
||||||
#[derive(Clone, AtatResp)]
|
|
||||||
pub struct GreetingText {
|
|
||||||
#[at_arg(position = 0)]
|
|
||||||
pub text: String<64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, AtatCmd)]
|
#[derive(Clone, AtatCmd)]
|
||||||
#[at_cmd("+CGMI", ManufacturerIdText)]
|
#[at_cmd("+CGMI", ManufacturerIdText)]
|
||||||
pub struct GetManufacturerId;
|
pub struct GetManufacturerId;
|
||||||
|
@ -46,12 +29,3 @@ pub enum Urc {
|
||||||
#[at_urc("+UMWI")]
|
#[at_urc("+UMWI")]
|
||||||
MessageWaitingIndication(MessageWaitingIndication),
|
MessageWaitingIndication(MessageWaitingIndication),
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModemClient<'a, W> = Client<'a, W, 256>;
|
|
||||||
|
|
||||||
pub fn setup_modem<W>(tx: W, res_channel: &'_ ResponseChannel<256>) -> ModemClient<'_, W>
|
|
||||||
where W: Write {
|
|
||||||
let config = Config::new();
|
|
||||||
let client: ModemClient<W> = Client::new(tx, res_channel, config);
|
|
||||||
client
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue