Skip to content

Commit

Permalink
FlightData: Improve xpdr timeout behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-inocencio authored and meee1 committed Oct 31, 2024
1 parent 6390e0d commit e07288d
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions GCSViews/FlightData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public enum actions
{11, "<3m" }
};

private bool transponderNeverConnected = true;

public FlightData()
{
log.Info("Ctor Start");
Expand Down Expand Up @@ -3296,6 +3298,8 @@ private void mainloop()

DateTime updatescreen = DateTime.Now;

DateTime transponderUpdate = DateTime.Now;

DateTime tsreal = DateTime.Now;
double taketime = 0;
double timeerror = 0;
Expand Down Expand Up @@ -4193,9 +4197,10 @@ private void mainloop()
Console.WriteLine("FD Main loop exception " + ex);
}

if (MainV2.comPort.MAV.cs.xpdr_status_pending)
if (MainV2.comPort.MAV.cs.xpdr_status_pending || transponderUpdate.AddMilliseconds(5000) < DateTime.Now)
{
BeginInvoke((Action) updateTransponder);
transponderUpdate = DateTime.Now;
}
}

Expand Down Expand Up @@ -6239,7 +6244,7 @@ private void XPDRConnect_btn_Click(object sender, EventArgs e)
{
updateTransponder();
}
else CustomMessageBox.Show("Timeout.");
else CustomMessageBox.Show("Timeout: Status message not received.");

}
catch (Exception ex)
Expand All @@ -6250,14 +6255,38 @@ private void XPDRConnect_btn_Click(object sender, EventArgs e)

private void updateTransponder()
{
static neverConnected = true;
MainV2.comPort.MAV.cs.xpdr_status_pending = false;
if (!MainV2.comPort.MAV.cs.xpdr_status_unavail)
if (!MainV2.comPort.MAV.cs.xpdr_status_pending)
{
if (neverConnected)
// timeout on status message
STBY_btn.Enabled = false;
ON_btn.Enabled = false;
ALT_btn.Enabled = false;
IDENT_btn.Enabled = false;
FlightID_tb.Enabled = false;
Squawk_nud.Enabled = false;

if (transponderNeverConnected)
{
XPDRConnect_btn.Text = "Connect To Transponder";
XPDRConnect_btn.Enabled = true;
}
else
{
// if we have connected before, we should have subscribed to the status message.
// something must have reset the message interval (AP power cycled, etc.)
// so indicate that the connection reset
XPDRConnect_btn.Text = "Transponder Status Lost";
XPDRConnect_btn.Enabled = true;
transponderNeverConnected = true;
}
}
else if (!MainV2.comPort.MAV.cs.xpdr_status_unavail)
{
if (transponderNeverConnected)
{
// subscribe to status message on first connection
MainV2.comPort.doCommand(MAVLink.MAV_CMD.SET_MESSAGE_INTERVAL, (float) MAVLink.MAVLINK_MSG_ID.UAVIONIX_ADSB_OUT_STATUS, (float) 1000000.0, 0, 0, 0, 0, 0);
transponderNeverConnected = false;
}

STBY_btn.Enabled = true;
Expand Down Expand Up @@ -6320,6 +6349,7 @@ private void updateTransponder()
IDENT_btn.Font = new Font(IDENT_btn.Font, MainV2.comPort.MAV.cs.xpdr_ident_active ? FontStyle.Bold : FontStyle.Regular);

XPDRConnect_btn.Text = "Transponder Connected!";
XPDRConnect_btn.Enabled = false;
}
else
{
Expand All @@ -6330,8 +6360,10 @@ private void updateTransponder()
FlightID_tb.Enabled = false;
Squawk_nud.Enabled = false;

XPDRConnect_btn.Text = "Connect to Transponder";
XPDRConnect_btn.Text = "Transponder Offline";
XPDRConnect_btn.Enabled = false;
}
MainV2.comPort.MAV.cs.xpdr_status_pending = false;
}

private void showIconsToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down

0 comments on commit e07288d

Please sign in to comment.