forked from pierr3/ModeS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModeSCodes.cpp
97 lines (83 loc) · 2.53 KB
/
ModeSCodes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdafx.h"
#include "ModeS2.h"
CModeSCodes::CModeSCodes(const DefaultCodes && dc) :
EQUIPEMENT_CODES(dc.EQUIPEMENT_CODES),
EQUIPEMENT_CODES_ICAO(dc.EQUIPEMENT_CODES_ICAO),
ICAO_MODES(dc.ICAO_MODES)
{}
CModeSCodes::~CModeSCodes()
{}
bool CModeSCodes::isAcModeS(const EuroScopePlugIn::CFlightPlan & FlightPlan) const
{
//check for ICAO suffix
if (&CModeS::ICAO)
{
std::string actype = FlightPlan.GetFlightPlanData().GetAircraftInfo();
std::regex icao_format("(.{2,4})\\/([LMHJ])-(.*)\\/(.*)", std::regex::icase);
std::smatch acdata;
if (std::regex_match(actype, acdata, icao_format) && acdata.size() == 5)
{
for (const auto& code : EQUIPEMENT_CODES_ICAO)
if (strncmp(acdata[4].str().c_str(), code.c_str(), 1))
return true;
}
}
//check for FAA suffix
if (&CModeS::FAA)
{
std::string equipement_suffix{ FlightPlan.GetFlightPlanData().GetCapibilities() };
if (equipement_suffix == "?")
return false;
for (auto& code : EQUIPEMENT_CODES)
if (equipement_suffix == code)
return true;
}
return false;
}
bool CModeSCodes::isEHS(const EuroScopePlugIn::CFlightPlan& FlightPlan) const
{
//check for ICAO suffix
std::string actype = FlightPlan.GetFlightPlanData().GetAircraftInfo();
std::regex icao_format("(.{2,4})\\/([LMHJ])-(.*)\\/(.*)", std::regex::icase);
std::smatch acdata;
if (std::regex_match(actype, acdata, icao_format) && acdata.size() == 5)
{
for (const auto& code : EQUIPEMENT_CODES_EHS)
if (strncmp(acdata[4].str().c_str(), code.c_str(), 1))
return true;
}
return false;
}
bool CModeSCodes::isApModeS(const std::string & icao) const
{
for (auto& zone : ICAO_MODES)
if (startsWith(zone, icao))
return true;
return false;
}
//bool CModeSCodes::isFlightModeS(const EuroScopePlugIn::CFlightPlan & FlightPlan) const
//{
// if (isAcModeS(FlightPlan) && isApModeS(FlightPlan.GetFlightPlanData().GetDestination()))
// return true;
// return false;
//}
void CModeSCodes::SetEquipementCodes(std::vector<std::string> && equipement_codes)
{
EQUIPEMENT_CODES = std::move(equipement_codes);
}
void CModeSCodes::SetICAOModeS(std::vector<std::string> && icao_modes)
{
ICAO_MODES = std::move(icao_modes);
}
//inline bool CModeSCodes::startsWith(const char * pre, const char * str)
//{
// size_t lenpre = strlen(pre),
// lenstr = strlen(str);
// return lenstr < lenpre ? false : strncmp(pre, str, lenpre) == 0;
//}
inline bool CModeSCodes::startsWith(const std::string & zone, const std::string & icao)
{
if (zone.compare(0, zone.length(), icao, 0, zone.length()) == 0)
return true;
return false;
}