Skip to content

Commit

Permalink
Build example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Slattery committed Oct 25, 2024
1 parent ef394f2 commit e75d6cb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ log = { version = "0.4", default-features = false }
uncased = { version = "0.9.7", default-features = false }
embedded-hal-async = { version = "1", default-features = false }
embedded-svc = { version = "0.28", default-features = false }
esp-idf-hal = { version = "0.44", default-features = false }
# esp-idf-hal ={path = "../esp-idf-hal"}
# esp-idf-hal = { version = "0.44", default-features = false }
esp-idf-hal = { path = "../esp-idf-hal" }
embassy-time-driver = { version = "0.1", optional = true, features = [
"tick-hz-1_000_000",
] }
Expand Down
31 changes: 25 additions & 6 deletions examples/lte_modem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ use embedded_svc::{
utils::io,
};

use esp_idf_hal::gpio;
use esp_idf_hal::uart::UartDriver;
use esp_idf_hal::units::Hertz;
use esp_idf_hal::{
delay,
gpio::{self, PinDriver},
};
use esp_idf_svc::modem::sim::sim7600::SIM7600;
use esp_idf_svc::modem::sim::SimModem;
use esp_idf_svc::modem::EspModem;
Expand All @@ -35,6 +38,22 @@ fn main() -> anyhow::Result<()> {
let tx = peripherals.pins.gpio17;
let rx = peripherals.pins.gpio18;

let mut lte_reset = PinDriver::output(peripherals.pins.gpio42).unwrap();
lte_reset.set_low().unwrap();

let mut lte_power = PinDriver::output(peripherals.pins.gpio41).unwrap();
let mut lte_on = PinDriver::output(peripherals.pins.gpio40).unwrap();
// turn lte device on
log::info!("Reset GSM Device");
lte_power.set_high().unwrap();
let delay = delay::Delay::new_default();
delay.delay_ms(100);
lte_on.set_high().unwrap();
delay.delay_ms(100);
lte_on.set_low().unwrap();
delay.delay_ms(10000);
log::info!("Reset Complete");

let mut serial = UartDriver::new(
serial,
tx,
Expand All @@ -47,11 +66,11 @@ fn main() -> anyhow::Result<()> {
},
)?;

let mut buff = [0u8; 64];
let mut buff = [0u8; 1024];

let (mut tx, rx) = serial.split();

let buf_reader = BufferedRead::new(rx, &mut buff);
let mut buf_reader = BufferedRead::new(rx, &mut buff);

let mut sim_device = SIM7600::new();

Expand All @@ -60,10 +79,12 @@ fn main() -> anyhow::Result<()> {
Ok(()) => log::info!("Device in PPP mode"),
}

let mut modem = EspModem::new(&mut tx, &mut buf_reader, sys_loop)?;
let modem = EspModem::new(&mut tx, &mut buf_reader, sys_loop)?;

let _scope = std::thread::scope::<_, anyhow::Result<()>>(|s| {
let my_thread: ScopedJoinHandle<anyhow::Result<()>> = s.spawn(|| {
let mut buff = [0u8; 64];

match modem.run(&mut buff) {
Err(x) => log::error!("Error: {:?}", x),
Ok(_x) => (),
Expand All @@ -72,8 +93,6 @@ fn main() -> anyhow::Result<()> {
});
std::thread::sleep(Duration::from_secs(10));



let mut client = HttpClient::wrap(EspHttpConnection::new(&Default::default())?);

// GET
Expand Down
39 changes: 30 additions & 9 deletions src/modem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,22 @@ where
}
}

unsafe impl<T, R, E> Send for EspModem<'_, T, R, E>
where
T: embedded_svc::io::Write<Error = E> + Send,
R: embedded_svc::io::Read<Error = E>,
EspIOError: From<E>,
{
}

unsafe impl<T, R, E> Sync for EspModem<'_, T, R, E>
where
T: embedded_svc::io::Write<Error = E> + Send,
R: embedded_svc::io::Read<Error = E>,
EspIOError: From<E>,
{
}

impl<'d, T, R, E> Drop for EspModem<'d, T, R, E>
where
T: embedded_svc::io::Write<Error = E> + Send,
Expand Down Expand Up @@ -729,7 +745,7 @@ pub mod sim {

fn reset<T: Write, R: Read>(
tx: &mut T,
_rx: &R,
rx: &mut R,
buff: &mut [u8],
) -> Result<(), ModemError> {
let cmd = CommandBuilder::create_execute(buff, false)
Expand All @@ -740,14 +756,19 @@ pub mod sim {
tx.write(cmd).map_err(|_| ModemError::IO)?;

// not sure if I need this or not
// let len = comm
// .read(buff, TickType::new_millis(1000).ticks())
// .map_err(|_| ModemError::IO)?;
// log::info!("got response{:?}", std::str::from_utf8(&buff[..len]));
// CommandParser::parse(&buff[..len])
// .expect_identifier(b"ATZ0\r")
// .expect_identifier(b"\r\nOK\r\n")
// .finish()?;
let len = rx.read(buff).map_err(|_| ModemError::IO)?;
log::info!("got response{:?}", std::str::from_utf8(&buff[..len]));
if CommandParser::parse(&buff[..len])
.expect_identifier(b"ATZ0\r")
.expect_identifier(b"\r\nOK\r\n")
.finish()
.is_err()
{
CommandParser::parse(&buff[..len])
.expect_identifier(b"ATZ0\r")
.expect_identifier(b"\r\nERROR\r\n")
.finish()?
}
Ok(())
}

Expand Down

0 comments on commit e75d6cb

Please sign in to comment.