PNI SeaTRAX User Manual

Page 70

Advertising
background image

PNI Sensor Corporation

DOC#1018154 r02

SeaTRAX User Manual

Page 65

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)

{

UInt16 crc, crcReceived;

// calculated and received crcs.

// Read block will return the number of
// requested (or available) bytes that are in the
// serial objects input buffer.

mSerialPort->ReadBlock(&mInData[2],

mExpectedLen - 2);

Advertising