From b6d7e16d76b108b915af9f2c8ae0ef6ed5d03b56 Mon Sep 17 00:00:00 2001 From: Justin Wai Date: Sun, 21 Jul 2024 15:12:55 +0800 Subject: [PATCH] Allow multiple missed approach acknowledgements * Avoid cluttering scratchpad string * Refactor checking to be called on controller data update instead of screen refresh --- MissedApproach/MissedApproachAlarm.cpp | 45 ++++++++++++------------- MissedApproach/MissedApproachPlugin.cpp | 13 ++----- MissedApproach/MissedApproachPlugin.hpp | 2 +- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/MissedApproach/MissedApproachAlarm.cpp b/MissedApproach/MissedApproachAlarm.cpp index 73bf40dd..f0284674 100644 --- a/MissedApproach/MissedApproachAlarm.cpp +++ b/MissedApproach/MissedApproachAlarm.cpp @@ -361,13 +361,6 @@ void MissedApproachAlarm::drawIndicatorUnit(HDC hDC, HKCPDisplay* Display) { } else { dc.FillSolidRect(buttonReset, BUTTON_RED_ON); - //Check for acknowledgement - const char* ackStationBuf = ma.checkForAck(selectedAcftData[0].c_str()); - if (!selectedAcftData.empty() && ackStationBuf != NULL) { - actButtonState = 2; - resetButtonState = 1; - ackStation = ackStationBuf; - } } dc.SelectObject(&fontLabelSmall); dc.SetTextColor(BLACK); @@ -464,25 +457,31 @@ void MissedApproachAlarm::OnFlightPlanControllerAssignedDataUpdate(CFlightPlan F CFlightPlanControllerAssignedData controllerData = FlightPlan.GetControllerAssignedData(); string scratchPadString = controllerData.GetScratchPadString(); - //Filter from scratchpad message - if (scratchPadString.find("MISAP_") == string::npos) return; - - //Handle tower case first - if (!selectedAcftData.empty()) { - if (ma.matchArrivalAirport(selectedAcftData[1].c_str())) { - actButtonState = 1; - resetButtonState = -1; + if (scratchPadString.find("MISAP-ACK_") != string::npos) { + //Check for acknowledgement (Tower) + if (!selectedAcftData.empty()) { + actButtonState = 2; + resetButtonState = 1; + ackStation = ma.checkForAck(scratchPadString); } - return; + scratchPadString.erase(0, strlen("MISAP-ACK_AP")); + controllerData.SetScratchPadString(scratchPadString.c_str()); } - //Don't add to vector unless runway is selected and active - if (find(activeMAPPRunways.begin(), activeMAPPRunways.end(), data.GetArrivalRwy()) == activeMAPPRunways.end()) return; + else if (scratchPadString.find("MISAP_") != string::npos) { + // Trigger Alarm (TWR) + actButtonState = 1; + resetButtonState = -1; - scratchPadString.erase(0, strlen("MISAP_")); - controllerData.SetScratchPadString(scratchPadString.c_str()); -; missedAcftData.push_back(FlightPlan.GetCallsign()); - missedAcftData.push_back(data.GetDestination()); - missedAcftData.push_back(data.GetArrivalRwy()); + // Trigger alarm (APP) + scratchPadString.erase(0, strlen("MISAP_")); + controllerData.SetScratchPadString(scratchPadString.c_str()); + + // Don't add to vector unless runway is selected and active + if (find(activeMAPPRunways.begin(), activeMAPPRunways.end(), data.GetArrivalRwy()) == activeMAPPRunways.end()) return; + missedAcftData.push_back(FlightPlan.GetCallsign()); + missedAcftData.push_back(data.GetDestination()); + missedAcftData.push_back(data.GetArrivalRwy()); + } } //---OnMoveScreenObject--------------------------------------------- diff --git a/MissedApproach/MissedApproachPlugin.cpp b/MissedApproach/MissedApproachPlugin.cpp index ca89c7d5..5a669f22 100644 --- a/MissedApproach/MissedApproachPlugin.cpp +++ b/MissedApproach/MissedApproachPlugin.cpp @@ -117,15 +117,6 @@ bool MissedApproachPlugin::matchArrivalAirport(const char* arrivalArpt) { return true; } -const char* MissedApproachPlugin::checkForAck(const char* callsign) { - CFlightPlanControllerAssignedData controllerData = FlightPlanSelect(callsign).GetControllerAssignedData(); - const char* ptr = strstr(controllerData.GetScratchPadString(), "MISAP-ACK_"); - if (ptr != NULL) { - string scratchPadString = ptr; - ptr = ptr + strlen("MISAP-ACK_"); - scratchPadString.erase(0, strlen("MISAP-ACK_AP")); - controllerData.SetScratchPadString(scratchPadString.c_str()); - return (ptr != NULL && strlen(ptr) == 2) ? ptr : "??"; - } - return NULL; +string MissedApproachPlugin::checkForAck(string scratchPadString) { + return scratchPadString.substr(10, 2); } diff --git a/MissedApproach/MissedApproachPlugin.hpp b/MissedApproach/MissedApproachPlugin.hpp index de9ddf8e..b7eecc18 100644 --- a/MissedApproach/MissedApproachPlugin.hpp +++ b/MissedApproach/MissedApproachPlugin.hpp @@ -36,6 +36,6 @@ class MissedApproachPlugin : bool matchArrivalAirport(const char* arrivalArpt); - const char* checkForAck(const char* callsign); + string checkForAck(string scratchPadString); };