Commprotocol.cpp file, 3 commprotocol.cpp file – PNI TCM User Manual
Page 69
![background image](/manuals/373140/69/background.png)
PNI Sensor Corporation
DOC#1014688 r06
TCM User Manual
– July 2013
Page 64
7.4.3
CommProtocol.cpp File
#i nc l ude " CommPr ot oc ol . h"
/ / i mpor t an obj ec t t hat wi l l pr ovi de a 10mSec t i c k count t hr ough
/ / a f unct i on cal l ed Ti ck s( )
#i nc l ude " Ti ck Gener at or . h"
/ / Ser Por t i s an obj ec t t hat c ont r ol s t he phy si cal ser i al
/ / i nt er f ace. I t handl es s endi ng out
/ / t he c har act er s, and buf f er s t he char act er s r ead i n unt i l
/ / we ar e r eady f or t hem.
/ /
CommPr ot oc ol : : CommPr ot ocol ( CommHandl er * handl er , Ser Por t * s er Por t )
: Pr ocess ( " CommPr ot ocol " )
{
mHandl er = handl er ;
/ / s t or e t he obj ec t t hat wi l l par se t he dat a when i t i s f ul l y
/ / r ec ei ved
mSer i al Por t = ser Por t ;
I ni t ( ) ;
}
/ / I ni t i al i ze t he s er i al por t and var i abl es t hat wi l l c ont r ol
/ / t hi s pr oc es s
v oi d CommPr ot ocol : : I ni t ( UI nt 32 baud)
{
Set Baud( baud) ;
mOl dI nLen = 0;
/ / no dat a pr evi ousl y r ec ei ved
mSt ep = 1;
/ / got o t he f i r s t st ep of our pr ocess
}
/ /
/ / Put t oget her t he f r ame t o send t o t he modul e
/ /
v oi d CommPr ot ocol : : SendDat a( UI nt 8 f r ameType, v oi d * dat aPt r , UI nt 32
l en)
{
UI nt 8 * dat a = ( UI nt 8 * ) dat aPt r ;
/ / t he dat a t o s end
UI nt 32 i ndex = 0;
/ / our l oc at i on i n t he f r ame we ar e put t i ng t oget her
UI nt 16 c r c ;
/ / t he CRC t o add t o t he end of t he pac k et
UI nt 16 c ount ;
/ / t he t ot al l engt h t he pac ket wi l l be
c ount = ( UI nt 16) l en + k Pack et Mi nSi z e;
/ / ex i t wi t hout s endi ng i f t her e i s t oo muc h dat a t o f i t
/ / i ns i de our pack et
i f ( l en > k Buf f er Si ze - kPac ket Mi nSi ze) r et ur n;
/ / St or e t he t ot al l en of t he pac ket i nc l udi ng t he l en byt es
/ / ( 2) , t he f r ame I D ( 1) ,
/ / t he dat a ( l en) , and t he cr c ( 2) . I f no dat a i s s ent , t he
/ / mi n l en i s 5