using System;
using System.IO;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要读取的文件路径:");
string filePath = Console.ReadLine();
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string outputPath = Path.Combine(desktopPath, "八协解mavlink结果2.txt");
FileStream fileStream = new FileStream(outputPath, FileMode.Create);
StreamWriter streamWriter = new StreamWriter(fileStream);
Console.SetOut(streamWriter);
FileStream fs = new FileStream(filePath, 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("飞行器纬度: {0}, 飞行器经度: {1}, 飞行器高度: {2}米", p.lat / 1E7, p.lon / 1E7, p.relative_alt / 1E3);
// 还可以执行其他操作...
}
}
fs.Close();
// 关闭文件流
streamWriter.Close();
fileStream.Close();
}
}