improve error handling
This commit is contained in:
parent
ea44093ce7
commit
c9989bf7aa
@ -14,6 +14,7 @@ delegate = "0.10"
|
||||
zerocopy = "0.6"
|
||||
csv = "1"
|
||||
num_enum = "0.6"
|
||||
thiserror = "1"
|
||||
|
||||
[dependencies.satrs-core]
|
||||
path = "../satrs-core"
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::tmtc::MpscStoreAndSendError;
|
||||
use log::warn;
|
||||
use satrs_core::pool::StoreAddr;
|
||||
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::tc::PusTc;
|
||||
use satrs_core::spacepackets::time::cds::TimeProvider;
|
||||
@ -72,7 +73,7 @@ impl PusReceiver {
|
||||
store_addr: StoreAddr,
|
||||
service: u8,
|
||||
pus_tc: &PusTc,
|
||||
) -> Result<(), MpscStoreAndSendError> {
|
||||
) -> Result<PusPacketHandlerResult, MpscStoreAndSendError> {
|
||||
let init_token = self.verif_reporter.add_tc(pus_tc);
|
||||
self.stamp_helper.update_from_now();
|
||||
let accepted_token = self
|
||||
@ -83,43 +84,35 @@ impl PusReceiver {
|
||||
match service {
|
||||
Ok(standard_service) => match standard_service {
|
||||
PusServiceId::Test => {
|
||||
let res = self
|
||||
.pus_router
|
||||
self.pus_router
|
||||
.test_service_receiver
|
||||
.send((store_addr, accepted_token));
|
||||
match res {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("Error {e}")
|
||||
}
|
||||
}
|
||||
.send((store_addr, accepted_token))?;
|
||||
}
|
||||
PusServiceId::Housekeeping => self
|
||||
.pus_router
|
||||
.hk_service_receiver
|
||||
.send((store_addr, accepted_token))
|
||||
.unwrap(),
|
||||
.send((store_addr, accepted_token))?,
|
||||
PusServiceId::Event => self
|
||||
.pus_router
|
||||
.event_service_receiver
|
||||
.send((store_addr, accepted_token))
|
||||
.unwrap(),
|
||||
.send((store_addr, accepted_token))?,
|
||||
PusServiceId::Scheduling => self
|
||||
.pus_router
|
||||
.sched_service_receiver
|
||||
.send((store_addr, accepted_token))
|
||||
.unwrap(),
|
||||
_ => self
|
||||
.verif_reporter
|
||||
.start_failure(
|
||||
.send((store_addr, accepted_token))?,
|
||||
_ => {
|
||||
let result = self.verif_reporter.start_failure(
|
||||
accepted_token,
|
||||
FailParams::new(
|
||||
Some(self.stamp_helper.stamp()),
|
||||
&tmtc_err::PUS_SERVICE_NOT_IMPLEMENTED,
|
||||
Some(&[standard_service as u8]),
|
||||
),
|
||||
)
|
||||
.expect("Start failure verification failed"),
|
||||
);
|
||||
if result.is_err() {
|
||||
warn!("Sending verification failure failed");
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) {
|
||||
@ -143,6 +136,6 @@ impl PusReceiver {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok(PusPacketHandlerResult::RequestHandled)
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
use log::info;
|
||||
use satrs_core::hal::host::udp_server::{ReceiveResult, UdpTcServer};
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::mpsc::{Receiver, SendError, Sender, TryRecvError};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::ccsds::CcsdsReceiver;
|
||||
use crate::pus::{PusReceiver, PusTcMpscRouter};
|
||||
use satrs_core::pool::{SharedPool, StoreAddr, StoreError};
|
||||
use satrs_core::pus::verification::StdVerifReporterWithSender;
|
||||
use satrs_core::pus::AcceptedTc;
|
||||
use satrs_core::spacepackets::ecss::{PusPacket, SerializablePusPacket};
|
||||
use satrs_core::spacepackets::tc::PusTc;
|
||||
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 {
|
||||
StoreError(StoreError),
|
||||
SendError(SendError<StoreAddr>),
|
||||
}
|
||||
|
||||
impl Display for MpscStoreAndSendError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
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)
|
||||
}
|
||||
#[error("Store error: {0}")]
|
||||
Store(#[from] StoreError),
|
||||
#[error("TC send error: {0}")]
|
||||
TcSend(#[from] SendError<AcceptedTc>),
|
||||
#[error("TMTC send error: {0}")]
|
||||
TmTcSend(#[from] SendError<StoreAddr>),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
Loading…
Reference in New Issue
Block a user