fixed problem: protocol message was treated as audio packet
This commit is contained in:
parent
ecd105d6ca
commit
956bb26211
3 changed files with 88 additions and 66 deletions
|
@ -583,11 +583,32 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
|||
{
|
||||
EPutDataStat eRet = PS_GEN_ERROR;
|
||||
|
||||
// init flags
|
||||
bool bIsProtocolPacket = false;
|
||||
bool bIsAudioPacket = false;
|
||||
bool bNewConnection = false;
|
||||
|
||||
if ( bIsEnabled )
|
||||
{
|
||||
bool bNewConnection = false;
|
||||
bool bIsAudioPacket = false;
|
||||
// first check if this is protocol data
|
||||
// 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
|
||||
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
|
||||
{
|
||||
// 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 ) )
|
||||
{
|
||||
eRet = PS_PROT_OK;
|
||||
|
||||
// create message for protocol status
|
||||
emit ProtocolStatus ( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
// the protocol parsing failed and this was no audio block,
|
||||
// we treat this as protocol error (unkown packet)
|
||||
eRet = PS_PROT_ERR;
|
||||
|
||||
// create message for protocol status
|
||||
emit ProtocolStatus ( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// inform other objects that new connection was established
|
||||
if ( bNewConnection )
|
||||
|
|
|
@ -15,10 +15,11 @@ Protocol message definition
|
|||
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
|
||||
- cnt: counter which is increment for each message and wraps around at 255
|
||||
- length n in bytes of the data
|
||||
|
@ -639,6 +640,15 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
|
|||
// decode header -----
|
||||
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 */
|
||||
iID = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
|
||||
|
||||
|
@ -715,9 +725,8 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
|||
// query length of data vector
|
||||
const int iDataLenByte = vecData.Size();
|
||||
|
||||
// total length of message = 7 + "iDataLenByte"
|
||||
// 2 byte ID + 1 byte cnt + 2 byte length + n bytes data + 2 bytes CRC
|
||||
const int iTotLenByte = 7 + iDataLenByte;
|
||||
// total length of message
|
||||
const int iTotLenByte = MESS_LEN_WITHOUT_DATA_BYTE + iDataLenByte;
|
||||
|
||||
// init message vector
|
||||
vecOut.Init( iTotLenByte );
|
||||
|
@ -725,15 +734,19 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
|||
// encode header -----
|
||||
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,
|
||||
static_cast<uint32_t> ( iID ), 2 );
|
||||
|
||||
/* 1 byte cnt */
|
||||
// 1 byte cnt
|
||||
PutValOnStream ( vecOut, iCurPos,
|
||||
static_cast<uint32_t> ( iCnt ), 1 );
|
||||
|
||||
/* 2 bytes length */
|
||||
// 2 bytes length
|
||||
PutValOnStream ( vecOut, iCurPos,
|
||||
static_cast<uint32_t> ( iDataLenByte ), 2 );
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@
|
|||
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
|
||||
|
||||
// lengths of message as defined in protocol.cpp file
|
||||
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
|
||||
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
|
||||
#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 (2) */ )
|
||||
|
||||
// time out for message re-send if no acknowledgement was received
|
||||
#define SEND_MESS_TIMEOUT_MS 400 // ms
|
||||
|
|
Loading…
Reference in a new issue