first version of message parsing
This commit is contained in:
parent
d8d0072eb7
commit
dee9e32f81
3 changed files with 53 additions and 19 deletions
|
@ -360,6 +360,10 @@
|
||||||
<name>text</name>
|
<name>text</name>
|
||||||
<string>C&onnect</string>
|
<string>C&onnect</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property stdset="1">
|
||||||
|
<name>default</name>
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</hbox>
|
</hbox>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -41,16 +41,15 @@ Protocol message definition
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
|
bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecIn,
|
||||||
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
|
int& iCnt,
|
||||||
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
|
int& iID,
|
||||||
|
CVector<uint8_t>& vecData )
|
||||||
bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecIn )
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
return code: true -> ok; false -> error
|
return code: true -> ok; false -> error
|
||||||
*/
|
*/
|
||||||
int iID, iCnt, iLenBy, i;
|
int iLenBy, i;
|
||||||
unsigned int iCurPos;
|
unsigned int iCurPos;
|
||||||
|
|
||||||
// query length of input vector
|
// query length of input vector
|
||||||
|
@ -82,9 +81,9 @@ bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecIn )
|
||||||
|
|
||||||
// now check CRC -----
|
// now check CRC -----
|
||||||
CCRC CRCObj;
|
CCRC CRCObj;
|
||||||
iCurPos = 0; // start from beginning
|
|
||||||
|
|
||||||
const int iLenCRCCalc = MESS_HEADER_LENGTH_BYTE + iLenBy;
|
const int iLenCRCCalc = MESS_HEADER_LENGTH_BYTE + iLenBy;
|
||||||
|
|
||||||
|
iCurPos = 0; // start from beginning
|
||||||
for ( i = 0; i < iLenCRCCalc; i++ )
|
for ( i = 0; i < iLenCRCCalc; i++ )
|
||||||
{
|
{
|
||||||
CRCObj.AddByte ( static_cast<uint8_t> (
|
CRCObj.AddByte ( static_cast<uint8_t> (
|
||||||
|
@ -96,9 +95,13 @@ bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecIn )
|
||||||
return false; // return error code
|
return false; // return error code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decode data -----
|
||||||
// TODO actual parsing of message data
|
iCurPos = MESS_HEADER_LENGTH_BYTE; // start from beginning of data
|
||||||
|
for ( i = 0; i < iLenBy; i++ )
|
||||||
|
{
|
||||||
|
vecData[i] = static_cast<uint8_t> (
|
||||||
|
GetValFromStream ( vecIn, iCurPos, 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
return true; // everything was ok
|
return true; // everything was ok
|
||||||
}
|
}
|
||||||
|
@ -127,8 +130,10 @@ uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn,
|
||||||
void CProtocol::GenMessage ( CVector<uint8_t>& vecOut,
|
void CProtocol::GenMessage ( CVector<uint8_t>& vecOut,
|
||||||
const int iCnt,
|
const int iCnt,
|
||||||
const int iID,
|
const int iID,
|
||||||
const CVector<uint8_t>& vecData)
|
const CVector<uint8_t>& vecData )
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
// query length of data vector
|
// query length of data vector
|
||||||
const int iDataLenByte = vecData.Size();
|
const int iDataLenByte = vecData.Size();
|
||||||
|
|
||||||
|
@ -154,12 +159,28 @@ void CProtocol::GenMessage ( CVector<uint8_t>& vecOut,
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos,
|
||||||
static_cast<uint32_t> ( iDataLenByte ), 2 );
|
static_cast<uint32_t> ( iDataLenByte ), 2 );
|
||||||
|
|
||||||
// TODO data, CRC
|
// encode data -----
|
||||||
|
for ( i = 0; i < iDataLenByte; i++ )
|
||||||
|
{
|
||||||
|
PutValOnStream ( vecOut, iCurPos,
|
||||||
|
static_cast<uint32_t> ( vecData[i] ), 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// encode CRC -----
|
||||||
|
CCRC CRCObj;
|
||||||
|
iCurPos = 0; // start from beginning
|
||||||
|
|
||||||
|
const int iLenCRCCalc = MESS_HEADER_LENGTH_BYTE + iDataLenByte;
|
||||||
|
for ( i = 0; i < iLenCRCCalc; i++ )
|
||||||
|
{
|
||||||
|
CRCObj.AddByte ( static_cast<uint8_t> (
|
||||||
|
GetValFromStream ( vecOut, iCurPos, 1 ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
PutValOnStream ( vecOut, iCurPos,
|
||||||
|
static_cast<uint32_t> ( CRCObj.GetCRC () ), 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
|
void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
|
||||||
unsigned int& iPos,
|
unsigned int& iPos,
|
||||||
const uint32_t iVal,
|
const uint32_t iVal,
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size
|
#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size
|
||||||
#define PROTMESSID_PING 11 // for measuring ping time
|
#define PROTMESSID_PING 11 // for measuring ping time
|
||||||
|
|
||||||
|
// lengths of message as defined in protocol.cpp file
|
||||||
|
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
|
||||||
|
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
class CProtocol
|
class CProtocol
|
||||||
|
@ -45,7 +49,11 @@ public:
|
||||||
virtual ~CProtocol() {}
|
virtual ~CProtocol() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool ParseMessage ( const CVector<uint8_t>& vecIn );
|
bool ParseMessage ( const CVector<uint8_t>& vecIn,
|
||||||
|
int& iCnt,
|
||||||
|
int& iID,
|
||||||
|
CVector<uint8_t>& vecData );
|
||||||
|
|
||||||
void GenMessage ( CVector<uint8_t>& vecOut,
|
void GenMessage ( CVector<uint8_t>& vecOut,
|
||||||
const int iCnt,
|
const int iCnt,
|
||||||
const int iID,
|
const int iID,
|
||||||
|
@ -55,9 +63,10 @@ protected:
|
||||||
unsigned int& iPos,
|
unsigned int& iPos,
|
||||||
const uint32_t iVal,
|
const uint32_t iVal,
|
||||||
const unsigned int iNumOfBytes );
|
const unsigned int iNumOfBytes );
|
||||||
uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
|
|
||||||
unsigned int& iPos,
|
uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
|
||||||
const unsigned int iNumOfBytes );
|
unsigned int& iPos,
|
||||||
|
const unsigned int iNumOfBytes );
|
||||||
|
|
||||||
uint8_t iCounter;
|
uint8_t iCounter;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue