android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / VegaEmulator.hpp
blobb903e309e9ccafa38d5fb99b59aeb741b32f203c
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 #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"
35 #include <string>
36 #include <map>
37 #include <stdio.h>
38 #include <string.h>
40 class VegaEmulator : public Emulator, PortLineSplitter {
41 std::map<std::string, std::string> settings;
43 public:
44 VegaEmulator() {
45 handler = this;
48 private:
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;
58 char buffer[512];
59 snprintf(buffer, ARRAY_SIZE(buffer), "PDVSC,A,%s,%s", name, value);
60 PortWriteNMEA(*port, buffer, env);
63 void PDVSC_R(NMEAInputLine &line) {
64 char name[64];
65 line.Read(name, ARRAY_SIZE(name));
67 auto i = settings.find(name);
68 if (i == settings.end())
69 return;
71 const char *value = i->second.c_str();
73 ConsoleOperationEnvironment env;
75 char buffer[512];
76 snprintf(buffer, ARRAY_SIZE(buffer), "PDVSC,A,%s,%s", name, value);
77 PortWriteNMEA(*port, buffer, env);
80 void PDVSC(NMEAInputLine &line) {
81 char command[4];
82 line.Read(command, ARRAY_SIZE(command));
84 if (strcmp(command, "S") == 0)
85 PDVSC_S(line);
86 else if (strcmp(command, "R") == 0)
87 PDVSC_R(line);
90 protected:
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))
98 return;
100 NMEAInputLine line(_line);
101 if (line.ReadCompare("$PDVSC"))
102 PDVSC(line);
106 #endif