beautypg.com

Commprotocol.cp file, 3 commprotocol.cp file – PNI CompassPoint Prime User Manual

Page 60

background image

PNI Sensor Corporation

DOC# 1014177 r08

Prime User Manual

– July 2011

Page 54

8.3

CommProtocol.cp File

#include "CommProtocol.h"

// import an object that will provide a 10mSec tick count through
// a function called Ticks()
#include "TickGenerator.h"


//
// SerPort is an object that controls the physical serial
// interface. It handles sending out the characters, and buffers
// the characters read in until we are ready for them.
//
CommProtocol::CommProtocol(CommHandler * handler, SerPort * serPort)
: Process("CommProtocol")
{
// store the object that will parse the data when it is fully
// received

mHandler = handler;

mSerialPort = serPort;

Init();

}

//
// Initialize the serial port and variables that will control
// this process
//
void CommProtocol::Init(UInt32 baud)
{

SetBaud(baud);

mOldInLen = 0;

// no data previously received


mStep = 1;

// goto the first step of our process

}

//
// Put together the frame to send to the unit
//
void CommProtocol::SendData(UInt8 frameType, void * dataPtr, UInt32
len)
{

UInt8 * data = (UInt8 *)dataPtr; // the data to send

UInt32 index = 0;

// our location in the frame we are

// putting together

UInt16 crc;

// the CRC to add to the end of the packet

UInt16 count;

// the total length the packet will be


count = (UInt16)len + kPacketMinSize;


// exit without sending if there is too much data to fit

// inside our packet