Skip to content

Commit

Permalink
implement get_time
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Mar 28, 2020
1 parent 4649191 commit b0eaa36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
27 changes: 27 additions & 0 deletions src/command/mobile_control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ pub struct GetModuleFunctionality;
#[at_cmd("+CIND?", IndicatorControl)]
pub struct GetIndicatorControl;

/// 5.7 Clock +CCLK
///
/// Sets the real-time clock of the MT
#[derive(Clone, AtatCmd)]
#[at_cmd("+CCLK", NoResponse)]
pub struct SetClock<'a> {
pub time: &'a str
}

/// 5.7 Clock +CCLK
///
/// Reads the real-time clock of the MT
///
/// **Notes:**
/// - If the parameter value is out of range, then the "+CME ERROR: operation
/// not supported" or "+CME ERROR: 4" will be provided (depending on the +CMEE
/// AT command setting).
/// - "TZ": The Time Zone information is represented by two digits. The value is
/// updated during the registration procedure when the automatic time zone
/// update is enabled (using +CTZU command) and the network supports the time
/// zone information.
/// - The Time Zone information is expressed in steps of 15 minutes and it can
/// assume a value in the range that goes from -96 to +96.
#[derive(Clone, AtatCmd)]
#[at_cmd("+CCLK?", DateTime)]
pub struct GetClock;

/// 5.15 Automatic time zone update +CTZU
///
/// Configures the automatic time zone update via NITZ. **Notes:**
Expand Down
8 changes: 8 additions & 0 deletions src/command/mobile_control/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ pub struct IndicatorControl {
pub simind: u8,
}

/// 5.7 Clock +CCLK
///
/// Reads the real-time clock of the MT
#[derive(Clone, Debug, AtatResp)]
pub struct DateTime {
pub time: heapless::String<heapless::consts::U20>
}

/// 5.19 Report mobile termination error +CMEE
///
/// Configures the formatting of the result code +CME ERROR: <err> as an indication of an error relating to the
Expand Down
26 changes: 2 additions & 24 deletions src/modules/gsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
pub trait GSM {
fn begin(&self, pin: &str) -> Result<(), Error>;
fn shutdown(&self, secure: bool) -> Result<(), Error>;
fn get_time(&self) -> Result<DateTimeString, Error>;
fn get_time(&self) -> Result<DateTime, Error>;
}

impl<C, RST, DTR> GSM for GSMClient<C, RST, DTR>
Expand Down Expand Up @@ -76,29 +76,7 @@ where
Ok(())
}

fn get_time(&self) -> Result<DateTimeString, Error> {
fn get_time(&self) -> Result<DateTime, Error> {
self.send_at(&mobile_control::GetClock)

// let parts: Vec<u8, consts::U7> = datetime
// .time
// .split(|c| c == '/' || c == ',' || c == ':' || c == '+' || c == '-')
// .map(|p| p.parse::<u8>().unwrap())
// .collect();

// let timezone: i8 = if datetime.time.contains("+") {
// parts[6] as i8
// } else {
// -(parts[6] as i8)
// };

// Ok(DateTime {
// year: parts[0],
// month: parts[1],
// day: parts[2],
// hours: parts[3],
// minutes: parts[4],
// seconds: parts[5],
// timezone
// })
}
}

0 comments on commit b0eaa36

Please sign in to comment.