beautypg.com

2 commprotocol.cp file – PNI TCM 5 User Manual

Page 50

background image

PNI Sensor Corporation

Doc #1007537 r12

TCM3 & TCM5 User Manual- Sept 2011

Page 50

4.4.2.2 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"

)

{

mHandler = handler;

// store the object that will parse the data when it

is fully received

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

if

(len > kBufferSize - kPacketMinSize)

return

;

This manual is related to the following products: