在 WM 平台上开发 GPS 导航系统
2010-02-21 22:52:00 来源:WEB开发网60 Dim Today As DateTime = System.DateTime.Now.ToUniversalTime
61 Dim SatelliteTime As New System.DateTime(Today.Year, Today.Month, _
62 Today.Day, UtcHours, UtcMinutes, UtcSeconds, UtcMilliseconds)
63 ' Notify of the new time, adjusted to the local time zone
64 RaiseEvent DateTimeChanged(SatelliteTime.ToLocalTime)
65 End If
66 ' Indicate that the sentence was recognized
67 Return True
68 End Function
69 ' Returns True if a sentence's checksum matches the calculated checksum
70 Public Function IsValid(ByVal sentence As String) As Boolean
71 ' Compare the characters after the asterisk to the calculation
72 Return sentence.Substring(sentence.IndexOf("*") + 1) = _
73 GetChecksum(sentence)
74 End Function
75 ' Calculates the checksum for a sentence
76 Public Function GetChecksum(ByVal sentence As String) As String
77 ' Loop through all chars to get a checksum
78 Dim Character As Char
79 Dim Checksum As Integer
80 For Each Character In sentence
81 Select Case Character
82 Case "$"c
83 ' Ignore the dollar sign
84 Case "*"c
85 ' Stop processing before the asterisk
86 Exit For
87 Case Else
88 ' Is this the first value for the checksum?
89 If Checksum = 0 Then
90 ' Yes. Set the checksum to the value
91 Checksum = Convert.ToByte(Character)
92 Else
93 ' No. XOR the checksum with this character's value
94 Checksum = Checksum Xor Convert.ToByte(Character)
95 End If
96 End Select
97 Next
98 ' Return the checksum formatted as a two-character hexadecimal
99 Return Checksum.ToString("X2")
100 End Function
赞助商链接