//
// 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 "dclgps.hxx"
#include <simgear/sg_inlines.h>
+#include <simgear/structure/commands.hxx>
+#include <Main/fg_props.hxx>
#include <iostream>
SG_USING_STD(cout);
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;
_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 ?
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";
_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;
// 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;
}
}
+// 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;
_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.
}
_obsMode = !_obsMode;
if(_obsMode) {
if(!_activeWaypoint.id.empty()) {
- _obsHeading = _dtkMag;
+ _obsHeading = static_cast<int>(_dtkMag);
}
// TODO - the _fromWaypoint location will change as the OBS heading changes.
// Might need to store the OBS initiation position somewhere in case it is needed again.