preparations for protocol (CRC class added)
This commit is contained in:
parent
824bc8ab5d
commit
c5e6c6b0c1
5 changed files with 133 additions and 19 deletions
14
src/global.h
14
src/global.h
|
@ -103,6 +103,20 @@
|
||||||
#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 ------------------------------------ */
|
||||||
typedef unsigned int _MESSAGE_IDENT;
|
typedef unsigned int _MESSAGE_IDENT;
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -59,5 +66,15 @@ protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CProtMessage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CProtMessage () {}
|
||||||
|
virtual ~CProtMessage () {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */
|
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */
|
||||||
|
|
75
src/util.cpp
75
src/util.cpp
|
@ -72,20 +72,50 @@ double CSignalLevelMeter::MicLevel ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Global functions implementation ********************************************/
|
/* CRC ---------------------------------------------------------------------- */
|
||||||
void DebugError(const char* pchErDescr, const char* pchPar1Descr,
|
void CCRC::Reset ()
|
||||||
const double dPar1, const char* pchPar2Descr,
|
|
||||||
const double dPar2)
|
|
||||||
{
|
{
|
||||||
FILE* pFile = fopen("DebugError.dat", "a");
|
/* Init state shift-register with ones. Set all registers to "1" with
|
||||||
fprintf(pFile, pchErDescr); fprintf(pFile, " ### ");
|
bit-wise not operation */
|
||||||
fprintf(pFile, pchPar1Descr); fprintf(pFile, ": ");
|
iStateShiftReg = ~uint32_t ( 0 );
|
||||||
fprintf(pFile, "%e ### ", dPar1);
|
}
|
||||||
fprintf(pFile, pchPar2Descr); fprintf(pFile, ": ");
|
|
||||||
fprintf(pFile, "%e\n", dPar2);
|
void CCRC::AddByte ( const uint8_t byNewInput )
|
||||||
fclose(pFile);
|
{
|
||||||
printf("\nDebug error! For more information see test/DebugError.dat\n");
|
for ( int i = 0; i < 8; i++ )
|
||||||
exit(1);
|
{
|
||||||
|
/* 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();
|
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);
|
||||||
|
}
|
||||||
|
|
20
src/util.h
20
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 ---------------------------------------------------------- */
|
/* Time conversion ---------------------------------------------------------- */
|
||||||
// needed for ping measurement
|
// needed for ping measurement
|
||||||
class CTimeConv
|
class CTimeConv
|
||||||
|
|
Loading…
Reference in a new issue