Define new protocol messages

This commit is contained in:
Peter L Jones 2020-03-29 18:00:07 +01:00
parent 70480cd626
commit a7a1549fe5
2 changed files with 149 additions and 7 deletions

View file

@ -153,6 +153,14 @@ MESSAGES (with connection)
| 1 byte licence type |
+---------------------+
- PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST: Opt in or out of the channel level list
+---------------+
| 1 byte option |
+---------------+
option is boolean, true to opt in, false to opt out
// #### COMPATIBILITY OLD VERSION, TO BE REMOVED ####
- PROTMESSID_OPUS_SUPPORTED: Informs that OPUS codec is supported
@ -276,6 +284,27 @@ CONNECTION LESS MESSAGES
note: does not have any data -> n = 0
- PROTMESSID_CLM_CHANNEL_LEVEL_LIST: The channel level list
+----------------------------------+
| ( ( n + 1 ) / 2 ) * 4 bit values |
+----------------------------------+
n is number of connected clients
the values are the maximum channel levels for a client frame converted
to the range of CMultiColorLEDBar in 4 bits, two entries per byte
with the earlier channel in the lower half of the byte
where an odd number of clients is connected, there will be four unused
upper bits in the final byte, containing 0xF (which is out of range)
the server may compute them message when any client has used
PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST to opt in
the server may issue to message only to a client that has used
PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST to opt in
******************************************************************************
*
@ -549,6 +578,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
case PROTMESSID_LICENCE_REQUIRED:
bRet = EvaluateLicenceRequiredMes ( vecbyMesBodyData );
break;
case PROTMESSID_REQ_CHANNEL_LEVEL_LIST:
bRet = EvaluateReqChannelLevelListMes ( vecbyMesBodyData );
break;
}
// immediately send acknowledge message
@ -634,6 +667,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
case PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST:
bRet = EvaluateCLReqConnClientsListMes ( InetAddr );
break;
case PROTMESSID_CLM_CHANNEL_LEVEL_LIST:
bRet = EvaluateCLChannelLevelListMes ( InetAddr, vecbyMesBodyData );
break;
}
}
else
@ -1234,6 +1271,40 @@ void CProtocol::CreateOpusSupportedMes()
CVector<uint8_t> ( 0 ) );
}
void CProtocol::CreateReqChannelLevelListMes ( const bool bRCL )
{
CVector<uint8_t> vecData ( 1 ); // 1 byte of data
int iPos = 0; // init position pointer
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( bRCL ), 1 );
CreateAndSendMessage ( PROTMESSID_REQ_CHANNEL_LEVEL_LIST, vecData );
}
bool CProtocol::EvaluateReqChannelLevelListMes ( const CVector<uint8_t>& vecData )
{
int iPos = 0; // init position pointer
// check size
if ( vecData.Size() != 1 )
{
return true; // return error code
}
// extract opt in / out for channel levels
uint32_t val = GetValFromStream ( vecData, iPos, 1 );
if ( val != 0 && val != 1 )
{
return true; // return error code
}
// invoke message action
emit ReqChannelLevelList ( static_cast<bool> ( val ) );
return false; // no error
}
// Connection less messages ----------------------------------------------------
void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )
@ -1936,6 +2007,65 @@ bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr )
return false; // no error
}
void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr,
const CVector<uint16_t>& vecLevelList,
const int iNumClients )
{
// This must be a multiple of bytes at four bits per client
const int iNumBytes = ( iNumClients + 1 ) / 2;
CVector<uint8_t> vecData( iNumBytes );
int iPos = 0; // init position pointer
for ( int i = 0, j = 0; i < iNumClients; i += 2 /* pack two per byte */, j++ )
{
uint16_t levelLo = vecLevelList[i] & 0x0F;
uint16_t levelHi = ( i + 1 < iNumClients ) ? vecLevelList[i + 1] & 0x0F : 0x0F;
uint8_t byte = static_cast<uint8_t> ( levelLo | ( levelHi << 4 ) );
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( byte ), 1 );
}
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CHANNEL_LEVEL_LIST,
vecData,
InetAddr );
}
bool CProtocol::EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData )
{
int iPos = 0; // init position pointer
const int iDataLen = vecData.Size(); // four bits per channel, 2 channels per byte
// may have one too many entries, last being 0xF
int iVecLen = iDataLen * 2; // one ushort per channel
CVector<uint16_t> vecLevelList ( iVecLen );
for (int i = 0, j = 0; i < iDataLen; i++, j += 2 )
{
uint8_t byte = static_cast<uint8_t> ( GetValFromStream ( vecData, iPos, 1 ) );
uint16_t levelLo = byte & 0x0F;
uint16_t levelHi = ( byte >> 4 ) & 0x0F;
vecLevelList[j] = levelLo;
if ( levelHi != 0x0F )
{
vecLevelList[j + 1] = levelHi;
}
else
{
vecLevelList.resize ( iVecLen - 1 );
break;
}
}
// invoke message action
emit CLChannelLevelListReceived ( InetAddr, vecLevelList );
return false; // no error
}
/******************************************************************************\
* Message generation and parsing *

View file

@ -54,6 +54,7 @@
#define PROTMESSID_CHANNEL_INFOS 25 // set channel infos
#define PROTMESSID_OPUS_SUPPORTED 26 // tells that OPUS codec is supported
#define PROTMESSID_LICENCE_REQUIRED 27 // licence required
#define PROTMESSID_REQ_CHANNEL_LEVEL_LIST 28 // request the channel level list
// message IDs of connection less messages (CLM)
// DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID
@ -71,6 +72,7 @@
#define PROTMESSID_CLM_REQ_VERSION_AND_OS 1012 // request version number and operating system
#define PROTMESSID_CLM_CONN_CLIENTS_LIST 1013 // channel infos for connected clients
#define PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST 1014 // request the connected clients list
#define PROTMESSID_CLM_CHANNEL_LEVEL_LIST 1015 // channel level list
// lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2)
@ -102,6 +104,7 @@ public:
void CreateReqNetwTranspPropsMes();
void CreateLicenceRequiredMes ( const ELicenceType eLicenceType );
void CreateOpusSupportedMes();
void CreateReqChannelLevelListMes ( const bool bRCL );
void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs );
void CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
@ -123,6 +126,9 @@ public:
void CreateCLConnClientsListMes ( const CHostAddress& InetAddr,
const CVector<CChannelInfo>& vecChanInfo );
void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
void CreateCLChannelLevelListMes ( const CHostAddress& InetAddr,
const CVector<uint16_t>& vecLevelList,
const int iNumClients );
static bool ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
const int iNumBytesIn,
@ -205,17 +211,18 @@ protected:
const CVector<uint8_t>& vecData,
const CHostAddress& InetAddr );
bool EvaluateJitBufMes ( const CVector<uint8_t>& vecData );
bool EvaluateJitBufMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqJitBufMes();
bool EvaluateChanGainMes ( const CVector<uint8_t>& vecData );
bool EvaluateConClientListMes ( const CVector<uint8_t>& vecData );
bool EvaluateChanGainMes ( const CVector<uint8_t>& vecData );
bool EvaluateConClientListMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqConnClientsList();
bool EvaluateChanInfoMes ( const CVector<uint8_t>& vecData );
bool EvaluateChanInfoMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqChanInfoMes();
bool EvaluateChatTextMes ( const CVector<uint8_t>& vecData );
bool EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData );
bool EvaluateChatTextMes ( const CVector<uint8_t>& vecData );
bool EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqNetwTranspPropsMes();
bool EvaluateLicenceRequiredMes ( const CVector<uint8_t>& vecData );
bool EvaluateLicenceRequiredMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqChannelLevelListMes ( const CVector<uint8_t>& vecData );
bool EvaluateCLPingMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
@ -236,6 +243,8 @@ protected:
bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
int iOldRecID;
int iOldRecCnt;
@ -270,6 +279,7 @@ signals:
void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void ReqNetTranspProps();
void LicenceRequired ( ELicenceType eLicenceType );
void ReqChannelLevelList ( bool bOptIn );
void CLPingReceived ( CHostAddress InetAddr,
int iMs );
@ -291,4 +301,6 @@ signals:
void CLConnClientsListMesReceived ( CHostAddress InetAddr,
CVector<CChannelInfo> vecChanInfo );
void CLReqConnClientsList ( CHostAddress InetAddr );
void CLChannelLevelListReceived ( CHostAddress InetAddr,
CVector<uint16_t> vecLevelList );
};