add status_time

This commit is contained in:
primardj 2024-04-11 17:45:35 +01:00
parent 28fb89caee
commit a4ee3033b0
2 changed files with 26 additions and 6 deletions

View file

@ -5,6 +5,7 @@ use std::path::Path;
use std::env::set_current_dir; use std::env::set_current_dir;
use std::fs; use std::fs;
use std::io::prelude::*; use std::io::prelude::*;
use std::time::SystemTime;
pub struct StatusObj { pub struct StatusObj {
svname: String, // Service name svname: String, // Service name
@ -81,7 +82,7 @@ impl StatusObj {
let seconds = misc::return_u8_in_u64(time_buf); let seconds = misc::return_u8_in_u64(time_buf);
let nano = misc::return_u8_in_u32(nano_buf); let nano = misc::return_u8_in_u32(nano_buf);
let pid_found = misc::return_u8_in_u32(pid_buf); let pid_found = misc::return_reverse_u8_in_u32(pid_buf);
let pause_run_raw = misc::make_pause_run(contents[16]); // done let pause_run_raw = misc::make_pause_run(contents[16]); // done
let up_down_raw = misc::make_up_down(contents[17]); // done let up_down_raw = misc::make_up_down(contents[17]); // done
@ -137,12 +138,17 @@ impl StatusObj {
} }
} }
let time_repaired: u64 = self.time; // TODO, change it to make the real tim eappear, of let time_repaired: u64 = self.time - 4611686018427387914;
// change misc::return_u8_in_u64 let sys_time_result = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH);
let sys_time = match sys_time_result {
Ok(x) => x.as_secs(),
Err(..) => time_repaired,
};
let dif_time = sys_time - time_repaired;
// Make return string with what made upper there. // Make return string with what made upper there.
let return_string: String = status_sv.to_owned() + " " + &self.svname + ": " + &pid_string + &time_repaired.to_string() + "s" + down_string; let return_string: String = status_sv.to_owned() + " " + &self.svname + ": " + &pid_string + &dif_time.to_string() + "s" + down_string;
return return_string; return return_string;
} }

View file

@ -31,7 +31,7 @@ pub fn make_run_finish(rf_int: u8) -> bool {
} }
} }
pub fn return_u8_in_u32(mut table: Vec<u8>) -> u32 { pub fn return_reverse_u8_in_u32(mut table: Vec<u8>) -> u32 {
// Table make 4 values u8 in one u32 // Table make 4 values u8 in one u32
if table.len() != 4 { if table.len() != 4 {
return 0 return 0
@ -46,13 +46,26 @@ pub fn return_u8_in_u32(mut table: Vec<u8>) -> u32 {
return r return r
} }
pub fn return_u8_in_u32(mut table: Vec<u8>) -> u32 {
// Table make 4 values u8 in one u32
if table.len() != 4 {
return 0
}
let mut r: u32 = 0;
for i in table.iter() {
//println!("{}",i);
r = r * 256;
r += <u8 as Into<u32>>::into(*i);
}
return r
}
pub fn return_u8_in_u64(mut table: Vec<u8>) -> u64 { pub fn return_u8_in_u64(mut table: Vec<u8>) -> u64 {
// Table make 8 values u8 in one u64 // Table make 8 values u8 in one u64
if table.len() != 8 { if table.len() != 8 {
return 0 return 0
} }
let mut r: u64 = 0; let mut r: u64 = 0;
table.reverse();
for i in table.iter() { for i in table.iter() {
//println!("{}",i); //println!("{}",i);
r = r * 256; r = r * 256;
@ -60,3 +73,4 @@ pub fn return_u8_in_u64(mut table: Vec<u8>) -> u64 {
} }
return r return r
} }