2 ******************************************************************************
4 * @file homelocationutil.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief Utilities to find the location of openpilot GCS files:
7 * - Plugins Share directory path
9 * @brief Home location utility functions
11 * @see The GNU Public License (GPL) Version 3
13 *****************************************************************************/
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "homelocationutil.h"
35 #include "worldmagmodel.h"
38 HomeLocationUtil::HomeLocationUtil()
42 * @brief Get local magnetic field
43 * @param[in] LLA The longitude-latitude-altitude coordinate to compute the magnetic field at
44 * @param[out] Be The resulting magnetic field at that location and time in [mGau](?)
45 * @returns 0 if successful, negative otherwise.
47 int HomeLocationUtil::getDetails(double LLA
[3], double Be
[3])
52 double latitude
= LLA
[0];
53 double longitude
= LLA
[1];
54 double altitude
= LLA
[2];
56 if (latitude
!= latitude
) {
57 return -1; // prevent nan error
59 if (longitude
!= longitude
) {
60 return -2; // prevent nan error
62 if (altitude
!= altitude
) {
63 return -3; // prevent nan error
65 if (latitude
< -90 || latitude
> 90) {
66 return -4; // range checking
68 if (longitude
< -180 || longitude
> 180) {
69 return -5; // range checking
71 QDateTime dt
= QDateTime::currentDateTime().toUTC();
73 // Fetch world magnetic model
74 int result
= WorldMagModel().GetMagVector(LLA
, dt
.date().month(), dt
.date().day(), dt
.date().year(), Be
);
75 Q_ASSERT(result
== 0);