2023-08-15 21:07:15 +02:00
|
|
|
use derive_new::new;
|
2023-02-15 02:12:00 +01:00
|
|
|
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
2023-02-14 15:53:14 +01:00
|
|
|
use satrs_core::events::{EventU32TypedSev, SeverityInfo};
|
2023-07-05 21:08:04 +02:00
|
|
|
use satrs_core::objects::ObjectId;
|
2023-08-29 10:22:23 +02:00
|
|
|
use satrs_core::spacepackets::ecss::tc::IsPusTelecommand;
|
2023-08-15 21:07:15 +02:00
|
|
|
use satrs_core::spacepackets::ecss::PusPacket;
|
2023-08-29 10:22:23 +02:00
|
|
|
use satrs_core::spacepackets::{ByteConversionError, CcsdsPacket};
|
2023-08-15 08:49:54 +02:00
|
|
|
use satrs_core::tmtc::TargetId;
|
2023-08-15 21:07:15 +02:00
|
|
|
use std::fmt;
|
|
|
|
use std::net::Ipv4Addr;
|
|
|
|
use thiserror::Error;
|
2022-08-18 01:32:02 +02:00
|
|
|
|
2022-11-27 22:30:38 +01:00
|
|
|
use satrs_mib::res_code::{ResultU16, ResultU16Info};
|
2022-11-27 22:32:10 +01:00
|
|
|
use satrs_mib::resultcode;
|
2023-08-15 08:49:54 +02:00
|
|
|
|
|
|
|
pub type Apid = u16;
|
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum TargetIdCreationError {
|
|
|
|
#[error("byte conversion")]
|
|
|
|
ByteConversion(#[from] ByteConversionError),
|
|
|
|
#[error("not enough app data to generate target ID")]
|
2023-08-15 21:07:15 +02:00
|
|
|
NotEnoughAppData(usize),
|
2023-08-15 08:49:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: can these stay pub?
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, new)]
|
|
|
|
pub struct TargetIdWithApid {
|
|
|
|
pub apid: Apid,
|
|
|
|
pub target: TargetId,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TargetIdWithApid {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}, {}", self.apid, self.target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetIdWithApid {
|
|
|
|
pub fn apid(&self) -> Apid {
|
|
|
|
self.apid
|
|
|
|
}
|
2023-08-15 21:07:15 +02:00
|
|
|
pub fn target_id(&self) -> TargetId {
|
2023-08-15 08:49:54 +02:00
|
|
|
self.target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetIdWithApid {
|
2023-08-15 21:07:15 +02:00
|
|
|
pub fn from_tc(
|
|
|
|
tc: &(impl CcsdsPacket + PusPacket + IsPusTelecommand),
|
|
|
|
) -> Result<Self, TargetIdCreationError> {
|
2023-08-15 08:49:54 +02:00
|
|
|
if tc.user_data().len() < 4 {
|
2023-08-29 10:22:23 +02:00
|
|
|
return Err(ByteConversionError::FromSliceTooSmall {
|
2023-08-15 08:49:54 +02:00
|
|
|
found: tc.user_data().len(),
|
|
|
|
expected: 8,
|
2023-08-29 10:22:23 +02:00
|
|
|
}
|
2023-08-15 21:07:15 +02:00
|
|
|
.into());
|
2023-08-15 08:49:54 +02:00
|
|
|
}
|
|
|
|
Ok(Self {
|
|
|
|
apid: tc.apid(),
|
|
|
|
target: u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-11 00:45:59 +02:00
|
|
|
pub const PUS_APID: u16 = 0x02;
|
|
|
|
|
2023-02-15 02:12:00 +01:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromPrimitive, IntoPrimitive)]
|
|
|
|
#[repr(u8)]
|
|
|
|
pub enum CustomPusServiceId {
|
|
|
|
Mode = 200,
|
|
|
|
Health = 201,
|
|
|
|
}
|
|
|
|
|
2022-12-21 10:01:19 +01:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
|
|
|
pub enum RequestTargetId {
|
|
|
|
AcsSubsystem = 1,
|
|
|
|
}
|
|
|
|
|
2023-08-15 08:49:54 +02:00
|
|
|
pub const AOCS_APID: u16 = 1;
|
|
|
|
|
2023-07-05 21:08:04 +02:00
|
|
|
pub const ACS_OBJECT_ID: ObjectId = ObjectId {
|
|
|
|
id: RequestTargetId::AcsSubsystem as u32,
|
|
|
|
name: "ACS_SUBSYSTEM",
|
|
|
|
};
|
|
|
|
|
2022-11-27 22:05:42 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum GroupId {
|
|
|
|
Tmtc = 0,
|
2022-12-20 15:45:09 +01:00
|
|
|
Hk = 1,
|
2022-11-27 22:05:42 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 19:35:24 +01:00
|
|
|
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
|
2022-08-18 01:32:02 +02:00
|
|
|
pub const SERVER_PORT: u16 = 7301;
|
2022-11-27 22:05:42 +01:00
|
|
|
|
2023-02-13 09:20:00 +01:00
|
|
|
pub const TEST_EVENT: EventU32TypedSev<SeverityInfo> =
|
|
|
|
EventU32TypedSev::<SeverityInfo>::const_new(0, 0);
|
|
|
|
|
2022-12-20 15:45:09 +01:00
|
|
|
pub mod tmtc_err {
|
|
|
|
use super::*;
|
2022-11-27 22:05:42 +01:00
|
|
|
|
2022-12-20 15:45:09 +01:00
|
|
|
#[resultcode]
|
|
|
|
pub const INVALID_PUS_SERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 0);
|
|
|
|
#[resultcode]
|
|
|
|
pub const INVALID_PUS_SUBSERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 1);
|
2023-02-15 02:12:00 +01:00
|
|
|
#[resultcode]
|
|
|
|
pub const PUS_SERVICE_NOT_IMPLEMENTED: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 2);
|
2023-07-05 21:08:04 +02:00
|
|
|
#[resultcode]
|
|
|
|
pub const UNKNOWN_TARGET_ID: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 3);
|
2022-11-27 22:05:42 +01:00
|
|
|
|
2023-02-15 11:05:32 +01:00
|
|
|
#[resultcode(
|
|
|
|
info = "Not enough data inside the TC application data field. Optionally includes: \
|
|
|
|
8 bytes of failure data containing 2 failure parameters, \
|
|
|
|
P1 (u32 big endian): Expected data length, P2: Found data length"
|
|
|
|
)]
|
2022-12-20 15:45:09 +01:00
|
|
|
pub const NOT_ENOUGH_APP_DATA: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 2);
|
|
|
|
|
|
|
|
pub const TMTC_RESULTS: &[ResultU16Info] = &[
|
|
|
|
INVALID_PUS_SERVICE_EXT,
|
|
|
|
INVALID_PUS_SUBSERVICE_EXT,
|
|
|
|
NOT_ENOUGH_APP_DATA_EXT,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod hk_err {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[resultcode]
|
|
|
|
pub const TARGET_ID_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 0);
|
|
|
|
#[resultcode]
|
|
|
|
pub const UNIQUE_ID_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 1);
|
|
|
|
#[resultcode]
|
|
|
|
pub const UNKNOWN_TARGET_ID: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 2);
|
|
|
|
#[resultcode]
|
|
|
|
pub const COLLECTION_INTERVAL_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 3);
|
|
|
|
}
|
2023-07-09 17:04:18 +02:00
|
|
|
|
|
|
|
#[allow(clippy::enum_variant_names)]
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
|
|
pub enum TmSenderId {
|
|
|
|
PusVerification = 0,
|
|
|
|
PusTest = 1,
|
|
|
|
PusEvent = 2,
|
|
|
|
PusHk = 3,
|
|
|
|
PusAction = 4,
|
|
|
|
PusSched = 5,
|
2023-07-10 00:29:31 +02:00
|
|
|
AllEvents = 6,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
|
|
pub enum TcReceiverId {
|
|
|
|
PusTest = 1,
|
|
|
|
PusEvent = 2,
|
|
|
|
PusHk = 3,
|
|
|
|
PusAction = 4,
|
|
|
|
PusSched = 5,
|
2023-07-09 17:04:18 +02:00
|
|
|
}
|