2024-04-09 11:18:54 +02:00
|
|
|
use satrs::spacepackets::time::cds::CdsTime;
|
|
|
|
use satrs::spacepackets::time::TimeWriter;
|
2024-04-08 17:29:18 +02:00
|
|
|
|
|
|
|
pub mod config;
|
2024-04-09 11:18:54 +02:00
|
|
|
|
2024-04-19 22:05:57 +02:00
|
|
|
#[derive(Debug)]
|
2024-04-09 11:18:54 +02:00
|
|
|
pub struct TimeStampHelper {
|
|
|
|
stamper: CdsTime,
|
|
|
|
time_stamp: [u8; 7],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TimeStampHelper {
|
|
|
|
pub fn stamp(&self) -> &[u8] {
|
|
|
|
&self.time_stamp
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_from_now(&mut self) {
|
|
|
|
self.stamper
|
|
|
|
.update_from_now()
|
|
|
|
.expect("Updating timestamp failed");
|
|
|
|
self.stamper
|
|
|
|
.write_to_bytes(&mut self.time_stamp)
|
|
|
|
.expect("Writing timestamp failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TimeStampHelper {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
stamper: CdsTime::now_with_u16_days().expect("creating time stamper failed"),
|
|
|
|
time_stamp: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-24 20:02:42 +02:00
|
|
|
|
|
|
|
pub fn update_time(time_provider: &mut CdsTime, timestamp: &mut [u8]) {
|
|
|
|
time_provider
|
|
|
|
.update_from_now()
|
|
|
|
.expect("Could not get current time");
|
|
|
|
time_provider
|
|
|
|
.write_to_bytes(timestamp)
|
|
|
|
.expect("Writing timestamp failed");
|
|
|
|
}
|