added cfg features to allow compilation on windows/non-unix using --no-default-features

This commit is contained in:
lkoester 2023-02-15 09:56:14 +01:00
parent 37cf90f559
commit ba31154990
8 changed files with 146 additions and 72 deletions

6
output.log Normal file
View File

@ -0,0 +1,6 @@
[2023-02-15][09:14:42][main][INFO] Starting TMTC task
[2023-02-15][09:14:42][main][INFO] Starting power task
[2023-02-15][09:14:42][main][INFO] Starting AOCS task
[2023-02-15][09:16:43][main][INFO] Starting TMTC task
[2023-02-15][09:16:43][main][INFO] Starting power task
[2023-02-15][09:16:43][main][INFO] Starting AOCS task

View File

@ -1,6 +1,7 @@
{
"com_if": "udp",
"tcpip_udp_ip_addr": "192.168.1.116",
"tcpip_udp_ip_addr_raspi": "192.168.1.116",
"tcpip_udp_ip_addr": "192.168.1.5",
"tcpip_udp_port": 7301,
"tcpip_udp_recv_max_size": 1500
}

View File

@ -1,12 +1,11 @@
use std::sync::{Arc, Mutex};
use crate::can::CanTxHandler;
use crate::can_ids::{DeviceId, PackageId, PackageModel};
use crate::hk::HkRequest;
use crate::power_handler::{DeviceState, PowerSwitcher};
use crate::requests::{Request, RequestWithToken};
use crate::ActionRequest;
use satrs_core::power::SwitchId;
use std::sync::mpsc::{Receiver, TryRecvError};
use std::sync::mpsc::{Receiver, Sender};
use serde::{Deserialize, Serialize};
pub enum AocsSensorMode {
@ -77,7 +76,7 @@ pub struct MGMHandler {
device_id: DeviceId,
switch_id: SwitchId,
device_state: DeviceState,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
mode: AocsSensorMode,
mode_rx: Receiver<AocsSensorMode>,
@ -99,7 +98,7 @@ impl AocsSensorHandler for MGMHandler {
}
fn send_message(&mut self, id: PackageId, buf: &[u8]) -> Result<(), Self::Error> {
self.can_tx.tx_socket(id, buf);
self.can_tx.send(PackageModel::new(id, buf).unwrap());
return Ok(());
}
}
@ -109,7 +108,7 @@ impl MGMHandler {
power_switcher: PowerSwitcher,
device_id: DeviceId,
switch_id: SwitchId,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
mode_rx: Receiver<AocsSensorMode>,
action_rx: Receiver<RequestWithToken>,
@ -153,7 +152,7 @@ impl MGMHandler {
self.handle_hk_request(hk_req);
}
Request::ActionRequest(action_request) => {
self.handle_action_request(action_request);
//self.handle_action_request(action_request);
}
}
}
@ -170,5 +169,5 @@ impl MGMHandler {
HkRequest::ModifyCollectionInterval(_, _) => {}
}
}
pub fn handle_action_request(&mut self, action_request: ActionRequest) {}
//pub fn handle_action_request(&mut self, action_request: ActionRequest) {}
}

View File

