FiveCo FMod-TCP BOX User Manual page 21

Ethernet converter device
Table of Contents

Advertisement

Here is an example of a checksum calculation function in C:
int RetCheckSum(Byte* ByteTab, int Size)
{
// This function returns the calculated checksum
unsigned int
bool
unsigned int
for(int i=0;i<Size;i++)
{
if(AddHighByte)
{
Sum+=((ByteTab[i])<<8)^0xFF00;
AddHighByte=false;
}
else
{
Sum+=(ByteTab[i])^0x00FF;
AddHighByte=true;
}
}
if (AddHighByte==false)
Sum+= 0xFF;
ChecksumCalculated = ((Sum>>16)&0xFFFF)+(Sum&0xFFFF);
ChecksumCalculated = ((ChecksumCalculated>>16)&0xFFFF)
return ChecksumCalculated;
}
This function needs a Byte array (ByteTab) containing the command
sequence and this array's length (Size) as input, it returns the checksum as an
int.
Sum=0;
AddHighByte=true;
ChecksumCalculated;
+(ChecksumCalculated&0xFFFF);
21 / 58
FMod-TCP User Manual v.2.8

Advertisement

Table of Contents
loading

Related Products for FiveCo FMod-TCP BOX

This manual is also suitable for:

Fmod-tcp box 2

Table of Contents