...
This commit is contained in:
parent
47e36cb0b5
commit
9e77b31d5a
@ -12,6 +12,7 @@ pub enum ActionIds {
|
|||||||
pub enum ActionRequest {
|
pub enum ActionRequest {
|
||||||
ImageRequest(RequestTargetId),
|
ImageRequest(RequestTargetId),
|
||||||
OrientationRequest(RequestTargetId),
|
OrientationRequest(RequestTargetId),
|
||||||
|
PointingRequest(RequestTargetId),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Subservice {
|
pub enum Subservice {
|
||||||
|
@ -16,6 +16,7 @@ pub enum ThreadId {
|
|||||||
AOCSThread,
|
AOCSThread,
|
||||||
PowerThread,
|
PowerThread,
|
||||||
PLDThread,
|
PLDThread,
|
||||||
|
DeviceHandlerThread,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, EnumIter, Eq, Hash, PartialEq, Copy, Clone, FromPrimitive)]
|
#[derive(Debug, EnumIter, Eq, Hash, PartialEq, Copy, Clone, FromPrimitive)]
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::sync::mpsc::{Receiver, Sender};
|
||||||
use log::info;
|
use log::info;
|
||||||
use crate::can_ids::{DeviceId, PackageId};
|
use crate::can_ids::{DeviceId, PackageId, PackageModel, ThreadId};
|
||||||
use socketcan::{errors, frame, socket, CanFrame, Socket};
|
use socketcan::{errors, frame, socket, CanFrame, Socket};
|
||||||
|
|
||||||
pub use num_derive::{FromPrimitive, ToPrimitive};
|
pub use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
pub use num_traits::{FromPrimitive, ToPrimitive};
|
pub use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
pub use strum::IntoEnumIterator; // 0.17.1
|
pub use strum::IntoEnumIterator; // 0.17.1
|
||||||
pub use strum_macros::EnumIter; // 0.17.1
|
pub use strum_macros::EnumIter;
|
||||||
|
use crate::can::{CanRxHandler, CanTxHandler}; // 0.17.1
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub enum DeviceState {
|
pub enum DeviceState {
|
||||||
On,
|
On,
|
||||||
Off,
|
Off,
|
||||||
@ -18,22 +20,24 @@ pub enum DeviceState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct DeviceHandler {
|
pub struct DeviceHandler {
|
||||||
device_state_map: HashMap<DeviceId, DeviceState>,
|
device_state_map: HashMap<DeviceId, DeviceState>,
|
||||||
|
can_tx_handler: CanTxHandler,
|
||||||
|
can_rx_receiver: Receiver<PackageModel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceHandler {
|
impl DeviceHandler {
|
||||||
pub fn new() -> DeviceHandler {
|
pub fn new(can_tx_handler: CanTxHandler, can_rx_receiver: Receiver<PackageModel>) -> DeviceHandler {
|
||||||
let mut device_state_map:HashMap<DeviceId, DeviceState> = HashMap::new();
|
let mut device_state_map:HashMap<DeviceId, DeviceState> = HashMap::new();
|
||||||
|
|
||||||
for id in DeviceId::iter() {
|
for id in DeviceId::iter() {
|
||||||
device_state_map.insert(id, DeviceState::Unknown);
|
device_state_map.insert(id, DeviceState::Unknown);
|
||||||
}
|
}
|
||||||
DeviceHandler{ device_state_map }
|
DeviceHandler{ device_state_map, can_tx_handler, can_rx_receiver }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn power_up_seq(&self) {
|
pub fn power_up_seq(&mut self) {
|
||||||
for id in DeviceId::iter() {
|
for id in DeviceId::iter() {
|
||||||
let power_on_success = self.power_on(id);
|
let power_on_success = self.power_on(id);
|
||||||
match power_on_success{
|
match power_on_success{
|
||||||
@ -43,39 +47,55 @@ impl DeviceHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn power_on(&self, id: DeviceId) -> Result<(),()> {
|
pub fn power_on(&mut self, id: DeviceId) -> Result<(),()> {
|
||||||
match id {
|
if !self.device_state_map.contains_key(&id) {
|
||||||
DeviceId::OBC => {}
|
return Err(());
|
||||||
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)
|
let msg_data: [u8; 1] = [id as u8];
|
||||||
|
self.can_tx_handler.tx_socket(PackageId::DevicePowerOnRequest, &msg_data);
|
||||||
|
|
||||||
|
match self.get_power_state(id) {
|
||||||
|
None => {return Err(());}
|
||||||
|
Some(power_state) => {
|
||||||
|
if *power_state != DeviceState::On {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_power_state(&self, id: DeviceId) -> Result<(),()> {
|
Ok(())
|
||||||
let power_state:DeviceState = DeviceState::Unknown;
|
}
|
||||||
|
|
||||||
|
pub fn get_power_state(&mut self, id: DeviceId) -> Option<&DeviceState> {
|
||||||
|
self.update_power_state(id).expect("Error updating power state.");
|
||||||
|
self.device_state_map.get(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_power_state(&mut self, id: DeviceId) -> Result<(),()> {
|
||||||
|
if !self.device_state_map.contains_key(&id) {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let msg_data: [u8; 1] = [id as u8];
|
||||||
|
self.can_tx_handler.tx_socket(PackageId::DevicePowerStatusRequest, &msg_data);
|
||||||
|
|
||||||
|
let response = self.can_rx_receiver.recv();
|
||||||
|
if let Ok(response) = response {
|
||||||
|
let data = response.data();
|
||||||
|
|
||||||
|
if data[0] == id as u8 {
|
||||||
|
if data[1] == 1 {
|
||||||
|
*self.device_state_map.get_mut(&id).unwrap() = DeviceState::On;
|
||||||
|
} else if data[1] == 0 {
|
||||||
|
*self.device_state_map.get_mut(&id).unwrap() = DeviceState::Off;
|
||||||
|
} else {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -218,15 +218,6 @@ 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 package_map_aocs_tx = load_package_ids();
|
||||||
let aocs_tm_funnel_tx = tm_funnel_tx.clone();
|
let aocs_tm_funnel_tx = tm_funnel_tx.clone();
|
||||||
let mut aocs_tm_store = tm_store.clone();
|
let mut aocs_tm_store = tm_store.clone();
|
||||||
@ -408,6 +399,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ActionRequest::OrientationRequest(_) => {}
|
ActionRequest::OrientationRequest(_) => {}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -415,8 +407,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
//let addr = pld_tm_store.add_pus_tm(&hk_tm);
|
|
||||||
//pld_tm_funnel_tx.send(a).expect("sending failed");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -310,6 +310,7 @@ impl PusReceiver {
|
|||||||
.send(RequestWithToken(Request::ActionRequest(request), token))
|
.send(RequestWithToken(Request::ActionRequest(request), token))
|
||||||
.unwrap_or_else(|_| panic!("Sending Action request {:?} failed", request));
|
.unwrap_or_else(|_| panic!("Sending Action request {:?} failed", request));
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user