@ -1,19 +1,13 @@
use crate::power_handler::DeviceState;
use crate::can_ids::{
can_id_to_package_id, package_id_to_can_id, value_to_package_id, DeviceId, PackageId,
can_id_to_package_id, package_id_to_can_id, DeviceId, PackageId,
PackageModel, SenderReceiverThread, ThreadId,
};
use embedded_can::{self, Frame};
use log::{debug, error, info, trace, warn};
use serde::{Deserialize, Serialize};
use serde_json;
use log::{info, warn};
use socketcan::{errors, frame, socket, CanFrame, Socket};
use std::collections::HashMap;
use std::ffi::c_void;
use std::io;
use std::mem::size_of;
use std::sync::mpsc::Sender;
use std::sync::mpsc::{Receiver, Sender};
pub struct CanRxHandler {
interface: &'static str,
@ -116,6 +110,70 @@ impl CanRxHandler {
}
pub struct CanTxHandler {
interface: &'static str,
socket: socket::CanSocket,
package_map: HashMap<PackageId, SenderReceiverThread>,
message_receiver: Receiver<PackageModel>,
}
impl CanTxHandler {
pub fn new_socket(
interface: &'static str,
package_map: HashMap<PackageId, SenderReceiverThread>,
message_receiver: Receiver<PackageModel>,
) -> Result<CanTxHandler, ()> {
let socket = socket::CanSocket::open(&interface);
if let Ok(socket) = socket {
socket.filter_drop_all().unwrap(); // tx nodes cannot receive data
Ok(CanTxHandler {
interface,
socket,
package_map,
message_receiver,
})
} else {
Err(())
}
}
pub fn process_incoming(&mut self) {
if let Ok(package) = self.message_receiver.recv() {
self.tx_socket(package.package_id(), package.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();
if value.get_sender() == DeviceId::OBC {
if data.len() <= 8 {
let frame_id = package_id_to_can_id(&package_id);
let frame = CanFrame::new(frame_id, data);
if let Some(frame) = frame {
self.socket
.write_frame(&frame)
.expect("Error writing frame.");
}
} else {
warn!(
"Message dismissed, data length ({:?}) exceeds 8 bytes",
data.len()
);
}
} else {
warn!(
"Message dismissed, wrong sender id: {:?}",
value.get_sender()
);
}
} else {
warn!("Message dismissed, wrong package id: {:?}", package_id);
}
}
}
/*pub struct CanTxHandler {
interface: &'static str,
socket: socket::CanSocket,
thread_id: ThreadId,
@ -209,6 +267,8 @@ impl CanTxHandler {
*/
}
*/
pub fn open_socket(interface: &str) -> Result<socket::CanSocket, errors::CanSocketOpenError> {
let socket = socket::CanSocket::open(&interface);
return socket;

View File

@ -1,8 +1,8 @@
use crate::aocs_handler::{AocsSensorHandler, MGMData, MGMHandler};
use crate::aocs_handler::{MGMData};
use crate::requests::Request;
use crate::requests::RequestWithToken;
use crate::tmtc::TmStore;
use eurosim_obsw::{hk_err, tmtc_err};
use eurosim_obsw::{hk_err};
use satrs_core::pool::StoreAddr;
use satrs_core::pus::hk::Subservice;
use satrs_core::pus::verification::{
@ -15,8 +15,7 @@ use satrs_core::spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use satrs_core::spacepackets::SpHeader;
use satrs_core::tmtc::AddressableId;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::ops::{Deref, DerefMut};
use std::ops::{Deref};
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
@ -124,7 +123,7 @@ impl AocsHousekeeper {
HkRequest::OneShot(id) => self.one_shot_hk(id),
HkRequest::Enable(id) => self.enable_hk(id),
HkRequest::Disable(id) => self.disable_hk(id),
HkRequest::ModifyCollectionInterval(id, collection_interval) => Ok(()),
HkRequest::ModifyCollectionInterval(_id, _collection_interval) => Ok(()),
} {
let cds_stamp = TimeProvider::from_now_with_u16_days().unwrap();
cds_stamp.write_to_bytes(&mut time_stamp_buf).unwrap();
@ -155,11 +154,11 @@ impl AocsHousekeeper {
Ok(())
}
pub fn enable_hk(&mut self, id: AddressableId) -> Result<(), ()> {
pub fn enable_hk(&mut self, _id: AddressableId) -> Result<(), ()> {
Ok(())
}
pub fn disable_hk(&mut self, id: AddressableId) -> Result<(), ()> {
pub fn disable_hk(&mut self, _id: AddressableId) -> Result<(), ()> {
Ok(())
}

View File

@ -2,6 +2,7 @@ mod action;
mod aocs;
mod aocs_handler;
mod cam;
#[cfg(feature = "can")]
mod can;
mod can_ids;
mod ccsds;
@ -13,7 +14,7 @@ mod pus;
mod requests;
mod tmtc;
use crate::requests::{Request, RequestWithToken};
use crate::requests::{RequestWithToken};
use crate::tmtc::{
core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmStore, PUS_APID,
};
@ -31,17 +32,13 @@ use satrs_core::pus::verification::{
};
use satrs_core::pus::{EcssTmErrorWithSend, EcssTmSenderCore};
use satrs_core::seq_count::SeqCountProviderSyncClonable;
use satrs_core::{
spacepackets::time::cds::TimeProvider, spacepackets::time::TimeWriter, spacepackets::tm::PusTm,
};
use satrs_core::{spacepackets::tm::PusTm};
use strum::IntoEnumIterator;
use crate::can_ids::{
can_id_to_package_id, load_package_ids, DeviceId, PackageId, PackageModel, ThreadId,
load_package_ids, DeviceId, PackageModel, ThreadId,
};
#[cfg(feature = "can")]
use embedded_can::{Id, StandardId};
use log::{info, warn};
use log::{info};
use satrs_core::power::{SwitchId, SwitchState};
use std::collections::HashMap;
use std::net::{IpAddr, SocketAddr};
@ -51,9 +48,10 @@ use std::thread;
//use libc::time64_t;
use crate::action::ActionRequest;
use crate::aocs_handler::MGMData;
use crate::cam::CameraRequest;
#[cfg(feature = "can")]
use crate::can::CanTxHandler;
use crate::hk::{AocsHousekeeper, AocsSensorData};
use crate::pld_handler::{core_pld_task, CameraHandler};
use crate::pld_handler::{core_pld_task};
use crate::power_handler::{core_power_task, PowerSwitcher};
#[derive(Clone)]
@ -196,20 +194,11 @@ fn main() {
core_tmtc_task(core_args, tc_args, tm_args);
});
let socket0 = can::CanRxHandler::new_socket("can0", can_senders, package_ids_rx).unwrap();
info!("Starting CAN Socket listening task");
let builder1 = thread::Builder::new().name("CanRxHandler".into());
let jh1 = builder1.spawn(move || loop {
let frame = socket0.rx_socket();
if let Some(frame) = frame {
let forward = socket0.forward_frame(frame);
}
});
let (can_tx_sender, can_tx_receiver) = channel();
let (pcdu_tx, pcdu_rx) = mpsc::channel::<(SwitchId, SwitchState)>();
let pcdu_can_tx =
can::CanTxHandler::new_socket("can0", ThreadId::PowerThread, load_package_ids()).unwrap();
let pcdu_can_tx_sender =
can_tx_sender.clone();
let mut device_state_map = HashMap::new();
for id in DeviceId::iter() {
@ -224,7 +213,7 @@ fn main() {
let jh2 = builder2.spawn(move || {
core_power_task(
pcdu_rx,
pcdu_can_tx,
pcdu_can_tx_sender,
power_can_rx,
clonable_device_state_map.clone(),
);
@ -326,8 +315,8 @@ fn main() {
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();
let pld_can_tx_sender =
can_tx_sender.clone();
//let mut pcdu_tx_clone = pcdu_tx.clone();
println!("Starting Payload Handling task");
@ -337,6 +326,7 @@ fn main() {
power_switcher.clone(),
pld_thread_rx,
pld_can_rx,
pld_can_tx_sender,
&mut reporter_pld,
);
});
@ -385,9 +375,32 @@ fn main() {
jh0.unwrap()
.join()
.expect("Joining UDP TMTC server thread failed");
jh1.unwrap()
.join()
.expect("Joining CAN Bus Listening thread failed");
#[cfg(feature = "can")]
{
let can_rx_socket = can::CanRxHandler::new_socket("can0", can_senders.clone(), package_ids_rx.clone()).unwrap();
info!("Starting CAN Socket listening task");
let builder1 = thread::Builder::new().name("CanRxHandler".into());
let jh1 = builder1.spawn(move || loop {
let frame = can_rx_socket.rx_socket();
if let Some(frame) = frame {
let forward = can_rx_socket.forward_frame(frame);
}
});
let mut can_tx_socket = CanTxHandler::new_socket("can0", package_ids_rx.clone(), can_tx_receiver).unwrap();
info!("Starting CAN Socket writing task");
let builderCanTx = thread::Builder::new().name("TxHandler".into());
let jhCanTx = builderCanTx.spawn( move || loop {
can_tx_socket.process_incoming();
});
jh1.unwrap()
.join()
.expect("Joining CAN Bus Listening thread failed");
jhCanTx.unwrap()
.join()
.expect("Joining CAN Bus Writing thread failed");
}
jh2.unwrap().join().expect("Joining power thread failed");
jh3.unwrap().join().expect("Joining PLD thread failed");
jh4.unwrap()

View File

@ -1,16 +1,15 @@
use crate::action::ActionRequest;
use crate::can::CanTxHandler;
use crate::can_ids::{load_package_ids, DeviceId, PackageId, PackageModel, ThreadId};
use crate::can_ids::{DeviceId, PackageId, PackageModel};
use crate::power_handler::{DeviceState, PowerSwitcher};
use crate::requests::{Request, RequestWithToken};
use eurosim_obsw::RequestTargetId;
use log::info;
use satrs_core::power::{PowerSwitchInfo, PowerSwitcherCommandSender, SwitchId, SwitchState};
use satrs_core::power::{PowerSwitchInfo, PowerSwitcherCommandSender, SwitchId};
use satrs_core::pus::verification::{StdVerifSenderError, VerificationReporterWithSender};
use satrs_core::spacepackets::time::cds::TimeProvider;
use satrs_core::spacepackets::time::TimeWriter;
use std::sync::mpsc;
use std::sync::mpsc::{Receiver, Sender, TryRecvError};
use std::sync::mpsc::{Receiver, Sender};
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum CameraMode {
@ -26,7 +25,7 @@ pub struct CameraHandler {
camera_device_id: DeviceId,
camera_switch_id: SwitchId,
device_state: DeviceState,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
mode: CameraMode,
mode_rx: Receiver<CameraMode>,
@ -37,7 +36,7 @@ impl CameraHandler {
pub fn new(
power_switcher: PowerSwitcher,
camera_device_id: DeviceId,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
mode_rx: Receiver<CameraMode>,
action_rx: Receiver<RequestWithToken>,
@ -148,7 +147,7 @@ impl CameraHandler {
}
}
if self.device_state == DeviceState::On {
self.can_tx.tx_socket(PackageId::CameraImageRequest, &[1]);
self.can_tx.send(PackageModel::new(PackageId::CameraImageRequest, &[1]).unwrap());
info!("sent camera request");
self.mode = CameraMode::Verification;
}
@ -208,17 +207,16 @@ pub fn core_pld_task(
power_switcher: PowerSwitcher,
pld_thread_rx: Receiver<RequestWithToken>,
pld_can_rx: Receiver<PackageModel>,
pld_can_tx: Sender<PackageModel>,
reporter_pld: &mut VerificationReporterWithSender<StdVerifSenderError>,
) {
let (camera_mode_tx, camera_mode_rx) = mpsc::channel();
let (action_tx, action_rx) = mpsc::channel();
let camera_can_tx =
CanTxHandler::new_socket("can0", ThreadId::PLDThread, load_package_ids()).unwrap();
let (_camera_mode_tx, camera_mode_rx) = mpsc::channel();
let (_action_tx, action_rx) = mpsc::channel();
let mut camera_handler = CameraHandler::new(
power_switcher,
DeviceId::Camera,
camera_can_tx,
pld_can_tx,
pld_can_rx,
camera_mode_rx,
action_rx,

View File

@ -1,4 +1,3 @@
use crate::can::CanTxHandler;
use crate::can_ids::{DeviceId, PackageId, PackageModel};
use log::info;
use satrs_core::power::{
@ -30,7 +29,7 @@ pub struct PowerSwitcher {
pub struct PCDU {
switch_rx: Receiver<(SwitchId, SwitchState)>,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
}
@ -93,7 +92,7 @@ impl PowerSwitchProvider for PowerSwitcher {
impl PCDU {
pub fn new(
switch_rx: Receiver<(SwitchId, SwitchState)>,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
) -> PCDU {
@ -109,7 +108,7 @@ impl PCDU {
return if let Ok(dev_id) = DeviceId::try_from(switch_id) {
let dev_id_bytes = dev_id as u8;
let buf: &[u8] = &dev_id_bytes.to_be_bytes();
self.can_tx.tx_socket(PackageId::DevicePowerOnRequest, buf);
self.can_tx.send(PackageModel::new(PackageId::DevicePowerOnRequest, buf).unwrap());
let mut map_lock = self.device_state_map.lock().unwrap();
*map_lock.get_mut(&dev_id).unwrap() = SwitchState::Unknown;
// TODO: potentially change bus logic -> remove acceptance and verification of power off/on, since status is simply called in next step anyway
@ -125,7 +124,7 @@ impl PCDU {
return if let Ok(dev_id) = DeviceId::try_from(switch_id) {
let dev_id_bytes = dev_id as u8;
let buf: &[u8] = &dev_id_bytes.to_be_bytes();
self.can_tx.tx_socket(PackageId::DevicePowerOffRequest, buf);
self.can_tx.send(PackageModel::new(PackageId::DevicePowerOffRequest, buf).unwrap());
let mut map_lock = self.device_state_map.lock().unwrap();
*map_lock.get_mut(&dev_id).unwrap() = SwitchState::Unknown;
self.can_rx.recv();
@ -140,8 +139,7 @@ impl PCDU {
let switch_id: SwitchId = *dev_id as u16;
let dev_id_bytes = *dev_id as u8;
let buf: &[u8] = &dev_id_bytes.to_be_bytes();
self.can_tx
.tx_socket(PackageId::DevicePowerStatusRequest, buf);
self.can_tx.send(PackageModel::new(PackageId::DevicePowerStatusRequest, buf).unwrap());
match self.can_rx.recv_timeout(Duration::from_secs(10)) {
Ok(msg) => {
if msg.package_id() == PackageId::DevicePowerStatusResponse
@ -223,7 +221,7 @@ impl PCDU {
pub fn core_power_task(
switch_rx: Receiver<(SwitchId, SwitchState)>,
can_tx: CanTxHandler,
can_tx: Sender<PackageModel>,
can_rx: Receiver<PackageModel>,
device_state_map: Arc<Mutex<HashMap<DeviceId, SwitchState>>>,
) {