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 #ifndef XCSOAR_VEGA_EMULATOR_HPP
25 #define XCSOAR_VEGA_EMULATOR_HPP
27 #include "DeviceEmulator.hpp"
28 #include "Device/Port/LineSplitter.hpp"
29 #include "Device/Internal.hpp"
30 #include "NMEA/InputLine.hpp"
31 #include "NMEA/Checksum.hpp"
32 #include "Util/Macros.hpp"
33 #include "Operation/ConsoleOperationEnvironment.hpp"
40 class VegaEmulator
: public Emulator
, PortLineSplitter
{
41 std::map
<std::string
, std::string
> settings
;
49 void PDVSC_S(NMEAInputLine
&line
) {
50 char name
[64], value
[256];
51 line
.Read(name
, ARRAY_SIZE(name
));
52 line
.Read(value
, ARRAY_SIZE(value
));
54 settings
[name
] = value
;
56 ConsoleOperationEnvironment env
;
59 snprintf(buffer
, ARRAY_SIZE(buffer
), "PDVSC,A,%s,%s", name
, value
);
60 PortWriteNMEA(*port
, buffer
, env
);
63 void PDVSC_R(NMEAInputLine
&line
) {
65 line
.Read(name
, ARRAY_SIZE(name
));
67 auto i
= settings
.find(name
);
68 if (i
== settings
.end())
71 const char *value
= i
->second
.c_str();
73 ConsoleOperationEnvironment env
;
76 snprintf(buffer
, ARRAY_SIZE(buffer
), "PDVSC,A,%s,%s", name
, value
);
77 PortWriteNMEA(*port
, buffer
, env
);
80 void PDVSC(NMEAInputLine
&line
) {
82 line
.Read(command
, ARRAY_SIZE(command
));
84 if (strcmp(command
, "S") == 0)
86 else if (strcmp(command
, "R") == 0)
91 virtual void DataReceived(const void *data
, size_t length
) {
92 fwrite(data
, 1, length
, stdout
);
93 PortLineSplitter::DataReceived(data
, length
);
96 virtual void LineReceived(const char *_line
) {
97 if (!VerifyNMEAChecksum(_line
))
100 NMEAInputLine
line(_line
);
101 if (line
.ReadCompare("$PDVSC"))