beautypg.com

PNI CompassPoint Prime User Manual

Page 62

background image

PNI Sensor Corporation

DOC# 1014177 r08

Prime User Manual

– July 2011

Page 56

}

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++ ; //go to next step in the process

}

break ;

}

case 2:

{

// wait for msg complete or timeout

if(inLen >= mExpectedLen - 2)

{

// calculated and received crcs.

UInt16 crc, crcReceived;

// Read block will return the number of

// requested (or available) bytes that are in

// the serial objects input buffer.