Check a Message Checksum
hard
Checks the checksum at the end of a GPS sentence before its data is used.
What it teaches
Many serial protocols end a message with a checksum so the receiver can tell when characters were lost or changed. An NMEA sentence uses the XOR of the codes of every character between '$' and '*', so changing one character changes the result. It is written after the '*' as two hex digits, as a byte was in Byte to Hex Text: 57 is written '39'. Anything before the '$' is noise, the $r$l after the digits from Strip the Terminator is not part of it, and a sentence without '*' is not valid.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| Out_Checksum | Output | DINT | 0 | The XOR of the characters between '$' and '*' |
| Sts_Valid | Output | BOOL | 0 | The checksum in the sentence matches |
| Ref_Sentence | InOut | STRING | — | A sentence from a GPS receiver |
Required behavior
- A GPS receiver sends sentences such as '$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41', ending with $r$l. The two hex digits after the '*' are a checksum.
- Out_Checksum is the XOR of the codes of every character between the '$' and the '*', not counting either of them. Every scan, Sts_Valid is 1 when Out_Checksum written as two upper-case hex digits is the two characters after the '*'.
- Anything before the '$' is noise from the line and is skipped. A sentence with no '$', or no '*' after it, gives Out_Checksum 0 and Sts_Valid 0.
- In text in quotes, $ starts a special character, so a dollar sign is written $$.
- Never change Ref_Sentence.