Skip to content

Commit

Permalink
Added (warning) tag item to indicated incorrect use or assignment of …
Browse files Browse the repository at this point in the history
…Squawk 1000

Restrict tag functions to aircraft not tracked by another controller
Improve logic to assign squawk 1000 (departure airport and/or active controller incl. distance from departure airport are taken into consideration as well)
Improved logic for auto assignment of squawk 1000 (same considerations as above)
  • Loading branch information
kusterjs committed Apr 22, 2021
1 parent a68e88b commit c465a92
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 89 deletions.
145 changes: 68 additions & 77 deletions CCAMS/CCAMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ CCAMS::CCAMS(PluginData pd, const DefaultCodes&& dc) :
RegisterTagItemType("EHS Heading", ItemCodes::TAG_ITEM_EHS_HDG);
RegisterTagItemType("EHS Roll Angle", ItemCodes::TAG_ITEM_EHS_ROLL);
RegisterTagItemType("EHS GS", ItemCodes::TAG_ITEM_EHS_GS);
RegisterTagItemType("Mode S squawk error", ItemCodes::TAG_ITEM_ERROR_MODES_USE);

RegisterTagItemFunction("Assign mode S squawk", ItemCodes::TAG_FUNC_ASSIGN_MODES);
RegisterTagItemFunction("Auto assign squawk", ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_AUTO);
RegisterTagItemFunction("Open SQUAWK assign popup", ItemCodes::TAG_FUNC_SQUAWK_POPUP);

Expand Down Expand Up @@ -161,7 +161,13 @@ void CCAMS::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int I
return;

