use mavinspect::parser::Inspector;
fn main() {
env_logger::builder()
.filter_level(log::LevelFilter::Info)
.filter_module(env!("CARGO_PKG_NAME"), log::LevelFilter::Trace)
.init();
let inspector = Inspector::builder()
.set_sources(&[
"./message_definitions/standard",
"./message_definitions/extra",
])
.set_include(&[
"ardupilotmega",
"common",
"matrixpilot",
"CrazyFlight",
"MAVInspect_test",
])
.set_exclude(&vec!["matrixpilot", "paparazzi"])
.build()
.unwrap();
let protocol = inspector.parse().unwrap();
assert!(protocol.contains_dialect_with_canonical_name("mav_inspect_test"));
assert!(protocol.contains_dialect_with_canonical_name("crazy_flight"));
assert!(protocol.contains_dialect_with_canonical_name("common"));
let common = protocol.get_dialect_by_canonical_name("common").unwrap();
let command = common.get_command_by_name("MAV_CMD_NAV_WAYPOINT").unwrap();
assert!(command.has_location());
assert!(command.is_destination());
assert!(!command.mission_only());
log::warn!("\n`MAV_CMD_NAV_WAYPOINT` command (`minimal` dialect): {command:#?}",);
let command = common.get_command_by_name("MAV_CMD_NAV_ROI").unwrap();
assert!(command.has_location());
assert!(!command.is_destination());
assert!(!command.mission_only());
let first_param_enum_name = command.params().first().unwrap().r#enum().unwrap();
assert_eq!(first_param_enum_name, "MAV_ROI");
log::warn!("\n`MAV_CMD_NAV_ROI` command (`minimal` dialect): {command:#?}",);
let mav_enum = common.get_enum_by_name(first_param_enum_name).unwrap();
assert_eq!(mav_enum.defined_in(), "common");
log::warn!("\n`MAV_ROI` enum (`minimal` dialect): {mav_enum:#?}",);
let crazyflight = protocol
.get_dialect_by_canonical_name("crazy_flight")
.unwrap();
let outcry_message = crazyflight.get_message_by_id(54000u32).unwrap();
assert_eq!(outcry_message.name(), "CRAZYFLIGHT_OUTCRY");
log::warn!("\n`CRAZYFLIGHT_OUTCRY` message: {outcry_message:#?}");
let heartbeat_message = crazyflight.get_message_by_id(0u32).unwrap();
assert_eq!(heartbeat_message.name(), "HEARTBEAT");
assert_eq!(heartbeat_message.defined_in(), "minimal");
}
#[cfg(test)]
#[test]
fn test_parser_example() {
main()
}