]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/dclgps.cxx
Win32 fixes
[flightgear.git] / src / Instrumentation / dclgps.cxx
index 8d4cb0265347a5750c779fc465d27d223c022b83..cafa056c1fdb7ecd502bc321c10474a2b6b83880 100644 (file)
@@ -5,7 +5,7 @@
 //
 // 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
@@ -19,7 +19,7 @@
 //
 // 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$
 
@@ -152,6 +152,22 @@ FGNPIAP::FGNPIAP() {
 FGNPIAP::~FGNPIAP() {
 }
 
+ClockTime::ClockTime() {
+    _hr = 0;
+    _min = 0;
+}
+
+ClockTime::ClockTime(int hr, int min) {
+    while(hr < 0) { hr += 24; }
+    _hr = hr % 24;
+    while(min < 0) { min += 60; }
+    while(min > 60) { min -= 60; }
+       _min = min;
+}
+
+ClockTime::~ClockTime() {
+}
+
 GPSPage::GPSPage(DCLGPS* parent) {
        _parent = parent;
        _subPage = 0;
@@ -256,6 +272,10 @@ DCLGPS::DCLGPS(RenderArea2D* instrument) {
        _departed = false;
        _departureTimeString = "----";
        _elapsedTime = 0.0;
+       _powerOnTime.set_hr(0);
+       _powerOnTime.set_min(0);
+       _powerOnTimerSet = false;
+       _alarmSet = false;
        
        // Configuration Initialisation
        // Should this be in kln89.cxx ?
@@ -561,33 +581,50 @@ void DCLGPS::init() {
        iap->_MAP.clear();
        // -------
        wp = new GPSWaypoint;
-       wp->id = "PATYY";
+       wp->id = "MAXNI";
        // Nasty using the find any function here, but it saves converting data from FGFix etc. 
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_IAF;
-       iap->_IAF.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAF;
+               iap->_IAF.push_back(wp);
+       }
+       // -------
+       wp = new GPSWaypoint;
+       wp->id = "PATYY";
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAF;
+               iap->_IAF.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "TRACY";
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_IAF;
-       iap->_IAF.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAF;
+               iap->_IAF.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "TRACY";
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_IAP;
-       iap->_IAP.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_IAP;
+               iap->_IAP.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "BABPI";
-       fp = FindFirstById(wp->id, multi, true); 
-       *wp = *fp;
-       wp->appType = GPS_FAF;
-       iap->_IAP.push_back(wp);
+       fp = FindFirstById(wp->id, multi, true);
+       if(fp) {
+               *wp = *fp;
+               wp->appType = GPS_FAF;
+               iap->_IAP.push_back(wp);
+       }
        // -------
        wp = new GPSWaypoint;
        wp->id = "AMOSY";
@@ -657,6 +694,20 @@ void DCLGPS::update(double dt) {
        _checkLon = _gpsLon;
        _checkLat = _gpsLat;
        
+       // TODO - check for unit power before running this.
+       if(!_powerOnTimerSet) {
+               SetPowerOnTimer();
+       } 
+       
+       // Check if an alarm timer has expired
+       if(_alarmSet) {
+               if(_alarmTime.hr() == atoi(fgGetString("/instrumentation/clock/indicated-hour"))
+               && _alarmTime.min() == atoi(fgGetString("/instrumentation/clock/indicated-min"))) {
+                       _messageStack.push_back("*Timer Expired");
+                       _alarmSet = false;
+               }
+       }
+       
        if(!_departed) {
                if(_groundSpeed_kts > 30.0) {
                        _departed = true;
@@ -842,9 +893,9 @@ void DCLGPS::update(double dt) {
                                                // Do nothing
                                        } else if(_activeWaypoint.appType == GPS_MAP) {
                                                // Don't sequence beyond the missed approach point
-                                               cout << "ACTIVE WAYPOINT is MAP - not sequencing!!!!!\n";
+                                               //cout << "ACTIVE WAYPOINT is MAP - not sequencing!!!!!\n";
                                        } else {
-                                               cout << "Sequencing...\n";
+                                               //cout << "Sequencing...\n";
                                                _fromWaypoint = _activeWaypoint;
                                                _activeWaypoint = *_activeFP->waypoints[idx + 1];
                                                _dto = false;
@@ -884,17 +935,34 @@ void DCLGPS::update(double dt) {
        }
 }
 
+// I don't yet fully understand all the gotchas about where to source time from.
+// This function sets the initial timer before the clock exports properties
+// and the one below uses the clock to be consistent with the rest of the code.
+// It might change soonish...
+void DCLGPS::SetPowerOnTimer() {
+       struct tm *t = globals->get_time_params()->getGmt();
+       _powerOnTime.set_hr(t->tm_hour);
+       _powerOnTime.set_min(t->tm_min);
+       _powerOnTimerSet = true;
+}
+
+void DCLGPS::ResetPowerOnTimer() {
+       _powerOnTime.set_hr(atoi(fgGetString("/instrumentation/clock/indicated-hour")));
+       _powerOnTime.set_min(atoi(fgGetString("/instrumentation/clock/indicated-min")));
+       _powerOnTimerSet = true;
+}
+
 double DCLGPS::GetCDIDeflection() const {
        double xtd = CalcCrossTrackDeviation(); //nm
        return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0);
 }
 
 void DCLGPS::DtoInitiate(const string& s) {
-       cout << "DtoInitiate, s = " << s << '\n';
+       //cout << "DtoInitiate, s = " << s << '\n';
        bool multi;
        const GPSWaypoint* wp = FindFirstById(s, multi, true);
        if(wp) {
-               cout << "Waypoint found, starting dto operation!\n";
+               //cout << "Waypoint found, starting dto operation!\n";
                _dto = true;
                _activeWaypoint = *wp;
                _fromWaypoint.lat = _gpsLat;
@@ -902,7 +970,7 @@ void DCLGPS::DtoInitiate(const string& s) {
                _fromWaypoint.type = GPS_WP_VIRT;
                _fromWaypoint.id = "DTOWP";
        } else {
-               cout << "Waypoint not found, ignoring dto request\n";
+               //cout << "Waypoint not found, ignoring dto request\n";
                // Should bring up the user waypoint page, but we're not implementing that yet.
                _dto = false;   // TODO - implement this some day.
        }