use crate::peripheral::DeimosDaqRev7;
use controller::context::ControllerCtx;
use std::net::Ipv4Addr;
use std::sync::atomic::Ordering;
use std::time::{Duration, SystemTime};
use deimos::{dispatcher::ReportingDispatcher, *};
const MULTICAST_GROUP: Ipv4Addr = Ipv4Addr::new(239, 255, 0, 1);
const MULTICAST_PORT: u16 = 29573;
fn main() {
let mut ctx = ControllerCtx::default();
ctx.op_name = "basic_example".into();
let rate_hz = 10.0;
ctx.dt_ns = (1e9_f64 / rate_hz).ceil() as u32;
ctx.op_dir = "./software/deimos/examples".into();
ctx.loop_method = LoopMethod::Efficient;
let mut controller = Controller::new(ctx);
let reporting = ReportingDispatcher::new(
MULTICAST_GROUP,
MULTICAST_PORT,
None, Duration::from_secs(2), );
let dropped_handle = reporting.dropped_frames_handle();
controller.add_dispatcher("reporting", reporting);
controller
.add_peripheral("p1", Box::new(DeimosDaqRev7 { serial_number: 3 }))
.unwrap();
let csv_dispatcher: Box<dyn Dispatcher> = CsvDispatcher::new(50, dispatcher::Overflow::Wrap);
controller.add_dispatcher("csv", csv_dispatcher);
let serialized_controller = serde_json::to_string_pretty(&controller).unwrap();
let _: Controller = serde_json::from_str(&serialized_controller).unwrap();
controller.run(&None, None).unwrap();
}