PNI CompassPoint Prime User Manual
Page 63
Prime User Manual r08
Page 57
mSerialPort->ReadBlock(&mInData[2],
mExpectedLen - 2);
// 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();
// Look for the next length bytes
mStep = 1 ;
}
}
break ;
}
default:
break ;
}
}