void mainloop()
{
threadrun = true;
comPort.NewLine = "\r\n";
int counter = 0;
while (threadrun)
{
try
{
double lat = (int) MainV2.comPort.MAV.cs.lat +
((MainV2.comPort.MAV.cs.lat - (int) MainV2.comPort.MAV.cs.lat)*.6f);
double lng = (int) MainV2.comPort.MAV.cs.lng +
((MainV2.comPort.MAV.cs.lng - (int) MainV2.comPort.MAV.cs.lng)*.6f);
string line = string.Format(System.Globalization.CultureInfo.InvariantCulture,
"$GP{0},{1:HHmmss.fff},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},", "GGA",
DateTime.Now.ToUniversalTime(), Math.Abs(lat*100).ToString("0.00000"), MainV2.comPort.MAV.cs.lat < 0 ? "S" : "N",
Math.Abs(lng*100).ToString("0.00000"), MainV2.comPort.MAV.cs.lng < 0 ? "W" : "E",
MainV2.comPort.MAV.cs.gpsstatus >= 3 ? 1 : 0, MainV2.comPort.MAV.cs.satcount,
MainV2.comPort.MAV.cs.gpshdop, MainV2.comPort.MAV.cs.altasl, "M", 0, "M", "");
string checksum = GetChecksum(line);
comPort.WriteLine(line + "*" + checksum);
line = string.Format(System.Globalization.CultureInfo.InvariantCulture,
"$GP{0},{1:HHmmss.fff},{2},{3},{4},{5},{6},{7},{8},{9:ddMMyy},{10},", "RMC",
DateTime.Now.ToUniversalTime(), "A", Math.Abs(lat*100).ToString("0.00000"),
MainV2.comPort.MAV.cs.lat < 0 ? "S" : "N", Math.Abs(lng*100).ToString("0.00000"),
MainV2.comPort.MAV.cs.lng < 0 ? "W" : "E", (MainV2.comPort.MAV.cs.groundspeed*1.943844).ToString("0.0"),
MainV2.comPort.MAV.cs.groundcourse.ToString("0.0"), DateTime.Now, 0);
checksum = GetChecksum(line);
comPort.WriteLine(line + "*" + checksum);
if (counter%20 == 0 && HomeLoc.Lat != 0 && HomeLoc.Lng != 0)
{
line = string.Format(System.Globalization.CultureInfo.InvariantCulture,
"$GP{0},{1:HHmmss.fff},{2},{3},{4},{5},{6},{7},", "HOM", DateTime.Now.ToUniversalTime(),
Math.Abs(HomeLoc.Lat*100).ToString("0.00000"), HomeLoc.Lat < 0 ? "S" : "N", Math.Abs(HomeLoc.Lng*100).ToString("0.00000"),
HomeLoc.Lng < 0 ? "W" : "E", HomeLoc.Alt, "M");
checksum = GetChecksum(line);
comPort.WriteLine(line + "*" + checksum);
}
line = string.Format(System.Globalization.CultureInfo.InvariantCulture, "$GP{0},{1},{2},{3},", "RPY",
MainV2.comPort.MAV.cs.roll.ToString("0.00000"), MainV2.comPort.MAV.cs.pitch.ToString("0.00000"), MainV2.comPort.MAV.cs.yaw.ToString("0.00000"));
checksum = GetChecksum(line);
comPort.WriteLine(line + "*" + checksum);
System.Threading.Thread.Sleep(200);
counter++;
}
catch
{
}
}
}