add fern logging support
This commit is contained in:
parent
cea5b3eeb1
commit
1ad04e8744
@ -6,6 +6,9 @@ authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||
default-run = "satrs-example"
|
||||
|
||||
[dependencies]
|
||||
fern = "0.6"
|
||||
chrono = "0.4"
|
||||
log = "0.4"
|
||||
crossbeam-channel = "0.5"
|
||||
delegate = "0.9"
|
||||
zerocopy = "0.6"
|
||||
|
16
satrs-example/src/logging.rs
Normal file
16
satrs-example/src/logging.rs
Normal file
@ -0,0 +1,16 @@
|
||||
pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
fern::Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"{}[{}][{}] {}",
|
||||
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
||||
std::thread::current().name().expect("unnamed_thread"),
|
||||
record.level(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.apply()?;
|
||||
Ok(())
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
mod ccsds;
|
||||
mod hk;
|
||||
mod logging;
|
||||
mod pus;
|
||||
mod requests;
|
||||
mod tmtc;
|
||||
|
||||
use log::{info, warn};
|
||||
|
||||
use crate::hk::AcsHkIds;
|
||||
use crate::logging::setup_logger;
|
||||
use crate::requests::{Request, RequestWithToken};
|
||||
use crate::tmtc::{
|
||||
core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmStore, PUS_APID,
|
||||
@ -66,6 +70,7 @@ impl EcssTmSenderCore for EventTmSender {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
setup_logger().expect("setting up logging with fern failed");
|
||||
println!("Running OBSW example");
|
||||
let tm_pool = LocalPool::new(PoolCfg::new(vec![
|
||||
(30, 32),
|
||||
@ -151,12 +156,12 @@ fn main() {
|
||||
let aocs_to_funnel = tm_funnel_tx.clone();
|
||||
let mut aocs_tm_store = tm_store.clone();
|
||||
|
||||
println!("Starting TMTC task");
|
||||
info!("Starting TMTC task");
|
||||
let jh0 = thread::spawn(move || {
|
||||
core_tmtc_task(core_args, tc_args, tm_args);
|
||||
});
|
||||
|
||||
println!("Starting TM funnel task");
|
||||
info!("Starting TM funnel task");
|
||||
let jh1 = thread::spawn(move || {
|
||||
let tm_funnel = TmFunnel {
|
||||
tm_server_tx,
|
||||
@ -172,7 +177,7 @@ fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
println!("Starting event handling task");
|
||||
info!("Starting event handling task");
|
||||
let jh2 = thread::spawn(move || {
|
||||
let mut timestamp: [u8; 7] = [0; 7];
|
||||
let mut sender = EventTmSender::new(tm_store, tm_funnel_tx);
|
||||
@ -211,14 +216,14 @@ fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
println!("Starting AOCS thread");
|
||||
info!("Starting AOCS thread");
|
||||
let jh3 = thread::spawn(move || {
|
||||
let mut timestamp: [u8; 7] = [0; 7];
|
||||
let mut time_provider = TimeProvider::new_with_u16_days(0, 0);
|
||||
loop {
|
||||
match acs_thread_rx.try_recv() {
|
||||
Ok(request) => {
|
||||
println!("ACS thread: Received HK request {:?}", request.0);
|
||||
info!("ACS thread: Received HK request {:?}", request.0);
|
||||
update_time(&mut time_provider, &mut timestamp);
|
||||
match request.0 {
|
||||
Request::HkRequest(hk_req) => match hk_req {
|
||||
@ -246,7 +251,7 @@ fn main() {
|
||||
HkRequest::ModifyCollectionInterval(_, _) => {}
|
||||
},
|
||||
Request::ModeRequest(_mode_req) => {
|
||||
println!("mode request handling not implemented yet")
|
||||
warn!("mode request handling not implemented yet")
|
||||
}
|
||||
}
|
||||
let started_token = reporter_aocs
|
||||
@ -259,7 +264,7 @@ fn main() {
|
||||
Err(e) => match e {
|
||||
TryRecvError::Empty => {}
|
||||
TryRecvError::Disconnected => {
|
||||
println!("ACS thread: Message Queue TX disconnected!")
|
||||
warn!("ACS thread: Message Queue TX disconnected!")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -186,7 +186,8 @@ impl PusReceiver {
|
||||
.expect("Error sending completion success");
|
||||
}
|
||||
128 => {
|
||||
self.tc_args.event_sender
|
||||
self.tc_args
|
||||
.event_sender
|
||||
.send((TEST_EVENT.into(), None))
|
||||
.expect("Sending test event failed");
|
||||
let start_token = self
|
||||
@ -247,7 +248,11 @@ impl PusReceiver {
|
||||
return;
|
||||
}
|
||||
let addressable_id = AddressableId::from_raw_be(user_data).unwrap();
|
||||
if !self.tc_args.request_map.contains_key(&addressable_id.target_id) {
|
||||
if !self
|
||||
.tc_args
|
||||
.request_map
|
||||
.contains_key(&addressable_id.target_id)
|
||||
{
|
||||
self.tm_args
|
||||
.verif_reporter
|
||||
.start_failure(
|
||||
@ -262,7 +267,11 @@ impl PusReceiver {
|
||||
return;
|
||||
}
|
||||
let send_request = |request: HkRequest| {
|
||||
let sender = self.tc_args.request_map.get(&addressable_id.target_id).unwrap();
|
||||
let sender = self
|
||||
.tc_args
|
||||
.request_map
|
||||
.get(&addressable_id.target_id)
|
||||
.unwrap();
|
||||
sender
|
||||
.send(RequestWithToken(Request::HkRequest(request), token))
|
||||
.unwrap_or_else(|_| panic!("Sending HK request {request:?} failed"));
|
||||
@ -338,7 +347,8 @@ impl PusReceiver {
|
||||
&mut self.tm_args.verif_reporter,
|
||||
self.stamp_helper.stamp(),
|
||||
);
|
||||
self.tc_args.event_request_tx
|
||||
self.tc_args
|
||||
.event_request_tx
|
||||
.send(EventRequestWithToken {
|
||||
request: EventRequest::Enable(event_id),
|
||||
token: start_token,
|
||||
@ -350,7 +360,8 @@ impl PusReceiver {
|
||||
&mut self.tm_args.verif_reporter,
|
||||
self.stamp_helper.stamp(),
|
||||
);
|
||||
self.tc_args.event_request_tx
|
||||
self.tc_args
|
||||
.event_request_tx
|
||||
.send(EventRequestWithToken {
|
||||
request: EventRequest::Disable(event_id),
|
||||
token: start_token,
|
||||
@ -530,8 +541,7 @@ impl PusReceiver {
|
||||
&tmtc_err::NOT_ENOUGH_APP_DATA,
|
||||
Some(
|
||||
format!(
|
||||
"expected {} bytes, found {}",
|
||||
min_len, app_data_len
|
||||
"expected {min_len} bytes, found {app_data_len}"
|
||||
)
|
||||
.as_bytes(),
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user