use typed timestamp

This commit is contained in:
lkoester 2022-12-19 10:11:11 +01:00
parent fbd5c27efc
commit 47b5f8a072

View File

@ -2,6 +2,8 @@
use core::mem::size_of; use core::mem::size_of;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::{Ptc, RealPfc, UnsignedPfc}; use spacepackets::ecss::{Ptc, RealPfc, UnsignedPfc};
use spacepackets::time::cds::TimeProvider;
use spacepackets::time::{CcsdsTimeProvider, TimeWriter};
enum NumOfParamsInfo { enum NumOfParamsInfo {
/// The parameter entry is a scalar field /// The parameter entry is a scalar field
@ -34,7 +36,7 @@ struct TestMgmHkWithIndividualValidity {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct TestMgmHkWithGroupValidity { struct TestMgmHkWithGroupValidity {
last_valid_stamp: [u8; 7], last_valid_stamp: TimeProvider,
valid: bool, valid: bool,
temp: f32, temp: f32,
mgm_vals: [u16; 3], mgm_vals: [u16; 3],
@ -90,9 +92,10 @@ impl TestMgmHkWithGroupValidity {
let mut curr_idx = 0; let mut curr_idx = 0;
buf[curr_idx] = self.valid as u8; buf[curr_idx] = self.valid as u8;
curr_idx += 1; curr_idx += 1;
buf[curr_idx..curr_idx + self.last_valid_stamp.len()] self.last_valid_stamp
.copy_from_slice(&self.last_valid_stamp); .write_to_bytes(&mut buf[curr_idx..curr_idx + self.last_valid_stamp.len_as_bytes()])
curr_idx += self.last_valid_stamp.len(); .unwrap();
curr_idx += self.last_valid_stamp.len_as_bytes();
buf[curr_idx] = 0; buf[curr_idx] = 0;
curr_idx += 1; curr_idx += 1;
buf[curr_idx] = Ptc::Real as u8; buf[curr_idx] = Ptc::Real as u8;
@ -147,11 +150,15 @@ pub fn main() {
// The easiest and probably best approach, trading off big advantages for TM downlink capacity: // The easiest and probably best approach, trading off big advantages for TM downlink capacity:
// Use a JSON format // Use a JSON format
let mgm_hk_group_validity = TestMgmHkWithGroupValidity { let mgm_hk_group_validity = TestMgmHkWithGroupValidity {
last_valid_stamp: [0; 7], last_valid_stamp: TimeProvider::from_now_with_u16_days().unwrap(),
valid: false, valid: false,
temp: 20.0, temp: 20.0,
mgm_vals: [0x1f1f, 0x2f2f, 0x3f3f], mgm_vals: [0x1f1f, 0x2f2f, 0x3f3f],
}; };
let mgm_as_json_str = serde_json::to_string(&mgm_hk_group_validity).unwrap(); let mgm_as_json_str = serde_json::to_string(&mgm_hk_group_validity).unwrap();
println!("JSON string with length {}: {}", mgm_as_json_str.len(), mgm_as_json_str); println!(
"JSON string with length {}: {}",
mgm_as_json_str.len(),
mgm_as_json_str
);
} }