dummy gprs connect with error handling
This commit is contained in:
parent
985ec56e2a
commit
fbe132295e
2 changed files with 29 additions and 3 deletions
|
@ -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 ...");
|
||||
}
|
||||
|
|
28
src/modem.rs
28
src/modem.rs
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue