2022-09-03 13:47:25 +02:00
|
|
|
mod ccsds;
|
2022-12-19 17:03:26 +01:00
|
|
|
mod hk;
|
2024-01-30 23:48:46 +01:00
|
|
|
mod logger;
|
2022-08-29 01:33:32 +02:00
|
|
|
mod pus;
|
2022-12-19 17:03:26 +01:00
|
|
|
mod requests;
|
2023-09-29 14:11:03 +02:00
|
|
|
mod tcp;
|
2022-08-29 01:33:32 +02:00
|
|
|
mod tmtc;
|
2023-09-29 12:38:57 +02:00
|
|
|
mod udp;
|
2022-08-29 01:33:32 +02:00
|
|
|
|
2023-02-15 22:30:32 +01:00
|
|
|
use log::{info, warn};
|
2023-09-29 14:11:03 +02:00
|
|
|
use satrs_core::hal::std::tcp_server::ServerConfig;
|
2023-09-27 00:21:03 +02:00
|
|
|
use satrs_core::hal::std::udp_server::UdpTcServer;
|
2023-02-15 22:30:32 +01:00
|
|
|
|
2023-09-27 00:21:03 +02:00
|
|
|
use crate::ccsds::CcsdsReceiver;
|
2023-08-15 21:07:15 +02:00
|
|
|
use crate::hk::{AcsHkIds, HkUniqueId};
|
2024-01-30 23:48:46 +01:00
|
|
|
use crate::logger::setup_logger;
|
2023-07-05 21:08:04 +02:00
|
|
|
use crate::pus::action::{Pus8Wrapper, PusService8ActionHandler};
|
2023-07-05 14:25:51 +02:00
|
|
|
use crate::pus::event::Pus5Wrapper;
|
2023-07-06 00:49:18 +02:00
|
|
|
use crate::pus::hk::{Pus3Wrapper, PusService3HkHandler};
|
2023-07-05 11:58:43 +02:00
|
|
|
use crate::pus::scheduler::Pus11Wrapper;
|
2023-07-05 11:25:23 +02:00
|
|
|
use crate::pus::test::Service17CustomWrapper;
|
2023-09-27 00:21:03 +02:00
|
|
|
use crate::pus::{PusReceiver, PusTcMpscRouter};
|
2022-12-22 09:26:00 +01:00
|
|
|
use crate::requests::{Request, RequestWithToken};
|
2023-09-29 14:11:03 +02:00
|
|
|
use crate::tcp::{SyncTcpTmSource, TcpTask};
|
2023-09-29 12:38:57 +02:00
|
|
|
use crate::tmtc::{PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmtcTask};
|
|
|
|
use crate::udp::UdpTmtcServer;
|
2022-11-20 19:54:14 +01:00
|
|
|
use satrs_core::event_man::{
|
2022-11-19 02:42:11 +01:00
|
|
|
EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider,
|
|
|
|
};
|
2022-11-20 19:54:14 +01:00
|
|
|
use satrs_core::events::EventU32;
|
2023-02-14 15:53:14 +01:00
|
|
|
use satrs_core::hk::HkRequest;
|
2023-02-27 17:00:21 +01:00
|
|
|
use satrs_core::pool::{LocalPool, PoolCfg};
|
2022-11-20 19:54:14 +01:00
|
|
|
use satrs_core::pus::event_man::{
|
2022-11-13 21:07:16 +01:00
|
|
|
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,
|
|
|
|
PusEventDispatcher,
|
|
|
|
};
|
2023-07-05 14:25:51 +02:00
|
|
|
use satrs_core::pus::event_srv::PusService5EventHandler;
|
2023-02-04 15:35:18 +01:00
|
|
|
use satrs_core::pus::hk::Subservice as HkSubservice;
|
2023-07-05 11:58:43 +02:00
|
|
|
use satrs_core::pus::scheduler::PusScheduler;
|
|
|
|
use satrs_core::pus::scheduler_srv::PusService11SchedHandler;
|
2023-07-05 11:25:23 +02:00
|
|
|
use satrs_core::pus::test::PusService17TestHandler;
|
2023-07-10 00:29:31 +02:00
|
|
|
use satrs_core::pus::verification::{
|
|
|
|
TcStateStarted, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken,
|
|
|
|
};
|
2024-01-31 12:09:55 +01:00
|
|
|
use satrs_core::pus::{EcssTcInStoreConverter, MpscTcInStoreReceiver, MpscTmInStoreSender};
|
2023-07-07 01:25:23 +02:00
|
|
|
use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore};
|
2023-07-11 00:28:28 +02:00
|
|
|
use satrs_core::spacepackets::ecss::tm::{PusTmCreator, PusTmZeroCopyWriter};
|
2023-01-10 17:16:57 +01:00
|
|
|
use satrs_core::spacepackets::{
|
2023-07-11 00:28:28 +02:00
|
|
|
ecss::tm::PusTmSecondaryHeader, time::cds::TimeProvider, time::TimeWriter, SequenceFlags,
|
|
|
|
SpHeader,
|
2023-01-10 17:16:57 +01:00
|
|
|
};
|
2023-07-05 11:25:23 +02:00
|
|
|
use satrs_core::tmtc::tm_helper::SharedTmStore;
|
2024-01-30 23:48:46 +01:00
|
|
|
use satrs_core::tmtc::{CcsdsDistributor, TargetId};
|
2023-07-10 00:29:31 +02:00
|
|
|
use satrs_core::ChannelId;
|
2023-07-11 00:45:59 +02:00
|
|
|
use satrs_example::{
|
2023-08-15 21:07:15 +02:00
|
|
|
RequestTargetId, TargetIdWithApid, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, PUS_APID,
|
|
|
|
SERVER_PORT,
|
2023-07-11 00:45:59 +02:00
|
|
|
};
|
2022-12-19 17:03:26 +01:00
|
|
|
use std::collections::HashMap;
|
2022-08-29 01:33:32 +02:00
|
|
|
use std::net::{IpAddr, SocketAddr};
|
2022-12-21 09:47:27 +01:00
|
|
|
use std::sync::mpsc::{channel, TryRecvError};
|
2023-07-05 11:25:23 +02:00
|
|
|
use std::sync::{Arc, RwLock};
|
2022-08-29 01:33:32 +02:00
|
|
|
use std::thread;
|
2022-12-20 15:33:00 +01:00
|
|
|
use std::time::Duration;
|
2022-08-29 01:33:32 +02:00
|
|
|
|
|
|
|
fn main() {
|
2023-02-15 22:30:32 +01:00
|
|
|
setup_logger().expect("setting up logging with fern failed");
|
2022-09-03 13:47:25 +02:00
|
|
|
println!("Running OBSW example");
|
2022-12-21 22:14:42 +01:00
|
|
|
let tm_pool = LocalPool::new(PoolCfg::new(vec![
|
|
|
|
(30, 32),
|
|
|
|
(15, 64),
|
|
|
|
(15, 128),
|
|
|
|
(15, 256),
|
|
|
|
(15, 1024),
|
|
|
|
(15, 2048),
|
|
|
|
]));
|
2023-07-09 20:05:45 +02:00
|
|
|
let shared_tm_store = SharedTmStore::new(Box::new(tm_pool));
|
|
|
|
let tm_store_event = shared_tm_store.clone();
|
2022-12-21 22:14:42 +01:00
|
|
|
let tc_pool = LocalPool::new(PoolCfg::new(vec![
|
|
|
|
(30, 32),
|
|
|
|
(15, 64),
|
|
|
|
(15, 128),
|
|
|
|
(15, 256),
|
|
|
|
(15, 1024),
|
|
|
|
(15, 2048),
|
|
|
|
]));
|
|
|
|
let tc_store = TcStore {
|
|
|
|
pool: Arc::new(RwLock::new(Box::new(tc_pool))),
|
|
|
|
};
|
2022-12-22 09:15:59 +01:00
|
|
|
|
2023-07-07 01:25:23 +02:00
|
|
|
let seq_count_provider = CcsdsSimpleSeqCountProvider::new();
|
2023-07-05 17:24:53 +02:00
|
|
|
let mut msg_counter_map: HashMap<u8, u16> = HashMap::new();
|
2022-12-21 22:14:42 +01:00
|
|
|
let sock_addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
|
|
|
let (tc_source_tx, tc_source_rx) = channel();
|
2022-11-13 21:07:16 +01:00
|
|
|
let (tm_funnel_tx, tm_funnel_rx) = channel();
|
|
|
|
let (tm_server_tx, tm_server_rx) = channel();
|
2023-07-08 14:57:11 +02:00
|
|
|
let verif_sender = MpscTmInStoreSender::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
TmSenderId::PusVerification as ChannelId,
|
2023-02-28 14:01:40 +01:00
|
|
|
"verif_sender",
|
2023-07-09 20:05:45 +02:00
|
|
|
shared_tm_store.clone(),
|
2023-02-28 14:01:40 +01:00
|
|
|
tm_funnel_tx.clone(),
|
|
|
|
);
|
2023-07-05 17:24:53 +02:00
|
|
|
let verif_cfg = VerificationReporterCfg::new(PUS_APID, 1, 2, 8).unwrap();
|
2023-02-16 01:02:14 +01:00
|
|
|
// Every software component which needs to generate verification telemetry, gets a cloned
|
|
|
|
// verification reporter.
|
2022-12-22 09:15:59 +01:00
|
|
|
let verif_reporter = VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
2023-07-19 11:27:35 +02:00
|
|
|
let reporter_event_handler = verif_reporter.clone();
|
|
|
|
let reporter_aocs = verif_reporter.clone();
|
2022-11-13 21:07:16 +01:00
|
|
|
|
|
|
|
// Create event handling components
|
2023-02-16 01:02:14 +01:00
|
|
|
// These sender handles are used to send event requests, for example to enable or disable
|
|
|
|
// certain events
|
2022-11-13 21:07:16 +01:00
|
|
|
let (event_request_tx, event_request_rx) = channel::<EventRequestWithToken>();
|
2023-02-16 01:02:14 +01:00
|
|
|
// The sender handle is the primary sender handle for all components which want to create events.
|
|
|
|
// The event manager will receive the RX handle to receive all the events.
|
2022-11-12 23:37:19 +01:00
|
|
|
let (event_sender, event_man_rx) = channel();
|
|
|
|
let event_recv = MpscEventReceiver::<EventU32>::new(event_man_rx);
|
2023-07-06 00:49:18 +02:00
|
|
|
let test_srv_event_sender = event_sender;
|
2022-11-19 02:42:11 +01:00
|
|
|
let mut event_man = EventManagerWithMpscQueue::new(Box::new(event_recv));
|
2023-02-16 01:02:14 +01:00
|
|
|
|
|
|
|
// All events sent to the manager are routed to the PUS event manager, which generates PUS event
|
|
|
|
// telemetry for each event.
|
2022-11-12 23:37:19 +01:00
|
|
|
let event_reporter = EventReporter::new(PUS_APID, 128).unwrap();
|
|
|
|
let pus_tm_backend = DefaultPusMgmtBackendProvider::<EventU32>::default();
|
2022-11-13 21:07:16 +01:00
|
|
|
let mut pus_event_dispatcher =
|
|
|
|
PusEventDispatcher::new(event_reporter, Box::new(pus_tm_backend));
|
2022-11-12 23:37:19 +01:00
|
|
|
let (pus_event_man_tx, pus_event_man_rx) = channel();
|
|
|
|
let pus_event_man_send_provider = MpscEventU32SendProvider::new(1, pus_event_man_tx);
|
2022-11-19 02:42:11 +01:00
|
|
|
event_man.subscribe_all(pus_event_man_send_provider.id());
|
2023-02-16 01:02:14 +01:00
|
|
|
event_man.add_sender(pus_event_man_send_provider);
|
2022-11-13 21:07:16 +01:00
|
|
|
|
2023-02-16 01:02:14 +01:00
|
|
|
// Some request are targetable. This map is used to retrieve sender handles based on a target ID.
|
2022-12-19 17:03:26 +01:00
|
|
|
let mut request_map = HashMap::new();
|
2022-12-21 10:23:32 +01:00
|
|
|
let (acs_thread_tx, acs_thread_rx) = channel::<RequestWithToken>();
|
2023-08-15 08:49:54 +02:00
|
|
|
let target_apid = TargetIdWithApid::new(PUS_APID, RequestTargetId::AcsSubsystem as TargetId);
|
|
|
|
request_map.insert(target_apid, acs_thread_tx);
|
2022-12-19 17:03:26 +01:00
|
|
|
|
2023-07-05 15:12:03 +02:00
|
|
|
let tc_source_wrapper = PusTcSource {
|
2023-07-04 18:51:54 +02:00
|
|
|
tc_store: tc_store.clone(),
|
2022-12-21 22:14:42 +01:00
|
|
|
tc_source: tc_source_tx,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create clones here to allow moving the values
|
|
|
|
let tc_args = TcArgs {
|
2023-07-05 15:12:03 +02:00
|
|
|
tc_source: tc_source_wrapper.clone(),
|
2022-12-21 22:14:42 +01:00
|
|
|
tc_receiver: tc_source_rx,
|
|
|
|
};
|
|
|
|
let tm_args = TmArgs {
|
2023-07-09 20:05:45 +02:00
|
|
|
tm_store: shared_tm_store.clone(),
|
2022-12-21 22:14:42 +01:00
|
|
|
tm_sink_sender: tm_funnel_tx.clone(),
|
2023-09-29 14:11:03 +02:00
|
|
|
tm_udp_server_rx: tm_server_rx,
|
2022-12-21 22:14:42 +01:00
|
|
|
};
|
2022-11-20 18:45:11 +01:00
|
|
|
|
2023-07-06 00:49:18 +02:00
|
|
|
let aocs_tm_funnel = tm_funnel_tx.clone();
|
2023-07-09 20:05:45 +02:00
|
|
|
let aocs_tm_store = shared_tm_store.clone();
|
2022-12-22 09:15:59 +01:00
|
|
|
|
2023-07-04 18:51:54 +02:00
|
|
|
let (pus_test_tx, pus_test_rx) = channel();
|
|
|
|
let (pus_event_tx, pus_event_rx) = channel();
|
|
|
|
let (pus_sched_tx, pus_sched_rx) = channel();
|
2023-07-06 00:49:18 +02:00
|
|
|
let (pus_hk_tx, pus_hk_rx) = channel();
|
2023-07-04 18:51:54 +02:00
|
|
|
let (pus_action_tx, pus_action_rx) = channel();
|
|
|
|
let pus_router = PusTcMpscRouter {
|
|
|
|
test_service_receiver: pus_test_tx,
|
|
|
|
event_service_receiver: pus_event_tx,
|
|
|
|
sched_service_receiver: pus_sched_tx,
|
|
|
|
hk_service_receiver: pus_hk_tx,
|
|
|
|
action_service_receiver: pus_action_tx,
|
|
|
|
};
|
2023-07-09 17:04:18 +02:00
|
|
|
let test_srv_tm_sender = MpscTmInStoreSender::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
TmSenderId::PusTest as ChannelId,
|
2023-07-09 17:04:18 +02:00
|
|
|
"PUS_17_TM_SENDER",
|
2023-07-09 20:05:45 +02:00
|
|
|
shared_tm_store.clone(),
|
2023-07-09 17:04:18 +02:00
|
|
|
tm_funnel_tx.clone(),
|
|
|
|
);
|
2023-07-10 00:29:31 +02:00
|
|
|
let test_srv_receiver = MpscTcInStoreReceiver::new(
|
|
|
|
TcReceiverId::PusTest as ChannelId,
|
|
|
|
"PUS_17_TC_RECV",
|
2023-07-04 18:51:54 +02:00
|
|
|
pus_test_rx,
|
2023-07-10 00:29:31 +02:00
|
|
|
);
|
|
|
|
let pus17_handler = PusService17TestHandler::new(
|
|
|
|
Box::new(test_srv_receiver),
|
2023-07-09 17:04:18 +02:00
|
|
|
Box::new(test_srv_tm_sender),
|
2023-07-04 22:26:41 +02:00
|
|
|
PUS_APID,
|
2023-07-05 11:58:43 +02:00
|
|
|
verif_reporter.clone(),
|
2024-01-31 12:09:55 +01:00
|
|
|
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
2023-07-04 18:51:54 +02:00
|
|
|
);
|
2023-07-05 11:58:43 +02:00
|
|
|
let mut pus_17_wrapper = Service17CustomWrapper {
|
2023-07-04 21:13:26 +02:00
|
|
|
pus17_handler,
|
|
|
|
test_srv_event_sender,
|
|
|
|
};
|
2023-07-09 17:04:18 +02:00
|
|
|
|
|
|
|
let sched_srv_tm_sender = MpscTmInStoreSender::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
TmSenderId::PusSched as ChannelId,
|
2023-07-09 17:04:18 +02:00
|
|
|
"PUS_11_TM_SENDER",
|
2023-07-09 20:05:45 +02:00
|
|
|
shared_tm_store.clone(),
|
2023-07-09 17:04:18 +02:00
|
|
|
tm_funnel_tx.clone(),
|
|
|
|
);
|
2023-07-10 00:29:31 +02:00
|
|
|
let sched_srv_receiver = MpscTcInStoreReceiver::new(
|
|
|
|
TcReceiverId::PusSched as ChannelId,
|
|
|
|
"PUS_11_TC_RECV",
|
|
|
|
pus_sched_rx,
|
|
|
|
);
|
2023-07-05 11:58:43 +02:00
|
|
|
let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5))
|
|
|
|
.expect("Creating PUS Scheduler failed");
|
2023-07-05 14:25:51 +02:00
|
|
|
let pus_11_handler = PusService11SchedHandler::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
Box::new(sched_srv_receiver),
|
2023-07-09 17:04:18 +02:00
|
|
|
Box::new(sched_srv_tm_sender),
|
2023-07-05 11:58:43 +02:00
|
|
|
PUS_APID,
|
2023-07-05 14:25:51 +02:00
|
|
|
verif_reporter.clone(),
|
2024-01-31 12:09:55 +01:00
|
|
|
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
|
|
|
tc_store.pool.clone(),
|
2023-07-05 11:58:43 +02:00
|
|
|
scheduler,
|
|
|
|
);
|
2023-07-05 15:12:03 +02:00
|
|
|
let mut pus_11_wrapper = Pus11Wrapper {
|
|
|
|
pus_11_handler,
|
|
|
|
tc_source_wrapper,
|
|
|
|
};
|
2023-07-09 17:04:18 +02:00
|
|
|
|
|
|
|
let event_srv_tm_sender = MpscTmInStoreSender::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
TmSenderId::PusEvent as ChannelId,
|
2023-07-09 17:04:18 +02:00
|
|
|
"PUS_5_TM_SENDER",
|
2023-07-09 20:05:45 +02:00
|
|
|
shared_tm_store.clone(),
|
2023-07-09 17:04:18 +02:00
|
|
|
tm_funnel_tx.clone(),
|
|
|
|
);
|
2023-07-10 00:29:31 +02:00
|
|
|
let event_srv_receiver = MpscTcInStoreReceiver::new(
|
|
|
|
TcReceiverId::PusEvent as ChannelId,
|
|
|
|
"PUS_5_TC_RECV",
|
2023-07-05 14:25:51 +02:00
|
|
|
pus_event_rx,
|
2023-07-10 00:29:31 +02:00
|
|
|
);
|
|
|
|
let pus_5_handler = PusService5EventHandler::new(
|
|
|
|
Box::new(event_srv_receiver),
|
2023-07-09 17:04:18 +02:00
|
|
|
Box::new(event_srv_tm_sender),
|
2023-07-05 14:25:51 +02:00
|
|
|
PUS_APID,
|
2023-07-05 21:08:04 +02:00
|
|
|
verif_reporter.clone(),
|
2024-01-31 12:09:55 +01:00
|
|
|
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
2023-07-05 14:25:51 +02:00
|
|
|
event_request_tx,
|
|
|
|
);
|
|
|
|
let mut pus_5_wrapper = Pus5Wrapper { pus_5_handler };
|
2023-07-04 15:17:43 +02:00
|
|
|
|
2023-07-09 17:04:18 +02:00
|
|
|
let action_srv_tm_sender = MpscTmInStoreSender::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
TmSenderId::PusAction as ChannelId,
|
2023-07-09 17:04:18 +02:00
|
|
|
"PUS_8_TM_SENDER",
|
2023-07-09 20:05:45 +02:00
|
|
|
shared_tm_store.clone(),
|
2023-07-09 17:04:18 +02:00
|
|
|
tm_funnel_tx.clone(),
|
|
|
|
);
|
2023-07-10 00:29:31 +02:00
|
|
|
let action_srv_receiver = MpscTcInStoreReceiver::new(
|
|
|
|
TcReceiverId::PusAction as ChannelId,
|
|
|
|
"PUS_8_TC_RECV",
|
2023-07-05 21:08:04 +02:00
|
|
|
pus_action_rx,
|
2023-07-10 00:29:31 +02:00
|
|
|
);
|
|
|
|
let pus_8_handler = PusService8ActionHandler::new(
|
|
|
|
Box::new(action_srv_receiver),
|
2023-07-09 17:04:18 +02:00
|
|
|
Box::new(action_srv_tm_sender),
|
2023-07-05 21:08:04 +02:00
|
|
|
PUS_APID,
|
2023-07-06 00:49:18 +02:00
|
|
|
verif_reporter.clone(),
|
2024-01-31 12:09:55 +01:00
|
|
|
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
2023-07-05 21:08:04 +02:00
|
|
|
request_map.clone(),
|
|
|
|
);
|
|
|
|
let mut pus_8_wrapper = Pus8Wrapper { pus_8_handler };
|
|
|
|
|
2023-07-09 17:04:18 +02:00
|
|
|
let hk_srv_tm_sender = MpscTmInStoreSender::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
TmSenderId::PusHk as ChannelId,
|
2023-07-09 17:04:18 +02:00
|
|
|
"PUS_3_TM_SENDER",
|
2023-07-09 20:05:45 +02:00
|
|
|
shared_tm_store.clone(),
|
2023-07-09 17:04:18 +02:00
|
|
|
tm_funnel_tx.clone(),
|
|
|
|
);
|
2023-07-10 00:29:31 +02:00
|
|
|
let hk_srv_receiver =
|
|
|
|
MpscTcInStoreReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx);
|
2023-07-06 00:49:18 +02:00
|
|
|
let pus_3_handler = PusService3HkHandler::new(
|
2023-07-10 00:29:31 +02:00
|
|
|
Box::new(hk_srv_receiver),
|
2023-07-09 17:04:18 +02:00
|
|
|
Box::new(hk_srv_tm_sender),
|
2023-07-06 00:49:18 +02:00
|
|
|
PUS_APID,
|
|
|
|
verif_reporter.clone(),
|
2024-01-31 12:09:55 +01:00
|
|
|
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
2023-07-06 00:49:18 +02:00
|
|
|
request_map,
|
|
|
|
);
|
|
|
|
let mut pus_3_wrapper = Pus3Wrapper { pus_3_handler };
|
|
|
|
|
2023-09-27 00:21:03 +02:00
|
|
|
let ccsds_receiver = CcsdsReceiver {
|
|
|
|
tc_source: tc_args.tc_source.clone(),
|
|
|
|
};
|
|
|
|
let mut tmtc_task = TmtcTask::new(tc_args, PusReceiver::new(verif_reporter, pus_router));
|
|
|
|
|
2023-09-29 14:11:03 +02:00
|
|
|
let udp_ccsds_distributor = CcsdsDistributor::new(Box::new(ccsds_receiver.clone()));
|
|
|
|
let udp_tc_server = UdpTcServer::new(sock_addr, 2048, Box::new(udp_ccsds_distributor))
|
2023-09-27 00:21:03 +02:00
|
|
|
.expect("creating UDP TMTC server failed");
|
|
|
|
let mut udp_tmtc_server = UdpTmtcServer {
|
|
|
|
udp_tc_server,
|
2023-09-29 14:11:03 +02:00
|
|
|
tm_rx: tm_args.tm_udp_server_rx,
|
2023-09-27 00:21:03 +02:00
|
|
|
tm_store: tm_args.tm_store.clone_backing_pool(),
|
|
|
|
};
|
|
|
|
|
2023-09-27 00:25:50 +02:00
|
|
|
info!("Starting TMTC and UDP task");
|
2023-09-29 14:11:03 +02:00
|
|
|
let jh_udp_tmtc = thread::Builder::new()
|
|
|
|
.name("TMTC and UDP".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
info!("Running UDP server on port {SERVER_PORT}");
|
|
|
|
loop {
|
|
|
|
udp_tmtc_server.periodic_operation();
|
|
|
|
tmtc_task.periodic_operation();
|
|
|
|
thread::sleep(Duration::from_millis(400));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let tcp_ccsds_distributor = CcsdsDistributor::new(Box::new(ccsds_receiver));
|
|
|
|
let tcp_server_cfg = ServerConfig::new(sock_addr, Duration::from_millis(400), 4096, 8192);
|
|
|
|
let mut sync_tm_tcp_source = SyncTcpTmSource::new(200);
|
|
|
|
let mut tcp_server = TcpTask::new(
|
|
|
|
tcp_server_cfg,
|
|
|
|
sync_tm_tcp_source.clone(),
|
|
|
|
tcp_ccsds_distributor,
|
|
|
|
)
|
|
|
|
.expect("tcp server creation failed");
|
|
|
|
info!("Starting TCP task");
|
|
|
|
let jh_tcp = thread::Builder::new()
|
|
|
|
.name("TCP".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
info!("Running TCP server on port {SERVER_PORT}");
|
|
|
|
loop {
|
|
|
|
tcp_server.periodic_operation();
|
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
})
|
|
|
|
.unwrap();
|
2022-08-29 01:33:32 +02:00
|
|
|
|
2023-02-15 22:30:32 +01:00
|
|
|
info!("Starting TM funnel task");
|
2023-02-16 01:02:14 +01:00
|
|
|
let jh1 = thread::Builder::new()
|
|
|
|
.name("TM Funnel".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
let tm_funnel = TmFunnel {
|
|
|
|
tm_server_tx,
|
|
|
|
tm_funnel_rx,
|
|
|
|
};
|
|
|
|
loop {
|
|
|
|
if let Ok(addr) = tm_funnel.tm_funnel_rx.recv() {
|
2023-07-05 19:31:48 +02:00
|
|
|
// Read the TM, set sequence counter and message counter, and finally update
|
|
|
|
// the CRC.
|
2023-07-10 00:29:31 +02:00
|
|
|
let shared_pool = shared_tm_store.clone_backing_pool();
|
2023-07-05 17:24:53 +02:00
|
|
|
let mut pool_guard = shared_pool.write().expect("Locking TM pool failed");
|
|
|
|
let tm_raw = pool_guard
|
|
|
|
.modify(&addr)
|
|
|
|
.expect("Reading TM from pool failed");
|
2023-07-05 19:31:48 +02:00
|
|
|
let mut zero_copy_writer = PusTmZeroCopyWriter::new(tm_raw)
|
|
|
|
.expect("Creating TM zero copy writer failed");
|
|
|
|
zero_copy_writer.set_apid(PUS_APID);
|
|
|
|
zero_copy_writer.set_seq_count(seq_count_provider.get_and_increment());
|
|
|
|
let entry = msg_counter_map
|
|
|
|
.entry(zero_copy_writer.service())
|
|
|
|
.or_insert(0);
|
|
|
|
zero_copy_writer.set_msg_count(*entry);
|
2023-07-05 19:11:09 +02:00
|
|
|
if *entry == u16::MAX {
|
|
|
|
*entry = 0;
|
|
|
|
} else {
|
|
|
|
*entry += 1;
|
|
|
|
}
|
2023-07-05 19:31:48 +02:00
|
|
|
|
|
|
|
// This operation has to come last!
|
|
|
|
zero_copy_writer.finish();
|
2023-02-16 01:02:14 +01:00
|
|
|
tm_funnel
|
|
|
|
.tm_server_tx
|
|
|
|
.send(addr)
|
|
|
|
.expect("Sending TM to server failed");
|
2023-09-29 14:11:03 +02:00
|
|
|
sync_tm_tcp_source.add_tm(tm_raw);
|
2023-02-16 01:02:14 +01:00
|
|
|
}
|
2022-08-29 01:33:32 +02:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
})
|
|
|
|
.unwrap();
|
2022-11-12 23:37:19 +01:00
|
|
|
|
2023-02-15 22:30:32 +01:00
|
|
|
info!("Starting event handling task");
|
2023-02-16 01:02:14 +01:00
|
|
|
let jh2 = thread::Builder::new()
|
|
|
|
.name("Event".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
let mut timestamp: [u8; 7] = [0; 7];
|
2023-07-10 00:29:31 +02:00
|
|
|
let mut sender = MpscTmInStoreSender::new(
|
|
|
|
TmSenderId::AllEvents as ChannelId,
|
|
|
|
"ALL_EVENTS_TX",
|
|
|
|
tm_store_event.clone(),
|
|
|
|
tm_funnel_tx,
|
|
|
|
);
|
2023-02-16 01:02:14 +01:00
|
|
|
let mut time_provider = TimeProvider::new_with_u16_days(0, 0);
|
2023-07-19 11:27:35 +02:00
|
|
|
let report_completion = |event_req: EventRequestWithToken, timestamp: &[u8]| {
|
2023-07-10 00:29:31 +02:00
|
|
|
let started_token: VerificationToken<TcStateStarted> = event_req
|
|
|
|
.token
|
|
|
|
.try_into()
|
|
|
|
.expect("expected start verification token");
|
2023-02-16 01:02:14 +01:00
|
|
|
reporter_event_handler
|
2023-07-10 00:29:31 +02:00
|
|
|
.completion_success(started_token, Some(timestamp))
|
2023-02-16 01:02:14 +01:00
|
|
|
.expect("Sending completion success failed");
|
|
|
|
};
|
|
|
|
loop {
|
|
|
|
// handle event requests
|
|
|
|
if let Ok(event_req) = event_request_rx.try_recv() {
|
|
|
|
match event_req.request {
|
|
|
|
EventRequest::Enable(event) => {
|
|
|
|
pus_event_dispatcher
|
|
|
|
.enable_tm_for_event(&event)
|
|
|
|
.expect("Enabling TM failed");
|
|
|
|
update_time(&mut time_provider, &mut timestamp);
|
|
|
|
report_completion(event_req, ×tamp);
|
|
|
|
}
|
|
|
|
EventRequest::Disable(event) => {
|
|
|
|
pus_event_dispatcher
|
|
|
|
.disable_tm_for_event(&event)
|
|
|
|
.expect("Disabling TM failed");
|
|
|
|
update_time(&mut time_provider, &mut timestamp);
|
|
|
|
report_completion(event_req, ×tamp);
|
|
|
|
}
|
2022-11-13 21:07:16 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
|
|
|
|
// Perform the event routing.
|
|
|
|
event_man
|
|
|
|
.try_event_handling()
|
|
|
|
.expect("event handling failed");
|
|
|
|
|
|
|
|
// Perform the generation of PUS event packets
|
|
|
|
if let Ok((event, _param)) = pus_event_man_rx.try_recv() {
|
|
|
|
update_time(&mut time_provider, &mut timestamp);
|
|
|
|
pus_event_dispatcher
|
|
|
|
.generate_pus_event_tm_generic(&mut sender, ×tamp, event, None)
|
|
|
|
.expect("Sending TM as event failed");
|
|
|
|
}
|
|
|
|
thread::sleep(Duration::from_millis(400));
|
2022-11-13 21:07:16 +01:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
})
|
|
|
|
.unwrap();
|
2022-11-12 23:37:19 +01:00
|
|
|
|
2023-02-15 22:30:32 +01:00
|
|
|
info!("Starting AOCS thread");
|
2023-02-16 01:02:14 +01:00
|
|
|
let jh3 = thread::Builder::new()
|
|
|
|
.name("AOCS".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
let mut timestamp: [u8; 7] = [0; 7];
|
|
|
|
let mut time_provider = TimeProvider::new_with_u16_days(0, 0);
|
|
|
|
loop {
|
2023-09-27 00:25:50 +02:00
|
|
|
// TODO: Move this into a separate function/task/module..
|
2023-02-16 01:02:14 +01:00
|
|
|
match acs_thread_rx.try_recv() {
|
|
|
|
Ok(request) => {
|
2023-02-27 13:44:24 +01:00
|
|
|
info!(
|
|
|
|
"ACS thread: Received HK request {:?}",
|
|
|
|
request.targeted_request
|
|
|
|
);
|
2023-02-16 01:02:14 +01:00
|
|
|
update_time(&mut time_provider, &mut timestamp);
|
2023-02-27 13:44:24 +01:00
|
|
|
match request.targeted_request.request {
|
2023-07-05 21:08:04 +02:00
|
|
|
Request::Hk(hk_req) => match hk_req {
|
2023-02-27 13:44:24 +01:00
|
|
|
HkRequest::OneShot(unique_id) => {
|
2024-01-30 23:59:29 +01:00
|
|
|
// TODO: We should check whether the unique ID is even valid.
|
2023-02-27 13:44:24 +01:00
|
|
|
let target = request.targeted_request.target_id;
|
2023-08-15 21:07:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
target.target_id(),
|
|
|
|
RequestTargetId::AcsSubsystem as u32
|
|
|
|
);
|
2023-08-15 08:49:54 +02:00
|
|
|
if request.targeted_request.target_id.target
|
2023-02-27 13:44:24 +01:00
|
|
|
== AcsHkIds::TestMgmSet as u32
|
|
|
|
{
|
2023-02-16 01:02:14 +01:00
|
|
|
let mut sp_header = SpHeader::tm(
|
|
|
|
PUS_APID,
|
|
|
|
SequenceFlags::Unsegmented,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
let sec_header = PusTmSecondaryHeader::new_simple(
|
|
|
|
3,
|
|
|
|
HkSubservice::TmHkPacket as u8,
|
|
|
|
×tamp,
|
|
|
|
);
|
|
|
|
let mut buf: [u8; 8] = [0; 8];
|
2024-01-30 23:59:29 +01:00
|
|
|
let hk_id = HkUniqueId::new(target.target_id(), unique_id);
|
|
|
|
hk_id.write_to_be_bytes(&mut buf).unwrap();
|
2023-07-11 00:28:28 +02:00
|
|
|
let pus_tm = PusTmCreator::new(
|
2023-02-16 01:02:14 +01:00
|
|
|
&mut sp_header,
|
|
|
|
sec_header,
|
2023-12-13 15:49:26 +01:00
|
|
|
&buf,
|
2023-02-16 01:02:14 +01:00
|
|
|
true,
|
|
|
|
);
|
2023-07-09 20:05:45 +02:00
|
|
|
let addr = aocs_tm_store
|
|
|
|
.add_pus_tm(&pus_tm)
|
|
|
|
.expect("Adding PUS TM failed");
|
2023-07-06 00:49:18 +02:00
|
|
|
aocs_tm_funnel.send(addr).expect("Sending HK TM failed");
|
2023-02-16 01:02:14 +01:00
|
|
|
}
|
2022-12-22 09:26:00 +01:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
HkRequest::Enable(_) => {}
|
|
|
|
HkRequest::Disable(_) => {}
|
|
|
|
HkRequest::ModifyCollectionInterval(_, _) => {}
|
|
|
|
},
|
2023-07-05 21:08:04 +02:00
|
|
|
Request::Mode(_mode_req) => {
|
2023-02-16 01:02:14 +01:00
|
|
|
warn!("mode request handling not implemented yet")
|
2022-12-22 09:26:00 +01:00
|
|
|
}
|
2023-07-05 21:08:04 +02:00
|
|
|
Request::Action(_action_req) => {
|
|
|
|
warn!("action request handling not implemented yet")
|
|
|
|
}
|
2023-02-15 11:19:23 +01:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
let started_token = reporter_aocs
|
2023-02-27 13:44:24 +01:00
|
|
|
.start_success(request.token, Some(×tamp))
|
2023-02-16 01:02:14 +01:00
|
|
|
.expect("Sending start success failed");
|
|
|
|
reporter_aocs
|
|
|
|
.completion_success(started_token, Some(×tamp))
|
|
|
|
.expect("Sending completion success failed");
|
2022-12-22 09:26:00 +01:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
Err(e) => match e {
|
|
|
|
TryRecvError::Empty => {}
|
|
|
|
TryRecvError::Disconnected => {
|
|
|
|
warn!("ACS thread: Message Queue TX disconnected!")
|
|
|
|
}
|
|
|
|
},
|
2022-12-21 09:47:27 +01:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
thread::sleep(Duration::from_millis(500));
|
2022-12-21 10:23:32 +01:00
|
|
|
}
|
2023-02-16 01:02:14 +01:00
|
|
|
})
|
|
|
|
.unwrap();
|
2022-12-20 15:33:00 +01:00
|
|
|
|
2023-07-04 15:17:43 +02:00
|
|
|
info!("Starting PUS handler thread");
|
|
|
|
let jh4 = thread::Builder::new()
|
2023-07-04 18:51:54 +02:00
|
|
|
.name("PUS".to_string())
|
2023-07-04 21:13:26 +02:00
|
|
|
.spawn(move || loop {
|
2023-07-05 15:12:03 +02:00
|
|
|
pus_11_wrapper.release_tcs();
|
|
|
|
loop {
|
|
|
|
let mut all_queues_empty = true;
|
|
|
|
let mut is_srv_finished = |srv_handler_finished: bool| {
|
|
|
|
if !srv_handler_finished {
|
|
|
|
all_queues_empty = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
is_srv_finished(pus_17_wrapper.handle_next_packet());
|
|
|
|
is_srv_finished(pus_11_wrapper.handle_next_packet());
|
|
|
|
is_srv_finished(pus_5_wrapper.handle_next_packet());
|
2023-07-05 21:08:04 +02:00
|
|
|
is_srv_finished(pus_8_wrapper.handle_next_packet());
|
2023-07-06 00:49:18 +02:00
|
|
|
is_srv_finished(pus_3_wrapper.handle_next_packet());
|
2023-07-05 15:12:03 +02:00
|
|
|
if all_queues_empty {
|
|
|
|
break;
|
2023-07-05 11:58:43 +02:00
|
|
|
}
|
2023-07-04 18:51:54 +02:00
|
|
|
}
|
2023-07-05 15:12:03 +02:00
|
|
|
thread::sleep(Duration::from_millis(200));
|
2023-07-04 18:51:54 +02:00
|
|
|
})
|
|
|
|
.unwrap();
|
2023-09-29 14:11:03 +02:00
|
|
|
jh_udp_tmtc
|
|
|
|
.join()
|
|
|
|
.expect("Joining UDP TMTC server thread failed");
|
|
|
|
jh_tcp
|
|
|
|
.join()
|
|
|
|
.expect("Joining TCP TMTC server thread failed");
|
2022-08-29 01:33:32 +02:00
|
|
|
jh1.join().expect("Joining TM Funnel thread failed");
|
2022-11-12 23:37:19 +01:00
|
|
|
jh2.join().expect("Joining Event Manager thread failed");
|
2022-12-20 15:33:00 +01:00
|
|
|
jh3.join().expect("Joining AOCS thread failed");
|
2023-07-04 15:17:43 +02:00
|
|
|
jh4.join().expect("Joining PUS handler thread failed");
|
2022-08-29 01:33:32 +02:00
|
|
|
}
|
2022-11-13 21:07:16 +01:00
|
|
|
|
2022-12-08 15:26:49 +01:00
|
|
|
pub fn update_time(time_provider: &mut TimeProvider, timestamp: &mut [u8]) {
|
2022-11-13 21:07:16 +01:00
|
|
|
time_provider
|
|
|
|
.update_from_now()
|
|
|
|
.expect("Could not get current time");
|
|
|
|
time_provider
|
|
|
|
.write_to_bytes(timestamp)
|
|
|
|
.expect("Writing timestamp failed");
|
|
|
|
}
|