Sshqgl[ $ 5hprwh $fwlydwlrq, Calculating the crc – Grass Valley XSwitch Feb 01 2005 User Manual
Page 34

©2001 XSWITCH Installation and Operations Manual 33
$SSHQGL[ $ 5HPRWH $FWLYDWLRQ
Calculating the CRC
Given: The XSWITCH information for the fields:
and the basic program to calculate the CRC:
BASIC CRC PROGRAM VER. 2.0 USING VISUAL BASIC 3.0
Static P(200) As Integer
ICRC = 0
POLY = &H8408
Dstring$ = Input_Text$
‘ This is the input string.
D = 0
i = 1
P(0) = 0
For J = 1 To Len(Dstring$)
c$ = Mid$(Dstring$, J, 1)
Casc = Asc(c$)
‘ Finds decimal value contained in character’s ASCII value.
D = D * 16 + Casc
‘ Hex value calculated.
P(0) = P(0) + 1
P(i) = D
i = i + 1
D = 0
Next J
‘ After calculating input string’s characters to hex value,
CRC = ICRC
Calculate the CRC.
For i = 1 To P(0)
D = P(i)
For J = 1 To 8
XFLG = (CRC Xor D) And 1
CRC = Int(CRC / 2) And &H7FFF
If XFLG Then CRC = CRC Xor POLY
D = Int(D / 2)
Next J
Next i
....................... CrCHexValue$ = Hex$(CRC)
‘ This is ENTIRE CRC string.
dummylength = Len(CrCHexValue$)
LSB = Val(“&H” + Right$(CrCHexValue$, 2)) ‘ Convert hex value to decimal value.
MSB = 0
If dummylength = 3 Then MSB = Val(“&H” + Left$(CrCHexValue$, 1))
If dummylength > 3 Then MSB = Val(“&H” + Mid$(CrCHexValue$, dummylength - 3, 2))
Packet$ = Dstring$ + Chr$(LSB) + Chr$(MSB) ‘ This is the packet string.
End
Where the input string is made up of single characters to represent the field’s decimal value in the character’s own
ASCII value AND the actual command string for the XSWITCH.
DEST
SRC
LEN
C/C
DATA1
…
DATAn
CRCL
CRCH