diff --git a/linux/Makefile.am b/linux/Makefile.am index 6e0360b0..02aa2831 100755 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -13,7 +13,8 @@ llcon_SOURCES = ../src/buffer.cpp \ ../src/llconserverdlg.cpp \ ../src/server.cpp \ ../src/settings.cpp \ - ../src/multicolorled.cpp \ + ../src/protocol.cpp \ + ../src/multicolorled.cpp \ sound.cpp \ ../src/buffer.h \ ../src/global.h \ @@ -26,6 +27,7 @@ llcon_SOURCES = ../src/buffer.cpp \ ../src/client.h \ ../src/server.h \ ../src/settings.h \ + ../src/protocol.h \ ../src/multicolorled.h \ ../src/llconserverdlg.h \ ../src/llconclientdlg.h \ diff --git a/src/channel.cpp b/src/channel.cpp index 17790821..ece0b8b4 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -63,37 +63,45 @@ int CChannelSet::CheckAddr(const CHostAddress& Addr) bool CChannelSet::PutData(const CVector& vecbyRecBuf, const int iNumBytesRead, const CHostAddress& HostAdr) { - Mutex.lock(); + Mutex.lock (); /* get channel ID ------------------------------------------------------- */ bool bChanOK = true; /* check address */ - int iCurChanID = CheckAddr(HostAdr); + int iCurChanID = CheckAddr ( HostAdr ); - if (iCurChanID == INVALID_CHANNEL_ID) + if ( iCurChanID == INVALID_CHANNEL_ID ) { /* a new client is calling, look for free channel */ - iCurChanID = GetFreeChan(); + iCurChanID = GetFreeChan (); - if (iCurChanID != INVALID_CHANNEL_ID) - vecChannels[iCurChanID].SetAddress(HostAdr); - else - bChanOK = false; /* no free channel available */ + if ( iCurChanID != INVALID_CHANNEL_ID ) + { + vecChannels[iCurChanID].SetAddress ( HostAdr ); + } + else + { + bChanOK = false; /* no free channel available */ + } } /* put received data in jitter buffer ----------------------------------- */ - if (bChanOK) + if ( bChanOK ) { /* put packet in socket buffer */ - if (vecChannels[iCurChanID].PutData(vecbyRecBuf, iNumBytesRead)) - PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID); - else - PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID); + if ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) ) + { + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID ); + } + else + { + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID ); + } } - Mutex.unlock(); + Mutex.unlock (); return !bChanOK; /* return 1 if error */ } @@ -213,25 +221,6 @@ void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks ) 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) { if (IsConnected()) @@ -262,9 +251,6 @@ bool CChannel::PutData(const CVector& vecbyData, /* do resampling to compensate for sample rate offsets in the 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++) vecdResInData[i] = (double) vecsData[i]; @@ -338,7 +324,25 @@ CVector CChannel::PrepSendPacket(const CVector& vecsNPacke 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 */ /* first, calculate averages */ double dTimeAv = 0; @@ -434,15 +436,10 @@ fflush(pFile); */ } - - /* static FILE* pFile = fopen("v.dat", "w"); fprintf(pFile, "%e\n", dSamRateEst); fflush(pFile); */ - - - } diff --git a/src/channel.h b/src/channel.h index e535c95f..62e9278a 100755 --- a/src/channel.h +++ b/src/channel.h @@ -26,12 +26,12 @@ #define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ #include +#include #include "global.h" #include "buffer.h" #include "audiocompr.h" #include "util.h" #include "resample.h" -#include "qdatetime.h" /* Definitions ****************************************************************/ diff --git a/src/global.h b/src/global.h index 1be219e5..407d5a18 100755 --- a/src/global.h +++ b/src/global.h @@ -98,7 +98,7 @@ /* time interval of taps for sample rate offset estimation (time stamps) */ #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 ) /* length of the moving average buffer for response time measurement */ diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index ac8a844c..e1e86d4a 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -68,9 +68,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, OnTimerStatus (); /* init sample rate offset label */ -// TextSamRateOffsValue->setText ( "0 Hz" ); -// FIXME disable sample rate estimation result label since estimation does not work -TextSamRateOffsValue->setText ( "---" ); + TextSamRateOffsValue->setText ( "0 Hz" ); /* init connection button text */ PushButtonConnect->setText ( CON_BUT_CONNECTTEXT ); @@ -275,17 +273,9 @@ void CLlconClientDlg::OnTimerStatus() TextLabelStatus->setText(tr("disconnected")); /* update sample rate offset label */ -// FIXME disable sample rate estimation result label since estimation does not work -/* QString strSamRaOffs; - -// 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); + strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset(), 'f', 2); TextSamRateOffsValue->setText(strSamRaOffs + " Hz"); -*/ /* response time */ TextLabelStdDevTimer->setText(QString(). diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index b6d8e4cc..caa3ec9b 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -107,7 +107,8 @@ CLlconServerDlg::CLlconServerDlg(QWidget* parent, const char* name, bool modal, void CLlconServerDlg::OnTimer() { CVector vecHostAddresses; - CVector vecdSamOffs; + CVector vecdSamOffs; + double dCurTiStdDev; ListViewMutex.lock(); @@ -140,9 +141,16 @@ void CLlconServerDlg::OnTimer() ListViewMutex.unlock(); - /* response time */ - TextLabelResponseTime->setText(QString(). - setNum(Server.GetTimingStdDev(), 'f', 2) + " ms"); + /* response time (if available) */ + if ( Server.GetTimingStdDev ( dCurTiStdDev ) ) + { + TextLabelResponseTime->setText(QString(). + setNum(dCurTiStdDev, 'f', 2) + " ms"); + } + else + { + TextLabelResponseTime->setText("---"); + } } void CLlconServerDlg::OnSliderNetBuf(int value) diff --git a/src/main.cpp b/src/main.cpp index 1b0fee49..80ed0f1e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,25 +34,27 @@ QApplication* pApp = NULL; -int main(int argc, char** argv) +int main ( int argc, char** argv ) { /* Application object */ - QApplication app(argc, argv); + QApplication app ( argc, argv ); /* check if server or client application shall be started */ bool bIsClient = true; /* QT docu: argv()[0] is the program name, argv()[1] is the first argument and argv()[argc()-1] is the last argument */ - if (argc > 1) + if ( argc > 1 ) { /* only "-s" is supported right now */ std::string strShortOpt = "-s"; - if (!strShortOpt.compare(argv[1])) - bIsClient = false; + if ( !strShortOpt.compare ( argv[1] ) ) + { + bIsClient = false; + } } - if (bIsClient) + if ( bIsClient ) { // actual client object CClient Client; @@ -98,7 +100,8 @@ void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam, /* In case of simulation no events should be generated */ 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 */ QThread::postEvent ( pApp->mainWidget (), LlconEv ); diff --git a/src/protocol.cpp b/src/protocol.cpp new file mode 100755 index 00000000..4753d020 --- /dev/null +++ b/src/protocol.cpp @@ -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 diff --git a/src/protocol.h b/src/protocol.h new file mode 100755 index 00000000..dbcdfbd3 --- /dev/null +++ b/src/protocol.h @@ -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_) */ diff --git a/src/server.cpp b/src/server.cpp index afce0053..9845774c 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -38,76 +38,119 @@ CServer::CServer() : Socket(&ChannelSet) } void CServer::Start() -{ - /* start main timer */ - Timer.start(BLOCK_DURATION_MS); +{ + if ( !IsRunning () ) + { + /* start main timer */ + Timer.start(BLOCK_DURATION_MS); - /* init time for response time evaluation */ - TimeLastBlock = QTime::currentTime(); -} + /* init time for response time evaluation */ + TimeLastBlock = QTime::currentTime(); + } +} + +void CServer::Stop() +{ + /* stop main timer */ + Timer.stop(); +} void CServer::OnTimer() { CVector vecChanID; - CVector > vecvecdData(BLOCK_SIZE_SAMPLES); + CVector > vecvecdData ( BLOCK_SIZE_SAMPLES ); /* get data from all connected clients */ - ChannelSet.GetBlockAllConC(vecChanID, vecvecdData); - - /* actual processing of audio data -> mix */ - vecsSendData = ProcessData(vecvecdData); - - /* get number of connected clients from vector size */ - const int iNumClients = vecvecdData.Size(); - - /* send the same data to all connected clients */ - for (int i = 0; i < iNumClients; i++) + 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 ) { - Socket.SendPacket(ChannelSet.PrepSendPacket(vecChanID[i], vecsSendData), - ChannelSet.GetAddress(vecChanID[i]), - ChannelSet.GetTimeStampIdx(vecChanID[i])); - } + /* actual processing of audio data -> mix */ + vecsSendData = ProcessData ( vecvecdData ); + + /* send the same data to all connected clients */ + for ( int i = 0; i < iNumClients; i++ ) + { + Socket.SendPacket ( + ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ), + ChannelSet.GetAddress ( vecChanID[i] ), + ChannelSet.GetTimeStampIdx ( vecChanID[i] ) ); + } - /* update response time measurement ------------------------------------- */ - /* add time difference */ - const QTime CurTime = QTime::currentTime(); + /* update response time measurement --------------------------------- */ + /* add time difference */ + const QTime CurTime = QTime::currentTime (); - /* we want to calculate the standard deviation (we assume that the mean is - correct at the block period time) */ - const double dCurAddVal = - ((double) TimeLastBlock.msecsTo(CurTime) - BLOCK_DURATION_MS); + /* we want to calculate the standard deviation (we assume that the mean + is correct at the block period time) */ + const double dCurAddVal = + ( (double) TimeLastBlock.msecsTo ( CurTime ) - BLOCK_DURATION_MS ); - RespTimeMoAvBuf.Add(dCurAddVal * dCurAddVal); /* add squared value */ + RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); /* add squared value */ - /* store old time value */ - TimeLastBlock = CurTime; + /* store old time value */ + 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 CServer::ProcessData(CVector >& vecvecdData) +CVector CServer::ProcessData ( CVector >& vecvecdData ) { CVector vecsOutData; - vecsOutData.Init(BLOCK_SIZE_SAMPLES); + vecsOutData.Init ( BLOCK_SIZE_SAMPLES ); - const int iNumClients = vecvecdData.Size(); + const int iNumClients = vecvecdData.Size (); /* we normalize with sqrt() of N to avoid that the level drops too much in case that a new client connects */ - const double dNorm = sqrt((double) iNumClients); + const double dNorm = sqrt ( (double) iNumClients ); /* mix all audio data from all clients together */ - for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++) + for ( int i = 0; i < BLOCK_SIZE_SAMPLES; i++ ) { double dMixedData = 0.0; - for (int j = 0; j < iNumClients; j++) + for ( int j = 0; j < iNumClients; j++ ) { dMixedData += vecvecdData[j][i]; } /* normalization and truncating to short */ - vecsOutData[i] = Double2Short(dMixedData / dNorm); + vecsOutData[i] = Double2Short ( dMixedData / dNorm ); } 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; + } +} diff --git a/src/server.h b/src/server.h index 31f7b346..d038fdf1 100755 --- a/src/server.h +++ b/src/server.h @@ -42,23 +42,23 @@ class CServer : public QObject Q_OBJECT public: - CServer(); - virtual ~CServer() {} + CServer (); + virtual ~CServer () {} - void Start(); - void GetConCliParam(CVector& vecHostAddresses, - CVector& vecdSamOffs) - {ChannelSet.GetConCliParam(vecHostAddresses, vecdSamOffs);} + void Start (); + void Stop (); + bool IsRunning() { return Timer.isActive (); } + void GetConCliParam ( CVector& vecHostAddresses, + CVector& vecdSamOffs ) + { ChannelSet.GetConCliParam ( vecHostAddresses, vecdSamOffs ); } - /* we want to return the standard deviation. For that we need to calculate - the sqaure root */ - double GetTimingStdDev() {return sqrt(RespTimeMoAvBuf.GetAverage());} + bool GetTimingStdDev ( double& dCurTiStdDev ); - CChannelSet* GetChannelSet() {return &ChannelSet;} + CChannelSet* GetChannelSet () { return &ChannelSet; } protected: - CVector ProcessData(CVector >& vecvecdData); - + CVector ProcessData ( CVector >& vecvecdData ); + QTimer Timer; CVector vecsSendData; @@ -71,7 +71,7 @@ protected: QTime TimeLastBlock; public slots: - void OnTimer(); + void OnTimer (); }; diff --git a/src/socket.cpp b/src/socket.cpp index 89ebb139..3db1ab6f 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -26,96 +26,104 @@ /* Implementation *************************************************************/ -void CSocket::Init() +void CSocket::Init () { /* allocate memory for network receive and send buffer in samples */ - vecbyRecBuf.Init(MAX_SIZE_BYTES_NETW_BUF); + vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF ); /* initialize the listening socket */ - bool bSuccess = SocketDevice.bind( - QHostAddress((Q_UINT32) 0) /* INADDR_ANY */, LLCON_PORT_NUMBER); + bool bSuccess = SocketDevice.bind ( + QHostAddress ( (Q_UINT32) 0 ) /* INADDR_ANY */, LLCON_PORT_NUMBER ); - if (bIsClient) + if ( bIsClient ) { /* if no success, try if server is on same machine (only for client) */ - if (!bSuccess) + if ( !bSuccess ) { /* if server and client is on same machine, decrease port number by one by definition */ - bSuccess = - SocketDevice.bind(QHostAddress((Q_UINT32) 0) /* INADDR_ANY */, - LLCON_PORT_NUMBER - 1); + bSuccess = SocketDevice.bind ( + QHostAddress( (Q_UINT32) 0 ) /* INADDR_ANY */, + LLCON_PORT_NUMBER - 1 ); } } - if (!bSuccess) + if ( !bSuccess ) { /* show error message */ - QMessageBox::critical(0, "Network Error", "Cannot bind the socket.", - QMessageBox::Ok, QMessageBox::NoButton); + QMessageBox::critical ( 0, "Network Error", "Cannot bind the socket.", + QMessageBox::Ok, QMessageBox::NoButton ); /* exit application */ - exit(1); + exit ( 1 ); } QSocketNotifier* pSocketNotivRead = - new QSocketNotifier(SocketDevice.socket(), QSocketNotifier::Read); + new QSocketNotifier ( SocketDevice.socket (), QSocketNotifier::Read ); /* connect the "activated" signal */ - QObject::connect(pSocketNotivRead, SIGNAL(activated(int)), - this, SLOT(OnDataReceived())); + QObject::connect ( pSocketNotivRead, SIGNAL ( activated ( int ) ), + this, SLOT ( OnDataReceived () ) ); } -void CSocket::SendPacket(const CVector& vecbySendBuf, - const CHostAddress& HostAddr, const int iTimeStampIdx) +void CSocket::SendPacket( const CVector& vecbySendBuf, + const CHostAddress& HostAddr, + const int iTimeStampIdx ) { - const int iVecSizeOut = vecbySendBuf.Size(); + const int iVecSizeOut = vecbySendBuf.Size (); if ( iVecSizeOut != 0 ) { /* send packet through network */ - SocketDevice.writeBlock ((const char*) &((CVector) vecbySendBuf)[0], - iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort); + SocketDevice.writeBlock ( + (const char*) &((CVector) vecbySendBuf)[0], + iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort ); } /* sent time stamp if required */ - if (iTimeStampIdx != INVALID_TIME_STAMP_IDX) + if ( iTimeStampIdx != INVALID_TIME_STAMP_IDX ) { /* Always one byte long */ - SocketDevice.writeBlock((const char*) &iTimeStampIdx, 1, - HostAddr.InetAddr, HostAddr.iPort); + SocketDevice.writeBlock ( (const char*) &iTimeStampIdx, 1, + HostAddr.InetAddr, HostAddr.iPort ); } } -void CSocket::OnDataReceived() +void CSocket::OnDataReceived () { /* read block from network interface */ - const int iNumBytesRead = SocketDevice.readBlock((char*) &vecbyRecBuf[0], + const int iNumBytesRead = SocketDevice.readBlock( (char*) &vecbyRecBuf[0], MAX_SIZE_BYTES_NETW_BUF); /* check if an error occurred */ - if (iNumBytesRead < 0) - return; + if ( iNumBytesRead < 0 ) + { + return; + } /* get host address of client */ - CHostAddress RecHostAddr(SocketDevice.peerAddress(), - SocketDevice.peerPort()); + CHostAddress RecHostAddr ( SocketDevice.peerAddress (), + SocketDevice.peerPort () ); - if (bIsClient) + if ( bIsClient ) { /* client */ /* check if packet comes from the server we want to connect */ - if (!(pChannel->GetAddress() == RecHostAddr)) + if ( ! ( pChannel->GetAddress () == RecHostAddr ) ) return; - if (pChannel->PutData(vecbyRecBuf, iNumBytesRead)) - PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_GREEN); - else - PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_RED); + if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) ) + { + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN ); + } + else + { + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED ); + } } else { - /* server */ - pChannelSet->PutData(vecbyRecBuf, iNumBytesRead, RecHostAddr); + /* server */ + pChannelSet->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr ); } } diff --git a/src/util.h b/src/util.h index 1c17c130..48896a6f 100755 --- a/src/util.h +++ b/src/util.h @@ -29,7 +29,8 @@ #include #include #include -#include +#include +#include #include #include "global.h" using namespace std; /* Because of the library: "vector" */ @@ -376,6 +377,43 @@ protected: double allpassCoefficient_; double combCoefficient_[4]; }; + + +/* Time conversion ---------------------------------------------------------- */ +// needed for ping measurement +class CTimeConv +{ +public: + // QTime to network time vector + static CVector QTi2NetTi ( const QTime qTiIn ) + { + // vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms + CVector veccNetTi ( 5 ); + + veccNetTi[0] = static_cast ( qTiIn.hour () ); + veccNetTi[1] = static_cast ( qTiIn.minute () ); + veccNetTi[2] = static_cast ( qTiIn.second () ); + + const int iMs = qTiIn.msec (); + veccNetTi[3] = static_cast ( ( iMs >> 8 ) & 255 ); + veccNetTi[4] = static_cast ( iMs & 255 ); + + return veccNetTi; + } + + // network time vector to QTime + static QTime NetTi2QTi ( const CVector netTiIn ) + { + // vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms + return QTime ( + static_cast ( netTiIn[0] ), // hour + static_cast ( netTiIn[1] ), // minute + static_cast ( netTiIn[2] ), // seconds + // msec + static_cast ( ( netTiIn[3] << 8 ) | netTiIn[4] ) + ); + } +}; #endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */ diff --git a/windows/llcon.dsp b/windows/llcon.dsp index 52588c97..30af9b4b 100755 --- a/windows/llcon.dsp +++ b/windows/llcon.dsp @@ -178,6 +178,10 @@ SOURCE=..\src\multicolorled.cpp # End Source File # Begin Source File +SOURCE=..\src\protocol.cpp +# End Source File +# Begin Source File + SOURCE=..\src\resample.cpp # End Source File # Begin Source File @@ -238,6 +242,10 @@ SOURCE=..\src\multicolorled.h # End Source File # Begin Source File +SOURCE=..\src\protocol.h +# End Source File +# Begin Source File + SOURCE=..\src\resample.h # End Source File # Begin Source File