improve error handling

This commit is contained in:
Robin Müller 2023-07-08 13:20:08 +02:00
parent ea44093ce7
commit c9989bf7aa
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 26 additions and 62 deletions

View File

@ -14,6 +14,7 @@ delegate = "0.10"
zerocopy = "0.6" zerocopy = "0.6"
csv = "1" csv = "1"
num_enum = "0.6" num_enum = "0.6"
thiserror = "1"
[dependencies.satrs-core] [dependencies.satrs-core]
path = "../satrs-core" path = "../satrs-core"

View File

@ -1,7 +1,8 @@
use crate::tmtc::MpscStoreAndSendError; use crate::tmtc::MpscStoreAndSendError;
use log::warn;
use satrs_core::pool::StoreAddr; use satrs_core::pool::StoreAddr;
use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender}; use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
use satrs_core::pus::AcceptedTc; use satrs_core::pus::{AcceptedTc, PusPacketHandlerResult};
use satrs_core::spacepackets::ecss::PusServiceId; use satrs_core::spacepackets::ecss::PusServiceId;
use satrs_core::spacepackets::tc::PusTc; use satrs_core::spacepackets::tc::PusTc;
use satrs_core::spacepackets::time::cds::TimeProvider; use satrs_core::spacepackets::time::cds::TimeProvider;
@ -72,7 +73,7 @@ impl PusReceiver {
store_addr: StoreAddr, store_addr: StoreAddr,
service: u8, service: u8,
pus_tc: &PusTc, pus_tc: &PusTc,
) -> Result<(), MpscStoreAndSendError> { ) -> Result<PusPacketHandlerResult, MpscStoreAndSendError> {
let init_token = self.verif_reporter.add_tc(pus_tc); let init_token = self.verif_reporter.add_tc(pus_tc);
self.stamp_helper.update_from_now(); self.stamp_helper.update_from_now();
let accepted_token = self let accepted_token = self
@ -83,43 +84,35 @@ impl PusReceiver {
match service { match service {
Ok(standard_service) => match standard_service { Ok(standard_service) => match standard_service {
PusServiceId::Test => { PusServiceId::Test => {
let res = self self.pus_router
.pus_router
.test_service_receiver .test_service_receiver
.send((store_addr, accepted_token)); .send((store_addr, accepted_token))?;
match res {
Ok(_) => {}
Err(e) => {
println!("Error {e}")
}
}
} }
PusServiceId::Housekeeping => self PusServiceId::Housekeeping => self
.pus_router .pus_router
.hk_service_receiver .hk_service_receiver
.send((store_addr, accepted_token)) .send((store_addr, accepted_token))?,
.unwrap(),
PusServiceId::Event => self PusServiceId::Event => self
.pus_router .pus_router
.event_service_receiver .event_service_receiver
.send((store_addr, accepted_token)) .send((store_addr, accepted_token))?,
.unwrap(),
PusServiceId::Scheduling => self PusServiceId::Scheduling => self
.pus_router .pus_router
.sched_service_receiver .sched_service_receiver
.send((store_addr, accepted_token)) .send((store_addr, accepted_token))?,
.unwrap(), _ => {
_ => self let result = self.verif_reporter.start_failure(
.verif_reporter
.start_failure(
accepted_token, accepted_token,
FailParams::new( FailParams::new(
Some(self.stamp_helper.stamp()), Some(self.stamp_helper.stamp()),
&tmtc_err::PUS_SERVICE_NOT_IMPLEMENTED, &tmtc_err::PUS_SERVICE_NOT_IMPLEMENTED,
Some(&[standard_service as u8]), Some(&[standard_service as u8]),
), ),
) );
.expect("Start failure verification failed"), if result.is_err() {
warn!("Sending verification failure failed");
}
}
}, },
Err(e) => { Err(e) => {
if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) { if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) {
@ -143,6 +136,6 @@ impl PusReceiver {
} }
} }
} }
Ok(()) Ok(PusPacketHandlerResult::RequestHandled)
} }
} }

View File

@ -1,16 +1,16 @@
use log::info; use log::info;
use satrs_core::hal::host::udp_server::{ReceiveResult, UdpTcServer}; use satrs_core::hal::host::udp_server::{ReceiveResult, UdpTcServer};
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::mpsc::{Receiver, SendError, Sender, TryRecvError}; use std::sync::mpsc::{Receiver, SendError, Sender, TryRecvError};
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use thiserror::Error;
use crate::ccsds::CcsdsReceiver; use crate::ccsds::CcsdsReceiver;
use crate::pus::{PusReceiver, PusTcMpscRouter}; use crate::pus::{PusReceiver, PusTcMpscRouter};
use satrs_core::pool::{SharedPool, StoreAddr, StoreError}; use satrs_core::pool::{SharedPool, StoreAddr, StoreError};
use satrs_core::pus::verification::StdVerifReporterWithSender; use satrs_core::pus::verification::StdVerifReporterWithSender;
use satrs_core::pus::AcceptedTc;
use satrs_core::spacepackets::ecss::{PusPacket, SerializablePusPacket}; use satrs_core::spacepackets::ecss::{PusPacket, SerializablePusPacket};
use satrs_core::spacepackets::tc::PusTc; use satrs_core::spacepackets::tc::PusTc;
use satrs_core::spacepackets::SpHeader; use satrs_core::spacepackets::SpHeader;
@ -37,44 +37,14 @@ impl TcArgs {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum MpscStoreAndSendError { pub enum MpscStoreAndSendError {
StoreError(StoreError), #[error("Store error: {0}")]
SendError(SendError<StoreAddr>), Store(#[from] StoreError),
} #[error("TC send error: {0}")]
TcSend(#[from] SendError<AcceptedTc>),
impl Display for MpscStoreAndSendError { #[error("TMTC send error: {0}")]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { TmTcSend(#[from] SendError<StoreAddr>),
match self {
MpscStoreAndSendError::StoreError(s) => {
write!(f, "store error {s}")
}
MpscStoreAndSendError::SendError(s) => {
write!(f, "send error {s}")
}
}
}
}
impl Error for MpscStoreAndSendError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
MpscStoreAndSendError::StoreError(s) => Some(s),
MpscStoreAndSendError::SendError(s) => Some(s),
}
}
}
impl From<StoreError> for MpscStoreAndSendError {
fn from(value: StoreError) -> Self {
Self::StoreError(value)
}
}
impl From<SendError<StoreAddr>> for MpscStoreAndSendError {
fn from(value: SendError<StoreAddr>) -> Self {
Self::SendError(value)
}
} }
#[derive(Clone)] #[derive(Clone)]