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.
25 #include "Device/Port/Port.hpp"
26 #include "Operation/Operation.hpp"
29 FlarmDevice::EnableNMEA(OperationEnvironment
&env
)
33 /* device could be in binary mode, we don't know, but this is the
35 if (!BinaryReset(env
, 500))
40 /* request self-test results and version information from FLARM */
49 /* no real difference between NMEA and TEXT; in mode==TEXT, the
50 Port thread is stopped, but the caller is responsible for
51 restarting it, which means there's nothing to do for us */
56 if (!BinaryReset(env
, 500)) {
71 FlarmDevice::BinaryMode(OperationEnvironment
&env
)
73 if (mode
== Mode::BINARY
)
78 // "Binary mode is engaged by sending the text command "$PFLAX"
79 // (including a newline character) to Flarm."
80 if (!Send("PFLAX", env
))
83 // Remember that we should now be in binary mode (for further assert() calls)
86 // "After switching, connection should again be checked by issuing a ping."
87 // Testing has revealed that switching the protocol takes a certain amount
88 // of time (around 1.5 sec). Due to that it is recommended to issue new pings
89 // for a certain time until the ping is ACKed properly or a timeout occurs.
90 for (unsigned i
= 0; i
< 10; ++i
) {
91 if (env
.IsCancelled()) {
92 BinaryReset(env
, 200);
97 if (BinaryPing(env
, 500))
98 // We are now in binary mode and have verified that with a binary ping
102 // Apparently the switch to binary mode didn't work
103 mode
= Mode::UNKNOWN
;