use mavwire::{Frame, MavMessage};
pub fn print_message(frame: &Frame, message: &MavMessage) {
let sys = frame.system_id();
let comp = frame.component_id();
match message {
MavMessage::Heartbeat(m) => {
println!(
"sys={sys} comp={comp} HEARTBEAT type={} autopilot={} base_mode={} custom_mode={} status={}",
m.mav_type, m.autopilot, m.base_mode, m.custom_mode, m.system_status
);
}
MavMessage::SysStatus(m) => {
println!(
"sys={sys} comp={comp} SYS_STATUS voltage={}mV current={}cA battery={}%",
m.voltage_battery, m.current_battery, m.battery_remaining
);
}
MavMessage::GpsRawInt(m) => {
println!(
"sys={sys} comp={comp} GPS_RAW_INT fix={} lat={} lon={} alt={}mm sats={}",
m.fix_type, m.lat, m.lon, m.alt, m.satellites_visible
);
}
MavMessage::Attitude(m) => {
println!(
"sys={sys} comp={comp} ATTITUDE roll={:.3} pitch={:.3} yaw={:.3}",
m.roll, m.pitch, m.yaw
);
}
MavMessage::GlobalPositionInt(m) => {
println!(
"sys={sys} comp={comp} GLOBAL_POSITION_INT lat={} lon={} alt={}mm hdg={}",
m.lat, m.lon, m.alt, m.hdg
);
}
MavMessage::RcChannels(m) => {
println!(
"sys={sys} comp={comp} RC_CHANNELS count={} ch1={} rssi={}",
m.chancount, m.channels[0], m.rssi
);
}
MavMessage::VfrHud(m) => {
println!(
"sys={sys} comp={comp} VFR_HUD airspeed={:.1}m/s groundspeed={:.1}m/s alt={:.1}m heading={}",
m.airspeed, m.groundspeed, m.alt, m.heading
);
}
MavMessage::ParamValue(m) => {
println!(
"sys={sys} comp={comp} PARAM_VALUE {}={} (index {}/{})",
m.param_id, m.param_value, m.param_index, m.param_count
);
}
MavMessage::CommandLong(m) => {
println!(
"sys={sys} comp={comp} COMMAND_LONG command={} target={}/{} param1={}",
m.command, m.target_system, m.target_component, m.params[0]
);
}
MavMessage::CommandAck(m) => {
println!(
"sys={sys} comp={comp} COMMAND_ACK command={} result={} progress={}",
m.command, m.result, m.progress
);
}
MavMessage::StatusText(m) => {
println!(
"sys={sys} comp={comp} STATUSTEXT severity={} text={}",
m.severity, m.text
);
}
other => println!("sys={sys} comp={comp} <unhandled message: {other:?}>"),
}
}