I was looking at the forum and noticed a NMEA checksum routine in the BASIC4PPC and thought i would create a B4A routine . The code is below and the attached ZIP file is the source.
Not sure if it is any use to anyone
Enjoy
Not sure if it is any use to anyone
Enjoy
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Button1 As Button
Dim EditText1 As EditText
Dim Label1 As Label
Dim Label2 As Label
Dim RadioButton1 As RadioButton
Dim RadioButton2 As RadioButton
Dim RadioButton3 As RadioButton
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout ("display")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub NMEA_Checksum(NMEA As String)
Dim stPos As Int, spPos As Int, a As Int, checksum As Int, charInt As Int,chk As String
a=0
Do While a<NMEA.Length-1
If NMEA.CharAt(a)="$" AND stPos=0 Then stPos=a+1
If NMEA.CharAt(a)="*" AND spPos=0 Then spPos=a-1
If stPos<>0 AND spPos<>0 Then a=NMEA.Length-2
a=a+1
Loop
checksum=0
If stPos<>0 AND spPos<>0 AND spPos>stPos Then
For a=stPos To spPos
charInt = Asc(NMEA.CharAt(a))
checksum = Bit.Xor(checksum,charInt)
Next
Return Bit.ToHexString(checksum).ToUpperCase
Else
Return Null
End If
End Sub
Sub Button1_Click
Dim ret As String
ret = NMEA_Checksum(EditText1.Text)
If ret = Null Then
Label2.Text="Checksum: NULL"
Else
If ret.Length =1 Then ret="0" & ret
Label2.Text="Checksum: " & ret
End If
End Sub
Sub RadioButton3_CheckedChange(Checked As Boolean)
EditText1.Text =RadioButton3.Text
End Sub
Sub RadioButton2_CheckedChange(Checked As Boolean)
EditText1.Text =RadioButton2.Text
End Sub
Sub RadioButton1_CheckedChange(Checked As Boolean)
EditText1.Text =RadioButton1.Text
End Sub