I have a need to create a checksum for a NMEA sentence I am creating in PBP. I am sure others have done this, but I have not - has anyone found a way to cycle through variables and compute checksum on a group?
The situation is this:
I have the following variables :
Dec_lat1 var word
Dec_lat2 var word
Dec_latD var word
Dec_long1 var word
Dec_Long2 var word
Dec_longD var word
wpt var word
Cksum var word - 2 characters
--------------------------------------------
I need to construce a '$GPWPL sentence' (waypoint), and to do this need to create a checksum on everything except the '$' and the '*' which comes before the checksum.
Ultimately, I need to output the following to the GPS:
serout2 Apin4, 84,[,10,13,"$GPWPL,",#Dec_lat1,".",#Dec_lat2,",#Dec_la tD,"]
serout2 Apin4, 84,[#Dec_long1,".",#Dec_long2,",#Dec_longD,","wpt"*",# Cksum]
It will look to the GPS like:
$GPWPL,119.098,W,47.3456,N,TOMHOME,*34
BUT
Problem is, the only code I can find for this is not compatible with PBP and deals with strings..
Public Function NMEA_Checksum(ByVal sSentence As String) As String
Dim i&, sum&
'The "sentence" is from position 1 (the $) to the "*"
'The checksum calc does NOT include the $ or *
For i = 2 To Len(sSentence) - 1
sum = sum Xor Asc(Mid$(sSentence, i, 1))
Next i
NMEA_Checksum = Right$("0" & Hex$(sum), 2)
'The returned value is a 2 character string containing the check sum value
Thanks,
Tom
Bookmarks