small changes to scheduler and main

This commit is contained in:
lkoester 2023-01-30 09:52:11 +01:00
parent d25f4aad87
commit 3fb028a239
3 changed files with 9 additions and 11 deletions

View File

@ -19,9 +19,9 @@ use std::time::SystemTimeError;
pub enum ScheduleError { pub enum ScheduleError {
PusError(PusError), PusError(PusError),
TimeMarginTooShort(UnixTimestamp, UnixTimestamp), TimeMarginTooShort(UnixTimestamp, UnixTimestamp),
NestedScheduledTC, NestedScheduledTc,
StoreError(StoreError), StoreError(StoreError),
TCDataEmpty, TcDataEmpty,
TimestampError(TimestampError), TimestampError(TimestampError),
WrongSubservice, WrongSubservice,
WrongService, WrongService,
@ -40,14 +40,14 @@ impl Display for ScheduleError {
current_time, timestamp current_time, timestamp
) )
} }
ScheduleError::NestedScheduledTC => { ScheduleError::NestedScheduledTc => {
write!(f, "Error: nested scheduling is not allowed") write!(f, "Error: nested scheduling is not allowed")
} }
ScheduleError::StoreError(e) => { ScheduleError::StoreError(e) => {
write!(f, "Store Error: {}", e) write!(f, "Store Error: {}", e)
} }
ScheduleError::TCDataEmpty => { ScheduleError::TcDataEmpty => {
write!(f, "Error: empty TC Data field") write!(f, "Error: empty Tc Data field")
} }
ScheduleError::TimestampError(e) => { ScheduleError::TimestampError(e) => {
write!(f, "Timestamp Error: {}", e) write!(f, "Timestamp Error: {}", e)
@ -134,7 +134,6 @@ impl PusScheduler {
} }
/// Like [Self::new], but sets the `init_current_time` parameter to the current system time. /// Like [Self::new], but sets the `init_current_time` parameter to the current system time.
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn new_with_current_init_time(time_margin: Duration) -> Result<Self, SystemTimeError> { pub fn new_with_current_init_time(time_margin: Duration) -> Result<Self, SystemTimeError> {
@ -221,8 +220,7 @@ impl PusScheduler {
) -> Result<StoreAddr, ScheduleError> { ) -> Result<StoreAddr, ScheduleError> {
let check_tc = PusTc::from_bytes(tc)?; let check_tc = PusTc::from_bytes(tc)?;
if PusPacket::service(&check_tc.0) == 11 && PusPacket::subservice(&check_tc.0) == 4 { if PusPacket::service(&check_tc.0) == 11 && PusPacket::subservice(&check_tc.0) == 4 {
// TODO: should not be able to schedule a scheduled tc return Err(ScheduleError::NestedScheduledTc);
return Err(ScheduleError::NestedScheduledTC);
} }
match pool.add(tc) { match pool.add(tc) {
@ -254,7 +252,7 @@ impl PusScheduler {
let stamp_len = stamp.len_as_bytes(); let stamp_len = stamp.len_as_bytes();
self.insert_unwrapped_tc(unix_stamp, &user_data[stamp_len..], pool) self.insert_unwrapped_tc(unix_stamp, &user_data[stamp_len..], pool)
} else { } else {
Err(ScheduleError::TCDataEmpty) Err(ScheduleError::TcDataEmpty)
}; };
} }

View File

@ -1,5 +1,3 @@
extern crate core;
mod ccsds; mod ccsds;
mod hk; mod hk;
mod pus; mod pus;

View File

@ -229,6 +229,7 @@ fn core_tmtc_loop(
scheduler scheduler
.release_telecommands(releaser, pool.as_mut()) .release_telecommands(releaser, pool.as_mut())
.expect("error releasing tc"); .expect("error releasing tc");
drop(pool);
while poll_tc_server(udp_tmtc_server) {} while poll_tc_server(udp_tmtc_server) {}
match tc_args.tc_receiver.try_recv() { match tc_args.tc_receiver.try_recv() {
@ -263,6 +264,7 @@ fn core_tmtc_loop(
} }
fn poll_tc_server(udp_tmtc_server: &mut UdpTmtcServer) -> bool { fn poll_tc_server(udp_tmtc_server: &mut UdpTmtcServer) -> bool {
match udp_tmtc_server.udp_tc_server.try_recv_tc() { match udp_tmtc_server.udp_tc_server.try_recv_tc() {
Ok(_) => true, Ok(_) => true,
Err(e) => match e { Err(e) => match e {