Philips FMod-TCP BOX Network Card User Manual


 
21 / 58
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 Sum=0;
bool AddHighByte=true;
unsigned int ChecksumCalculated;
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)
+(ChecksumCalculated&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.
FMod-TCP User Manual v.2.8