remove all unwraps :)
This commit is contained in:
parent
43424ba997
commit
17b54fbe3a
4 changed files with 11 additions and 6 deletions
|
@ -16,6 +16,7 @@ opt-level = "z"
|
|||
pio = ["esp-idf-sys/pio"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.57"
|
||||
embedded-hal = "0.2.7"
|
||||
esp-idf-hal = "0.37.4"
|
||||
esp-idf-sys = { version = "0.31.5", features = ["binstart"] }
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#[allow(dead_code)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct Command {
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -3,11 +3,12 @@ mod modem;
|
|||
#[allow(dead_code)]
|
||||
mod command;
|
||||
|
||||
use anyhow;
|
||||
use esp_idf_hal::prelude::*;
|
||||
use esp_idf_hal::peripherals::Peripherals;
|
||||
use esp_idf_hal::serial;
|
||||
|
||||
fn main() {
|
||||
fn main() -> anyhow::Result<()> {
|
||||
esp_idf_sys::link_patches();
|
||||
|
||||
let dp = Peripherals::take().unwrap();
|
||||
|
@ -36,15 +37,17 @@ fn main() {
|
|||
let modem_rst = dp.pins.gpio5.into_output().unwrap();
|
||||
let modem_power = dp.pins.gpio23.into_output().unwrap();
|
||||
|
||||
modem::init(modem_pwrkey, modem_rst, modem_power).unwrap();
|
||||
modem::init(modem_pwrkey, modem_rst, modem_power)?;
|
||||
|
||||
let (tx, rx) = serial.split();
|
||||
let mut mdm = modem::Modem::new(tx, rx);
|
||||
|
||||
let _ = mdm.modem_info().unwrap();
|
||||
let _ = mdm.modem_info()?;
|
||||
let _ = mdm.connect_to_gprs_ap(
|
||||
config::A1_GPRS_AP.apn,
|
||||
config::A1_GPRS_AP.username,
|
||||
config::A1_GPRS_AP.password,
|
||||
).unwrap();
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::command::Command;
|
|||
|
||||
use std::iter::FromIterator;
|
||||
use std::thread;
|
||||
use std::error::Error;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use embedded_hal::serial::{Read, Write};
|
||||
|
@ -21,6 +22,8 @@ pub enum ModemError {
|
|||
SetupError(String),
|
||||
}
|
||||
|
||||
impl Error for ModemError {}
|
||||
|
||||
impl std::fmt::Display for ModemError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
|
|
Loading…
Reference in a new issue