added requested changes and used clippy to clean up code

This commit is contained in:
lkoester 2023-02-01 10:27:12 +01:00
parent 7569244a90
commit c2768a2735
4 changed files with 12 additions and 36 deletions

View File

@ -6,11 +6,10 @@ use alloc::vec::Vec;
use core::fmt::{Debug, Display, Formatter};
use core::time::Duration;
use spacepackets::ecss::{PusError, PusPacket};
use spacepackets::tc::{GenericPusTcSecondaryHeader, PusTc};
use spacepackets::tc::PusTc;
use spacepackets::time::cds::DaysLen24Bits;
use spacepackets::time::{CcsdsTimeProvider, TimeReader, TimestampError, UnixTimestamp};
use std::collections::BTreeMap;
use std::dbg;
#[cfg(feature = "std")]
use std::error::Error;
#[cfg(feature = "std")]
@ -85,7 +84,7 @@ impl From<TimestampError> for ScheduleError {
impl Error for ScheduleError {}
//TODO: Move to spacepackets
#[derive(Debug, PartialEq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum ScheduleSubservice {
EnableScheduling = 1,
DisableScheduling = 2,
@ -229,9 +228,7 @@ impl PusScheduler {
self.insert_unwrapped_and_stored_tc(time_stamp, addr)?;
Ok(addr)
}
Err(err) => {
return Err(err.into());
}
Err(err) => Err(err.into()),
}
}
@ -248,7 +245,7 @@ impl PusScheduler {
return Err(ScheduleError::WrongSubservice);
}
return if let Some(user_data) = pus_tc.user_data() {
let mut stamp: TimeStamp = TimeReader::from_bytes(user_data)?;
let stamp: TimeStamp = TimeReader::from_bytes(user_data)?;
let unix_stamp = stamp.unix_stamp();
let stamp_len = stamp.len_as_bytes();
self.insert_unwrapped_tc(unix_stamp, &user_data[stamp_len..], pool)

View File

@ -2,29 +2,26 @@ use crate::hk::{CollectionIntervalFactor, HkRequest};
use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{PusTcSource, TmStore};
use satrs_core::events::EventU32;
use satrs_core::pool::{StoreAddr, StoreError};
use satrs_core::pool::StoreAddr;
use satrs_core::pus::event::Subservices;
use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken};
use satrs_core::pus::hk;
use satrs_core::pus::scheduling::{PusScheduler, ScheduleSubservice};
use satrs_core::pus::scheduling::PusScheduler;
use satrs_core::pus::verification::{
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
};
use satrs_core::res_code::ResultU16;
use satrs_core::spacepackets::time::{CcsdsTimeProvider, UnixTimestamp};
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use satrs_core::tmtc::{AddressableId, PusServiceProvider};
use satrs_core::{
spacepackets, spacepackets::ecss::PusPacket, spacepackets::tc::PusTc,
spacepackets::time::cds::TimeProvider, spacepackets::time::TimeWriter, spacepackets::SpHeader,
spacepackets::ecss::PusPacket, spacepackets::tc::PusTc, spacepackets::time::cds::TimeProvider,
spacepackets::time::TimeWriter, spacepackets::SpHeader,
};
use satrs_example::{hk_err, tmtc_err};
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::sync::{Arc, LockResult, Mutex};
use std::time::Duration;
pub struct PusReceiver {
pub tm_helper: PusTmWithCdsShortHelper,
@ -373,17 +370,11 @@ impl PusReceiver {
scheduler
.insert_wrapped_tc::<TimeProvider>(pus_tc, pool.as_mut())
.expect("TODO: panic message");
let time =
TimeProvider::from_bytes_with_u16_days(&pus_tc.user_data().unwrap()).unwrap();
drop(scheduler);
self.verif_reporter
.completion_success(start_token, Some(&self.time_stamp))
.expect("Error sending completion success");
//let addr = self.tc_source.tc_store.add_pus_tc().unwrap();
//let unix_time = UnixTimestamp::new_only_seconds(self.stamper.unix_seconds());
//let worked = self.scheduler.insert_tc(unix_time, );
}
_ => {
self.verif_reporter
@ -396,7 +387,6 @@ impl PusReceiver {
),
)
.expect("Sending start failure TM failed");
return;
}
}
}

View File

@ -8,7 +8,6 @@ use std::fmt::{Display, Formatter};
use std::net::SocketAddr;
use std::rc::Rc;
use std::sync::mpsc::{Receiver, SendError, Sender, TryRecvError};
use std::sync::{Arc, LockResult, Mutex};
use std::thread;
use std::time::Duration;
@ -162,11 +161,11 @@ impl ReceivesCcsdsTc for PusTcSource {
}
}
pub fn core_tmtc_task(args: OtherArgs, mut tc_args: TcArgs, tm_args: TmArgs) {
let mut scheduler = Rc::new(RefCell::new(
let scheduler = Rc::new(RefCell::new(
PusScheduler::new_with_current_init_time(Duration::from_secs(5)).unwrap(),
));
let mut sched_clone = scheduler.clone();
let sched_clone = scheduler.clone();
let mut pus_receiver = PusReceiver::new(
PUS_APID,
tm_args.tm_sink_sender,
@ -193,17 +192,13 @@ pub fn core_tmtc_task(args: OtherArgs, mut tc_args: TcArgs, tm_args: TmArgs) {
tm_store: tm_args.tm_store.pool.clone(),
};
//let (mut tc_source, mut tc_receiver) = tc_args.split();
let mut tc_buf: [u8; 4096] = [0; 4096];
loop {
let mut tmtc_sched = scheduler.clone();
let tmtc_sched = scheduler.clone();
core_tmtc_loop(
&mut udp_tmtc_server,
&mut tc_args,
&mut tc_buf,
//&mut tc_source,
//&mut tc_receiver,
&mut pus_receiver,
tmtc_sched,
);
@ -215,16 +210,11 @@ fn core_tmtc_loop(
udp_tmtc_server: &mut UdpTmtcServer,
tc_args: &mut TcArgs,
tc_buf: &mut [u8],
//tc_source: &mut PusTcSource,
//tc_receiver: &mut Receiver<StoreAddr>,
pus_receiver: &mut PusReceiver,
scheduler: Rc<RefCell<PusScheduler>>,
) {
let releaser = |enabled: bool, addr: &StoreAddr| -> bool {
match tc_args.tc_source.tc_source.send(*addr) {
Ok(_) => true,
Err(_) => false,
}
tc_args.tc_source.tc_source.send(*addr).is_ok()
};
let mut pool = tc_args
@ -244,7 +234,6 @@ fn core_tmtc_loop(
}
Err(_) => {}
}
//.expect("error releasing tc");
drop(pool);
drop(scheduler);