dummy gprs connect with error handling

This commit is contained in:
Vladan Popovic 2022-06-11 16:49:16 +02:00
parent 985ec56e2a
commit fbe132295e
2 changed files with 29 additions and 3 deletions

View file

@ -4,7 +4,7 @@ use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, alway
fn main() {
println!("Starting GPRS ...");
// TODO: start sim module
// TODO: connect to GPRS
let sim800l = modem::Modem::new();
sim800l.connect_to_gprs_ap("internet", "internet", "internet");
println!("GPRS started ...");
}

View file

@ -1,3 +1,29 @@
use std;
pub struct Modem {
// TODO: connect to GPRS
is_connected: bool,
}
#[derive(Debug, Clone)]
pub struct ModemConnectionError;
impl std::fmt::Display for ModemConnectionError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "gprs connection error")
}
}
type ModemConnection = Result<Modem, ModemConnectionError>;
impl Modem {
pub fn new() -> Self {
Self {
is_connected: false,
}
}
pub fn connect_to_gprs_ap(mut self, apn: &str, username: &str, password: &str)-> ModemConnection {
// TODO: set AT command for connecting to gprs
self.is_connected = true;
Ok(self)
}
}