From fbe132295e06415be4e6d718446a9a7d5ce74858 Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Sat, 11 Jun 2022 16:49:16 +0200 Subject: [PATCH] dummy gprs connect with error handling --- src/main.rs | 4 ++-- src/modem.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2c01ecb..0b2c8e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 ..."); } diff --git a/src/modem.rs b/src/modem.rs index b9294bd..4e98b58 100644 --- a/src/modem.rs +++ b/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; + +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) + } }