4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ExternalSettings.hpp"
27 ExternalSettings::Clear()
29 mac_cready_available
.Clear();
30 ballast_fraction_available
.Clear();
31 ballast_overload_available
.Clear();
32 wing_loading_available
.Clear();
33 bugs_available
.Clear();
34 qnh_available
.Clear();
35 volume_available
.Clear();
39 ExternalSettings::Expire(fixed time
)
41 /* the settings do not expire, they are only updated with a new
46 ExternalSettings::Complement(const ExternalSettings
&add
)
48 if (add
.mac_cready_available
.Modified(mac_cready_available
)) {
49 mac_cready
= add
.mac_cready
;
50 mac_cready_available
= add
.mac_cready_available
;
53 if (add
.ballast_fraction_available
.Modified(ballast_fraction_available
)) {
54 ballast_fraction
= add
.ballast_fraction
;
55 ballast_fraction_available
= add
.ballast_fraction_available
;
58 if (add
.wing_loading_available
.Modified(wing_loading_available
)) {
59 wing_loading
= add
.wing_loading
;
60 wing_loading_available
= add
.wing_loading_available
;
63 if (add
.ballast_overload_available
.Modified(ballast_overload_available
)) {
64 ballast_overload
= add
.ballast_overload
;
65 ballast_overload_available
= add
.ballast_overload_available
;
68 if (add
.bugs_available
.Modified(bugs_available
)) {
70 bugs_available
= add
.bugs_available
;
73 if (add
.qnh_available
.Modified(qnh_available
)) {
75 qnh_available
= add
.qnh_available
;
78 if (add
.volume_available
.Modified(volume_available
)) {
80 volume_available
= add
.volume_available
;
85 ExternalSettings::EliminateRedundant(const ExternalSettings
&other
,
86 const ExternalSettings
&last
)
88 if (mac_cready_available
&& other
.CompareMacCready(mac_cready
) &&
89 !last
.CompareMacCready(mac_cready
))
90 mac_cready_available
.Clear();
92 if (ballast_fraction_available
&&
93 other
.CompareBallastFraction(ballast_fraction
) &&
94 !last
.CompareBallastFraction(ballast_fraction
))
95 ballast_fraction_available
.Clear();
97 if (ballast_overload_available
&&
98 other
.CompareBallastOverload(ballast_overload
) &&
99 !last
.CompareBallastOverload(ballast_overload
))
100 ballast_overload_available
.Clear();
102 if (wing_loading_available
&& other
.CompareWingLoading(wing_loading
) &&
103 !last
.CompareWingLoading(wing_loading
))
104 wing_loading_available
.Clear();
106 if (bugs_available
&& other
.CompareBugs(bugs
) &&
107 !last
.CompareBugs(bugs
))
108 bugs_available
.Clear();
110 if (qnh_available
&& other
.CompareQNH(qnh
) && !last
.CompareQNH(qnh
))
111 qnh_available
.Clear();
113 if (volume_available
&& other
.CompareVolume(volume
) &&
114 !last
.CompareVolume(volume
))
115 volume_available
.Clear();
119 ExternalSettings::ProvideMacCready(fixed value
, fixed time
)
121 if (negative(value
) || value
> fixed(20))
122 /* failed sanity check */
125 if (CompareMacCready(value
))
129 mac_cready_available
.Update(time
);
134 ExternalSettings::ProvideBallastFraction(fixed value
, fixed time
)
136 if (negative(value
) || value
> fixed(1))
137 /* failed sanity check */
140 if (CompareBallastFraction(value
))
143 ballast_fraction
= value
;
144 ballast_fraction_available
.Update(time
);
149 ExternalSettings::ProvideBallastOverload(fixed value
, fixed time
)
151 if (value
< fixed(1) || value
> fixed(5))
152 /* failed sanity check */
155 if (CompareBallastOverload(value
))
158 ballast_overload
= value
;
159 ballast_overload_available
.Update(time
);
164 ExternalSettings::ProvideWingLoading(fixed value
, fixed time
)
166 if (value
< fixed(1) || value
> fixed(200))
167 /* failed sanity check */
170 if (CompareWingLoading(value
))
173 wing_loading
= value
;
174 wing_loading_available
.Update(time
);
179 ExternalSettings::ProvideBugs(fixed value
, fixed time
)
181 if (value
< fixed(0.5) || value
> fixed(1))
182 /* failed sanity check */
185 if (CompareBugs(value
))
189 bugs_available
.Update(time
);
194 ExternalSettings::ProvideQNH(AtmosphericPressure value
, fixed time
)
196 if (value
.GetHectoPascal() < fixed(500) ||
197 value
.GetHectoPascal() > fixed(1500))
198 /* failed sanity check */
201 if (CompareQNH(value
))
205 qnh_available
.Update(time
);
210 ExternalSettings::ProvideVolume(unsigned value
, fixed time
)
213 /* failed sanity check */
216 if (CompareVolume(value
))
220 volume_available
.Update(time
);