mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
update RTC functions to use libstd
This commit is contained in:
parent
4b25be75d5
commit
107c63f7c2
2 changed files with 32 additions and 7 deletions
|
|
@ -47,6 +47,8 @@ num-derive = {version = "0.3.3", default-features = false}
|
||||||
num-traits = {version = "0.2.14", default-features = false}
|
num-traits = {version = "0.2.14", default-features = false}
|
||||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||||
|
|
||||||
|
chrono = {version = "0.4.19", default-features = false, features = ["std"]}
|
||||||
|
|
||||||
# for audio self-test analysis
|
# for audio self-test analysis
|
||||||
spectrum-analyzer = "0.5.2"
|
spectrum-analyzer = "0.5.2"
|
||||||
# used to parse net connectivity results
|
# used to parse net connectivity results
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
use crate::{ShellCmdApi,CommonEnv};
|
||||||
use xous_ipc::String;
|
use xous_ipc::String;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
use chrono::offset::Utc;
|
||||||
|
use chrono::{DateTime, NaiveDateTime};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RtcCmd {
|
pub struct RtcCmd {
|
||||||
|
|
@ -16,19 +19,39 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
||||||
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
let helpstring = "rtc options: set, get";
|
let helpstring = "rtc options: utc local";
|
||||||
|
|
||||||
let mut tokens = args.as_str().unwrap().split(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
"get" => {
|
"utc" => {
|
||||||
write!(ret, "{}", "Requesting DateTime from RTC...").unwrap();
|
let system_time = SystemTime::now();
|
||||||
// TODO_RTC
|
let datetime: DateTime<Utc> = system_time.into();
|
||||||
},
|
write!(ret, "UTC time is {}", datetime.format("%m/%d/%Y %T")).unwrap();
|
||||||
"set" => {
|
|
||||||
// TODO_RTC
|
|
||||||
},
|
},
|
||||||
|
"local" => {
|
||||||
|
let localtime = llio::LocalTime::new();
|
||||||
|
if let Some(timestamp) = localtime.get_local_time_ms() {
|
||||||
|
// we "say" UTC but actually local time is in whatever the local time is
|
||||||
|
let dt = chrono::DateTime::<Utc>::from_utc(
|
||||||
|
NaiveDateTime::from_timestamp(timestamp as i64 / 1000, 0),
|
||||||
|
chrono::offset::Utc
|
||||||
|
);
|
||||||
|
let timestr = dt.format("%m/%d/%Y %T").to_string();
|
||||||
|
write!(
|
||||||
|
ret,
|
||||||
|
"Local time is {}",
|
||||||
|
timestr
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
write!(
|
||||||
|
ret,
|
||||||
|
"Local time has not been set up"
|
||||||
|
).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue