1 // tcas.hxx -- Traffic Alert and Collision Avoidance System (TCAS)
3 // Written by Thorsten Brehm, started December 2010.
5 // Copyright (C) 2010 Thorsten Brehm - brehmt (at) gmail com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __INSTRUMENTS_TCAS_HXX
22 #define __INSTRUMENTS_TCAS_HXX
30 #include <simgear/props/props.hxx>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <Sound/voiceplayer.hxx>
40 #include <Main/globals.hxx>
43 # pragma warning( push )
44 # pragma warning( disable: 4355 )
47 ///////////////////////////////////////////////////////////////////////////////
48 // TCAS //////////////////////////////////////////////////////////////////////
49 ///////////////////////////////////////////////////////////////////////////////
51 class TCAS : public SGSubsystem
56 AdvisoryClear = 0, /*< Clear of traffic */
57 AdvisoryIntrusion = 1, /*< Intrusion flag */
58 AdvisoryClimb = AdvisoryIntrusion|(1 << 1), /*< RA climb */
59 AdvisoryDescend = AdvisoryIntrusion|(1 << 2), /*< RA descend */
60 AdvisoryAdjustVSpeed = AdvisoryIntrusion|(1 << 3), /*< RA adjust vertical speed (TCAS II 7.0 only) */
61 AdvisoryMaintVSpeed = AdvisoryIntrusion|(1 << 4), /*< RA maintain vertical speed */
62 AdvisoryMonitorVSpeed = AdvisoryIntrusion|(1 << 5), /*< RA monitor vertical speed */
63 AdvisoryLevelOff = AdvisoryIntrusion|(1 << 6) /*< RA level off (TCAS II 7.1 only) */
68 OptionNone = 0, /*< no option modifier */
69 OptionIncreaseClimb = (1 << 0), /*< increase climb */
70 OptionIncreaseDescend = (1 << 1), /*< increase descend */
71 OptionCrossingClimb = (1 << 2), /*< crossing climb */
72 OptionCrossingDescent = (1 << 3) /*< crossing descent */
77 SwitchOff = 0, /*< TCAS switched off */
78 SwitchStandby = 1, /*< TCAS standby (no TA/RA) */
79 SwitchTaOnly = 2, /*< TCAS in TA-only mode (no RA) */
80 SwitchAuto = 3 /*< TCAS in TA/RA mode */
85 ThreatInvisible = -1,/*< Traffic is invisible to TCAS (i.e. no transponder) */
86 ThreatNone = 0, /*< Traffic is visible but no threat. */
87 ThreatProximity = 1, /*< Proximity intruder traffic (no threat). */
88 ThreatTA = 2, /*< TA-level threat traffic. */
89 ThreatRA = 3 /*< RA-level threat traffic. */
94 int threatLevel; /*< intruder threat level: 0=clear, 1=proximity,
95 2=intruder, 3=proximity intruder */
96 int RA; /*< resolution advisory */
97 int RAOption; /*< option flags for advisory */
102 float Tau; /*< vertical/horizontal protection range in seconds */
103 float DMOD; /*< horizontal protection range in nm */
104 float ALIM; /*< vertical protection range in ft */
109 double maxAltitude; /*< max altitude for this sensitivity level */
110 int sl; /*< sensitivity level */
111 Thresholds TA; /*< thresholds for TA-level threats */
112 Thresholds RA; /*< thresholds for RA-level threats */
125 float relativeAltitudeFt;
137 typedef map<string,TrackerTarget*> TrackerTargets;
147 } LocalInfo; /*< info structure for local aircraft */
149 /////////////////////////////////////////////////////////////////////////////
150 // TCAS::PropertiesHandler ///////////////////////////////////////////////
151 /////////////////////////////////////////////////////////////////////////////
153 class PropertiesHandler : public FGVoicePlayer::PropertiesHandler
158 PropertiesHandler (TCAS *device) :
159 FGVoicePlayer::PropertiesHandler(), tcas(device) {}
161 PropertiesHandler (void) : FGVoicePlayer::PropertiesHandler() {}
164 /////////////////////////////////////////////////////////////////////////////
165 // TCAS::VoicePlayer ////////////////////////////////////////////////////////
166 /////////////////////////////////////////////////////////////////////////////
172 VoicePlayer (TCAS* tcas) :
173 FGVoicePlayer(&tcas->properties_handler, "tcas") {}
175 ~VoicePlayer (void) {}
181 Voice* pTrafficTraffic;
184 Voice* pClimbCrossing;
185 Voice* pClimbIncrease;
188 Voice* pDescendCrossing;
189 Voice* pDescendIncrease;
191 Voice* pAdjustVSpeed;
193 Voice* pMonitorVSpeed;
199 SGPropertyNode_ptr nodeSoundFilePrefix;
202 /////////////////////////////////////////////////////////////////////////////
203 // TCAS::Annunciator ////////////////////////////////////////////////////////
204 /////////////////////////////////////////////////////////////////////////////
209 Annunciator (TCAS* tcas);
210 ~Annunciator (void) {}
211 void bind (SGPropertyNode* node);
215 void trigger (const ResolutionAdvisory& newAdvisory, bool revertedRA);
216 void test (bool testOk);
218 bool isPlaying (void) { return voicePlayer.is_playing();}
222 ResolutionAdvisory previous;
223 FGVoicePlayer::Voice* pLastVoice;
224 VoicePlayer voicePlayer;
225 SGPropertyNode_ptr nodeGpwsAlertOn;
228 /////////////////////////////////////////////////////////////////////////////
229 // TCAS::AdvisoryCoordinator ////////////////////////////////////////////////
230 /////////////////////////////////////////////////////////////////////////////
232 class AdvisoryCoordinator
235 AdvisoryCoordinator (TCAS* _tcas);
236 ~AdvisoryCoordinator (void) {}
238 void bind (SGPropertyNode* node);
240 void update (int mode);
243 void add (const ResolutionAdvisory& newAdvisory);
248 ResolutionAdvisory current;
249 ResolutionAdvisory previous;
250 SGPropertyNode_ptr nodeTAWarning;
253 /////////////////////////////////////////////////////////////////////////////
254 // TCAS::Tracker ////////////////////////////////////////////////////////////
255 /////////////////////////////////////////////////////////////////////////////
260 Tracker (TCAS* _tcas);
265 void add (const string callsign, int detectedLevel);
266 bool active (void) { return haveTargets;}
267 bool newTraffic (void) { return newTargets;}
268 bool isTracked (string callsign) { if (!haveTargets) return false;else return _isTracked(callsign);}
269 bool _isTracked (string callsign);
270 int getThreatLevel (string callsign);
277 TrackerTargets targets;
280 /////////////////////////////////////////////////////////////////////////////
281 // TCAS::AdvisoryGenerator //////////////////////////////////////////////////
282 /////////////////////////////////////////////////////////////////////////////
284 class AdvisoryGenerator
287 AdvisoryGenerator (TCAS* _tcas);
288 ~AdvisoryGenerator (void) {}
290 void init (const LocalInfo* _pSelf, ThreatInfo* _pCurrentThreat);
292 void setAlarmThresholds (const SensitivityLevel* _pAlarmThresholds);
294 int resolution (int mode, int threatLevel, float distanceNm,
295 float altFt, float heading, float velocityKt);
298 float verticalSeparation (float newVerticalFps);
299 void determineRAsense (int& RASense, bool& isCrossing);
303 const LocalInfo* pSelf; /*< info structure for local aircraft */
304 ThreatInfo* pCurrentThreat; /*< info structure on current intruder/threat */
305 const SensitivityLevel* pAlarmThresholds;
308 /////////////////////////////////////////////////////////////////////////////
309 // TCAS::ThreatDetector /////////////////////////////////////////////////////
310 /////////////////////////////////////////////////////////////////////////////
315 ThreatDetector (TCAS* _tcas);
316 ~ThreatDetector (void) {}
321 bool checkTransponder (const SGPropertyNode* pModel, float velocityKt);
322 int checkThreat (int mode, const SGPropertyNode* pModel);
323 void checkVerticalThreat (void);
324 void horizontalThreat (float bearing, float distanceNm, float heading,
327 void setAlt (float altFt) { self.altFt = altFt;}
328 float getAlt (void) { return self.altFt;}
329 float getVelocityKt (void) { return self.velocityKt;}
330 int getRASense (void) { return currentThreat.RASense;}
333 void unitTest (void);
336 static const SensitivityLevel sensitivityLevels[];
341 SGPropertyNode_ptr nodeLat;
342 SGPropertyNode_ptr nodeLon;
343 SGPropertyNode_ptr nodeAlt;
344 SGPropertyNode_ptr nodeHeading;
345 SGPropertyNode_ptr nodeVelocity;
346 SGPropertyNode_ptr nodeVerticalFps;
348 LocalInfo self; /*< info structure for local aircraft */
349 ThreatInfo currentThreat; /*< info structure on current intruder/threat */
350 const SensitivityLevel* pAlarmThresholds;
356 double nextUpdateTime;
359 SGPropertyNode_ptr nodeModeSwitch;
360 SGPropertyNode_ptr nodeServiceable;
361 SGPropertyNode_ptr nodeSelfTest;
362 SGPropertyNode_ptr nodeDebugTrigger;
363 SGPropertyNode_ptr nodeDebugRA;
364 SGPropertyNode_ptr nodeDebugThreat;
366 PropertiesHandler properties_handler;
367 ThreatDetector threatDetector;
369 AdvisoryCoordinator advisoryCoordinator;
370 AdvisoryGenerator advisoryGenerator;
371 Annunciator annunciator;
374 void selfTest (void);
377 TCAS (SGPropertyNode* node);
379 virtual void bind (void);
380 virtual void unbind (void);
381 virtual void init (void);
382 virtual void update (double dt);
386 # pragma warning( pop )
389 #endif // __INSTRUMENTS_TCAS_HXX