fixed problem: protocol message was treated as audio packet

This commit is contained in:
Volker Fischer 2006-12-10 12:02:28 +00:00
parent ecd105d6ca
commit 956bb26211
3 changed files with 88 additions and 66 deletions

View file

@ -583,11 +583,32 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
{ {
EPutDataStat eRet = PS_GEN_ERROR; EPutDataStat eRet = PS_GEN_ERROR;
// init flags
bool bIsProtocolPacket = false;
bool bIsAudioPacket = false;
bool bNewConnection = false;
if ( bIsEnabled ) if ( bIsEnabled )
{ {
bool bNewConnection = false; // first check if this is protocol data
bool bIsAudioPacket = false; // only use protocol data if channel is connected
if ( IsConnected() )
{
// this seems not to be an audio block, parse the message
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) )
{
// set status flags
eRet = PS_PROT_OK;
bIsProtocolPacket = true;
// create message for protocol status
emit ProtocolStatus ( true );
}
}
// only try to parse audio if it was not a protocol packet
if ( !bIsProtocolPacket )
{
// check if this is an audio packet by checking all possible lengths // check if this is an audio packet by checking all possible lengths
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ ) for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{ {
@ -647,26 +668,14 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) {
} }
else else
{ {
// only use protocol data if channel is connected // the protocol parsing failed and this was no audio block,
if ( IsConnected() ) // we treat this as protocol error (unkown packet)
{
// this seems not to be an audio block, parse the message
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) )
{
eRet = PS_PROT_OK;
// create message for protocol status
emit ProtocolStatus ( true );
}
else
{
eRet = PS_PROT_ERR; eRet = PS_PROT_ERR;
// create message for protocol status // create message for protocol status
emit ProtocolStatus ( false ); emit ProtocolStatus ( false );
} }
} }
}
// inform other objects that new connection was established // inform other objects that new connection was established
if ( bNewConnection ) if ( bNewConnection )

View file

@ -15,10 +15,11 @@ Protocol message definition
MAIN FRAME MAIN FRAME
---------- ----------
+------------+------------+------------------+--------------+-------------+ +-------------+------------+------------+------------------+--------------+-------------+
| 2 bytes ID | 1 byte cnt | 2 bytes length n | n bytes data | 2 bytes CRC | | 2 bytes TAG | 2 bytes ID | 1 byte cnt | 2 bytes length n | n bytes data | 2 bytes CRC |
+------------+------------+------------------+--------------+-------------+ +-------------+------------+------------+------------------+--------------+-------------+
- TAG is an all zero bit word to identify protocol messages
- message ID defined by the defines PROTMESSID_x - message ID defined by the defines PROTMESSID_x
- cnt: counter which is increment for each message and wraps around at 255 - cnt: counter which is increment for each message and wraps around at 255
- length n in bytes of the data - length n in bytes of the data
@ -639,6 +640,15 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
// decode header ----- // decode header -----
iCurPos = 0; // start from beginning iCurPos = 0; // start from beginning
// 2 bytes TAG
const int iTag = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
// check if tag is correct
if ( iTag != 0 )
{
return false; // return error code
}
/* 2 bytes ID */ /* 2 bytes ID */
iID = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) ); iID = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
@ -715,9 +725,8 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
// query length of data vector // query length of data vector
const int iDataLenByte = vecData.Size(); const int iDataLenByte = vecData.Size();
// total length of message = 7 + "iDataLenByte" // total length of message
// 2 byte ID + 1 byte cnt + 2 byte length + n bytes data + 2 bytes CRC const int iTotLenByte = MESS_LEN_WITHOUT_DATA_BYTE + iDataLenByte;
const int iTotLenByte = 7 + iDataLenByte;
// init message vector // init message vector
vecOut.Init( iTotLenByte ); vecOut.Init( iTotLenByte );
@ -725,15 +734,19 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
// encode header ----- // encode header -----
unsigned int iCurPos = 0; // init position pointer unsigned int iCurPos = 0; // init position pointer
/* 2 bytes ID */ // 2 bytes TAG (all zero bits)
PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( 0 ), 2 );
// 2 bytes ID
PutValOnStream ( vecOut, iCurPos, PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( iID ), 2 ); static_cast<uint32_t> ( iID ), 2 );
/* 1 byte cnt */ // 1 byte cnt
PutValOnStream ( vecOut, iCurPos, PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( iCnt ), 1 ); static_cast<uint32_t> ( iCnt ), 1 );
/* 2 bytes length */ // 2 bytes length
PutValOnStream ( vecOut, iCurPos, PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( iDataLenByte ), 2 ); static_cast<uint32_t> ( iDataLenByte ), 2 );

View file

@ -48,8 +48,8 @@
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag #define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
// lengths of message as defined in protocol.cpp file // lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ #define MESS_HEADER_LENGTH_BYTE 7 /* TAG (2), ID (2), cnt (1), length (2) */
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ ) #define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
// time out for message re-send if no acknowledgement was received // time out for message re-send if no acknowledgement was received
#define SEND_MESS_TIMEOUT_MS 400 // ms #define SEND_MESS_TIMEOUT_MS 400 // ms