PNI TCM 5 User Manual
Page 52
PNI Sensor Corporation
Doc #1007537 r12
TCM3 & TCM5 User Manual- Sept 2011
Page 52
crc ^= (crc <<
8
) <<
4
;
crc ^= ((crc &
0xff
) <<
4
) <<
1
;
}
return
crc;
}
//
// This is called each time this process gets a turn to execute.
//
void
CommProtocol::Control()
{
// InLen returns the number of bytes in the input buffer of the serial object that are
available
// for us to read.
UInt32 inLen = mSerialPort->InLen();
switch
(mStep)
{
case
1
:
{
// wait for length bytes to be received by the serial object
if
(inLen >=
2
)
{
// Read block will return the number of requested (or available) bytes that
are in the
// serial objects input buffer.
// read the byte count
mSerialPort->ReadBlock(mInData,
2
);
// byte count is ALWAYS transmitted in big endian, copy byte count to
mExpectedLen to
// native endianess
mExpectedLen = (mInData[
0
] <<
8
) | mInData[
1
];
// Ticks is a timer function. 1 tick = 10msec.
// wait up to 1/2s for the complete frame (mExpectedLen) to be received
mTime = Ticks() +
50
;
mStep++ ;
// goto the next step in the process
}
break
;
}
case
2
:
{
// wait for msg complete or timeout
if
(inLen >= mExpectedLen -
2
)
{