解析包含 NMEA 语句 C++ 的日志文件

Parsing log files containing NMEA sentences C++

我有多个 NMEA 语句的日志文件,其中包含相机捕获的地理位置。 其中一个句子的示例:$GPRMC,100101.000,A,3723.1741,N,00559.5624,W,0.000,0.00,150914,A*63

我的问题是,你认为我可以从哪里着手?只需要有人把我推向正确的方向,谢谢。

我在我的 GPSReverse 驱动程序中使用了这个校验和函数。

string chk(const char* data)
    {
    // Assuming data contains a NMEA sentence (check it)
    // Variables for keeping track of data index and checksum 
    const char *datapointer = &data[1];
    char checksum = 0;
    // Loop through entire string, XORing each character to the next 
    while (*datapointer != '[=10=]')
        {
        checksum ^= *datapointer;
        datapointer++;
        }
    // Print out the checksum in ASCII hex nybbles 
    char x[100] = {0};
    sprintf_s(x,100,"%02X",checksum);
    return x;
    }

然后,一些附加到 NMEA 字符串(比如 GGA):

string re = chk(gga.c_str());
gga += "*";
gga += re;
gga += "\r\n";

所以你可以读到*,计算校验和,看它是否匹配*后面的字符串。

阅读更多here

Each sentence begins with a '$' and ends with a carriage return/line feed sequence and can be no longer than 80 characters of visible text (plus the line terminators). The data is contained within this single line with data items separated by commas. The data itself is just ascii text and may extend over multiple sentences in certain specialized instances but is normally fully contained in one variable length sentence. The data may vary in the amount of precision contained in the message. For example time might be indicated to decimal parts of a second or location may be show with 3 or even 4 digits after the decimal point. Programs that read the data should only use the commas to determine the field boundaries and not depend on column positions. There is a provision for a checksum at the end of each sentence which may or may not be checked by the unit that reads the data. The checksum field consists of a '' and two hex digits representing an 8 bit exclusive OR of all characters between, but not including, the '$' and ''. A checksum is required on some sentences.