preparations for protocol (CRC class added)

This commit is contained in:
Volker Fischer 2006-02-18 22:05:46 +00:00
parent 824bc8ab5d
commit c5e6c6b0c1
5 changed files with 133 additions and 19 deletions

View file

@ -68,8 +68,8 @@
much higher DSL network latencies. A length of 6 ms seems to be optimal */ much higher DSL network latencies. A length of 6 ms seems to be optimal */
#define BLOCK_DURATION_MS 6 /* ms */ #define BLOCK_DURATION_MS 6 /* ms */
#define BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * 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) #define SND_CRD_BLOCK_SIZE_SAMPLES ( BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 )
/* maximum network buffer size (which can be chosen by slider) */ /* maximum network buffer size (which can be chosen by slider) */
#define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */ #define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */
@ -102,6 +102,20 @@
#define _MAXSHORT 32767 #define _MAXSHORT 32767
#define _MAXBYTE 255 /* binary: 11111111 */ #define _MAXBYTE 255 /* binary: 11111111 */
#define _MINSHORT (-32768) #define _MINSHORT (-32768)
#if HAVE_STDINT_H
# include <stdint.h>
#elif HAVE_INTTYPES_H
# include <inttypes.h>
#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 ------------------------------------ */ /* Definitions for window message system ------------------------------------ */

View file

@ -4,6 +4,20 @@
* Author(s): * Author(s):
* Volker Fischer * 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
* *
****************************************************************************** ******************************************************************************
* *

View file

@ -28,6 +28,13 @@
#include "global.h" #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 ********************************************************************/ /* Classes ********************************************************************/
class CProtocol class CProtocol
{ {
@ -58,6 +65,16 @@ public:
protected: protected:
}; };
class CProtMessage
{
public:
CProtMessage () {}
virtual ~CProtMessage () {}
protected:
};
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */ #endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */

View file

@ -70,23 +70,53 @@ double CSignalLevelMeter::MicLevel ()
return -100000.0; /* large negative value */ return -100000.0; /* large negative value */
} }
} }
/* Global functions implementation ********************************************/ /* CRC ---------------------------------------------------------------------- */
void DebugError(const char* pchErDescr, const char* pchPar1Descr, void CCRC::Reset ()
const double dPar1, const char* pchPar2Descr, {
const double dPar2) /* Init state shift-register with ones. Set all registers to "1" with
{ bit-wise not operation */
FILE* pFile = fopen("DebugError.dat", "a"); iStateShiftReg = ~uint32_t ( 0 );
fprintf(pFile, pchErDescr); fprintf(pFile, " ### "); }
fprintf(pFile, pchPar1Descr); fprintf(pFile, ": ");
fprintf(pFile, "%e ### ", dPar1); void CCRC::AddByte ( const uint8_t byNewInput )
fprintf(pFile, pchPar2Descr); fprintf(pFile, ": "); {
fprintf(pFile, "%e\n", dPar2); for ( int i = 0; i < 8; i++ )
fclose(pFile); {
printf("\nDebug error! For more information see test/DebugError.dat\n"); /* Shift bits in shift-register for transistion */
exit(1); 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(); insertSeparator();
insertItem ( tr ( "&About..." ), this, SLOT ( OnHelpAbout () ) ); 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);
}

View file

@ -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 ---------------------------------------------------------- */ /* Time conversion ---------------------------------------------------------- */
// needed for ping measurement // needed for ping measurement
class CTimeConv class CTimeConv