PNI SeaTRAX User Manual

Page 71

Advertising
background image

PNI Sensor Corporation

DOC#1018154 r02

SeaTRAX User Manual

Page 66

// in CRC verification, don't include the CRC in the recalculation
(-2)

crc = CRC(mInData, mExpectedLen - 2);

// CRC is also ALWAYS transmitted in big endian

crcReceived = (mInData[mExpectedLen - 2] <<

8) | mInData[mExpectedLen - 1] ;

if(crc == crcReceived)

{

// the crc is correct, so pass the frame up for processing.

if(mHandler) mHandler-

>HandleComm(mInData[2], &mInData[3], mExpectedLen - kPacketMinSize);

}

else

{

// crc's don't match so clear everything that is currently in the
// input buffer since the data is not reliable.

mSerialPort->InClear();

}

// go back to looking for the length bytes.

mStep = 1 ;

}

else

{

// Ticks is a timer function. 1 tick = 10msec.

if(Ticks() > mTime)

{

// Corrupted message. We did not get the length we were
// expecting within 1/2sec of receiving the length bytes. Clear
// everything in the input buffer since the data is unreliable

mSerialPort->InClear();

mStep = 1 ;

// Look for the next length bytes

}

}

break ;

}

default:

break ;

}

}

Advertising