From 1e3aa40a87357b16576f1ab60747c6663744f733 Mon Sep 17 00:00:00 2001 From: lkoester Date: Thu, 19 Jan 2023 16:16:48 +0100 Subject: [PATCH] added some stuff --- src/cam.rs | 12 ++++++ src/can_ids.rs | 13 ++++--- src/device_handler.rs | 88 ++++++++++++++++++++++++++++++++----------- src/example_main.rs | 1 + src/hk.rs | 2 +- src/lib.rs | 2 +- src/main.rs | 54 +++++++++++++++++++++++--- src/pus.rs | 6 +++ src/requests.rs | 2 + 9 files changed, 146 insertions(+), 34 deletions(-) create mode 100644 src/cam.rs diff --git a/src/cam.rs b/src/cam.rs new file mode 100644 index 0000000..af2d89d --- /dev/null +++ b/src/cam.rs @@ -0,0 +1,12 @@ +use satrs_core::tmtc::AddressableId; + +pub type CollectionIntervalFactor = u32; + +//#[derive(Debug, Copy, Clone, PartialEq, Eq)] + + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum CameraRequest { + OneShot(AddressableId), + OneShotWithTimeStamp(AddressableId), +} diff --git a/src/can_ids.rs b/src/can_ids.rs index e00fbec..b7e388b 100644 --- a/src/can_ids.rs +++ b/src/can_ids.rs @@ -5,11 +5,11 @@ use std::fs; use std::sync::mpsc::Sender; use std::thread::Thread; -use crate::device_handler::{DeviceProperties, DeviceState, DeviceType}; -use num_derive::{FromPrimitive, ToPrimitive}; -use num_traits::{FromPrimitive, ToPrimitive}; -use strum::IntoEnumIterator; // 0.17.1 -use strum_macros::EnumIter; // 0.17.1 + +pub use num_derive::{FromPrimitive, ToPrimitive}; +pub use num_traits::{FromPrimitive, ToPrimitive}; +pub use strum::IntoEnumIterator; // 0.17.1 +pub use strum_macros::EnumIter; // 0.17.1 #[derive(Debug, EnumIter, Eq, Hash, PartialEq, Copy, Clone, FromPrimitive)] pub enum ThreadId { @@ -208,6 +208,7 @@ pub fn load_package_ids() -> HashMap { return package_map; } +/* pub fn load_device_ids() { let mut package_map: HashMap = HashMap::new(); @@ -238,6 +239,8 @@ pub fn load_device_ids() { } } + */ + //TODO: change ids from u32 to embeddedcan ids pub fn package_id_to_value(packageid: &PackageId) -> u32 { *packageid as u32 diff --git a/src/device_handler.rs b/src/device_handler.rs index 922d6e5..8af5cfc 100644 --- a/src/device_handler.rs +++ b/src/device_handler.rs @@ -1,7 +1,14 @@ +use std::collections::HashMap; +use log::info; use crate::can_ids::DeviceId; use socketcan::{errors, frame, socket, CanFrame, Socket}; -#[derive(Copy, Clone)] +pub use num_derive::{FromPrimitive, ToPrimitive}; +pub use num_traits::{FromPrimitive, ToPrimitive}; +pub use strum::IntoEnumIterator; // 0.17.1 +pub use strum_macros::EnumIter; // 0.17.1 + +#[derive(Copy, Clone, Debug)] pub enum DeviceState { On, Off, @@ -9,29 +16,66 @@ pub enum DeviceState { Unknown, } -#[derive(Copy, Clone)] -pub enum DeviceType { - MGM, - MGT, - RWL, - STR, - CRS, - OBC, - PCDU, - CAM, +#[derive(Clone, Debug)] +pub struct DeviceHandler { + device_state_map: HashMap, + } -#[derive(Copy, Clone)] -pub struct DeviceProperties { - device_type: DeviceType, - device_state: DeviceState, -} +impl DeviceHandler { + pub fn new() -> DeviceHandler { + let mut device_state_map:HashMap = HashMap::new(); -impl DeviceProperties { - pub fn new(device_type: DeviceType, device_state: DeviceState) -> DeviceProperties { - return DeviceProperties { - device_type, - device_state, - }; + for id in DeviceId::iter() { + device_state_map.insert(id, DeviceState::Unknown); + } + DeviceHandler{ device_state_map } + } + + pub fn power_up_seq(&self) { + for id in DeviceId::iter() { + let power_on_success = self.power_on(id); + match power_on_success{ + Ok(_) => {info!("{:?} powered up successfully.", id)} + Err(_) => {info!("{:?} failed to power up.", id)} + } + } + } + + pub fn power_on(&self, id: DeviceId) -> Result<(),()> { + match id { + DeviceId::OBC => {} + DeviceId::PCDU => {} + DeviceId::MGM1 => {} + DeviceId::MGM2 => {} + DeviceId::MGM3 => {} + DeviceId::MGM4 => {} + DeviceId::SunSensor1 => {} + DeviceId::SunSensor2 => {} + DeviceId::SunSensor3 => {} + DeviceId::SunSensor4 => {} + DeviceId::SunSensor5 => {} + DeviceId::SunSensor6 => {} + DeviceId::StarTracker => {} + DeviceId::MGT1 => {} + DeviceId::MGT2 => {} + DeviceId::MGT3 => {} + DeviceId::MGT4 => {} + DeviceId::RWL1 => {} + DeviceId::RWL2 => {} + DeviceId::RWL3 => {} + DeviceId::RWL4 => {} + DeviceId::Camera => {} + DeviceId::All => {} + } + + self.get_power_state(id) + + } + + pub fn get_power_state(&self, id: DeviceId) -> Result<(),()> { + let power_state:DeviceState = DeviceState::Unknown; + Ok(()) } } + diff --git a/src/example_main.rs b/src/example_main.rs index b7c1ec9..a47b568 100644 --- a/src/example_main.rs +++ b/src/example_main.rs @@ -213,6 +213,7 @@ fn example_main() { HkRequest::Disable(_) => {} HkRequest::ModifyCollectionInterval(_, _) => {} }, + _ => {} } let started_token = reporter_aocs .start_success(request.1, ×tamp) diff --git a/src/hk.rs b/src/hk.rs index d27c0f0..6bd07bd 100644 --- a/src/hk.rs +++ b/src/hk.rs @@ -13,4 +13,4 @@ pub enum HkRequest { Enable(AddressableId), Disable(AddressableId), ModifyCollectionInterval(AddressableId, CollectionIntervalFactor), -} +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index c958d06..1be8ca2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use satrs_mib::resultcode; #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum RequestTargetId { AcsSubsystem = 1, - CanTask = 2, + PldSubsystem = 2, } #[derive(Debug)] diff --git a/src/main.rs b/src/main.rs index 1d479e5..5693721 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod pus; mod requests; mod tmtc; mod aocs; +mod cam; use crate::hk::{AcsHkIds, HkRequest}; use crate::requests::{Request, RequestWithToken}; @@ -50,6 +51,7 @@ use std::sync::mpsc::{channel, TryRecvError}; use std::sync::{mpsc, Arc, RwLock}; use std::thread; use std::time::Duration; +use crate::cam::CameraRequest; #[derive(Clone)] struct EventTmSender { @@ -142,8 +144,9 @@ fn main() { let mut request_map = HashMap::new(); let (acs_thread_tx, acs_thread_rx) = channel::(); - let (can_thread_tx, can_thread_rx) = channel::(); + let (pld_thread_tx, pld_thread_rx) = channel::(); request_map.insert(RequestTargetId::AcsSubsystem as u32, acs_thread_tx); + request_map.insert(RequestTargetId::PldSubsystem as u32, pld_thread_tx); //request_map.insert(RequestTargetId::CanTask as u32, can_thread_tx); let tc_source = PusTcSource { @@ -196,7 +199,8 @@ fn main() { let socket0 = can::CanRxHandler::new_socket("can0", can_senders, package_ids_rx).unwrap(); info!("Starting TMTC task"); - let jh0 = thread::spawn(move || { + let builder0 = thread::Builder::new().name("TMTCThread".into()); + let jh0 = builder0.spawn(move || { core_tmtc_task(core_args, tc_args, tm_args); }); @@ -209,16 +213,21 @@ fn main() { } }); + /* let allowed_ids_range = 101..110; let mut allowed_ids_aocs = Vec::new(); for id in allowed_ids_range { allowed_ids_aocs.push(Id::Standard(StandardId::new(id).unwrap())); } + */ + let package_map_aocs_tx = load_package_ids(); let aocs_tm_funnel_tx = tm_funnel_tx.clone(); let mut aocs_tm_store = tm_store.clone(); + + // AOCS Thread let socket1 = can::CanTxHandler::new_socket("can0", ThreadId::AOCSThread, package_map_aocs_tx).unwrap(); info!("Starting AOCS receiving thread"); @@ -299,6 +308,7 @@ fn main() { HkRequest::ModifyCollectionInterval(_, _) => {} } } + _ => {} } } Err(_) => {} @@ -306,8 +316,41 @@ fn main() { } }); + let package_map_pld_tx = load_package_ids(); + let pld_tm_funnel_tx = tm_funnel_tx.clone(); + let mut pld_tm_store = tm_store.clone(); + + let PLDCanSocket = + can::CanTxHandler::new_socket("can0", ThreadId::PLDThread, package_map_pld_tx).unwrap(); + println!("Starting Payload Handling task"); + let builder3 = thread::Builder::new().name("PLDThread".into()); + let jh3 = builder3.spawn(move || { + loop { + match pld_thread_rx.try_recv() { + Ok(request_with_token) => { + match request_with_token.0 { + Request::CameraRequest(cam_req) => { + match cam_req { + CameraRequest::OneShot(id) => { + + } + CameraRequest::OneShotWithTimeStamp(id) => {} + } + } + _ => {} + } + } + Err(_) => {} + } + //let addr = pld_tm_store.add_pus_tm(&hk_tm); + //pld_tm_funnel_tx.send(a).expect("sending failed"); + } + }); + + println!("Starting TM funnel task"); - let jh3 = thread::spawn(move || { + let builder4 = thread::Builder::new().name("TMFunnelThread".into()); + let jh4 = builder4.spawn(move || { let tm_funnel = TmFunnel { tm_server_tx, tm_funnel_rx, @@ -322,12 +365,13 @@ fn main() { } }); - jh0.join().expect("Joining UDP TMTC server thread failed"); + jh0.unwrap().join().expect("Joining UDP TMTC server thread failed"); jh1.unwrap() .join() .expect("Joining CAN Bus Listening thread failed"); jh2.unwrap().join().expect("Joing AOCS thread failed"); - jh3.join().expect("Joing AOCS thread failed"); + jh3.unwrap().join().expect("Joing AOCS thread failed"); + jh4.unwrap().join().expect("Joing AOCS thread failed"); /* jh1.join().expect("Joining TM Funnel thread failed"); diff --git a/src/pus.rs b/src/pus.rs index ee0ada9..b71de50 100644 --- a/src/pus.rs +++ b/src/pus.rs @@ -79,6 +79,8 @@ impl PusServiceProvider for PusReceiver { self.handle_event_request(pus_tc, accepted_token); } else if service == 3 { self.handle_hk_request(pus_tc, accepted_token); + } else if service == 8 { + self.handle_function_request(pus_tc, accepted_token); } else { self.update_time_stamp(); self.verif_reporter @@ -270,4 +272,8 @@ impl PusReceiver { } } } + + fn handle_function_request(&mut self, pus_tc: &PusTc, token: VerificationToken) { + + } } diff --git a/src/requests.rs b/src/requests.rs index cac2277..7bd0f68 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -1,9 +1,11 @@ use crate::hk::HkRequest; use satrs_core::pus::verification::{TcStateAccepted, VerificationToken}; +use crate::cam::CameraRequest; #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum Request { HkRequest(HkRequest), + CameraRequest(CameraRequest), } #[derive(Copy, Clone, Eq, PartialEq, Debug)]