//
// Written by David Luff, started 2005.
//
-// Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
+// Copyright (C) 2005 - David C Luff: daveluff --AT-- ntlworld --D0T-- com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include <vector>
#include <map>
-#include <Cockpit/panel.hxx>
-
-#include <Navaids/navrecord.hxx>
-#include <Navaids/navlist.hxx>
-#include <Navaids/fixlist.hxx>
-#include <Airports/simple.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/props/props.hxx>
+#include <Navaids/positioned.hxx>
-using namespace std;
-
-enum GPSDistanceUnits {
- GPS_DIST_UNITS_NM = 0,
- GPS_DIST_UNITS_KM
-};
-
-enum GPSSpeedUnits {
- GPS_VEL_UNITS_KT,
- GPS_VEL_UNITS_KPH
-};
-
-enum GPSAltitudeUnits {
- GPS_ALT_UNITS_FT,
- GPS_ALT_UNITS_M
-};
+class SGTime;
+class FGPositioned;
-enum GPSPressureUnits {
- GPS_PRES_UNITS_IN = 1,
- GPS_PRES_UNITS_MB,
- GPS_PRES_UNITS_HP
-};
+// XXX fix me
+class FGNavRecord;
+class FGAirport;
+class FGFix;
// --------------------- Waypoint / Flightplan stuff -----------------------------
// This should be merged with other similar stuff in FG at some point.
GPS_APP_NONE // Not part of the approach sequence - the default.
};
-ostream& operator << (ostream& os, GPSAppWpType type);
+std::ostream& operator << (std::ostream& os, GPSAppWpType type);
struct GPSWaypoint {
GPSWaypoint();
+
+ GPSWaypoint(const std::string& aIdent, float lat, float lon, GPSWpType aType);
+
+ static GPSWaypoint* createFromPositioned(const FGPositioned* aFix);
+
~GPSWaypoint();
- string GetAprId(); // Returns the id with i, f, m or h added if appropriate. (Initial approach fix, final approach fix, etc)
- string id;
+ std::string GetAprId(); // Returns the id with i, f, m or h added if appropriate. (Initial approach fix, final approach fix, etc)
+ std::string id;
float lat; // Radians
float lon; // Radians
GPSWpType type;
GPSAppWpType appType; // only used for waypoints that are part of an approach sequence
};
-typedef vector < GPSWaypoint* > gps_waypoint_array;
+typedef std::vector < GPSWaypoint* > gps_waypoint_array;
typedef gps_waypoint_array::iterator gps_waypoint_array_iterator;
-typedef map < string, gps_waypoint_array > gps_waypoint_map;
+typedef std::map < std::string, gps_waypoint_array > gps_waypoint_map;
typedef gps_waypoint_map::iterator gps_waypoint_map_iterator;
typedef gps_waypoint_map::const_iterator gps_waypoint_map_const_iterator;
class GPSFlightPlan {
public:
- vector<GPSWaypoint*> waypoints;
+ std::vector<GPSWaypoint*> waypoints;
inline bool IsEmpty() { return(waypoints.size() == 0); }
};
virtual ~FGIAP() = 0;
//protected:
- string _id; // The ID of the airport this approach is for
- string _name; // The approach name, eg "VOR/DME OR GPS-B"
- string _abbrev; // The abbreviation the GPS unit uses - eg "VOR/D" in this instance. Possibly GPS model specific.
- string _rwyStr; // The string used to specify the rwy - eg "B" in this instance.
+ std::string _aptIdent; // The ident of the airport this approach is for
+ std::string _ident; // The approach ident.
+ std::string _name; // The full approach name.
+ std::string _rwyStr; // The string used to specify the rwy - eg "B" in this instance.
bool _precision; // True for precision approach, false for non-precision.
};
~FGNPIAP();
//private:
public:
- vector<GPSWaypoint*> _IAF; // The initial approach fix(es)
- vector<GPSWaypoint*> _IAP; // The compulsory waypoints of the approach procedure (may duplicate one of the above).
- // _IAP includes the FAF and MAF.
- vector<GPSWaypoint*> _MAP; // The missed approach procedure (doesn't include the MAF).
+ std::vector<GPSFlightPlan*> _approachRoutes; // The approach route(s) from the IAF(s) to the IF.
+ // NOTE: It is an assumption in the code that uses this that there is a unique IAF per approach route.
+ std::vector<GPSWaypoint*> _IAP; // The compulsory waypoints of the approach procedure (may duplicate one of the above).
+ // _IAP includes the FAF and MAF, and the missed approach waypoints.
};
-typedef vector < FGIAP* > iap_list_type;
-typedef map < string, iap_list_type > iap_map_type;
+typedef std::vector < FGIAP* > iap_list_type;
+typedef std::map < std::string, iap_list_type > iap_map_type;
typedef iap_map_type::iterator iap_map_iterator;
-// ------------------------------------------------------------------------------
-
-class DCLGPS;
+// A class to encapsulate hr:min representation of time.
-class GPSPage {
-
+class ClockTime {
public:
- GPSPage(DCLGPS* parent);
- virtual ~GPSPage() = 0;
- virtual void Update(double dt);
- virtual void Knob1Left1();
- virtual void Knob1Right1();
- virtual void Knob2Left1();
- virtual void Knob2Right1();
- virtual void CrsrPressed();
- virtual void EntPressed();
- virtual void ClrPressed();
- virtual void DtoPressed();
- virtual void NrstPressed();
- virtual void AltPressed();
- virtual void OBSPressed();
- virtual void MsgPressed();
-
- // Sometimes a page needs to maintain state for some return paths,
- // but change it for others. The CleanUp function can be used for
- // changing state for non-ENT return paths in conjunction with
- // GPS::_cleanUpPage
- virtual void CleanUp();
-
- // The LooseFocus function is called when a page or subpage looses focus
- // and allow pages to clean up state that is maintained whilst focus is
- // retained, but lost on return.
- virtual void LooseFocus();
-
- // Allows pages that display info for a given ID to have it set/get if they implement these functions.
- virtual void SetId(string s);
- virtual string GetId();
-
- inline int GetSubPage() { return(_subPage); }
-
- inline int GetNSubPages() { return(_nSubPages); }
-
- inline string GetName() { return(_name); }
-
-protected:
- DCLGPS* _parent;
- string _name; // eg. "APT", "NAV" etc
- int _nSubPages;
- // _subpage is zero based
- int _subPage; // The subpage gets remembered when other pages are displayed
- string GPSitoa(int n);
-};
+ ClockTime();
+ ClockTime(int hr, int min);
+ ~ClockTime();
+ inline void set_hr(int hr) { _hr = hr; }
+ inline int hr() const { return(_hr); }
+ inline void set_min(int min) { _min = min; }
+ inline int min() const { return(_min); }
+
+ ClockTime operator+ (const ClockTime& t) {
+ int cumMin = _hr * 60 + _min + t.hr() * 60 + t.min();
+ ClockTime t2(cumMin / 60, cumMin % 60);
+ return(t2);
+ }
+ // Operator - has a max difference of 23:59,
+ // and assumes the day has wrapped if the second operand
+ // is larger that the first.
+ // eg. 2:59 - 3:00 = 23:59
+ ClockTime operator- (const ClockTime& t) {
+ int diff = (_hr * 60 + _min) - (t.hr() * 60 + t.min());
+ if(diff < 0) { diff += 24 * 60; }
+ ClockTime t2(diff / 60, diff % 60);
+ return(t2);
+ }
+ friend std::ostream& operator<< (std::ostream& out, const ClockTime& t);
-/*-----------------------------------------------------------------------*/
+private:
+ int _hr;
+ int _min;
+};
-typedef vector<GPSPage*> gps_page_list_type;
-typedef gps_page_list_type::iterator gps_page_list_itr;
+// ------------------------------------------------------------------------------
// TODO - merge generic GPS functions instead and split out KLN specific stuff.
-class DCLGPS : public SGSubsystem, public FGPanelInstrument {
-
- friend class GPSPage;
+class DCLGPS : public SGSubsystem {
public:
DCLGPS(RenderArea2D* instrument);
virtual ~DCLGPS() = 0;
- virtual void draw();
+ virtual void draw(osg::State& state);
virtual void init();
virtual void bind();
virtual void unbind();
virtual void update(double dt);
+
+ // Expand a SIAP ident to the full procedure name.
+ std::string ExpandSIAPIdent(const std::string& ident);
// Render string s in display field field at position x, y
// WHERE POSITION IS IN CHARACTER UNITS!
// zero y at bottom?
- virtual void DrawText(const string& s, int field, int px, int py, bool bold = false);
+ virtual void DrawText(const std::string& s, int field, int px, int py, bool bold = false);
// Render a char at a given position as above
virtual void DrawChar(char c, int field, int px, int py, bool bold = false);
- virtual void Knob1Right1();
- virtual void Knob1Left1();
- virtual void Knob2Right1();
- virtual void Knob2Left1();
- virtual void CrsrPressed();
- virtual void EntPressed();
- virtual void ClrPressed();
- virtual void DtoPressed();
- virtual void NrstPressed();
- virtual void AltPressed();
- virtual void OBSPressed();
- virtual void MsgPressed();
+ virtual void ToggleOBSMode();
// Set the number of fields
inline void SetNumFields(int n) { _nFields = (n > _maxFields ? _maxFields : (n < 1 ? 1 : n)); }
- // Set Units
- // m if true, ft if false
- inline void SetAltUnitsSI(bool b) { _altUnits = (b ? GPS_ALT_UNITS_M : GPS_ALT_UNITS_FT); }
- // Returns true if alt units are SI (m), false if ft
- inline bool GetAltUnitsSI() { return(_altUnits == GPS_ALT_UNITS_M ? true : false); }
- // km and k/h if true, nm and kt if false
- inline void SetDistVelUnitsSI(bool b) { _distUnits = (b ? GPS_DIST_UNITS_KM : GPS_DIST_UNITS_NM); _velUnits = (b ? GPS_VEL_UNITS_KPH : GPS_VEL_UNITS_KT); }
- // Returns true if dist/vel units are SI
- inline bool GetDistVelUnitsSI() { return(_distUnits == GPS_DIST_UNITS_KM && _velUnits == GPS_VEL_UNITS_KPH ? true : false); }
- // Set baro units - 1 = in, 2 = mB, 3 = hP Wrapping if for the convienience of the GPS setter.
- void SetBaroUnits(int n, bool wrap = false);
- // Get baro units: 1 = in, 2 = mB, 3 = hP
- inline int GetBaroUnits() { return((int)_baroUnits); }
-
// It is expected that specific GPS units will override these functions.
// Increase the CDI full-scale deflection (ie. increase the nm per dot) one (GPS unit dependent) increment. Wraps if necessary (GPS unit dependent).
virtual void CDIFSDIncrease();
void SetOBSFromWaypoint();
- inline GPSWaypoint* GetActiveWaypoint() { return &_activeWaypoint; }
+ GPSWaypoint* GetActiveWaypoint();
// Get the (zero-based) position of the active waypoint in the active flightplan
// Returns -1 if no active waypoint.
int GetActiveWaypointIndex();
// Ditto for an arbitrary waypoint id
- int GetWaypointIndex(string id);
+ int GetWaypointIndex(const std::string& id);
// Returns meters
- inline float GetDistToActiveWaypoint() { return _dist2Act; }
+ float GetDistToActiveWaypoint();
// Returns degrees (magnetic)
float GetHeadingToActiveWaypoint();
// Returns degrees (magnetic)
// returns -1 if groundspeed is less than 30kts.
// If the waypoint is an unreached part of the active flight plan the time will be via each leg.
// otherwise it will be a direct-to time.
- double GetTimeToWaypoint(string id);
+ double GetTimeToWaypoint(const std::string& id);
// Return true if waypoint alerting is occuring
inline bool GetWaypointAlert() const { return(_waypointAlert); }
inline bool GetToFlag() const { return(_headingBugTo); }
// Initiate Direct To operation to the supplied ID.
- void DtoInitiate(string id);
+ virtual void DtoInitiate(const std::string& id);
// Cancel Direct To operation
void DtoCancel();
// 2D rendering area
RenderArea2D* _instrument;
- // The actual pages
- gps_page_list_type _pages;
-
- // The currently active page
- GPSPage* _activePage;
- // And a facility to save the immediately preceeding active page
- GPSPage* _lastActivePage;
-
- // Units
- GPSSpeedUnits _velUnits;
- GPSDistanceUnits _distUnits;
- GPSPressureUnits _baroUnits;
- GPSAltitudeUnits _altUnits;
-
// CDI full-scale deflection, specified either as an index into a vector of values (standard values) or as a double precision float (intermediate values).
// This will influence how an externally driven CDI will display as well as the NAV1 page.
// Hence the variables are located here, not in the nav page class.
- vector<float> _cdiScales;
+ std::vector<float> _cdiScales;
unsigned int _currentCdiScaleIndex;
bool _cdiScaleTransition; // Set true when the floating CDI value is used during transitions
double _currentCdiScale; // The floating value to use.
//
// Data and lookup functions
- // All waypoints mapped by id.
- gps_waypoint_map _waypoints;
-private:
- // Worker function for the below.
- const GPSWaypoint* ActualFindFirstById(string id, bool exact = false);
+
+
protected:
+ void LoadApproachData();
+
// Find first of any type of waypoint by id. (TODO - Possibly we should return multiple waypoints here).
- const GPSWaypoint* FindFirstById(string id, bool &multi, bool exact = false);
- FGNavRecord* FindFirstVorById(string id, bool &multi, bool exact = false);
- FGNavRecord* FindFirstNDBById(string id, bool &multi, bool exact = false);
- const FGAirport* FindFirstAptById(string id, bool &multi, bool exact = false);
- const FGFix* FindFirstIntById(string id, bool &multi, bool exact = false);
+ GPSWaypoint* FindFirstById(const std::string& id) const;
+ GPSWaypoint* FindFirstByExactId(const std::string& id) const;
+
+ FGNavRecord* FindFirstVorById(const std::string& id, bool &multi, bool exact = false);
+ FGNavRecord* FindFirstNDBById(const std::string& id, bool &multi, bool exact = false);
+ const FGAirport* FindFirstAptById(const std::string& id, bool &multi, bool exact = false);
+ const FGFix* FindFirstIntById(const std::string& id, bool &multi, bool exact = false);
// Find the closest VOR to a position in RADIANS.
FGNavRecord* FindClosestVor(double lat_rad, double lon_rad);
+ // helper to implement the above FindFirstXXX methods
+ FGPositioned* FindTypedFirstById(const std::string& id, FGPositioned::Type ty, bool &multi, bool exact);
+
// Position, orientation and velocity.
// These should be read from FG's built-in GPS logic if possible.
// Use the property node pointers below to do this.
// Flightplans
// GPS can have up to _maxFlightPlans flightplans stored, PLUS an active FP which may or my not be one of the stored ones.
// This is from KLN89, but is probably not far off the mark for most if not all GPS.
- vector<GPSFlightPlan*> _flightPlans;
+ std::vector<GPSFlightPlan*> _flightPlans;
unsigned int _maxFlightPlans;
GPSFlightPlan* _activeFP;
bool _headingBugTo; // Set true when the heading bug is TO, false when FROM.
bool _waypointAlert; // Set true when waypoint alerting is happening. (This is a variable NOT a user-setting).
bool _departed; // Set when groundspeed first exceeds 30kts.
- string _departureTimeString; // Ditto.
+ std::string _departureTimeString; // Ditto.
double _elapsedTime; // Elapsed time in seconds since departure
+ ClockTime _powerOnTime; // Time (hr:min) of unit power-up.
+ bool _powerOnTimerSet; // Indicates that we have set the above following power-up.
+ void SetPowerOnTimer();
+public:
+ void ResetPowerOnTimer();
+ // Set the alarm to go off at a given time.
+ inline void SetAlarm(int hr, int min) {
+ _alarmTime.set_hr(hr);
+ _alarmTime.set_min(min);
+ _alarmSet = true;
+ }
+protected:
+ ClockTime _alarmTime;
+ bool _alarmSet;
// Configuration that affects flightplan operation
bool _turnAnticipationEnabled;
-
- // Configuration that affects general operation
- bool _suaAlertEnabled; // Alert user to potential SUA entry
- bool _altAlertEnabled; // Alert user to min safe alt violation
// Magvar stuff. Might get some of this stuff (such as time) from FG in future.
SGTime* _time;
- list<string> _messageStack;
+ std::list<std::string> _messageStack;
- virtual void CreateFlightPlan(GPSFlightPlan* fp, vector<string> ids, vector<GPSWpType> wps);
+ virtual void CreateFlightPlan(GPSFlightPlan* fp, std::vector<std::string> ids, std::vector<GPSWpType> wps);
// Orientate the GPS unit to a flightplan - ie. figure out from current position
// and possibly orientation which leg of the FP we are on.
// the scale change, but it's in the manual...
bool _approachActive; // Set true when in approach-active mode
GPSFlightPlan* _approachFP; // Current approach - not necessarily loaded.
- string _approachID; // ID of the airport we have an approach loaded for - bit of a hack that can hopefully be removed in future.
+ std::string _approachID; // ID of the airport we have an approach loaded for - bit of a hack that can hopefully be removed in future.
// More hackery since we aren't actually storing an approach class... Doh!
- string _approachAbbrev;
- string _approachRwyStr;
+ std::string _approachAbbrev;
+ std::string _approachRwyStr;
};
#endif // _DCLGPS_HXX