CRCs are used to very data is correct they are a type of checksum. Evolve supports the following CRC types.
The CRC calculations work on byte lists the following examples show the commands in action.
//---------------------------------------
// File: CRC.e
//---------------------------------------
//---------------------------------------
// Block: Go
//---------------------------------------
block Go
Data[0] = '1'
Data[1] = '2'
Data[2] = '3'
Data[3] = '4'
Data[4] = '5'
Data[5] = '6'
Data[6] = '7'
Data[7] = '8'
Data[8] = '9'
out_ibase #HEX
//initialise the crc
Crc = 0
//CRC16
crc Crc Data 9 #CRC16
outl "CRC16: 0x" Crc
//CRC32
crc Crc Data 9 #CRC32
outl "CRC32: 0x" Crc
//CRCCCIT_XMODEM
crc Crc Data 9 #CRCCCIT_XMODEM
outl "CRCCCIT: 0x" Crc
//CRCDNP
crc Crc Data 9 #CRCDNP
outl "CRCDNP: 0x" Crc
//CRCCCIT_KERMIT
crc Crc Data 9 #CRCCCIT_KERMIT
outl "CRCCCIT_KERMIT: 0x" Crc
//CRC16_SICK
crc Crc Data 9 #CRC16_SICK
outl "CRC16_SICK: 0x" Crc
//CRC16_MODBUS
crc Crc Data 9 #CRC16_MODBUS
outl "CRC16_MODBUS: 0x" Crc
//CRCCCIT_FFFF
crc Crc Data 9 #CRCCCIT_FFFF
outl "CRCCCIT_0xFFFF: 0x" Crc
//CRCCCIT_1D0F
crc Crc Data 9 #CRCCCIT_1D0F
outl "CRCCCIT_0x1D0F: 0x" Crc
_block
The MD5 check sum is commonly used to check the contents of software files is correct. There are three commands used to create an MD5 checksum the first md5_init initialises the check sum. Blocks of data can then be added into the check sum using the md5_update statement, this takes 2 arguments the first is the byte array with the data to add and the second is the number of bytes to add. To get the result of the calculation md5_result is used this takes a single argument which is a byte buffer which will contain the 16 byte MD5 checksum result.
The following code calculates a checksum and checks that it is correct.
//---------------------------------------
// File: md5.e
//---------------------------------------
//---------------------------------------
// Block: Go
//---------------------------------------
block Go
CORRECT_RESULT = { 0x7a 0xce 0xdd 0x1a 0x84 0xa4 0xcf 0xcb 0x6e 0x7a 0x16 0x00 0x32 0x42 0x94 0x5e }
//fill a buffer with some data
Data = 0x00
loop Index 100
Data[Index] = Index
_loop
//calc the md5
md5_init
md5_update Data 100
md5_result ResultData
//validate the checksum
loop Index 16
if ResultData[Index] != CORRECT_RESULT[Index]
outl "MD5 Error"
_if
_loop
new_line
//print the checksum
out_ibase #HEX
loop Index 16
out ResultData[Index]
_loop
new_line
_block