more protocol implementations
This commit is contained in:
parent
ab19f4f2ae
commit
5308f3bf85
6 changed files with 106 additions and 63 deletions
|
@ -216,8 +216,9 @@ CChannel::CChannel ()
|
|||
|
||||
/* connections ---------------------------------------------------------- */
|
||||
// just route message through this class
|
||||
QObject::connect ( &Protocol, SIGNAL ( MessReadyForSending () ),
|
||||
SIGNAL ( MessReadyForSending () ) );
|
||||
QObject::connect ( &Protocol,
|
||||
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
||||
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ) );
|
||||
|
||||
QObject::connect ( &Protocol, SIGNAL ( ChangeJittBufSize ( int ) ),
|
||||
this, SLOT ( OnJittBufSizeChange ( int ) ) );
|
||||
|
@ -235,6 +236,9 @@ void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
|
|||
|
||||
void CChannel::OnJittBufSizeChange ( int iNewJitBufSize )
|
||||
{
|
||||
// TEST
|
||||
qDebug ( "new jitter buffer size: %d", iNewJitBufSize );
|
||||
|
||||
SetSockBufSize ( MIN_BLOCK_SIZE_SAMPLES, iNewJitBufSize );
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ public:
|
|||
bool GetData ( CVector<double>& vecdData );
|
||||
|
||||
CVector<unsigned char> PrepSendPacket ( const CVector<short>& vecsNPacket );
|
||||
CVector<unsigned char> GetSendMessage () { return Protocol.GetSendMessage (); }
|
||||
|
||||
bool IsConnected () const { return iConTimeOut > 0; }
|
||||
|
||||
|
@ -138,7 +137,7 @@ public slots:
|
|||
void OnJittBufSizeChange ( int iNewJitBufSize );
|
||||
|
||||
signals:
|
||||
void MessReadyForSending ();
|
||||
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -32,15 +32,23 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ),
|
|||
bReverbOnLeftChan ( false )
|
||||
{
|
||||
// connection for protocol
|
||||
QObject::connect ( &Channel, SIGNAL ( MessReadyForSending () ),
|
||||
this, SLOT ( OnSendProtMessage () ) );
|
||||
QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
||||
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
|
||||
}
|
||||
|
||||
void CClient::OnSendProtMessage ()
|
||||
void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||
{
|
||||
|
||||
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
|
||||
CVector<unsigned char> vecbyDataConv ( vecMessage.Size () );
|
||||
for ( int i = 0; i < vecMessage.Size (); i++ ) {
|
||||
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
|
||||
}
|
||||
|
||||
|
||||
// the protocol queries me to call the function to send the message
|
||||
// send it through the network
|
||||
Socket.SendPacket ( Channel.GetSendMessage (),
|
||||
Socket.SendPacket ( vecbyDataConv,
|
||||
Channel.GetAddress () );
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ protected:
|
|||
QTime TimeLastBlock;
|
||||
|
||||
public slots:
|
||||
void OnSendProtMessage ();
|
||||
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
*
|
||||
|
||||
Protocol message definition
|
||||
---------------------------
|
||||
|
||||
- All messages received need to be acknowledged by an acknowledge packet
|
||||
|
||||
|
||||
|
||||
MAIN FRAME
|
||||
|
@ -26,13 +30,21 @@ MAIN FRAME
|
|||
MESSAGES
|
||||
--------
|
||||
|
||||
- Acknowledgement message: PROTMESSID_ACKN
|
||||
|
||||
+-----------------------------------+
|
||||
| 2 bytes ID of message to be ackn. |
|
||||
+-----------------------------------+
|
||||
|
||||
note: the cnt value is the same as of the message to be acknowledged
|
||||
|
||||
|
||||
- Jitter buffer size: PROTMESSID_JITT_BUF_SIZE
|
||||
|
||||
+--------------------------+
|
||||
| 2 bytes number of blocks |
|
||||
+--------------------------+
|
||||
|
||||
This message requires acknowledgement
|
||||
|
||||
|
||||
|
||||
|
@ -60,30 +72,17 @@ MESSAGES
|
|||
|
||||
|
||||
/* Implementation *************************************************************/
|
||||
CVector<unsigned char> CProtocol::GetSendMessage ()
|
||||
{
|
||||
// TEST, TODO implement protocol handling here (timers, etc.)
|
||||
|
||||
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
|
||||
CVector<unsigned char> vecbyDataConv ( vecMessage.Size () );
|
||||
for ( int i = 0; i < vecMessage.Size (); i++ ) {
|
||||
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
|
||||
}
|
||||
|
||||
return vecbyDataConv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage )
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
emit MessReadyForSending ();
|
||||
emit MessReadyForSending ( vecMessage );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TODO take care of mutexing ressources!!!!!!
|
||||
|
||||
|
||||
|
||||
|
@ -107,42 +106,55 @@ for ( int i = 0; i < iNumBytes; i++ ) {
|
|||
}
|
||||
|
||||
|
||||
// In case we received a message and returned an answer but our answer did
|
||||
// not make it to the receiver, he will resend his message. We check here
|
||||
// if the message is the same as the old one, and if this is the case, just
|
||||
// resend our old answer again
|
||||
// TODO
|
||||
|
||||
|
||||
// important: vecbyDataConv must have iNumBytes to get it work!!!
|
||||
if ( ParseMessageFrame ( vecbyDataConv, iRecCounter, iRecID, vecData ) )
|
||||
{
|
||||
|
||||
|
||||
// TEST
|
||||
qDebug ( "parsing successful" );
|
||||
|
||||
|
||||
// In case we received a message and returned an answer but our answer
|
||||
// did not make it to the receiver, he will resend his message. We check
|
||||
// here if the message is the same as the old one, and if this is the
|
||||
// case, just resend our old answer again
|
||||
if ( ( iOldRecID == iRecID ) && ( iOldRecCnt == iRecCounter ) )
|
||||
{
|
||||
// acknowledgments are not acknowledged
|
||||
if ( iRecID != PROTMESSID_ACKN )
|
||||
{
|
||||
// re-send acknowledgement
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// check which type of message we received and do action
|
||||
switch ( iRecID )
|
||||
{
|
||||
case PROTMESSID_ACKN:
|
||||
|
||||
// TODO implement acknowledge code -> do implementation in CProtocol since
|
||||
// it can be used in the server protocol, too
|
||||
// TODO
|
||||
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case PROTMESSID_JITT_BUF_SIZE:
|
||||
|
||||
// TODO acknowledgement
|
||||
|
||||
// extract data from stream and emit signal for received value
|
||||
iPos = 0;
|
||||
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||
|
||||
// invoke message action and send acknowledge message
|
||||
emit ChangeJittBufSize ( iData );
|
||||
CreateAndSendAcknMess ( iRecID, iRecCounter );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// save current message ID and counter to find out if message was re-sent
|
||||
iOldRecID = iRecID;
|
||||
iOldRecCnt = iRecCounter;
|
||||
|
||||
return true; // everything was ok
|
||||
}
|
||||
|
@ -152,23 +164,40 @@ qDebug ( "parsing successful" );
|
|||
}
|
||||
}
|
||||
|
||||
void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt )
|
||||
{
|
||||
CVector<uint8_t> vecAcknMessage;
|
||||
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
|
||||
unsigned int iPos = 0; // init position pointer
|
||||
|
||||
// build data vector
|
||||
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iID ), 2 );
|
||||
|
||||
// build complete message
|
||||
GenMessageFrame ( vecAcknMessage, iCnt, PROTMESSID_ACKN, vecData );
|
||||
|
||||
// immediately send acknowledge message
|
||||
emit MessReadyForSending ( vecAcknMessage );
|
||||
}
|
||||
|
||||
void CProtocol::CreateJitBufMes ( const int iJitBufSize )
|
||||
{
|
||||
CVector<uint8_t> vecData ( 2 );
|
||||
unsigned int iPos = 0;
|
||||
CVector<uint8_t> vecNewMessage;
|
||||
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
|
||||
unsigned int iPos = 0; // init position pointer
|
||||
|
||||
// build data vector
|
||||
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iJitBufSize ), 2 );
|
||||
|
||||
// build complete message
|
||||
GenMessageFrame ( vecMessage, iCounter, PROTMESSID_JITT_BUF_SIZE, vecData );
|
||||
GenMessageFrame ( vecNewMessage, iCounter, PROTMESSID_JITT_BUF_SIZE, vecData );
|
||||
|
||||
// increase counter (wraps around automatically)
|
||||
// TODO: make it thread safe!!!!!!!!!!!!
|
||||
iCounter++;
|
||||
|
||||
// enqueue message
|
||||
EnqueueMessage ( vecMessage );
|
||||
EnqueueMessage ( vecNewMessage );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
|
||||
/* Definitions ****************************************************************/
|
||||
// protocol message IDs
|
||||
#define PROTMESSID_ACKN 0 // acknowledge
|
||||
#define PROTMESSID_ILLEGAL 0 // illegal ID
|
||||
#define PROTMESSID_ACKN 1 // acknowledge
|
||||
#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size
|
||||
#define PROTMESSID_PING 11 // for measuring ping time
|
||||
|
||||
|
@ -48,16 +49,17 @@ class CProtocol : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CProtocol () : iCounter ( 0 ) {}
|
||||
CProtocol () : iCounter ( 0 ),
|
||||
iOldRecID ( PROTMESSID_ILLEGAL ), iOldRecCnt ( 0 ) {}
|
||||
virtual ~CProtocol () {}
|
||||
|
||||
void CreateJitBufMes ( const int iJitBufSize );
|
||||
|
||||
void CreateAndSendAcknMess ( const int& iID, const int& iCnt );
|
||||
|
||||
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
|
||||
const int iNumBytes );
|
||||
|
||||
CVector<unsigned char> GetSendMessage ();
|
||||
|
||||
protected:
|
||||
void EnqueueMessage ( CVector<uint8_t>& vecMessage );
|
||||
|
||||
|
@ -83,10 +85,11 @@ protected:
|
|||
|
||||
CVector<uint8_t> vecMessage;
|
||||
uint8_t iCounter;
|
||||
int iOldRecID, iOldRecCnt;
|
||||
|
||||
signals:
|
||||
// transmitting
|
||||
void MessReadyForSending ();
|
||||
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
||||
|
||||
// receiving
|
||||
void ChangeJittBufSize ( int iNewJitBufSize );
|
||||
|
|
Loading…
Reference in a new issue