-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodChecksums.vb
108 lines (87 loc) · 3.11 KB
/
modChecksums.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Module modChecksums
Public Function GetChecksum(ByVal inputString As String) As String
Dim nCount As Integer
Dim nHolder As Integer
nHolder = 0
For nCount = 1 To Len(inputString)
nHolder = (nHolder Xor CByte(Asc(Mid(inputString, nCount, 1))))
Next nCount
GetChecksum = IIf(Len(Hex(nHolder)) = 1, "0", "") & Hex(nHolder)
End Function
Public Function GetFY21APChecksum(ByVal inputString As String) As String
Dim nLength As Integer
Dim nCount As Integer
Dim nA As Long
nA = 0
nLength = Len(inputString)
For nCount = 1 To nLength
nA = nA + Asc(Mid(inputString, nCount, 1))
Next nCount
nA = nA Mod 256
GetFY21APChecksum = Chr("&h" & Hex(nA).PadLeft(2, "0"))
End Function
Public Function GetSiRFChecksum(ByVal inputString As String) As String
Dim nLength As Integer
Dim nCount As Integer
Dim nA As Long
nA = 0
nLength = Len(inputString)
For nCount = 1 To nLength
nA = nA + Asc(Mid(inputString, nCount, 1))
nA = nA And ((2 ^ 15) - 1)
Next nCount
' Debug.Print "nA=" & Hex(nA) & ",nB=" & Hex(nB)
GetSiRFChecksum = Hex(nA).PadLeft(4, "0")
GetSiRFChecksum = Chr("&h" & Mid(GetSiRFChecksum, 1, 2)) & Chr("&h" & Mid(GetSiRFChecksum, 3, 2))
End Function
Public Function GetXbeeChecksum(ByVal inputString As String) As String
Dim nLength As Integer
Dim nCount As Integer
Dim nA As Long
nA = 0
nLength = Len(inputString)
For nCount = 1 To nLength
nA = nA + Asc(Mid(inputString, nCount, 1))
Next nCount
nA = nA And CDec("&HFF")
nA = CDec("&HFF") - nA
GetXbeeChecksum = Chr("&h" & Hex(nA).PadLeft(2, "0"))
End Function
Public Function GetuBloxChecksum(ByVal inputString As String) As String
Dim nLength As Integer
Dim nCount As Integer
Dim nA As Long
Dim nB As Long
nA = 0
nB = 0
nLength = Len(inputString)
For nCount = 1 To nLength
nA = nA + Asc(Mid(inputString, nCount, 1))
nB = nB + nA
Next nCount
nA = nA And &HFF
nB = nB And &HFF
' Debug.Print "nA=" & Hex(nA) & ",nB=" & Hex(nB)
GetuBloxChecksum = Chr(nA) & Chr(nB)
End Function
Public Function GetuBloxChecksumByte(ByVal inputString As String) As Byte()
Dim nLength As Integer
Dim nCount As Integer
Dim nA As Long
Dim nB As Long
Dim arr(0 To 1) As Byte
nA = 0
nB = 0
nLength = Len(inputString)
For nCount = 1 To nLength
nA = nA + Asc(Mid(inputString, nCount, 1))
nB = nB + nA
Next nCount
nA = nA And &HFF
nB = nB And &HFF
' Debug.Print "nA=" & Hex(nA) & ",nB=" & Hex(nB)
arr(0) = CInt(nA)
arr(1) = CInt(nB)
Return arr
End Function
End Module