⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nmeaparser.h

📁 GPS用
💻 H
字号:
//---------------------------------------------------------------------------
// NMEAParser.h:
//
// NMEA Messages parsed:
//      GPGGA, GPGSA, GPRMC, GPGSV, GPRMB, GPZDA
//
// TMneaSentence:   Validate the original message received from GPS,
//                  Split command the data fields from NMEA message,
//                  Can reorganize all received NMEA sentences for monitoring.

#ifndef NMEAParserH
#define NMEAParserH
//---------------------------------------------------------------------------
#include <string>
#include <vector>
using namespace std;

// The basic class, NMEA sentence processing.
class TNmeaSentence
{
public:
	TNmeaSentence();
	virtual ~TNmeaSentence();

    // Parse a chunk of GPS message into NMEA sentences.
	bool ParseBuffer(char *Buffer, int BufferLength);

    // Retrieve all parsed sentences, total retrieves will be returned.
    int RetrieveSentences(vector<string> &SentenceOut);

private:
    enum{                               // Current state machine parser is in.
    	STATE_SOM,		                // Search for start of message.
    	STATE_CMD,					    // Get command.
    	STATE_DATA,					    // Get data.
    	STATE_CHECKSUM1,			    // Get first checksum character.
    	STATE_CHECKSUM2,			    // get second checksum character.
    }MachineState;

    int ChecksumReceived;			    // Checksum in original message.

    struct SentenceData{                // Factors for single NMEA sentence.
        string Command;                 // NMEA command.
	    string Data;                    // NMEA data.
        int Checksum;			        // Calculated checksum.
    }SenBuff;

   	string::size_type FieldPosition;

protected:
    vector<SentenceData> Sentences;     // Parsed NMEA sentence vector.

    // Return false while specified filed is null, Out will not modified.
    bool GetField(string &Data, int FieldNumber, string &Out);
    bool GetField(string &Data, int FieldNumber, int &Out);
    bool GetField(string &Data, int FieldNumber, double &Out);
};
//---------------------------------------------------------------------------
class TNmeaData : public TNmeaSentence
{
public:
    TNmeaData();
    ~TNmeaData();

	// $GPGGA,153628.502,3957.1224,N,11616.9212,E,1,03,39.4,67.6,M,,,,0000*09
    class GpggaData : TNmeaSentence{    // GPS fix data.
    public:
    	int Hour;				        // UTC time of position fix.
    	int Minute;				        //
    	double Second;	  		        //
    	double Latitude;			    // <0 =South, >0 =North
    	double Longitude;			    // <0 =West, >0 =East
    	int GpsQuality;			        // 0 = fix not available,
                                        // 1 = GPS sps mode fix available,
                                        // 2 = Differential GPS fix availabel,
                                        // 3 = GPS PPS mode fix.
                                        // 6 = Estimated.
    	int SatellitesInUse;            // Number of satellites in use, 0 to 32.
    	double HDop;				    // Horizontal dilution of precision.
    	double AntennaHeight;		    // Above/below mean sea level, meters.
        string AntennaUnit;             // Unit for AntennaHeight.
    	double GeoidalHeight;		    // Above/below mean sea level, meters.
        string GeoidalUnit;             // Unit for Geoid.
        double DGpsDataAge;             // Number of seconds since last valid.
                                        // For RTCM SC-104, null if non-DGPS.
        int DGpsStationId;              // Reference station ID, 0 to 1023.
                                        //
    	int Count;				        // Number of GPGGA received.
    	double OldVSpeedSeconds; 	    //
    	double OldVSpeedAlt;		    //
    	double VerticalSpeed;	        //

        GpggaData();
        bool ParseData(string &Data);
    }Gpgga;

    // $GPGSA,A,2,03,01,20,,,,,,,,,,50.0,39.4,50.0*0D
    class GpgsaData : TNmeaSentence{    // GPS DOP and Active Satellites.
    public:
    	string Mode;					// GPS mode, M=manual, A=automatic.
	    int FixMode;				    // 1=fix not available, 2=2D, 3=3D.
	    vector<int> PrnNumber;          // IDs of satellites in use.
	    double PDop;					// Position dilusion of precision.
	    double HDop;					// Horizontal dilusion of precision.
	    double VDop;					// Vertical dilusion of precision.
	    int Count;					    // Number of GPGSA received.

        GpgsaData();
        bool ParseData(string &Data);
    }Gpgsa;

    // Parse a chunk of data buffer into NMEA sentences.
	bool ParseBuffer(char *Buffer, int BufferLength);
};
//---------------------------------------------------------------------------
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -