some more protocol implementations
This commit is contained in:
parent
5308f3bf85
commit
a9183633bc
4 changed files with 171 additions and 32 deletions
|
@ -215,15 +215,29 @@ CChannel::CChannel ()
|
||||||
|
|
||||||
|
|
||||||
/* connections ---------------------------------------------------------- */
|
/* connections ---------------------------------------------------------- */
|
||||||
// just route message through this class
|
|
||||||
QObject::connect ( &Protocol,
|
QObject::connect ( &Protocol,
|
||||||
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
||||||
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ) );
|
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
|
||||||
|
|
||||||
QObject::connect ( &Protocol, SIGNAL ( ChangeJittBufSize ( int ) ),
|
QObject::connect ( &Protocol, SIGNAL ( ChangeJittBufSize ( int ) ),
|
||||||
this, SLOT ( OnJittBufSizeChange ( int ) ) );
|
this, SLOT ( OnJittBufSizeChange ( int ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||||
|
{
|
||||||
|
// only send messages if we are connected, otherwise delete complete queue
|
||||||
|
// if ( IsConnected () )
|
||||||
|
// {
|
||||||
|
// emit message to actually send the data
|
||||||
|
emit MessReadyForSending ( vecMessage );
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // delete send message queue
|
||||||
|
// Protocol.DeleteSendMessQueue();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
|
void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
|
||||||
{
|
{
|
||||||
/* this opperation must be done with mutex */
|
/* this opperation must be done with mutex */
|
||||||
|
@ -343,6 +357,13 @@ CVector<unsigned char> CChannel::PrepSendPacket(const CVector<short>& vecsNPacke
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* CSampleOffsetEst *
|
* CSampleOffsetEst *
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
|
@ -134,6 +134,7 @@ protected:
|
||||||
QMutex Mutex;
|
QMutex Mutex;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
||||||
void OnJittBufSizeChange ( int iNewJitBufSize );
|
void OnJittBufSizeChange ( int iNewJitBufSize );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
102
src/protocol.cpp
102
src/protocol.cpp
|
@ -74,19 +74,69 @@ MESSAGES
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
|
|
||||||
|
|
||||||
void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage )
|
|
||||||
{
|
|
||||||
/* TODO */
|
|
||||||
|
|
||||||
emit MessReadyForSending ( vecMessage );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO take care of mutexing ressources!!!!!!
|
// TODO take care of mutexing ressources!!!!!!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CProtocol::CProtocol() : iCounter ( 0 ), iOldRecID ( PROTMESSID_ILLEGAL ),
|
||||||
|
iOldRecCnt ( 0 )
|
||||||
|
{
|
||||||
|
SendMessQueue.clear();
|
||||||
|
|
||||||
|
// connections
|
||||||
|
QObject::connect ( &TimerSendMess, SIGNAL ( timeout() ),
|
||||||
|
this, SLOT ( OnTimerSendMess() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage,
|
||||||
|
const int iCnt,
|
||||||
|
const int iID )
|
||||||
|
{
|
||||||
|
// check if list is empty so that we have to initiate a send process
|
||||||
|
const bool bListWasEmpty = SendMessQueue.empty();
|
||||||
|
|
||||||
|
// create send message object for the queue
|
||||||
|
CSendMessage SendMessageObj ( vecMessage, iCnt, iID );
|
||||||
|
|
||||||
|
// we want to have a FIFO: we add at the end and take from the beginning
|
||||||
|
SendMessQueue.push_back ( SendMessageObj );
|
||||||
|
|
||||||
|
// if list was empty, initiate send process
|
||||||
|
if ( bListWasEmpty )
|
||||||
|
{
|
||||||
|
SendMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CProtocol::SendMessage()
|
||||||
|
{
|
||||||
|
// we have to check that list is not empty, since in another thread the
|
||||||
|
// last element of the list might have been erased
|
||||||
|
if ( !SendMessQueue.empty() )
|
||||||
|
{
|
||||||
|
// send message
|
||||||
|
emit MessReadyForSending ( SendMessQueue.front().vecMessage );
|
||||||
|
|
||||||
|
// start time-out timer if not active
|
||||||
|
if ( !TimerSendMess.isActive() )
|
||||||
|
{
|
||||||
|
TimerSendMess.start ( SEND_MESS_TIMEOUT_MS );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// no message to send, stop timer
|
||||||
|
TimerSendMess.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CProtocol::DeleteSendMessQueue()
|
||||||
|
{
|
||||||
|
// delete complete "send message queue"
|
||||||
|
SendMessQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
|
bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
|
||||||
const int iNumBytes )
|
const int iNumBytes )
|
||||||
|
@ -131,10 +181,20 @@ for ( int i = 0; i < iNumBytes; i++ ) {
|
||||||
{
|
{
|
||||||
case PROTMESSID_ACKN:
|
case PROTMESSID_ACKN:
|
||||||
|
|
||||||
// TODO
|
// extract data from stream and emit signal for received value
|
||||||
|
iPos = 0;
|
||||||
|
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
|
|
||||||
|
// check if this is the correct acknowledgment
|
||||||
|
if ( ( SendMessQueue.front().iCnt == iRecCounter ) &&
|
||||||
|
( SendMessQueue.front().iID == iData ) )
|
||||||
|
{
|
||||||
|
// message acknowledged, remove from queue
|
||||||
|
SendMessQueue.pop_front();
|
||||||
|
|
||||||
|
// send next message in queue
|
||||||
|
SendMessage();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -144,8 +204,10 @@ for ( int i = 0; i < iNumBytes; i++ ) {
|
||||||
iPos = 0;
|
iPos = 0;
|
||||||
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
|
|
||||||
// invoke message action and send acknowledge message
|
// invoke message action
|
||||||
emit ChangeJittBufSize ( iData );
|
emit ChangeJittBufSize ( iData );
|
||||||
|
|
||||||
|
// send acknowledge message
|
||||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -197,10 +259,28 @@ void CProtocol::CreateJitBufMes ( const int iJitBufSize )
|
||||||
iCounter++;
|
iCounter++;
|
||||||
|
|
||||||
// enqueue message
|
// enqueue message
|
||||||
EnqueueMessage ( vecNewMessage );
|
EnqueueMessage ( vecNewMessage, iCounter, PROTMESSID_JITT_BUF_SIZE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Message generation (parsing) *
|
* Message generation (parsing) *
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
#include <qtimer.h>
|
||||||
|
#include <list>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -42,6 +44,9 @@
|
||||||
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
|
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
|
||||||
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
|
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
|
||||||
|
|
||||||
|
// time out for message re-send if no acknowledgement was received
|
||||||
|
#define SEND_MESS_TIMEOUT_MS 400 // ms
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
class CProtocol : public QObject
|
class CProtocol : public QObject
|
||||||
|
@ -49,9 +54,8 @@ class CProtocol : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CProtocol () : iCounter ( 0 ),
|
CProtocol();
|
||||||
iOldRecID ( PROTMESSID_ILLEGAL ), iOldRecCnt ( 0 ) {}
|
virtual ~CProtocol() {}
|
||||||
virtual ~CProtocol () {}
|
|
||||||
|
|
||||||
void CreateJitBufMes ( const int iJitBufSize );
|
void CreateJitBufMes ( const int iJitBufSize );
|
||||||
|
|
||||||
|
@ -60,9 +64,35 @@ public:
|
||||||
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
|
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
|
||||||
const int iNumBytes );
|
const int iNumBytes );
|
||||||
|
|
||||||
protected:
|
void DeleteSendMessQueue ();
|
||||||
void EnqueueMessage ( CVector<uint8_t>& vecMessage );
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
class CSendMessage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CSendMessage() : vecMessage ( 0 ), iID ( PROTMESSID_ILLEGAL ),
|
||||||
|
iCnt ( 0 ) {}
|
||||||
|
CSendMessage ( const CVector<uint8_t>& nMess, const int iNCnt,
|
||||||
|
const int iNID ) : vecMessage ( nMess ), iID ( iNID ),
|
||||||
|
iCnt ( iNCnt ) {}
|
||||||
|
|
||||||
|
CSendMessage& operator= ( const CSendMessage& NewSendMess )
|
||||||
|
{
|
||||||
|
vecMessage.Init ( NewSendMess.vecMessage.Size() );
|
||||||
|
vecMessage = NewSendMess.vecMessage;
|
||||||
|
|
||||||
|
iID = NewSendMess.iID;
|
||||||
|
iCnt = NewSendMess.iCnt;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CVector<uint8_t> vecMessage;
|
||||||
|
int iID, iCnt;
|
||||||
|
};
|
||||||
|
|
||||||
|
void EnqueueMessage ( CVector<uint8_t>& vecMessage,
|
||||||
|
const int iCnt,
|
||||||
|
const int iID );
|
||||||
|
|
||||||
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
|
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
|
||||||
int& iCnt,
|
int& iCnt,
|
||||||
|
@ -83,9 +113,16 @@ protected:
|
||||||
unsigned int& iPos,
|
unsigned int& iPos,
|
||||||
const unsigned int iNumOfBytes );
|
const unsigned int iNumOfBytes );
|
||||||
|
|
||||||
CVector<uint8_t> vecMessage;
|
void SendMessage();
|
||||||
|
|
||||||
uint8_t iCounter;
|
uint8_t iCounter;
|
||||||
int iOldRecID, iOldRecCnt;
|
int iOldRecID, iOldRecCnt;
|
||||||
|
std::list<CSendMessage> SendMessQueue;
|
||||||
|
QTimer TimerSendMess;
|
||||||
|
QMutex Mutex;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void OnTimerSendMess() { SendMessage(); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// transmitting
|
// transmitting
|
||||||
|
|
Loading…
Reference in a new issue