if (isEHS(FlightPlan))
{
snprintf(sItemString, 16, "%03i", RadarTarget.GetPosition().GetReportedHeading() % 360);
#ifdef _DEBUG
string DisplayMsg{ to_string(RadarTarget.GetPosition().GetReportedHeading()) };
DisplayUserMessage(this->pluginData.PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}

else if (ItemCode == ItemCodes::TAG_ITEM_EHS_ROLL)
Expand All @@ -173,6 +179,10 @@ void CCAMS::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int I
{
auto rollb = RadarTarget.GetPosition().GetReportedBank();
snprintf(sItemString, 16, "%c%i", rollb < 0 ? 'R' : 'L', abs(rollb));
#ifdef _DEBUG
string DisplayMsg{ to_string(abs(rollb)) };
DisplayUserMessage(this->pluginData.PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}

Expand All @@ -182,7 +192,33 @@ void CCAMS::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int I
return;

if (isEHS(FlightPlan) && FlightPlan.GetCorrelatedRadarTarget().IsValid())
{
snprintf(sItemString, 16, "%03i", RadarTarget.GetPosition().GetReportedGS());
#ifdef _DEBUG
string DisplayMsg{ to_string(RadarTarget.GetPosition().GetReportedGS()) };
DisplayUserMessage(this->pluginData.PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}

else if (ItemCode == ItemCodes::TAG_ITEM_ERROR_MODES_USE)
{
if (!FlightPlan.IsValid() || !RadarTarget.IsValid())
return;

if (isAcModeS(FlightPlan) && isApModeS(FlightPlan.GetFlightPlanData().GetDestination()) &&
(isApModeS(FlightPlan.GetFlightPlanData().GetOrigin()) || !isADEPvicinity(FlightPlan)))
//(isApModeS(FlightPlan.GetFlightPlanData().GetOrigin()) || (!isADEPvicinity(FlightPlan) && isApModeS(ControllerMyself().GetCallsign()))))
return;

auto assr = RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk();
auto pssr = RadarTarget.GetPosition().GetSquawk();
if (strcmp(assr, ::mode_s_code) != 0 &&
strcmp(pssr, ::mode_s_code) != 0)
return;

*pColorCode = EuroScopePlugIn::TAG_COLOR_INFORMATION;
strcpy_s(sItemString, 16, "MSSQ");
}
}

Expand Down Expand Up @@ -224,6 +260,16 @@ void CCAMS::OnRefreshFpListContent(CFlightPlanList AcList)

void CCAMS::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area)
{
CFlightPlan FlightPlan = FlightPlanSelectASEL();
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
return;

if (!FlightPlan.IsValid())
return;

if (!FlightPlan.GetTrackingControllerIsMe() && strlen(FlightPlan.GetTrackingControllerCallsign())>0)
return;

if (FunctionId == ItemCodes::TAG_FUNC_SQUAWK_POPUP)
{
OpenPopupList(Area, "Squawk", 1);
Expand All @@ -238,35 +284,17 @@ void CCAMS::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RE
}
else if (FunctionId == ItemCodes::TAG_FUNC_ASSIGN_SQUAWK)
{
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
return;

CFlightPlan FlightPlan = FlightPlanSelectASEL();
if (!FlightPlan.IsValid())
return;

FlightPlan.GetControllerAssignedData().SetSquawk(sItemString);
}
else if (FunctionId == ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_AUTO)
{
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
return;

CFlightPlan FlightPlan = FlightPlanSelectASEL();
if (!FlightPlan.IsValid())
return;

//if (!strcmp(FlightPlan.GetFlightPlanData().GetPlanType(), "V"))
// //FlightPlan.GetControllerAssignedData().SetSquawk(this->squawkVFR);
// return;

if (isAcModeS(FlightPlan) && isApModeS(FlightPlan.GetFlightPlanData().GetDestination()))
if (isAcModeS(FlightPlan) && isApModeS(FlightPlan.GetFlightPlanData().GetDestination()) &&
(isApModeS(FlightPlan.GetFlightPlanData().GetOrigin()) || (!isADEPvicinity(FlightPlan) && isApModeS(ControllerMyself().GetCallsign()))))
{
FlightPlan.GetControllerAssignedData().SetSquawk(::mode_s_code);
return;
}


try
{
if (PendingSquawks.find(FlightPlan.GetCallsign()) == PendingSquawks.end())
Expand Down Expand Up @@ -321,24 +349,8 @@ void CCAMS::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RE
}
}

#ifdef _DEBUG
//std::ostringstream codes;
//std::copy(usedCodes.begin(), usedCodes.end(), std::ostream_iterator<std::string>(codes, ","));
//string codes;
//for (int i = 0; i < usedCodes.size(); i++)
//{
// if (i > 0)
// codes += ",";
// codes += usedCodes[i];
//}
#endif
if (FlightPlan.GetCorrelatedRadarTarget().GetGS() > this->APTcodeMaxGS ||
FlightPlan.GetDistanceFromOrigin()>this->APTcodeMaxDist)
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
"", std::string(ControllerMyself().GetCallsign()), usedCodes)));
else
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
std::string(FlightPlan.GetFlightPlanData().GetOrigin()), std::string(ControllerMyself().GetCallsign()), usedCodes)));
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
FlightPlan, ControllerMyself(), usedCodes, isADEPvicinity(FlightPlan))));
}
}
catch (std::runtime_error const& e)
Expand All @@ -351,31 +363,8 @@ void CCAMS::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RE
}

}
else if (FunctionId == ItemCodes::TAG_FUNC_ASSIGN_MODES)
{
// if the AC is not mode S eligible, then no squawk code change is done
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
return;

CFlightPlan FlightPlan = FlightPlanSelectASEL();
if (!FlightPlan.IsValid())
return;

if (!strcmp(FlightPlan.GetFlightPlanData().GetPlanType(), "V"))
return;

if (isAcModeS(FlightPlan) && isApModeS(FlightPlan.GetFlightPlanData().GetDestination()))
FlightPlan.GetControllerAssignedData().SetSquawk(::mode_s_code);
}
else if (FunctionId == ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_VFR)
{
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
return;

CFlightPlan FlightPlan = FlightPlanSelectASEL();
if (!FlightPlan.IsValid())
return;

FlightPlan.GetControllerAssignedData().SetSquawk(this->squawkVFR);
}
}
Expand All @@ -401,13 +390,17 @@ void CCAMS::AutoAssignMSCC()
RadarTarget.IsValid();
RadarTarget = RadarTargetSelectNext(RadarTarget))
{

if (RadarTarget.GetPosition().IsFPTrackPosition() ||
RadarTarget.GetPosition().GetFlightLevel() < 24500)
return;

CFlightPlan FlightPlan = RadarTarget.GetCorrelatedFlightPlan();
if (!FlightPlan.IsValid() || !FlightPlan.GetTrackingControllerIsMe())
if (!FlightPlan.IsValid())
return;

if ((!FlightPlan.GetTrackingControllerIsMe() && (strlen(FlightPlan.GetTrackingControllerCallsign()) > 0 ||
FlightPlan.GetCoordinatedNextController()!=ControllerMyself().GetCallsign()) ||
FlightPlan.GetSectorEntryMinutes()>15))
return;

//Check if FlightPlan is already processed
Expand All @@ -417,6 +410,8 @@ void CCAMS::AutoAssignMSCC()
if (strcmp(FlightPlan.GetFlightPlanData().GetPlanType(), "V") == 0)
return;

//if (isAcModeS(FlightPlan) && isApModeS(FlightPlan.GetFlightPlanData().GetDestination()) &&
// (isApModeS(FlightPlan.GetFlightPlanData().GetOrigin()) || (!isADEPvicinity(FlightPlan) && isApModeS(ControllerMyself().GetCallsign()))))
if (!isAcModeS(FlightPlan) ||
!isApModeS(FlightPlan.GetFlightPlanData().GetDestination()))
return;
Expand Down Expand Up @@ -475,9 +470,7 @@ void CCAMS::DoInitialLoad(future<string> & fmessage)
smatch match;
if (regex_match(message, match, update_string))
{
//msc.SetEquipementCodes(split(match[1].str(), ','));
EQUIPMENT_CODES = std::move(split(match[1].str(), ','));
//msc.SetICAOModeS(split(match[2].str(), ','));
ICAO_MODES = std::move(split(match[2].str(), ','));

int new_v = stoi(match[3].str(), nullptr, 0);
Expand Down Expand Up @@ -540,6 +533,14 @@ bool CCAMS::isAcModeS(const EuroScopePlugIn::CFlightPlan& FlightPlan)
return false;
}

bool CCAMS::isADEPvicinity(const EuroScopePlugIn::CFlightPlan& FlightPlan)
{
if (FlightPlan.GetCorrelatedRadarTarget().GetGS() < this->APTcodeMaxGS &&
FlightPlan.GetDistanceFromOrigin() < this->APTcodeMaxDist)
return true;
return false;
}

bool CCAMS::isApModeS(const std::string& icao) const
{
for (auto& zone : ICAO_MODES)
Expand All @@ -562,14 +563,4 @@ bool CCAMS::isEHS(const EuroScopePlugIn::CFlightPlan& FlightPlan) const
}

return false;
}

