android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / NMEA / ExternalSettings.cpp
blob104f0f8bb1eaecb33f58c6576384fa8d17d3b00f
1 /*
2 Copyright_License {
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"
26 void
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();
38 void
39 ExternalSettings::Expire(fixed time)
41 /* the settings do not expire, they are only updated with a new
42 value */
45 void
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)) {
69 bugs = add.bugs;
70 bugs_available = add.bugs_available;
73 if (add.qnh_available.Modified(qnh_available)) {
74 qnh = add.qnh;
75 qnh_available = add.qnh_available;
78 if (add.volume_available.Modified(volume_available)) {
79 volume = add.volume;
80 volume_available = add.volume_available;
84 void
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();
118 bool
119 ExternalSettings::ProvideMacCready(fixed value, fixed time)
121 if (negative(value) || value > fixed(20))
122 /* failed sanity check */
123 return false;
125 if (CompareMacCready(value))
126 return false;
128 mac_cready = value;
129 mac_cready_available.Update(time);
130 return true;
133 bool
134 ExternalSettings::ProvideBallastFraction(fixed value, fixed time)
136 if (negative(value) || value > fixed(1))
137 /* failed sanity check */
138 return false;
140 if (CompareBallastFraction(value))
141 return false;
143 ballast_fraction = value;
144 ballast_fraction_available.Update(time);
145 return true;
148 bool
149 ExternalSettings::ProvideBallastOverload(fixed value, fixed time)
151 if (value < fixed(1) || value > fixed(5))
152 /* failed sanity check */
153 return false;
155 if (CompareBallastOverload(value))
156 return false;
158 ballast_overload = value;
159 ballast_overload_available.Update(time);
160 return true;
163 bool
164 ExternalSettings::ProvideWingLoading(fixed value, fixed time)
166 if (value < fixed(1) || value > fixed(200))
167 /* failed sanity check */
168 return false;
170 if (CompareWingLoading(value))
171 return false;
173 wing_loading = value;
174 wing_loading_available.Update(time);
175 return true;
178 bool
179 ExternalSettings::ProvideBugs(fixed value, fixed time)
181 if (value < fixed(0.5) || value > fixed(1))
182 /* failed sanity check */
183 return false;
185 if (CompareBugs(value))
186 return false;
188 bugs = value;
189 bugs_available.Update(time);
190 return true;
193 bool
194 ExternalSettings::ProvideQNH(AtmosphericPressure value, fixed time)
196 if (value.GetHectoPascal() < fixed(500) ||
197 value.GetHectoPascal() > fixed(1500))
198 /* failed sanity check */
199 return false;
201 if (CompareQNH(value))
202 return false;
204 qnh = value;
205 qnh_available.Update(time);
206 return true;
209 bool
210 ExternalSettings::ProvideVolume(unsigned value, fixed time)
212 if (value > 100)
213 /* failed sanity check */
214 return false;
216 if (CompareVolume(value))
217 return false;
219 volume = value;
220 volume_available.Update(time);
221 return true;