added new file for protocol (just template right now), new code style
This commit is contained in:
parent
270725688f
commit
dd914c411c
14 changed files with 351 additions and 160 deletions
|
@ -13,6 +13,7 @@ llcon_SOURCES = ../src/buffer.cpp \
|
||||||
../src/llconserverdlg.cpp \
|
../src/llconserverdlg.cpp \
|
||||||
../src/server.cpp \
|
../src/server.cpp \
|
||||||
../src/settings.cpp \
|
../src/settings.cpp \
|
||||||
|
../src/protocol.cpp \
|
||||||
../src/multicolorled.cpp \
|
../src/multicolorled.cpp \
|
||||||
sound.cpp \
|
sound.cpp \
|
||||||
../src/buffer.h \
|
../src/buffer.h \
|
||||||
|
@ -26,6 +27,7 @@ llcon_SOURCES = ../src/buffer.cpp \
|
||||||
../src/client.h \
|
../src/client.h \
|
||||||
../src/server.h \
|
../src/server.h \
|
||||||
../src/settings.h \
|
../src/settings.h \
|
||||||
|
../src/protocol.h \
|
||||||
../src/multicolorled.h \
|
../src/multicolorled.h \
|
||||||
../src/llconserverdlg.h \
|
../src/llconserverdlg.h \
|
||||||
../src/llconclientdlg.h \
|
../src/llconclientdlg.h \
|
||||||
|
|
|
@ -77,10 +77,14 @@ bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
|
||||||
iCurChanID = GetFreeChan ();
|
iCurChanID = GetFreeChan ();
|
||||||
|
|
||||||
if ( iCurChanID != INVALID_CHANNEL_ID )
|
if ( iCurChanID != INVALID_CHANNEL_ID )
|
||||||
|
{
|
||||||
vecChannels[iCurChanID].SetAddress ( HostAdr );
|
vecChannels[iCurChanID].SetAddress ( HostAdr );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
bChanOK = false; /* no free channel available */
|
bChanOK = false; /* no free channel available */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* put received data in jitter buffer ----------------------------------- */
|
/* put received data in jitter buffer ----------------------------------- */
|
||||||
|
@ -88,10 +92,14 @@ bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
|
||||||
{
|
{
|
||||||
/* put packet in socket buffer */
|
/* put packet in socket buffer */
|
||||||
if ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) )
|
if ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) )
|
||||||
|
{
|
||||||
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID );
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID );
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Mutex.unlock ();
|
Mutex.unlock ();
|
||||||
|
|
||||||
|
@ -213,25 +221,6 @@ void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
|
||||||
Mutex.unlock ();
|
Mutex.unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CChannel::GetTimeStampIdx ()
|
|
||||||
{
|
|
||||||
/* only send time stamp index after a pre-defined number of packets */
|
|
||||||
if ( iTimeStampActCnt > 0 )
|
|
||||||
{
|
|
||||||
iTimeStampActCnt--;
|
|
||||||
return INVALID_TIME_STAMP_IDX;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* reset time stamp activation counter */
|
|
||||||
iTimeStampActCnt = NUM_BL_TIME_STAMPS - 1;
|
|
||||||
|
|
||||||
/* wraps around automatically */
|
|
||||||
byTimeStampIdxCnt++;
|
|
||||||
return byTimeStampIdxCnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
||||||
{
|
{
|
||||||
if (IsConnected())
|
if (IsConnected())
|
||||||
|
@ -262,9 +251,6 @@ bool CChannel::PutData(const CVector<unsigned char>& vecbyData,
|
||||||
|
|
||||||
/* do resampling to compensate for sample rate offsets in the
|
/* do resampling to compensate for sample rate offsets in the
|
||||||
different sound cards of the clients */
|
different sound cards of the clients */
|
||||||
// we should not do resampling here since we already have resampling
|
|
||||||
// in the client audio path, we could use this resampling for this
|
|
||||||
// sample rate correction, too
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
||||||
vecdResInData[i] = (double) vecsData[i];
|
vecdResInData[i] = (double) vecsData[i];
|
||||||
|
@ -339,6 +325,24 @@ CVector<unsigned char> CChannel::PrepSendPacket(const CVector<short>& vecsNPacke
|
||||||
return vecbySendBuf;
|
return vecbySendBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CChannel::GetTimeStampIdx ()
|
||||||
|
{
|
||||||
|
/* only send time stamp index after a pre-defined number of packets */
|
||||||
|
if ( iTimeStampActCnt > 0 )
|
||||||
|
{
|
||||||
|
iTimeStampActCnt--;
|
||||||
|
return INVALID_TIME_STAMP_IDX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* reset time stamp activation counter */
|
||||||
|
iTimeStampActCnt = NUM_BL_TIME_STAMPS - 1;
|
||||||
|
|
||||||
|
/* wraps around automatically */
|
||||||
|
byTimeStampIdxCnt++;
|
||||||
|
return byTimeStampIdxCnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
|
@ -395,8 +399,6 @@ fflush(pFile);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* calculate linear regression for sample rate estimation */
|
/* calculate linear regression for sample rate estimation */
|
||||||
/* first, calculate averages */
|
/* first, calculate averages */
|
||||||
double dTimeAv = 0;
|
double dTimeAv = 0;
|
||||||
|
@ -434,15 +436,10 @@ fflush(pFile);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static FILE* pFile = fopen("v.dat", "w");
|
static FILE* pFile = fopen("v.dat", "w");
|
||||||
fprintf(pFile, "%e\n", dSamRateEst);
|
fprintf(pFile, "%e\n", dSamRateEst);
|
||||||
fflush(pFile);
|
fflush(pFile);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
||||||
|
|
||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
#include <qdatetime.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "audiocompr.h"
|
#include "audiocompr.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "resample.h"
|
#include "resample.h"
|
||||||
#include "qdatetime.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
/* time interval of taps for sample rate offset estimation (time stamps) */
|
/* time interval of taps for sample rate offset estimation (time stamps) */
|
||||||
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
|
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
|
||||||
|
|
||||||
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / MIN_BLOCK_DURATION_MS )
|
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / BLOCK_DURATION_MS )
|
||||||
#define VEC_LEN_SAM_OFFS_EST ( TIME_INT_SAM_OFFS_EST / INTVL_TAPS_SAM_OFF_SET )
|
#define VEC_LEN_SAM_OFFS_EST ( TIME_INT_SAM_OFFS_EST / INTVL_TAPS_SAM_OFF_SET )
|
||||||
|
|
||||||
/* length of the moving average buffer for response time measurement */
|
/* length of the moving average buffer for response time measurement */
|
||||||
|
|
|
@ -68,9 +68,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
||||||
OnTimerStatus ();
|
OnTimerStatus ();
|
||||||
|
|
||||||
/* init sample rate offset label */
|
/* init sample rate offset label */
|
||||||
// TextSamRateOffsValue->setText ( "0 Hz" );
|
TextSamRateOffsValue->setText ( "0 Hz" );
|
||||||
// FIXME disable sample rate estimation result label since estimation does not work
|
|
||||||
TextSamRateOffsValue->setText ( "---" );
|
|
||||||
|
|
||||||
/* init connection button text */
|
/* init connection button text */
|
||||||
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
|
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
|
||||||
|
@ -275,17 +273,9 @@ void CLlconClientDlg::OnTimerStatus()
|
||||||
TextLabelStatus->setText(tr("disconnected"));
|
TextLabelStatus->setText(tr("disconnected"));
|
||||||
|
|
||||||
/* update sample rate offset label */
|
/* update sample rate offset label */
|
||||||
// FIXME disable sample rate estimation result label since estimation does not work
|
|
||||||
/*
|
|
||||||
QString strSamRaOffs;
|
QString strSamRaOffs;
|
||||||
|
strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset(), 'f', 2);
|
||||||
// FIXME: sample rate estimation result must be corrected since we use
|
|
||||||
// smaller buffers in client now. Actual estimation should be fixed, not here
|
|
||||||
|
|
||||||
strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset() *
|
|
||||||
MIN_BLOCK_DURATION_MS / BLOCK_DURATION_MS, 'f', 2);
|
|
||||||
TextSamRateOffsValue->setText(strSamRaOffs + " Hz");
|
TextSamRateOffsValue->setText(strSamRaOffs + " Hz");
|
||||||
*/
|
|
||||||
|
|
||||||
/* response time */
|
/* response time */
|
||||||
TextLabelStdDevTimer->setText(QString().
|
TextLabelStdDevTimer->setText(QString().
|
||||||
|
|
|
@ -108,6 +108,7 @@ void CLlconServerDlg::OnTimer()
|
||||||
{
|
{
|
||||||
CVector<CHostAddress> vecHostAddresses;
|
CVector<CHostAddress> vecHostAddresses;
|
||||||
CVector<double> vecdSamOffs;
|
CVector<double> vecdSamOffs;
|
||||||
|
double dCurTiStdDev;
|
||||||
|
|
||||||
ListViewMutex.lock();
|
ListViewMutex.lock();
|
||||||
|
|
||||||
|
@ -140,9 +141,16 @@ void CLlconServerDlg::OnTimer()
|
||||||
|
|
||||||
ListViewMutex.unlock();
|
ListViewMutex.unlock();
|
||||||
|
|
||||||
/* response time */
|
/* response time (if available) */
|
||||||
|
if ( Server.GetTimingStdDev ( dCurTiStdDev ) )
|
||||||
|
{
|
||||||
TextLabelResponseTime->setText(QString().
|
TextLabelResponseTime->setText(QString().
|
||||||
setNum(Server.GetTimingStdDev(), 'f', 2) + " ms");
|
setNum(dCurTiStdDev, 'f', 2) + " ms");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TextLabelResponseTime->setText("---");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLlconServerDlg::OnSliderNetBuf(int value)
|
void CLlconServerDlg::OnSliderNetBuf(int value)
|
||||||
|
|
|
@ -49,8 +49,10 @@ int main(int argc, char** argv)
|
||||||
/* only "-s" is supported right now */
|
/* only "-s" is supported right now */
|
||||||
std::string strShortOpt = "-s";
|
std::string strShortOpt = "-s";
|
||||||
if ( !strShortOpt.compare ( argv[1] ) )
|
if ( !strShortOpt.compare ( argv[1] ) )
|
||||||
|
{
|
||||||
bIsClient = false;
|
bIsClient = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( bIsClient )
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
|
@ -98,7 +100,8 @@ void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam,
|
||||||
/* In case of simulation no events should be generated */
|
/* In case of simulation no events should be generated */
|
||||||
if ( pApp != NULL )
|
if ( pApp != NULL )
|
||||||
{
|
{
|
||||||
CLlconEvent* LlconEv = new CLlconEvent ( MessID, iMessageParam, iChanNum );
|
CLlconEvent* LlconEv =
|
||||||
|
new CLlconEvent ( MessID, iMessageParam, iChanNum );
|
||||||
|
|
||||||
/* Qt will delete the event object when done */
|
/* Qt will delete the event object when done */
|
||||||
QThread::postEvent ( pApp->mainWidget (), LlconEv );
|
QThread::postEvent ( pApp->mainWidget (), LlconEv );
|
||||||
|
|
31
src/protocol.cpp
Executable file
31
src/protocol.cpp
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
/******************************************************************************\
|
||||||
|
* Copyright (c) 2004-2006
|
||||||
|
*
|
||||||
|
* Author(s):
|
||||||
|
* Volker Fischer
|
||||||
|
*
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
\******************************************************************************/
|
||||||
|
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Implementation *************************************************************/
|
||||||
|
|
||||||
|
// TODO
|
63
src/protocol.h
Executable file
63
src/protocol.h
Executable file
|
@ -0,0 +1,63 @@
|
||||||
|
/******************************************************************************\
|
||||||
|
* Copyright (c) 2004-2006
|
||||||
|
*
|
||||||
|
* Author(s):
|
||||||
|
* Volker Fischer
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
\******************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_)
|
||||||
|
#define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Classes ********************************************************************/
|
||||||
|
class CProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CProtocol() {}
|
||||||
|
virtual ~CProtocol() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CServerProtocol : public CProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CServerProtocol() {}
|
||||||
|
virtual ~CServerProtocol() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CClientProtocol : public CProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CClientProtocol() {}
|
||||||
|
virtual ~CClientProtocol() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */
|
|
@ -38,6 +38,8 @@ CServer::CServer() : Socket(&ChannelSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::Start()
|
void CServer::Start()
|
||||||
|
{
|
||||||
|
if ( !IsRunning () )
|
||||||
{
|
{
|
||||||
/* start main timer */
|
/* start main timer */
|
||||||
Timer.start(BLOCK_DURATION_MS);
|
Timer.start(BLOCK_DURATION_MS);
|
||||||
|
@ -45,6 +47,13 @@ void CServer::Start()
|
||||||
/* init time for response time evaluation */
|
/* init time for response time evaluation */
|
||||||
TimeLastBlock = QTime::currentTime();
|
TimeLastBlock = QTime::currentTime();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServer::Stop()
|
||||||
|
{
|
||||||
|
/* stop main timer */
|
||||||
|
Timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
void CServer::OnTimer()
|
void CServer::OnTimer()
|
||||||
{
|
{
|
||||||
|
@ -53,28 +62,31 @@ void CServer::OnTimer()
|
||||||
|
|
||||||
/* get data from all connected clients */
|
/* get data from all connected clients */
|
||||||
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
|
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
|
||||||
|
const int iNumClients = vecvecdData.Size ();
|
||||||
|
|
||||||
|
/* Check if at least one client is connected. If not, stop server until
|
||||||
|
one client is connected */
|
||||||
|
if ( iNumClients != 0 )
|
||||||
|
{
|
||||||
/* actual processing of audio data -> mix */
|
/* actual processing of audio data -> mix */
|
||||||
vecsSendData = ProcessData ( vecvecdData );
|
vecsSendData = ProcessData ( vecvecdData );
|
||||||
|
|
||||||
/* get number of connected clients from vector size */
|
|
||||||
const int iNumClients = vecvecdData.Size();
|
|
||||||
|
|
||||||
/* send the same data to all connected clients */
|
/* send the same data to all connected clients */
|
||||||
for ( int i = 0; i < iNumClients; i++ )
|
for ( int i = 0; i < iNumClients; i++ )
|
||||||
{
|
{
|
||||||
Socket.SendPacket(ChannelSet.PrepSendPacket(vecChanID[i], vecsSendData),
|
Socket.SendPacket (
|
||||||
|
ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ),
|
||||||
ChannelSet.GetAddress ( vecChanID[i] ),
|
ChannelSet.GetAddress ( vecChanID[i] ),
|
||||||
ChannelSet.GetTimeStampIdx ( vecChanID[i] ) );
|
ChannelSet.GetTimeStampIdx ( vecChanID[i] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* update response time measurement ------------------------------------- */
|
/* update response time measurement --------------------------------- */
|
||||||
/* add time difference */
|
/* add time difference */
|
||||||
const QTime CurTime = QTime::currentTime ();
|
const QTime CurTime = QTime::currentTime ();
|
||||||
|
|
||||||
/* we want to calculate the standard deviation (we assume that the mean is
|
/* we want to calculate the standard deviation (we assume that the mean
|
||||||
correct at the block period time) */
|
is correct at the block period time) */
|
||||||
const double dCurAddVal =
|
const double dCurAddVal =
|
||||||
( (double) TimeLastBlock.msecsTo ( CurTime ) - BLOCK_DURATION_MS );
|
( (double) TimeLastBlock.msecsTo ( CurTime ) - BLOCK_DURATION_MS );
|
||||||
|
|
||||||
|
@ -83,6 +95,17 @@ void CServer::OnTimer()
|
||||||
/* store old time value */
|
/* store old time value */
|
||||||
TimeLastBlock = CurTime;
|
TimeLastBlock = CurTime;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* disable server */
|
||||||
|
|
||||||
|
// TODO not yet working since the socket does not have access to the server
|
||||||
|
// object and cannot restart the server if packets arrive...
|
||||||
|
|
||||||
|
// Stop ();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
|
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
|
||||||
{
|
{
|
||||||
|
@ -111,3 +134,23 @@ CVector<short> CServer::ProcessData(CVector<CVector<double> >& vecvecdData)
|
||||||
|
|
||||||
return vecsOutData;
|
return vecsOutData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CServer::GetTimingStdDev ( double& dCurTiStdDev )
|
||||||
|
{
|
||||||
|
dCurTiStdDev = 0.0; /* init return value */
|
||||||
|
|
||||||
|
/* only return value if server is active and the actual measurement is
|
||||||
|
updated */
|
||||||
|
if ( IsRunning () )
|
||||||
|
{
|
||||||
|
/* we want to return the standard deviation, for that we need to calculate
|
||||||
|
the sqaure root */
|
||||||
|
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage () );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -46,13 +46,13 @@ public:
|
||||||
virtual ~CServer () {}
|
virtual ~CServer () {}
|
||||||
|
|
||||||
void Start ();
|
void Start ();
|
||||||
|
void Stop ();
|
||||||
|
bool IsRunning() { return Timer.isActive (); }
|
||||||
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
||||||
CVector<double>& vecdSamOffs )
|
CVector<double>& vecdSamOffs )
|
||||||
{ ChannelSet.GetConCliParam ( vecHostAddresses, vecdSamOffs ); }
|
{ ChannelSet.GetConCliParam ( vecHostAddresses, vecdSamOffs ); }
|
||||||
|
|
||||||
/* we want to return the standard deviation. For that we need to calculate
|
bool GetTimingStdDev ( double& dCurTiStdDev );
|
||||||
the sqaure root */
|
|
||||||
double GetTimingStdDev() {return sqrt(RespTimeMoAvBuf.GetAverage());}
|
|
||||||
|
|
||||||
CChannelSet* GetChannelSet () { return &ChannelSet; }
|
CChannelSet* GetChannelSet () { return &ChannelSet; }
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ void CSocket::Init()
|
||||||
{
|
{
|
||||||
/* if server and client is on same machine, decrease port number by
|
/* if server and client is on same machine, decrease port number by
|
||||||
one by definition */
|
one by definition */
|
||||||
bSuccess =
|
bSuccess = SocketDevice.bind (
|
||||||
SocketDevice.bind(QHostAddress((Q_UINT32) 0) /* INADDR_ANY */,
|
QHostAddress( (Q_UINT32) 0 ) /* INADDR_ANY */,
|
||||||
LLCON_PORT_NUMBER - 1 );
|
LLCON_PORT_NUMBER - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,14 +67,16 @@ void CSocket::Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSocket::SendPacket( const CVector<unsigned char>& vecbySendBuf,
|
void CSocket::SendPacket( const CVector<unsigned char>& vecbySendBuf,
|
||||||
const CHostAddress& HostAddr, const int iTimeStampIdx)
|
const CHostAddress& HostAddr,
|
||||||
|
const int iTimeStampIdx )
|
||||||
{
|
{
|
||||||
const int iVecSizeOut = vecbySendBuf.Size ();
|
const int iVecSizeOut = vecbySendBuf.Size ();
|
||||||
|
|
||||||
if ( iVecSizeOut != 0 )
|
if ( iVecSizeOut != 0 )
|
||||||
{
|
{
|
||||||
/* send packet through network */
|
/* send packet through network */
|
||||||
SocketDevice.writeBlock ((const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
|
SocketDevice.writeBlock (
|
||||||
|
(const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
|
||||||
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
|
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +97,9 @@ void CSocket::OnDataReceived()
|
||||||
|
|
||||||
/* check if an error occurred */
|
/* check if an error occurred */
|
||||||
if ( iNumBytesRead < 0 )
|
if ( iNumBytesRead < 0 )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* get host address of client */
|
/* get host address of client */
|
||||||
CHostAddress RecHostAddr ( SocketDevice.peerAddress (),
|
CHostAddress RecHostAddr ( SocketDevice.peerAddress (),
|
||||||
|
@ -109,10 +113,14 @@ void CSocket::OnDataReceived()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
|
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
|
||||||
|
{
|
||||||
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN );
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED );
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* server */
|
/* server */
|
||||||
|
|
38
src/util.h
38
src/util.h
|
@ -30,6 +30,7 @@
|
||||||
#include <qwhatsthis.h>
|
#include <qwhatsthis.h>
|
||||||
#include <qtextview.h>
|
#include <qtextview.h>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
|
#include <qdatetime.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
using namespace std; /* Because of the library: "vector" */
|
using namespace std; /* Because of the library: "vector" */
|
||||||
|
@ -378,4 +379,41 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Time conversion ---------------------------------------------------------- */
|
||||||
|
// needed for ping measurement
|
||||||
|
class CTimeConv
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// QTime to network time vector
|
||||||
|
static CVector<unsigned char> QTi2NetTi ( const QTime qTiIn )
|
||||||
|
{
|
||||||
|
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
|
||||||
|
CVector<unsigned char> veccNetTi ( 5 );
|
||||||
|
|
||||||
|
veccNetTi[0] = static_cast<unsigned char> ( qTiIn.hour () );
|
||||||
|
veccNetTi[1] = static_cast<unsigned char> ( qTiIn.minute () );
|
||||||
|
veccNetTi[2] = static_cast<unsigned char> ( qTiIn.second () );
|
||||||
|
|
||||||
|
const int iMs = qTiIn.msec ();
|
||||||
|
veccNetTi[3] = static_cast<unsigned char> ( ( iMs >> 8 ) & 255 );
|
||||||
|
veccNetTi[4] = static_cast<unsigned char> ( iMs & 255 );
|
||||||
|
|
||||||
|
return veccNetTi;
|
||||||
|
}
|
||||||
|
|
||||||
|
// network time vector to QTime
|
||||||
|
static QTime NetTi2QTi ( const CVector<unsigned char> netTiIn )
|
||||||
|
{
|
||||||
|
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
|
||||||
|
return QTime (
|
||||||
|
static_cast<int> ( netTiIn[0] ), // hour
|
||||||
|
static_cast<int> ( netTiIn[1] ), // minute
|
||||||
|
static_cast<int> ( netTiIn[2] ), // seconds
|
||||||
|
// msec
|
||||||
|
static_cast<int> ( ( netTiIn[3] << 8 ) | netTiIn[4] )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */
|
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */
|
||||||
|
|
|
@ -178,6 +178,10 @@ SOURCE=..\src\multicolorled.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\protocol.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\resample.cpp
|
SOURCE=..\src\resample.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@ -238,6 +242,10 @@ SOURCE=..\src\multicolorled.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\protocol.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\resample.h
|
SOURCE=..\src\resample.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
Loading…
Reference in a new issue