Camera Link registers
21
Goldeye Camera Link Register Controls Reference V1.0.0
GenCP Checksum Calculation Function
Because the GenCP standard is very unclear about calculating a packet's checksum,
a reference implementation is provided here that shows how the calculation is to
be done. The function works with GenCP packets up to 64Kb size. It assumes, that
the packet data exists in memory in big endian format. Its return value, however, is
in host format.
uint16 GenCpChecksum16(uint8* pBuffer, uint32 nNumBytes)
{
uint32 nChecksum = 0;
uint16 nCurVal;
uint32 nByteCounter;
uint32 nNumBytesEven = nNumBytes & ~(sizeof(uint16) - 1);
// for reasons of performance, this function is limited to
64Kb length.
// Since the GenCP standard recommends to have
packets <= 1Kb, this should not be a problem.
assert(nNumBytes < 65535);
for (nByteCounter = 0; nByteCounter < nNumBytesEven;
nByteC= sizeof(uint16))
{
// pBuffer is interpreted as an array of big endian
16 bit values.
nCurVal = (((uint16) pBuffer[nByteCounter]) << 8) |
((uint16) pBuffer[nByteC 1]);
nCh= (uint32) nCurVal;
}
if ((nNumBytes & (sizeof(uint16) - 1)) != 0)
{
// special case: buffer length is odd number
nCh= (((uint32) pBuffer[nNumBytesEven]) << 8);
}
while ((nChecksum & 0xFFFF0000) != 0)
{
nChecksum = (nChecksum & 0xFFFF) + (nChecksum >> 16);
}
return(~((uint16) nChecksum));
}