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 "Internal.hpp"
25 #include "Message.hpp"
26 #include "NMEA/Info.hpp"
27 #include "NMEA/InputLine.hpp"
29 #include "Util/Macros.hpp"
40 PDSWC(NMEAInputLine
&line
, NMEAInfo
&info
, Vega::VolatileData
&volatile_data
)
43 if (line
.ReadChecked(value
) &&
44 info
.settings
.ProvideMacCready(fixed(value
) / 10, info
.clock
))
45 volatile_data
.mc
= value
;
47 auto &switches
= info
.switch_state
;
48 auto &vs
= switches
.vega
;
49 vs
.inputs
= line
.ReadHex(0);
50 vs
.outputs
= line
.ReadHex(0);
52 if (vs
.GetFlapLanding())
53 switches
.flap_position
= SwitchState::FlapPosition::LANDING
;
54 else if (vs
.GetFlapZero())
55 switches
.flap_position
= SwitchState::FlapPosition::NEUTRAL
;
56 else if (vs
.GetFlapNegative())
57 switches
.flap_position
= SwitchState::FlapPosition::NEGATIVE
;
58 else if (vs
.GetFlapPositive())
59 switches
.flap_position
= SwitchState::FlapPosition::POSITIVE
;
61 switches
.flap_position
= SwitchState::FlapPosition::UNKNOWN
;
63 if (vs
.GetUserSwitchMiddle())
64 switches
.user_switch
= SwitchState::UserSwitch::MIDDLE
;
65 else if (vs
.GetUserSwitchUp())
66 switches
.user_switch
= SwitchState::UserSwitch::UP
;
67 else if (vs
.GetUserSwitchDown())
68 switches
.user_switch
= SwitchState::UserSwitch::DOWN
;
70 switches
.user_switch
= SwitchState::UserSwitch::UNKNOWN
;
72 if (vs
.GetAirbrakeLocked())
73 switches
.airbrake_state
= SwitchState::AirbrakeState::LOCKED
;
74 else if (vs
.GetAirbrakeNotLocked())
75 switches
.airbrake_state
= SwitchState::AirbrakeState::NOT_LOCKED
;
77 switches
.airbrake_state
= SwitchState::AirbrakeState::UNKNOWN
;
79 switches
.flight_mode
= vs
.GetCircling()
80 ? SwitchState::FlightMode::CIRCLING
81 : SwitchState::FlightMode::CRUISE
;
83 if (line
.ReadChecked(value
)) {
84 info
.voltage
= fixed(value
) / 10;
85 info
.voltage_available
.Update(info
.clock
);
91 //#include "Audio/VarioSound.h"
94 PDAAV(NMEAInputLine
&line
, gcc_unused NMEAInfo
&info
)
96 gcc_unused
unsigned short beepfrequency
= line
.Read(0);
97 gcc_unused
unsigned short soundfrequency
= line
.Read(0);
98 gcc_unused
unsigned char soundtype
= line
.Read(0);
100 // Temporarily commented out - function as yet undefined
101 // audio_setconfig(beepfrequency, soundfrequency, soundtype);
107 VegaDevice::PDVSC(NMEAInputLine
&line
, gcc_unused NMEAInfo
&info
)
109 char responsetype
[10];
110 line
.Read(responsetype
, 10);
115 if (strcmp(name
, "ERROR") == 0)
116 // ignore error responses...
119 int value
= line
.Read(0);
121 if (strcmp(name
, "ToneDeadbandCruiseLow") == 0)
122 value
= std::max(value
, -value
);
123 if (strcmp(name
, "ToneDeadbandCirclingLow") == 0)
124 value
= std::max(value
, -value
);
127 settings
.Set(name
, value
);
134 // $PDVDV,vario,ias,densityratio,altitude,staticpressure
137 PDVDV(NMEAInputLine
&line
, NMEAInfo
&info
)
141 if (line
.ReadChecked(value
))
142 info
.ProvideTotalEnergyVario(fixed(value
) / 10);
144 bool ias_available
= line
.ReadChecked(value
);
145 int tas_ratio
= line
.Read(1024);
147 const fixed ias
= fixed(value
) / 10;
148 info
.ProvideBothAirspeeds(ias
, ias
* tas_ratio
/ 1024);
153 if (line
.ReadChecked(value
))
154 info
.ProvidePressureAltitude(fixed(value
));
160 // $PDVDS,nx,nz,flap,stallratio,netto
162 PDVDS(NMEAInputLine
&line
, NMEAInfo
&info
)
164 const int accel_x
= line
.Read(0), accel_z
= line
.Read(0);
166 fixed mag
= SmallHypot(fixed(accel_x
), fixed(accel_z
));
167 info
.acceleration
.ProvideGLoad(mag
/ 100, true);
170 double flap = line.Read(0.0);
174 info
.stall_ratio
= line
.Read(fixed(0));
175 info
.stall_ratio_available
.Update(info
.clock
);
178 if (line
.ReadChecked(value
))
179 info
.ProvideNettoVario(fixed(value
) / 10);
187 PDVVT(NMEAInputLine
&line
, NMEAInfo
&info
)
190 info
.temperature_available
= line
.ReadChecked(value
);
191 if (info
.temperature_available
)
192 info
.temperature
= fixed(value
) / 10;
194 info
.humidity_available
= line
.ReadChecked(info
.humidity
);
199 // PDTSM,duration_ms,"free text"
201 PDTSM(NMEAInputLine
&line
, gcc_unused NMEAInfo
&info
)
204 int duration = (int)strtol(String, NULL, 10);
208 const auto message
= line
.Rest();
210 StaticString
<256> buffer
;
211 buffer
.SetASCII(message
.begin(), message
.end());
213 // todo duration handling
214 Message::AddMessage(_T("VEGA:"), buffer
);
220 VegaDevice::ParseNMEA(const char *String
, NMEAInfo
&info
)
222 NMEAInputLine
line(String
);
226 if (memcmp(type
, "$PD", 3) == 0)
229 if (strcmp(type
, "$PDSWC") == 0)
230 return PDSWC(line
, info
, volatile_data
);
231 else if (strcmp(type
, "$PDAAV") == 0)
232 return PDAAV(line
, info
);
233 else if (strcmp(type
, "$PDVSC") == 0)
234 return PDVSC(line
, info
);
235 else if (strcmp(type
, "$PDVDV") == 0)
236 return PDVDV(line
, info
);
237 else if (strcmp(type
, "$PDVDS") == 0)
238 return PDVDS(line
, info
);
239 else if (strcmp(type
, "$PDVVT") == 0)
240 return PDVVT(line
, info
);
241 else if (strcmp(type
, "$PDVSD") == 0) {
242 const auto message
= line
.Rest();
243 StaticString
<256> buffer
;
244 buffer
.SetASCII(message
.begin(), message
.end());
245 Message::AddMessage(buffer
);
247 } else if (strcmp(type
, "$PDTSM") == 0)
248 return PDTSM(line
, info
);