Commprotocol.cpp file, 3 commprotocol.cpp file – PNI SeaTRAX User Manual
Page 68
PNI Sensor Corporation
DOC#1018154 r02
SeaTRAX User Manual
Page 63
7.4.3
CommProtocol.cpp 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 module
//
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