This commit is contained in:
lkoester 2023-04-26 17:17:35 +02:00
parent bbd90ef0d4
commit 322fc70ac7
11 changed files with 191 additions and 217 deletions

View File

@ -1,28 +1,16 @@
use crate::action::ActionRequest;
use crate::aocs::AOCSSensorMode::{Idle, SendingData};
use crate::can_ids::PackageId::AOCSDataStarTracker1;
use crate::can_ids::{DeviceId, PackageId, PackageModel};
use crate::can_ids::{DeviceId, MessageId, MessageModel};
use crate::helpers::{ModeHelper, VerifHelper};
use crate::hk::{AocsDataMap, AocsDataType, AocsHousekeeper, CSS_SUN_VECTOR_1, CSS_SUN_VECTOR_2, CSS_SUN_VECTOR_3, CSS_VOLTAGE_4, CSS_VOLTAGE_5, CSS_VOLTAGE_6, GPS_ALTITUDE, GPS_LATITUDE, GPS_LONGITUDE, MGM_FIELD_1, MGM_FIELD_2, MGM_FIELD_3, STR_QUATERNION_1, STR_QUATERNION_2, STR_QUATERNION_3, STR_QUATERNION_4};
use crate::hk::{AocsDataMap, AocsDataType, CSS_SUN_VECTOR_1, CSS_SUN_VECTOR_2, CSS_SUN_VECTOR_3, CSS_VOLTAGE_4, CSS_VOLTAGE_5, CSS_VOLTAGE_6, GPS_ALTITUDE, GPS_LATITUDE, GPS_LONGITUDE, MGM_FIELD_1, MGM_FIELD_2, MGM_FIELD_3, STR_QUATERNION_1, STR_QUATERNION_2, STR_QUATERNION_3, STR_QUATERNION_4};
use crate::power_handler::{DeviceState, PowerSwitcher};
use crate::requests::{Request, RequestWithToken};
use crate::tmtc::TmStore;
use byteorder::{ByteOrder, LittleEndian};
use num_derive::ToPrimitive;
use satrs_core::hk::HkRequest;
use satrs_core::mode::{ModeAndSubmode, ModeRequest};
use satrs_core::pool::StoreAddr;
use satrs_core::power::{PowerSwitcherCommandSender, SwitchId};
use satrs_core::pus::verification::{
TcStateAccepted, TcStateNone, VerificationReporterWithSender, VerificationToken,
};
use satrs_core::pus::MpscPusInStoreSendError;
use satrs_core::seq_count::SeqCountProviderSyncClonable;
use satrs_core::spacepackets::time::cds::TimeProvider;
use serde::{Deserialize, Serialize};
use std::sync::mpsc::{channel, Receiver, Sender, TryRecvError};
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
use std::u32;
use log::debug;
#[derive(ToPrimitive, PartialEq, Copy, Clone)]
@ -34,8 +22,8 @@ pub enum AOCSSensorMode {
pub trait AocsSensorHandler {
type Error;
fn get_package_id(&mut self) -> Result<PackageId, Self::Error>;
fn send_message(&mut self, id: PackageId, buf: &[u8]) -> Result<(), Self::Error>;
fn get_package_id(&mut self) -> Result<MessageId, Self::Error>;
fn send_message(&mut self, id: MessageId, buf: &[u8]) -> Result<(), Self::Error>;
fn enable_sensor_data_generation(&mut self) -> Result<(), Self::Error> {
let id = self.get_package_id()?;
@ -60,8 +48,8 @@ pub struct CSSHandler {
device_state: DeviceState,
mode: AOCSSensorMode,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -70,13 +58,13 @@ pub struct CSSHandler {
impl AocsSensorHandler for CSSHandler {
type Error = ();
fn get_package_id(&mut self) -> Result<PackageId, Self::Error> {
Ok(PackageId::AOCSDataRequestSunSensor1)
fn get_package_id(&mut self) -> Result<MessageId, Self::Error> {
Ok(MessageId::AOCSDataRequestSunSensor1)
}
fn send_message(&mut self, id: PackageId, buf: &[u8]) -> Result<(), Self::Error> {
fn send_message(&mut self, id: MessageId, buf: &[u8]) -> Result<(), Self::Error> {
self.can_tx
.send(PackageModel::new(id, buf).unwrap())
.send(MessageModel::new(id, buf).unwrap())
.unwrap();
return Ok(());
}
@ -88,8 +76,8 @@ impl CSSHandler {
device_id: DeviceId,
device_state: DeviceState,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -221,29 +209,29 @@ impl CSSHandler {
if let Ok(package) = self.can_rx.try_recv() {
let mut map = self.aocs_data.lock().expect("error locking data map");
let float_data = self.decode_sensor_data(package.data());
match package.package_id() {
PackageId::AOCSDataSunSensor1 => {
map.update_value(CSS_SUN_VECTOR_1, AocsDataType::float_value(float_data))
match package.message_id() {
MessageId::AOCSDataSunSensor1 => {
map.update_value(CSS_SUN_VECTOR_1, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataSunSensor2 => {
map.update_value(CSS_SUN_VECTOR_2, AocsDataType::float_value(float_data))
MessageId::AOCSDataSunSensor2 => {
map.update_value(CSS_SUN_VECTOR_2, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataSunSensor3 => {
map.update_value(CSS_SUN_VECTOR_3, AocsDataType::float_value(float_data))
MessageId::AOCSDataSunSensor3 => {
map.update_value(CSS_SUN_VECTOR_3, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataSunSensor4 => {
map.update_value(CSS_VOLTAGE_4, AocsDataType::float_value(float_data))
MessageId::AOCSDataSunSensor4 => {
map.update_value(CSS_VOLTAGE_4, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataSunSensor5 => {
map.update_value(CSS_VOLTAGE_5, AocsDataType::float_value(float_data))
MessageId::AOCSDataSunSensor5 => {
map.update_value(CSS_VOLTAGE_5, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataSunSensor6 => {
map.update_value(CSS_VOLTAGE_6, AocsDataType::float_value(float_data))
MessageId::AOCSDataSunSensor6 => {
map.update_value(CSS_VOLTAGE_6, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
_ => {}
@ -264,8 +252,8 @@ pub struct MGMHandler {
device_state: DeviceState,
mode: AOCSSensorMode,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -274,13 +262,13 @@ pub struct MGMHandler {
impl AocsSensorHandler for MGMHandler {
type Error = ();
fn get_package_id(&mut self) -> Result<PackageId, Self::Error> {
Ok(PackageId::AOCSDataRequestMGM1)
fn get_package_id(&mut self) -> Result<MessageId, Self::Error> {
Ok(MessageId::AOCSDataRequestMGM1)
}
fn send_message(&mut self, id: PackageId, buf: &[u8]) -> Result<(), Self::Error> {
fn send_message(&mut self, id: MessageId, buf: &[u8]) -> Result<(), Self::Error> {
self.can_tx
.send(PackageModel::new(id, buf).unwrap())
.send(MessageModel::new(id, buf).unwrap())
.unwrap();
return Ok(());
}
@ -292,8 +280,8 @@ impl MGMHandler {
device_id: DeviceId,
device_state: DeviceState,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -426,17 +414,17 @@ impl MGMHandler {
if let Ok(package) = self.can_rx.try_recv() {
let mut map = self.aocs_data.lock().expect("error locking data map");
let float_data = self.decode_sensor_data(package.data());
match package.package_id() {
PackageId::AOCSDataMGM1 => {
map.update_value(MGM_FIELD_1, AocsDataType::float_value(float_data))
match package.message_id() {
MessageId::AOCSDataMGM1 => {
map.update_value(MGM_FIELD_1, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataMGM2 => {
map.update_value(MGM_FIELD_2, AocsDataType::float_value(float_data))
MessageId::AOCSDataMGM2 => {
map.update_value(MGM_FIELD_2, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataMGM3 => {
map.update_value(MGM_FIELD_3, AocsDataType::float_value(float_data))
MessageId::AOCSDataMGM3 => {
map.update_value(MGM_FIELD_3, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
_ => {}
@ -457,8 +445,8 @@ pub struct STRHandler {
device_state: DeviceState,
mode: AOCSSensorMode,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -467,13 +455,13 @@ pub struct STRHandler {
impl AocsSensorHandler for STRHandler {
type Error = ();
fn get_package_id(&mut self) -> Result<PackageId, Self::Error> {
Ok(PackageId::AOCSDataRequestStarTracker)
fn get_package_id(&mut self) -> Result<MessageId, Self::Error> {
Ok(MessageId::AOCSDataRequestStarTracker)
}
fn send_message(&mut self, id: PackageId, buf: &[u8]) -> Result<(), Self::Error> {
fn send_message(&mut self, id: MessageId, buf: &[u8]) -> Result<(), Self::Error> {
self.can_tx
.send(PackageModel::new(id, buf).unwrap())
.send(MessageModel::new(id, buf).unwrap())
.unwrap();
return Ok(());
}
@ -485,8 +473,8 @@ impl STRHandler {
device_id: DeviceId,
device_state: DeviceState,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -618,21 +606,21 @@ impl STRHandler {
if let Ok(package) = self.can_rx.try_recv() {
let mut map = self.aocs_data.lock().expect("error locking data map");
let float_data = self.decode_sensor_data(package.data());
match package.package_id() {
PackageId::AOCSDataStarTracker1 => {
map.update_value(STR_QUATERNION_1, AocsDataType::float_value(float_data))
match package.message_id() {
MessageId::AOCSDataStarTracker1 => {
map.update_value(STR_QUATERNION_1, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataStarTracker2 => {
map.update_value(STR_QUATERNION_2, AocsDataType::float_value(float_data))
MessageId::AOCSDataStarTracker2 => {
map.update_value(STR_QUATERNION_2, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataStarTracker3 => {
map.update_value(STR_QUATERNION_3, AocsDataType::float_value(float_data))
MessageId::AOCSDataStarTracker3 => {
map.update_value(STR_QUATERNION_3, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataStarTracker4 => {
map.update_value(STR_QUATERNION_4, AocsDataType::float_value(float_data))
MessageId::AOCSDataStarTracker4 => {
map.update_value(STR_QUATERNION_4, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
_ => {}
@ -653,8 +641,8 @@ pub struct GPSHandler {
device_state: DeviceState,
mode: AOCSSensorMode,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -663,13 +651,13 @@ pub struct GPSHandler {
impl AocsSensorHandler for GPSHandler {
type Error = ();
fn get_package_id(&mut self) -> Result<PackageId, Self::Error> {
Ok(PackageId::AOCSDataRequestGPS)
fn get_package_id(&mut self) -> Result<MessageId, Self::Error> {
Ok(MessageId::AOCSDataRequestGPS)
}
fn send_message(&mut self, id: PackageId, buf: &[u8]) -> Result<(), Self::Error> {
fn send_message(&mut self, id: MessageId, buf: &[u8]) -> Result<(), Self::Error> {
self.can_tx
.send(PackageModel::new(id, buf).unwrap())
.send(MessageModel::new(id, buf).unwrap())
.unwrap();
return Ok(());
}
@ -681,8 +669,8 @@ impl GPSHandler {
device_id: DeviceId,
device_state: DeviceState,
aocs_data: Arc<Mutex<AocsDataMap>>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
request_rx: Receiver<RequestWithToken>,
verif_helper: VerifHelper,
mode_helper: ModeHelper,
@ -814,17 +802,17 @@ impl GPSHandler {
if let Ok(package) = self.can_rx.try_recv() {
let mut map = self.aocs_data.lock().expect("error locking data map");
let float_data = self.decode_sensor_data(package.data());
match package.package_id() {
PackageId::AOCSDataGPSLatitude => {
map.update_value(GPS_LATITUDE, AocsDataType::float_value(float_data))
match package.message_id() {
MessageId::AOCSDataGPSLatitude => {
map.update_value(GPS_LATITUDE, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataGPSLongitude => {
map.update_value(GPS_LONGITUDE, AocsDataType::float_value(float_data))
MessageId::AOCSDataGPSLongitude => {
map.update_value(GPS_LONGITUDE, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
PackageId::AOCSDataGPSAltitude => {
map.update_value(GPS_ALTITUDE, AocsDataType::float_value(float_data))
MessageId::AOCSDataGPSAltitude => {
map.update_value(GPS_ALTITUDE, AocsDataType::FloatValue(float_data))
.expect("error updating value");
}
_ => {}

View File

@ -1,5 +1,5 @@
use crate::can_ids::{
can_id_to_package_id, package_id_to_can_id, DeviceId, PackageId, PackageModel,
can_id_to_message_id, message_id_to_can_id, DeviceId, MessageId, MessageModel,
SenderReceiverApid, SenderReceiverThread, ThreadId,
};
use embedded_can::{self, Frame};
@ -13,9 +13,9 @@ pub struct CanRxHandler {
interface: &'static str,
socket: socket::CanSocket,
//frame_id_to_sender_id: HashMap<embedded_can::Id, u32>, // double hash map: frame id -> receiver id -> sender handle
can_senders: HashMap<u16, Sender<PackageModel>>,
can_senders: HashMap<u16, Sender<MessageModel>>,
//dismissed_ids: Vec<embedded_can::Id>,
package_map: HashMap<PackageId, SenderReceiverApid>,
message_map: HashMap<MessageId, SenderReceiverApid>,
//packet_id_to_sender_id: HashMap<PackageId, ThreadId>,
}
@ -23,8 +23,8 @@ impl CanRxHandler {
pub fn new_socket(
interface: &'static str,
//frame_id_to_sender_id: HashMap<embedded_can::Id, u32>,
can_senders: HashMap<u16, Sender<PackageModel>>,
package_map: HashMap<PackageId, SenderReceiverApid>,
can_senders: HashMap<u16, Sender<MessageModel>>,
message_map: HashMap<MessageId, SenderReceiverApid>,
) -> Result<CanRxHandler, ()> {
let socket = socket::CanSocket::open(&interface);
if let Ok(socket) = socket {
@ -32,7 +32,7 @@ impl CanRxHandler {
interface,
socket,
can_senders,
package_map,
message_map,
})
} else {
Err(())
@ -60,16 +60,16 @@ impl CanRxHandler {
}
pub fn forward_frame(&self, frame: CanFrame) {
let frame_id = can_id_to_package_id(frame.id());
let frame_id = can_id_to_message_id(frame.id());
debug!("Frame forwarding with id: {:?}", frame_id);
if let Some(frame_id) = frame_id {
if self.package_map.contains_key(&frame_id) {
let value = self.package_map.get(&frame_id).unwrap();
if self.message_map.contains_key(&frame_id) {
let value = self.message_map.get(&frame_id).unwrap();
if value.get_sender() != DeviceId::OBC {
let message_sender = self.can_senders.get(&value.get_apid()).unwrap();
let data = frame.data();
let message =
PackageModel::new(frame_id, data).expect("Error generating message.");
MessageModel::new(frame_id, data).expect("Error generating message.");
message_sender.send(message).expect(&*format!(
"Failure sending can bus frame to thread{:?}, frame id {:?}",
value.get_apid(),
@ -84,15 +84,15 @@ impl CanRxHandler {
pub struct CanTxHandler {
interface: &'static str,
socket: socket::CanSocket,
package_map: HashMap<PackageId, SenderReceiverApid>,
message_receiver: Receiver<PackageModel>,
message_map: HashMap<MessageId, SenderReceiverApid>,
message_receiver: Receiver<MessageModel>,
}
impl CanTxHandler {
pub fn new_socket(
interface: &'static str,
package_map: HashMap<PackageId, SenderReceiverApid>,
message_receiver: Receiver<PackageModel>,
message_map: HashMap<MessageId, SenderReceiverApid>,
message_receiver: Receiver<MessageModel>,
) -> Result<CanTxHandler, ()> {
let socket = socket::CanSocket::open(&interface);
@ -101,7 +101,7 @@ impl CanTxHandler {
Ok(CanTxHandler {
interface,
socket,
package_map,
message_map,
message_receiver,
})
} else {
@ -110,17 +110,17 @@ impl CanTxHandler {
}
pub fn process_incoming(&mut self) {
if let Ok(package) = self.message_receiver.recv() {
self.tx_socket(package.package_id(), package.data());
if let Ok(message) = self.message_receiver.recv() {
self.tx_socket(message.message_id(), message.data());
}
}
pub fn tx_socket(&self, package_id: PackageId, data: &[u8]) {
if self.package_map.contains_key(&package_id) {
let value = self.package_map.get(&package_id).unwrap();
pub fn tx_socket(&self, message_id: MessageId, data: &[u8]) {
if self.message_map.contains_key(&message_id) {
let value = self.message_map.get(&message_id).unwrap();
if value.get_sender() == DeviceId::OBC {
if data.len() <= 8 {
let frame_id = package_id_to_can_id(&package_id);
let frame_id = message_id_to_can_id(&message_id);
let frame = CanFrame::new(frame_id, data);
if let Some(frame) = frame {
self.socket
@ -140,7 +140,7 @@ impl CanTxHandler {
);
}
} else {
warn!("Message dismissed, wrong package id: {:?}", package_id);
warn!("Message dismissed, wrong package id: {:?}", message_id);
}
}
}

View File

@ -17,7 +17,7 @@ pub enum ThreadId {
}
#[derive(Debug, EnumIter, Eq, Hash, PartialEq, Copy, Clone, FromPrimitive)]
pub enum PackageId {
pub enum MessageId {
PCDUStatusRequest = 10,
DevicePowerOnRequest = 11,
DevicePowerOffRequest = 12,
@ -134,26 +134,26 @@ impl TryFrom<u16> for DeviceId {
}
#[derive(Debug)]
pub struct PackageModel {
package_id: PackageId,
pub struct MessageModel {
message_id: MessageId,
data: Vec<u8>,
}
impl PackageModel {
pub fn new(package_id: PackageId, data: &[u8]) -> Result<PackageModel, ()> {
impl MessageModel {
pub fn new(message_id: MessageId, data: &[u8]) -> Result<MessageModel, ()> {
if data.len() > 8 {
warn!("Data exceeds maximum length.");
return Err(());
}
let vec = Vec::from(data);
return Ok(PackageModel {
package_id,
return Ok(MessageModel {
message_id,
data: vec,
});
}
pub fn package_id(&self) -> PackageId {
self.package_id
pub fn message_id(&self) -> MessageId {
self.message_id
}
pub fn data(&self) -> &Vec<u8> {
@ -189,8 +189,8 @@ impl SenderReceiverThread {
}
}
pub fn load_package_id_to_threads() -> HashMap<PackageId, SenderReceiverThread> {
let mut package_map: HashMap<PackageId, SenderReceiverThread> = HashMap::new();
pub fn load_message_id_to_threads() -> HashMap<MessageId, SenderReceiverThread> {
let mut message_map: HashMap<MessageId, SenderReceiverThread> = HashMap::new();
let properties = vec![
SenderReceiverThread::new(DeviceId::OBC, DeviceId::PCDU, ThreadId::PowerThread),
@ -247,13 +247,13 @@ pub fn load_package_id_to_threads() -> HashMap<PackageId, SenderReceiverThread>
];
let mut i = 0;
for id in PackageId::iter() {
for id in MessageId::iter() {
let value = properties.get(i).unwrap();
package_map.insert(id, *value);
message_map.insert(id, *value);
i += 1;
}
return package_map;
return message_map;
}
#[derive(Debug, Copy, Clone)]
@ -283,8 +283,8 @@ impl SenderReceiverApid {
}
}
pub fn load_package_id_to_apids() -> HashMap<PackageId, SenderReceiverApid> {
let mut package_map: HashMap<PackageId, SenderReceiverApid> = HashMap::new();
pub fn load_message_id_to_apids() -> HashMap<MessageId, SenderReceiverApid> {
let mut message_map: HashMap<MessageId, SenderReceiverApid> = HashMap::new();
let properties = vec![
SenderReceiverApid::new(DeviceId::OBC, DeviceId::PCDU, PWR_APID),
@ -341,13 +341,13 @@ pub fn load_package_id_to_apids() -> HashMap<PackageId, SenderReceiverApid> {
];
let mut i = 0;
for id in PackageId::iter() {
for id in MessageId::iter() {
let value = properties.get(i).unwrap();
package_map.insert(id, *value);
message_map.insert(id, *value);
i += 1;
}
return package_map;
return message_map;
}
/*
@ -384,10 +384,10 @@ pub fn load_device_ids() {
*/
//TODO: change ids from u32 to embeddedcan ids
pub fn package_id_to_value(packageid: &PackageId) -> u32 {
pub fn message_id_to_value(packageid: &MessageId) -> u32 {
*packageid as u32
}
pub fn package_id_to_can_id(packageid: &PackageId) -> Id {
pub fn message_id_to_can_id(packageid: &MessageId) -> Id {
let x = *packageid as u16;
Id::Standard(StandardId::new(x).unwrap())
}
@ -396,12 +396,12 @@ pub fn device_id_to_value(deviceid: &DeviceId) -> u32 {
*deviceid as u32
}
pub fn value_to_package_id(value: u32) -> Option<PackageId> {
pub fn value_to_message_id(value: u32) -> Option<MessageId> {
let element = FromPrimitive::from_u32(value);
return element;
}
pub fn can_id_to_package_id(value: Id) -> Option<PackageId> {
pub fn can_id_to_message_id(value: Id) -> Option<MessageId> {
let buf = match value {
Id::Standard(id) => id.as_raw() as u32,
Id::Extended(id) => id.as_raw(),

View File

@ -38,7 +38,6 @@ impl CcsdsPacketHandler for CcsdsReceiver {
} else {
return self.tc_source.pass_ccsds(sp_header, tc_raw);
}
Ok(())
}
fn handle_unknown_apid(

View File

@ -5,11 +5,10 @@ use satrs_core::mode::ModeAndSubmode;
use satrs_core::pool::StoreAddr;
use satrs_core::pus::mode::Subservice::TmModeReply;
use satrs_core::pus::verification::{
FailParams, TcStateAccepted, TcStateStarted, VerificationReporterWithSender, VerificationToken,
FailParams, TcStateStarted, VerificationReporterWithSender, VerificationToken,
};
use satrs_core::pus::MpscPusInStoreSendError;
use satrs_core::seq_count::{SeqCountProviderSyncClonable, SequenceCountProviderCore};
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::spacepackets::time::cds::TimeProvider;
use satrs_core::spacepackets::time::TimeWriter;
use satrs_core::spacepackets::tm::{PusTm, PusTmSecondaryHeader};
@ -148,7 +147,7 @@ impl ModeHelper {
SpHeader::tm_unseg(self.apid, self.seq_count_provider.get_and_increment(), 0).unwrap();
self.buf[0..4].copy_from_slice(&mode_submode.mode().to_be_bytes());
self.buf[4..6].copy_from_slice(&mode_submode.submode().to_be_bytes());
let mut len = 6;
let len = 6;
let data = self.buf[0..len].to_vec();
let tm_sec_header =
PusTmSecondaryHeader::new_simple(200, TmModeReply as u8, &self.time_stamp_buf);

View File

@ -1,7 +1,6 @@
use std::collections::HashMap;
use strum::IntoEnumIterator;
use crate::hk::AocsDataType::float_value;
use crate::hk::AocsDataType::FloatValue;
use crate::requests::Request;
use crate::requests::RequestWithToken;
use crate::tmtc::{TmStore, AOCS_HK_APID};
@ -9,21 +8,16 @@ use byteorder::{BigEndian, ByteOrder, LittleEndian};
use chrono::Duration;
use eurosim_obsw::hk_err;
use log::debug;
use num_enum::FromPrimitive;
use satrs_core::hk::{HkRequest, UniqueId};
use satrs_core::pool::StoreAddr;
use satrs_core::pus::hk::Subservice;
use satrs_core::pus::verification::{FailParams, VerificationReporterWithSender};
use satrs_core::pus::MpscPusInStoreSendError;
use satrs_core::seq_count::{SeqCountProviderSyncClonable, SequenceCountProviderCore};
use satrs_core::spacepackets::time::cds::{CdsCommon, TimeProvider};
use satrs_core::spacepackets::time::cds::{TimeProvider};
use satrs_core::spacepackets::time::{CcsdsTimeProvider, TimeWriter};
use satrs_core::spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use satrs_core::spacepackets::SpHeader;
use satrs_core::tmtc::AddressableId;
use serde::{Deserialize, Serialize};
use serde_json::from_slice;
use std::ops::Deref;
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
use strum_macros::EnumIter;
@ -64,22 +58,22 @@ impl AocsDataMap {
pub fn new() -> Self {
let mut data_map = HashMap::new();
data_map.insert(MGM_FIELD_1, float_value(0.0));
data_map.insert(MGM_FIELD_2, float_value(0.0));
data_map.insert(MGM_FIELD_3, float_value(0.0));
data_map.insert(CSS_SUN_VECTOR_1, float_value(0.0));
data_map.insert(CSS_SUN_VECTOR_2, float_value(0.0));
data_map.insert(CSS_SUN_VECTOR_3, float_value(0.0));
data_map.insert(CSS_VOLTAGE_4, float_value(0.0));
data_map.insert(CSS_VOLTAGE_5, float_value(0.0));
data_map.insert(CSS_VOLTAGE_6, float_value(0.0));
data_map.insert(STR_QUATERNION_1, float_value(0.0));
data_map.insert(STR_QUATERNION_2, float_value(0.0));
data_map.insert(STR_QUATERNION_3, float_value(0.0));
data_map.insert(STR_QUATERNION_4, float_value(0.0));
data_map.insert(GPS_LATITUDE, float_value(0.0));
data_map.insert(GPS_LONGITUDE, float_value(0.0));
data_map.insert(GPS_ALTITUDE, float_value(0.0));
data_map.insert(MGM_FIELD_1, FloatValue(0.0));
data_map.insert(MGM_FIELD_2, FloatValue(0.0));
data_map.insert(MGM_FIELD_3, FloatValue(0.0));
data_map.insert(CSS_SUN_VECTOR_1, FloatValue(0.0));
data_map.insert(CSS_SUN_VECTOR_2, FloatValue(0.0));
data_map.insert(CSS_SUN_VECTOR_3, FloatValue(0.0));
data_map.insert(CSS_VOLTAGE_4, FloatValue(0.0));
data_map.insert(CSS_VOLTAGE_5, FloatValue(0.0));
data_map.insert(CSS_VOLTAGE_6, FloatValue(0.0));
data_map.insert(STR_QUATERNION_1, FloatValue(0.0));
data_map.insert(STR_QUATERNION_2, FloatValue(0.0));
data_map.insert(STR_QUATERNION_3, FloatValue(0.0));
data_map.insert(STR_QUATERNION_4, FloatValue(0.0));
data_map.insert(GPS_LATITUDE, FloatValue(0.0));
data_map.insert(GPS_LONGITUDE, FloatValue(0.0));
data_map.insert(GPS_ALTITUDE, FloatValue(0.0));
Self { map: data_map }
}
@ -104,7 +98,7 @@ impl AocsDataMap {
map_as_vec.sort();
for element in map_as_vec {
match map.get(element).unwrap() {
float_value(val) => {
FloatValue(val) => {
let val_as_byte = BigEndian::write_f64(&mut (buf[i..i + 8]), *val);
}
}
@ -117,7 +111,7 @@ impl AocsDataMap {
#[derive(Debug, EnumIter, PartialEq, Copy, Clone)]
pub enum AocsDataType {
float_value(f64),
FloatValue(f64),
}
pub struct AocsHousekeeper {
@ -295,9 +289,9 @@ impl AocsHousekeeper {
let mut buf: [u8; 8] = [0; 8];
if let Some(ids) = &self.periodic_hk_ids {
for id in ids.clone() {
if let Some(float_value(field)) = data_copy.get_value(id) {
if let Some(FloatValue(field)) = data_copy.get_value(id) {
let data_str = LittleEndian::write_f64(&mut buf, *field);
&self.send_hk_packet(id, &buf);
let _ = &self.send_hk_packet(id, &buf);
}
}
}
@ -317,7 +311,7 @@ impl AocsHousekeeper {
let data_copy = data.clone();
drop(data);
let mut buf: [u8; 8] = [0; 8];
if let Some(float_value(field)) = data_copy.get_value(id) {
if let Some(FloatValue(field)) = data_copy.get_value(id) {
let data_str = LittleEndian::write_f64(&mut buf, *field);
self.send_hk_packet(id, &buf);
return Ok(());

View File

@ -26,20 +26,18 @@ use satrs_core::event_man::{
EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider,
};
use satrs_core::events::EventU32;
use satrs_core::pool::{LocalPool, PoolCfg, StoreAddr};
use satrs_core::pool::{LocalPool, PoolCfg};
use satrs_core::pus::event_man::{
DefaultPusMgmtBackendProvider, EventReporter, EventRequestWithToken, PusEventDispatcher,
};
use satrs_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
};
use satrs_core::pus::{EcssTmErrorWithSend, EcssTmSenderCore};
use satrs_core::seq_count::SeqCountProviderSyncClonable;
use satrs_core::spacepackets::tm::PusTm;
use strum::IntoEnumIterator;
use crate::can_ids::{
load_package_id_to_apids, load_package_id_to_threads, DeviceId, PackageModel, ThreadId,
load_message_id_to_apids, load_message_id_to_threads, DeviceId, MessageModel,
};
use chrono::Duration;
use log::info;
@ -50,11 +48,11 @@ use std::sync::mpsc::channel;
use std::sync::{mpsc, Arc, Mutex, RwLock};
use std::thread;
//use libc::time64_t;
use crate::aocs::{core_aocs_loop, AocsController, MGMHandler, STRHandler, GPSHandler, CSSHandler};
use crate::aocs::{AocsController, MGMHandler, STRHandler, GPSHandler, CSSHandler};
#[cfg(feature = "can")]
use crate::can::CanTxHandler;
use crate::helpers::{ModeHelper, VerifHelper};
use crate::hk::{AocsDataMap, AocsDataType, AocsHousekeeper};
use crate::hk::{AocsDataMap, AocsHousekeeper};
use crate::pld_handler::core_pld_task;
use crate::power_handler::{core_power_task, DeviceState, PowerSwitcher};
@ -182,14 +180,14 @@ fn main() {
tm_server_rx,
};
let (mgm_can_tx, mgm_can_rx) = mpsc::channel::<PackageModel>();
let (mgt_can_tx, mgt_can_rx) = mpsc::channel::<PackageModel>();
let (css_can_tx, css_can_rx) = mpsc::channel::<PackageModel>();
let (rwl_can_tx, rwl_can_rx) = mpsc::channel::<PackageModel>();
let (str_can_tx, str_can_rx) = mpsc::channel::<PackageModel>();
let (gps_can_tx, gps_can_rx) = mpsc::channel::<PackageModel>();
let (power_can_tx, power_can_rx) = mpsc::channel::<PackageModel>();
let (pld_can_tx, pld_can_rx) = mpsc::channel::<PackageModel>();
let (mgm_can_tx, mgm_can_rx) = mpsc::channel::<MessageModel>();
let (mgt_can_tx, mgt_can_rx) = mpsc::channel::<MessageModel>();
let (css_can_tx, css_can_rx) = mpsc::channel::<MessageModel>();
let (rwl_can_tx, rwl_can_rx) = mpsc::channel::<MessageModel>();
let (str_can_tx, str_can_rx) = mpsc::channel::<MessageModel>();
let (gps_can_tx, gps_can_rx) = mpsc::channel::<MessageModel>();
let (power_can_tx, power_can_rx) = mpsc::channel::<MessageModel>();
let (pld_can_tx, pld_can_rx) = mpsc::channel::<MessageModel>();
// make tx thread id hashmap
let mut can_senders = HashMap::new();
@ -203,7 +201,7 @@ fn main() {
can_senders.insert(GPS_APID, gps_can_tx);
// get package id hashmap
let package_ids_rx = load_package_id_to_apids();
let message_ids_rx = load_message_id_to_apids();
info!("Starting TMTC task");
let builder0 = thread::Builder::new().name("TMTCThread".into());
@ -215,7 +213,7 @@ fn main() {
#[cfg(feature = "can")]
let mut can_rx_socket =
can::CanRxHandler::new_socket("can0", can_senders.clone(), package_ids_rx.clone()).unwrap();
can::CanRxHandler::new_socket("can0", can_senders.clone(), message_ids_rx.clone()).unwrap();
#[cfg(feature = "can")]
info!("Starting CAN Socket listening task");
@ -227,7 +225,7 @@ fn main() {
#[cfg(feature = "can")]
let mut can_tx_socket =
CanTxHandler::new_socket("can0", package_ids_rx.clone(), can_tx_receiver).unwrap();
CanTxHandler::new_socket("can0", message_ids_rx.clone(), can_tx_receiver).unwrap();
#[cfg(feature = "can")]
info!("Starting CAN Socket writing task");
@ -259,7 +257,7 @@ fn main() {
);
});
let package_map_pld_tx = load_package_id_to_threads();
let package_map_pld_tx = load_message_id_to_threads();
let pld_tm_funnel_tx = tm_funnel_tx.clone();
let pld_tm_store = tm_store.clone();
@ -297,11 +295,11 @@ fn main() {
}
});
let package_map_aocs_tx = load_package_id_to_threads();
let package_map_aocs_tx = load_message_id_to_threads();
let aocs_tm_funnel_tx = tm_funnel_tx.clone();
let aocs_tm_store = tm_store.clone();
let mut aocs_data_not_threadsafe = AocsDataMap::new();
let aocs_data_not_threadsafe = AocsDataMap::new();
/*
aocs_data_not_threadsafe
.update_value(1, AocsDataType::float_value(1.0))

View File

@ -1,11 +1,11 @@
use crate::action::ActionRequest;
use crate::can_ids::{DeviceId, PackageId, PackageModel};
use crate::can_ids::{DeviceId, MessageId, MessageModel};
use crate::power_handler::{DeviceState, PowerSwitcher};
use crate::requests::{Request, RequestWithToken};
use eurosim_obsw::{tmtc_err, RequestTargetId};
use eurosim_obsw::{RequestTargetId};
use log::debug;
use satrs_core::power::{PowerSwitchInfo, PowerSwitcherCommandSender, SwitchId};
use satrs_core::pus::verification::{FailParams, VerificationReporterWithSender};
use satrs_core::pus::verification::{VerificationReporterWithSender};
use satrs_core::pus::MpscPusInStoreSendError;
use satrs_core::spacepackets::time::cds::TimeProvider;
use satrs_core::spacepackets::time::TimeWriter;
@ -29,8 +29,8 @@ pub struct CameraHandler {
camera_device_id: DeviceId,
camera_switch_id: SwitchId,
device_state: DeviceState,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
mode: CameraMode,
mode_rx: Receiver<CameraMode>,
action_rx: Receiver<RequestWithToken>,
@ -40,8 +40,8 @@ impl CameraHandler {
pub fn new(
power_switcher: PowerSwitcher,
camera_device_id: DeviceId,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
mode_rx: Receiver<CameraMode>,
action_rx: Receiver<RequestWithToken>,
) -> CameraHandler {
@ -157,7 +157,7 @@ impl CameraHandler {
}
if self.device_state == DeviceState::On {
self.can_tx
.send(PackageModel::new(PackageId::CameraImageRequest, &[1]).unwrap())
.send(MessageModel::new(MessageId::CameraImageRequest, &[1]).unwrap())
.unwrap();
debug!("sent camera request");
self.mode = CameraMode::Verification;
@ -167,7 +167,7 @@ impl CameraHandler {
if self.device_state == DeviceState::On {
debug!("waiting for image request confirmation");
if let Ok(msg) = self.can_rx.recv() {
if msg.package_id() == PackageId::CameraImageRequestConfirmation {
if msg.message_id() == MessageId::CameraImageRequestConfirmation {
self.mode = CameraMode::Start;
}
}
@ -177,7 +177,7 @@ impl CameraHandler {
if self.device_state == DeviceState::On {
debug!("waiting for image start confirmation");
if let Ok(msg) = self.can_rx.recv() {
if msg.package_id() == PackageId::CameraImageExecutionStart {
if msg.message_id() == MessageId::CameraImageExecutionStart {
self.mode = CameraMode::End;
}
}
@ -187,7 +187,7 @@ impl CameraHandler {
if self.device_state == DeviceState::On {
debug!("waiting for image end confirmation");
if let Ok(msg) = self.can_rx.recv() {
if msg.package_id() == PackageId::CameraImageExectutionEnd {
if msg.message_id() == MessageId::CameraImageExectutionEnd {
self.power_switcher
.send_switch_off_cmd(self.camera_switch_id)
.expect("sending switch command failed");
@ -217,8 +217,8 @@ impl CameraHandler {
pub fn core_pld_task(
power_switcher: PowerSwitcher,
pld_thread_rx: Receiver<RequestWithToken>,
pld_can_rx: Receiver<PackageModel>,
pld_can_tx: Sender<PackageModel>,
pld_can_rx: Receiver<MessageModel>,
pld_can_tx: Sender<MessageModel>,
reporter_pld: &mut VerificationReporterWithSender<MpscPusInStoreSendError>,
) {
let (_camera_mode_tx, camera_mode_rx) = mpsc::channel();
@ -234,7 +234,7 @@ pub fn core_pld_task(
);
let mut time_stamp_buf: [u8; 7] = [0; 7];
'outer: loop {
loop {
match pld_thread_rx.try_recv() {
Ok(request_with_token) => {
match request_with_token.0 {

View File

@ -1,11 +1,9 @@
use crate::can_ids::{DeviceId, PackageId, PackageModel};
use log::debug;
use crate::can_ids::{DeviceId, MessageId, MessageModel};
use satrs_core::power::{PowerSwitchInfo, PowerSwitcherCommandSender, SwitchId, SwitchState};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::vec;
pub use strum::IntoEnumIterator; // 0.17.1
pub use strum_macros::EnumIter; // 0.17.1
@ -25,10 +23,10 @@ pub struct PowerSwitcher {
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
}
pub struct PCDU {
pub struct PCDUHandler {
switch_rx: Receiver<(SwitchId, SwitchState)>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
}
@ -83,14 +81,14 @@ impl PowerSwitchInfo for PowerSwitcher {
}
}
impl PCDU {
impl PCDUHandler {
pub fn new(
switch_rx: Receiver<(SwitchId, SwitchState)>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
) -> PCDU {
PCDU {
) -> PCDUHandler {
PCDUHandler {
switch_rx,
can_tx,
can_rx,
@ -103,7 +101,7 @@ impl PCDU {
let dev_id_bytes = dev_id as u8;
let buf: &[u8] = &dev_id_bytes.to_be_bytes();
self.can_tx
.send(PackageModel::new(PackageId::DevicePowerOnRequest, buf).unwrap())
.send(MessageModel::new(MessageId::DevicePowerOnRequest, buf).unwrap())
.unwrap();
let mut map_lock = self.device_state_map.lock().unwrap();
*map_lock.get_mut(&dev_id).unwrap() = SwitchState::Unknown;
@ -119,7 +117,7 @@ impl PCDU {
let dev_id_bytes = dev_id as u8;
let buf: &[u8] = &dev_id_bytes.to_be_bytes();
self.can_tx
.send(PackageModel::new(PackageId::DevicePowerOffRequest, buf).unwrap())
.send(MessageModel::new(MessageId::DevicePowerOffRequest, buf).unwrap())
.unwrap();
let mut map_lock = self.device_state_map.lock().unwrap();
*map_lock.get_mut(&dev_id).unwrap() = SwitchState::Unknown;
@ -228,11 +226,11 @@ impl PCDU {
pub fn core_power_task(
switch_rx: Receiver<(SwitchId, SwitchState)>,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
can_tx: Sender<MessageModel>,
can_rx: Receiver<MessageModel>,
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
) {
let mut pcdu = PCDU::new(switch_rx, can_tx, can_rx, device_state_map);
let mut pcdu = PCDUHandler::new(switch_rx, can_tx, can_rx, device_state_map);
loop {
pcdu.handle_power_requests().unwrap();
}

View File

@ -7,7 +7,7 @@ use eurosim_obsw::{hk_err, tmtc_err, CustomPusServiceId, TEST_EVENT};
use log::{info, warn};
use satrs_core::events::EventU32;
use satrs_core::hk::{CollectionIntervalFactor, HkRequest, UniqueId};
use satrs_core::mode::{ModeAndSubmode, ModeCommand, ModeRequest};
use satrs_core::mode::{ModeAndSubmode, ModeRequest};
use satrs_core::params::Params;
use satrs_core::pool::StoreAddr;
use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken};
@ -25,7 +25,7 @@ use satrs_core::seq_count::{SeqCountProviderSyncClonable, SequenceCountProviderC
use satrs_core::spacepackets::ecss::{scheduling, PusServiceId};
use satrs_core::spacepackets::CcsdsPacket;
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use satrs_core::tmtc::{AddressableId, PusServiceProvider, TargetId};
use satrs_core::tmtc::{PusServiceProvider, TargetId};
use satrs_core::{
spacepackets::ecss::PusPacket, spacepackets::tc::PusTc, spacepackets::time::cds::TimeProvider,
spacepackets::time::TimeWriter, spacepackets::SpHeader,
@ -33,7 +33,6 @@ use satrs_core::{
use std::cell::RefCell;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::hash::Hash;
use std::rc::Rc;
use std::sync::mpsc::Sender;

View File

@ -20,7 +20,6 @@ use satrs_core::pus::event_man::EventRequestWithToken;
use satrs_core::pus::scheduling::{PusScheduler, TcInfo};
use satrs_core::pus::verification::StdVerifReporterWithSender;
use satrs_core::seq_count::SeqCountProviderSyncClonable;
use satrs_core::spacepackets::tc::PUS_TC_MIN_LEN_WITHOUT_APP_DATA;
use satrs_core::spacepackets::{ecss::PusPacket, tc::PusTc, tm::PusTm, SpHeader};
use satrs_core::tmtc::{
CcsdsDistributor, CcsdsError, PusServiceProvider, ReceivesCcsdsTc, ReceivesEcssPusTc,