//
// 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 <Navaids/positioned.hxx>
+
+class SGTime;
+class FGPositioned;
-using namespace std;
+// XXX fix me
+class FGNavRecord;
+class FGAirport;
+class FGFix;
enum GPSDistanceUnits {
GPS_DIST_UNITS_NM = 0,
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;
typedef map < string, iap_list_type > iap_map_type;
typedef iap_map_type::iterator iap_map_iterator;
+// A class to encapsulate hr:min representation of time.
+
+class ClockTime {
+public:
+ 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 ostream& operator<< (ostream& out, const ClockTime& t);
+
+private:
+ int _hr;
+ int _min;
+};
+
// ------------------------------------------------------------------------------
class DCLGPS;
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
+ // and allows 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();
+ virtual void SetId(const string& s);
+ virtual const string& GetId()=0;
inline int GetSubPage() { return(_subPage); }
inline int GetNSubPages() { return(_nSubPages); }
- inline string GetName() { return(_name); }
+ inline const string& GetName() { return(_name); }
protected:
DCLGPS* _parent;
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 {
+class DCLGPS : public SGSubsystem {
friend class GPSPage;
// Returns -1 if no active waypoint.
int GetActiveWaypointIndex();
// Ditto for an arbitrary waypoint id
- int GetWaypointIndex(string id);
+ int GetWaypointIndex(const string& id);
// Returns meters
inline float GetDistToActiveWaypoint() { return _dist2Act; }
// 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 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);
+ void DtoInitiate(const string& id);
// Cancel Direct To operation
void DtoCancel();
//
// 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:
// 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 string& id) const;
+ GPSWaypoint* FindFirstByExactId(const string& id) const;
+
+ FGNavRecord* FindFirstVorById(const string& id, bool &multi, bool exact = false);
+ FGNavRecord* FindFirstNDBById(const string& id, bool &multi, bool exact = false);
+ const FGAirport* FindFirstAptById(const string& id, bool &multi, bool exact = false);
+ const FGFix* FindFirstIntById(const 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.
bool _departed; // Set when groundspeed first exceeds 30kts.
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;