深圳市天工测控技术有限
公司
文件编号
QW-RD-21
NMEA Packet
版本号
A/1
发行日期
2021-7-26
History
Revision
Description
Approved
Date
A/0
Initial Release
Simon
20210726
NMEA Packet Format
Preamble
PktType
DataField
*
CHK1
CHK2
CR
LF
Packet Length:
The maximum length of each packet is restricted to 255 bytes.
Packet Contents:
Preamble: One byte character.
$
TalkerID: Four bytes character string.
PMTK
PktType: Three bytes character string.
From 000 to 999
An identifier used to tell the decoder how to decode the packet.
DataField: The DataField has variable length depending on the packet type.
A comma symbol , must be inserted ahead each data filed to help the decoder process the DataField.
*: 1 byte character. The star symbol is used to mark the end of DataField.
CHK1, CHK2: Two bytes character string. CHK1 and CHK2 are the checksum of the data between Preamble and *.
CR, LF: Two bytes binary data. The two bytes are used to identify the end of a packet.
Sample Packet:
$PMTK000*32<CR><LF>
NMEA Packet Protocol:
In order to inform the sender whether the receiver has received the packet, an acknowledge packet PMTK_ACK should return after the
receiver receives a packet.
CK1 And CK2
CHK1 and CHK2 are the checksum of the data between Preamble and ‘*’, the checksum is the exclusive OR of all characters between
Preamble and ‘*’. The C reference example:
char a[]="$PMTK000*32\r\n";
char Checksum,Checksum1,Checksum2;
int i;
for(Checksum=a[1],i=2;a[i]!='*' && i<255;++i)
{
Checksum^=a[i];
}
printf("Checksum =%02X\n\n",Checksum);// ”32”
if( (Checksum/0x10 )+0x30 <=57) //Checksum1
Checksum1=Checksum/0x10+0x30;
else
Checksum1=Checksum/0x10+0x30+0x07;
if( (Checksum%0x10)+0x30 <=57) //Checksum2
Checksum2=Checksum%0x10+0x30;
else
Checksum2=Checksum%0x10+0x30+0x07;
if(a[++i]==Checksum1)
printf("Checksum1 =%C\n",Checksum1);// 3’
if(a[++i]==Checksum2)
printf("Checksum2 =%C\n",Checksum2);// 2’
Commonly Used Commands
Note: <CR> is carriage return character, <LF> is line feed character.