using System;
using System.IO;
internal class Program
{
static void Main(string[] args)
{
// 设置输出重定向到文件
string outputPath = @"output.txt";
FileStream fileStream = new FileStream(outputPath, FileMode.Create);
StreamWriter streamWriter = new StreamWriter(fileStream);
Console.SetOut(streamWriter);
FileStream fs = new FileStream(@"C:\Users\lx192\Desktop\NetAssist.bin", FileMode.Open);
MAVLink.MavlinkParse parse = new MAVLink.MavlinkParse();
while (fs.Position < fs.Length)
{
var msg = parse.ReadPacket(fs);
if (msg != null && msg.msgid == 33)
{
MAVLink.mavlink_global_position_int_t p = (MAVLink.mavlink_global_position_int_t)msg.data;
Console.WriteLine("Latitude: {0}, Longitude: {1}, Altitude: {2}", p.lat, p.lon, p.relative_alt);
// 还可以执行其他操作...
}
else if (msg.msgid == 30)
{
// 处理姿态数据
MAVLink.mavlink_attitude_t attitude = (MAVLink.mavlink_attitude_t)msg.data;
double roll_deg = attitude.roll * (180 / Math.PI); // 将弧度转换为度
double pitch_deg = attitude.pitch * (180 / Math.PI); // 将弧度转换为度
double yaw_deg = attitude.yaw * (180 / Math.PI); // 将弧度转换为度
Console.WriteLine("Roll: {0}, Pitch: {1}, Yaw: {2}", roll_deg, pitch_deg, yaw_deg);
}
else if (msg.msgid == 0) // 假定的心跳消息ID,请根据实际情况替换
{
MAVLink.mavlink_heartbeat_t n = (MAVLink.mavlink_heartbeat_t)msg.data;
// 假设data中存在载具ID的字段,这里仅为示意
int vehicletype = n.type;
Console.WriteLine("vehicle type : " + vehicletype);
}
}
fs.Close();
// 关闭文件流
streamWriter.Close();
fileStream.Close();
}
}
八协解城市擦擦
于 2024-06-04 18:44:30 首次发布