//bool CModeS::ICAO()
//{
// return this->acceptEquipmentICAO;
//}
//
//bool CModeS::FAA()
//{
// return this->acceptEquipmentFAA;
//}
}
3 changes: 1 addition & 2 deletions CCAMS/CCAMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class CCAMS :
void OnTimer(int Counter);

bool Help(const char* Command);
bool ICAO();
bool FAA();

private:
future<string> fUpdateString;
Expand All @@ -68,6 +66,7 @@ class CCAMS :
bool isAcModeS(const EuroScopePlugIn::CFlightPlan& FlightPlan);
bool isApModeS(const std::string& icao) const;
bool isEHS(const EuroScopePlugIn::CFlightPlan& FlightPlan) const;
bool isADEPvicinity(const EuroScopePlugIn::CFlightPlan& FlightPlan);

std::map<const char*, std::future<std::string>> PendingSquawks;
};
27 changes: 23 additions & 4 deletions CCAMS/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Helpers.h"


std::string LoadUpdateString(PluginData p)
string LoadUpdateString(PluginData p)
{
const std::string AGENT { "EuroScope CCAMS/" + std::string { p.PLUGIN_VERSION } };
HINTERNET connect = InternetOpen(AGENT.c_str(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
Expand All @@ -27,7 +27,7 @@ std::string LoadUpdateString(PluginData p)
return answer;
}

std::string LoadWebSquawk(std::string origin, std::string callsign, std::vector<const char*> usedCodes)
string LoadWebSquawk(EuroScopePlugIn::CFlightPlan FP, EuroScopePlugIn::CController ATCO, vector<const char*> usedCodes, bool vicinityADEP)
{
PluginData p;
const std::string AGENT{ "EuroScope CCAMS/" + std::string { p.PLUGIN_VERSION } };
Expand All @@ -36,19 +36,38 @@ std::string LoadWebSquawk(std::string origin, std::string callsign, std::vector<
return "0000";
}

std::string codes;
string codes;
for (size_t i = 0; i < usedCodes.size(); i++)
{
if (i > 0)
codes += ",";
codes += usedCodes[i];
}

std::string build_url = "https://kilojuliett.ch/webtools/api/ssrcode?orig=" + origin + "&callsign=" + callsign + "&codes=" + codes;
string build_url = "https://ccams.kilojuliett.ch/squawk?callsign=" + string(ATCO.GetCallsign());
if (FP.IsValid())
{
if (vicinityADEP)
{
build_url += "&orig=" + string(FP.GetFlightPlanData().GetOrigin());
}
build_url += "&dest=" + string(FP.GetFlightPlanData().GetDestination()) +
"&flightrules=" + string(FP.GetFlightPlanData().GetPlanType());
if (FP.GetFPState() == FLIGHT_PLAN_STATE_SIMULATED)
{
build_url += "&sim";
}
}
build_url += "&codes=" + codes;

HINTERNET OpenAddress = InternetOpenUrl(connect, build_url.c_str(), NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
if (!OpenAddress) {
InternetCloseHandle(connect);
#ifdef _DEBUG
throw error{ std::string { "Failed reach the CCAMS server. Error: " + std::to_string(GetLastError()) } };

#endif // DEBUG

return "0000";
}

Expand Down
9 changes: 7 additions & 2 deletions CCAMS/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
#include "version.h"
#include "CCAMS.h"

std::string LoadUpdateString(PluginData p);

std::string LoadWebSquawk(std::string origin, std::string callsign, std::vector<const char*> usedCodes);
using namespace std;


string LoadUpdateString(PluginData p);

//std::string LoadWebSquawk(std::string origin, std::string callsign, std::vector<const char*> usedCodes);
string LoadWebSquawk(EuroScopePlugIn::CFlightPlan FP, EuroScopePlugIn::CController ATCO, vector<const char*> usedCodes, bool vicinityADEP);


inline std::vector<std::string> split(const std::string & s, char delim)
Expand Down
2 changes: 1 addition & 1 deletion CCAMS/ver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
H,L,E,G,W,Q,S|EB,EL,ET,ED,LF,LH,LR,LZ,EH,LK,LO,LIM,LIR,EP,LD,LSZR,LSZB,LSZG,LSGC,LSZH,LSGG|965
H,L,E,G,W,Q,S|EB,EL,ET,ED,LF,LH,LR,LZ,EH,LK,LO,LIM,LIR,EP,LD,LSZR,LSZB,LSZG,LSGC,LSZH,LSGG|970
7 changes: 4 additions & 3 deletions CCAMS/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
struct PluginData
{
const char * PLUGIN_NAME { "CCAMS" };
const char * PLUGIN_VERSION { "1.6.5" };
const char * PLUGIN_VERSION { "1.7.0" };
const char * PLUGIN_AUTHOR { "Pierre Ferran, Oliver Grützmann, Jonas Kuster" };
const char * PLUGIN_LICENSE { "GPL v3" };
const char * UPDATE_URL { "https://raw.githubusercontent.com/kusterjs/CCAMS/master/CCAMS/ver.txt" };
const int VERSION_CODE { 965 };
const int VERSION_CODE { 970 };
};

struct ItemCodes
Expand All @@ -19,7 +19,8 @@ struct ItemCodes
TAG_ITEM_ISMODES = 501,
TAG_ITEM_EHS_HDG,
TAG_ITEM_EHS_ROLL,
TAG_ITEM_EHS_GS
TAG_ITEM_EHS_GS,
TAG_ITEM_ERROR_MODES_USE
};

enum ItemFunctions : int
Expand Down

0 comments on commit c465a92

Please sign in to comment.