| 1 | // nmea.hxx -- NMEA protocol class |
| 2 | // |
| 3 | // Written by Curtis Olson, started November 1999. |
| 4 | // |
| 5 | // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public License as |
| 9 | // published by the Free Software Foundation; either version 2 of the |
| 10 | // License, or (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, but |
| 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | // General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | // |
| 21 | // $Id$ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #include <simgear/compiler.h> |
| 26 | |
| 27 | #include <string> |
| 28 | |
| 29 | #include "protocol.hxx" |
| 30 | |
| 31 | class FlightProperties; |
| 32 | |
| 33 | namespace NMEA |
| 34 | { |
| 35 | // supported NMEA messages |
| 36 | const unsigned int GPRMC = (1<<0); |
| 37 | const unsigned int GPGGA = (1<<1); |
| 38 | const unsigned int GPGSA = (1<<2); |
| 39 | |
| 40 | const unsigned int SET = (GPRMC|GPGGA|GPGSA); |
| 41 | } |
| 42 | |
| 43 | class FGNMEA : public FGProtocol { |
| 44 | |
| 45 | protected: |
| 46 | char mBuf[FG_MAX_MSG_SIZE]; |
| 47 | unsigned int mLength; |
| 48 | unsigned int mNmeaMessages; |
| 49 | unsigned int mMaxReceiveLines; |
| 50 | bool mBiDirectionalSupport; |
| 51 | FlightProperties mFdm; |
| 52 | const char* mLineFeed; |
| 53 | std::string mNmeaSentence; |
| 54 | |
| 55 | void add_with_checksum(char *sentence, unsigned int buf_size); |
| 56 | |
| 57 | // process a single NMEA line |
| 58 | void parse_line(); |
| 59 | |
| 60 | // generate output message(s) |
| 61 | virtual bool gen_message(); |
| 62 | |
| 63 | // process a single NMEA sentence |
| 64 | virtual void parse_message(const std::vector<std::string>& tokens); |
| 65 | |
| 66 | public: |
| 67 | FGNMEA(); |
| 68 | ~FGNMEA(); |
| 69 | |
| 70 | // open hailing frequencies |
| 71 | virtual bool open(); |
| 72 | |
| 73 | // process work for this port |
| 74 | virtual bool process(); |
| 75 | |
| 76 | // close the channel |
| 77 | virtual bool close(); |
| 78 | }; |