Sub Process_Globals
Dim mHexImage() As Byte
End Sub
Sub AppStart (Args() As String)
Log("Hello world!!!")
Dim aString As String = "Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» Hello WorldýâЪuz» " & Chr(0)
mHexImage = aString.GetBytes("iso-8859-1")
'Log($"10: ${mHexImage(10)}, 11: ${mHexImage(11)}"$)
Log($"CRC value: ${Get_Buf_CRC(0, 221)}"$)
End Sub
Sub Get_Buf_CRC( buf_offset As Int, numBytes As Int) As Int ' needs unsigned int16
Dim crc As Int = 0, i As Int
For i = 0 To numBytes-1
crc = UpdateCRC( crc, mHexImage(buf_offset + i))
Next
Return crc
End Sub
Sub UpdateCRC( crc As Int, newbyte As Byte ) As Int
Dim CRCpoly As Int = 0x8408 ' CRC16-CCITT FCS (X^16+X^12+X^5+1)
Dim i As Int
crc = Bit.Xor( crc, Bit.And(newbyte, 0xFF) )
For i = 0 To 7
If Bit.And( crc, 0x0001 ) = 1 Then
crc = crc/2
crc = Bit.Xor( crc, CRCpoly )
Else
crc = crc/2
End If
Next
Return crc
End Sub