diff --git a/src/global.h b/src/global.h index ea3fe43f..4f445a3c 100755 --- a/src/global.h +++ b/src/global.h @@ -68,8 +68,8 @@ much higher DSL network latencies. A length of 6 ms seems to be optimal */ #define BLOCK_DURATION_MS 6 /* ms */ -#define BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SAMPLE_RATE / 1000) -#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000) +#define BLOCK_SIZE_SAMPLES ( BLOCK_DURATION_MS * SAMPLE_RATE / 1000 ) +#define SND_CRD_BLOCK_SIZE_SAMPLES ( BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 ) /* maximum network buffer size (which can be chosen by slider) */ #define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */ @@ -102,6 +102,20 @@ #define _MAXSHORT 32767 #define _MAXBYTE 255 /* binary: 11111111 */ #define _MINSHORT (-32768) + +#if HAVE_STDINT_H +# include +#elif HAVE_INTTYPES_H +# include +#elif defined ( _WIN32 ) +typedef unsigned __int32 uint32_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int8 uint8_t; +#else +typedef unsigned int uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; +#endif /* Definitions for window message system ------------------------------------ */ diff --git a/src/protocol.cpp b/src/protocol.cpp index 4753d020..df82d071 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -4,6 +4,20 @@ * Author(s): * Volker Fischer * + +Protocol message definition + + +-----------+------------+-----------------+--------------+-------------+ + | 2 byte ID | 1 byte cnt | 2 byte length n | n bytes data | 2 bytes CRC | + +-----------+------------+-----------------+--------------+-------------+ + +- message ID defined by the defines PROTMESSID_x +- cnt: counter which is incremet for each message and wraps around at 255 +- length n in bytes of the data +- actual data, dependent on message type +- 16 bits CRC, calculating over the entire message, is transmitted inverted + Generator polynom: G_16(x) = x^16 + x^12 + x^5 + 1, initial state: all ones + * ****************************************************************************** * diff --git a/src/protocol.h b/src/protocol.h index dbcdfbd3..c734855a 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -28,6 +28,13 @@ #include "global.h" +/* Definitions ****************************************************************/ +// protocol message IDs +#define PROTMESSID_ACKN 0 // acknowledge +#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size +#define PROTMESSID_PING 11 // for measuring ping time + + /* Classes ********************************************************************/ class CProtocol { @@ -58,6 +65,16 @@ public: protected: }; + +class CProtMessage +{ +public: + CProtMessage () {} + virtual ~CProtMessage () {} + +protected: + +}; #endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */ diff --git a/src/util.cpp b/src/util.cpp index 5ed27c04..33582b42 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -70,23 +70,53 @@ double CSignalLevelMeter::MicLevel () return -100000.0; /* large negative value */ } } - - -/* Global functions implementation ********************************************/ -void DebugError(const char* pchErDescr, const char* pchPar1Descr, - const double dPar1, const char* pchPar2Descr, - const double dPar2) -{ - FILE* pFile = fopen("DebugError.dat", "a"); - fprintf(pFile, pchErDescr); fprintf(pFile, " ### "); - fprintf(pFile, pchPar1Descr); fprintf(pFile, ": "); - fprintf(pFile, "%e ### ", dPar1); - fprintf(pFile, pchPar2Descr); fprintf(pFile, ": "); - fprintf(pFile, "%e\n", dPar2); - fclose(pFile); - printf("\nDebug error! For more information see test/DebugError.dat\n"); - exit(1); -} + + +/* CRC ---------------------------------------------------------------------- */ +void CCRC::Reset () +{ + /* Init state shift-register with ones. Set all registers to "1" with + bit-wise not operation */ + iStateShiftReg = ~uint32_t ( 0 ); +} + +void CCRC::AddByte ( const uint8_t byNewInput ) +{ + for ( int i = 0; i < 8; i++ ) + { + /* Shift bits in shift-register for transistion */ + iStateShiftReg <<= 1; + + /* Take bit, which was shifted out of the register-size and place it + at the beginning (LSB) + (If condition is not satisfied, implicitely a "0" is added) */ + if ( ( iStateShiftReg & iBitOutMask) > 0 ) + { + iStateShiftReg |= 1; + } + + /* Add new data bit to the LSB */ + if ( ( byNewInput & ( 1 << ( 8 - i - 1 ) ) ) > 0 ) + { + iStateShiftReg ^= 1; + } + + /* Add mask to shift-register if first bit is true */ + if ( iStateShiftReg & 1 ) + { + iStateShiftReg ^= iPoly; + } + } +} + +uint32_t CCRC::GetCRC() +{ + /* Return inverted shift-register (1's complement) */ + iStateShiftReg = ~iStateShiftReg; + + /* Remove bit which where shifted out of the shift-register frame */ + return iStateShiftReg & ( iBitOutMask - 1 ); +} /******************************************************************************\ @@ -316,3 +346,22 @@ CLlconHelpMenu::CLlconHelpMenu ( QWidget* parent ) : QPopupMenu ( parent ) insertSeparator(); insertItem ( tr ( "&About..." ), this, SLOT ( OnHelpAbout () ) ); } + + +/******************************************************************************\ +* Global functions implementation * +\******************************************************************************/ +void DebugError(const char* pchErDescr, const char* pchPar1Descr, + const double dPar1, const char* pchPar2Descr, + const double dPar2) +{ + FILE* pFile = fopen("DebugError.dat", "a"); + fprintf(pFile, pchErDescr); fprintf(pFile, " ### "); + fprintf(pFile, pchPar1Descr); fprintf(pFile, ": "); + fprintf(pFile, "%e ### ", dPar1); + fprintf(pFile, pchPar2Descr); fprintf(pFile, ": "); + fprintf(pFile, "%e\n", dPar2); + fclose(pFile); + printf("\nDebug error! For more information see test/DebugError.dat\n"); + exit(1); +} diff --git a/src/util.h b/src/util.h index 4a97268c..01f04b13 100755 --- a/src/util.h +++ b/src/util.h @@ -381,6 +381,26 @@ protected: }; +/* CRC ---------------------------------------------------------------------- */ +class CCRC +{ +public: + CCRC () : iPoly ( ( 1 << 5 ) | ( 1 << 12 ) ), iBitOutMask ( 1 << 16 ) + { Reset (); } + virtual ~CCRC () {} + + void Reset (); + void AddByte ( const uint8_t byNewInput ); + bool CheckCRC ( const uint32_t iCRC ) { return iCRC == GetCRC(); } + uint32_t GetCRC (); + +protected: + uint32_t iBitOutMask; + uint32_t iPoly; + uint32_t iStateShiftReg; +}; + + /* Time conversion ---------------------------------------------------------- */ // needed for ping measurement class CTimeConv