ptlbase.cpp
来自「ABis无线接口全套资料」· C++ 代码 · 共 1,059 行 · 第 1/2 页
CPP
1,059 行
}
}
else
{
r = -2; // The repeated IE not exist.
}
}
else
{
DeleteIEbyIndex(idx);
}
}
else
{
r= -1; // The IE not be included.
}
return r;
}
// ===========================================================================
//
// Description: Gain the repeated times of IE.
// Input:
// id IE ID.
// Output: Null
// Return: UINT8
// 0 IE not exist.
// n (>0) Repeated times.
//
// ===========================================================================
UINT8 CPduBase::RepeatedTimes(UINT8 id) // Calculate the repeated time of this IE.
{
UINT8 cnt = 0;
for (int i=0; i<IeCounter; ++i)
{
if (IE[i].id == id)
{
++ cnt;
}
}
return cnt;
}
/*
void CPduBase::GetFirstRepeatedIE(CIeBase& ie) // Get the first IE of which can repeated.
{
}
CIeBase& CPduBase::GetFirstRepeatedIE(CIeBase& ie)
{
}
void CPduBase::GetNextRepeatedIE(CIeBase& ie) // Get the next repeated IE.
{
}
CIeBase& CPduBase::GetNextRepeatedIE(CIeBase& ie)
{
}
void CPduBase::GetLastRepeatedIE(CIeBase& ie) // Get the last IE of which can repeated.
{
}
CIeBase& CPduBase::GetLastRepeatedIE(CIeBase& ie)
{
}
*/
// ===========================================================================
//
// Description: Unpack the PDU.
// Input:
// ptr Pointer point to PDU data string.
// len Length of PDU data.
// mod PDU protocol mode. Mode define please refer to MOD_XXXXX macro.
// Output: Null
// Return: int
// >=0 Success.
// -1 Incompleted PDU.
// -2 Exceed data in PDU.
//
// ===========================================================================
int CPduBase::Unpacked(char * ptr, UINT16 len)
{ // Unpacked the PDU octets string.
int r = 0;
switch (GetProtocolType( ))
{
case MOD_JOYIT:
case MOD_TUPAPI:
case MOD_ISUPAPI:
case MOD_Q931API:
r = DecomposeJoyitApi(ptr, len);
break;
/*
case MOD_INTER:
r = DecomposeInterApi(ptr, len);
break;
*/
default:
break;
} // End of switch(mod)
return r;
}
// ===========================================================================
//
// Description: Pack up IE into PDU.
// Input:
// mod PDU protocol mode.
// Output:
// len Length of PDU data string.
// Return: char *
// NULL Failure.
// Other Pointer point to PDU data.
//
// ===========================================================================
char * CPduBase::Output(UINT16& len)
{ // Packed the PDU in dedicat model.
char * pPdu = NULL;
len = 0;
switch (GetProtocolType( ))
{
case MOD_JOYIT:
case MOD_TUPAPI:
case MOD_ISUPAPI:
case MOD_Q931API:
pPdu = ComposeJoyitApi(len);
break;
/*
case MOD_INTER: // Add 2005-10-26, by Wujianjin.
pPdu = ComposeInterApi(len);
break;
*/
default:
break;
} // End of switch(mod)
return pPdu;
}
// ===========================================================================
//
// Description: Decompose Joyit API message.
// Input:
// ptr Pointer point to Joyit API message string.
// len Length of Joyit API message.
// Output: Null
// Return: int
// >=0 Success.
// -1 Incompleted PDU.
// -2 Exceed data in PDU.
//
// ===========================================================================
int CPduBase::DecomposeJoyitApi(char * ptr, UINT16 len)
{
int r = 0;
char *pPdu = ptr;
UINT8 noie;
UINT16 pos = 0; // Calculate the length of PDU.
if (len > sizeof(SInterApiHead))
{
// Store the PDU header.
LengthOfHeader = sizeof(SInterApiHead);
memcpy(Header, pPdu, sizeof(SInterApiHead));
pPdu += LengthOfHeader;
pos += LengthOfHeader;
// Get the primitive type and number of IEs.
// mType = ((SJoyitApiHead *)Header)->msgType;
primType = ((SInterApiHead *)Header)->primType; // Modify 2005-10-27, by Wujianjin.
noie = ((SInterApiHead *)Header)->noie;
// Get all IEs.
for (int i=0; i<noie; i++)
{
UINT8 ieId, ieLen;
char * pIedata;
ieId = *pPdu++;
ieLen = *pPdu++;
pIedata = pPdu;
pPdu += ieLen;
pos += (ieLen + 2);
if (pos > len)
{
r = -1; // Imcompleted PDU.
break;
}
else
{
PutIE(ieId, ieLen, pIedata);
if (PSG_IE_MSGTYPE == ieId) // Add 2005-10-27, by Wujianjin. Save the message type value.
{
mType = *((UINT16 *)pIedata);
}
}
}
if (pos < len)
{ // Exceed data in PDU.
r = -2; // Exceed data.
}
}
else
{
r = -1; // Imcompleted PDU.
}
return r;
}
// ===========================================================================
//
// Description: Pack up IE into Joyit API message.
// Input: Null
// Output:
// len Length of Joyit API message.
// Return: char *
// NULL Failure.
// Other Pointer point to Joyit API message.
//
// ===========================================================================
char * CPduBase::ComposeJoyitApi(UINT16& len)
{
char * pPdu = NULL;
char pdu[MAX_MSGLEN] = { 0 };
UINT8 pos = 0;
UINT16 l;
int i;
// Make up API header.
memcpy(pdu, Header, sizeof(SInterApiHead));
pos += sizeof(SInterApiHead);
// #### Add 2005-10-30, by Wujianjin. ###
// Construct the FIX information element first.
UINT8 pt = GetProtocolType( );
if ((MOD_TUPAPI == pt)
|| (MOD_ISUPAPI == pt)
|| (MOD_Q931API == pt))
{ // Construct the fix ie first.
// Message index.
CIeBase * pIe;
pIe = GetIE(PSG_IE_MSGTYPE);
if ((pIe != NULL)
&& (pIe->id != IE_NOT_EXIST))
{
pdu[pos++] = pIe->id;
pdu[pos++] = pIe->len;
memcpy(pdu+pos, pIe->GetIeData(l), pIe->len);
pos += pIe->len;
}
else
{ // Not exist, I will get it from mType.
pdu[pos++] = PSG_IE_MSGTYPE;
pdu[pos++] = 2;
memcpy(pdu+pos, &mType, 2);
pos += 2;
}
if (pIe != NULL)
{
DelIE(PSG_IE_MSGTYPE);
}
// Circuit structure.
pIe = GetIE(PSG_IE_CIR_STRUCT);
if ((pIe != NULL)
&& (pIe->id != IE_NOT_EXIST))
{
pdu[pos++] = pIe->id;
pdu[pos++] = pIe->len;
memcpy(pdu+pos, pIe->GetIeData(l), pIe->len);
pos += pIe->len;
DelIE(PSG_IE_CIR_STRUCT);
}
else
{ // Exception handle.
return pPdu;
}
// Circuit group indicator.
pIe = GetIE(PSG_IE_CG_IND);
if ((pIe != NULL)
&& (pIe->id != IE_NOT_EXIST))
{
pdu[pos++] = pIe->id;
pdu[pos++] = pIe->len;
memcpy(pdu+pos, pIe->GetIeData(l), pIe->len);
pos += pIe->len;
}
if (pIe != NULL)
{
DelIE(PSG_IE_CG_IND);
}
}
// ### End 2005-10-30 ###
// Make up all other IEs.
for (i=0; i<IeCounter; ++i)
{
pdu[pos++] = IE[i].id;
pdu[pos++] = IE[i].len;
if ((pos + IE[i].len) >= MAX_MSGLEN)
{ // Message too long.
printf("Joyit API too long. mType:0x%04X\n", mType);
break;
}
memcpy(pdu+pos, IE[i].GetIeData(l), IE[i].len);
pos += IE[i].len;
}
// Allocate memory for this PDU.
if (i == IeCounter)
{
pPdu = new char[pos];
if (pPdu != NULL)
{
// ((SJoyitApiHead *)pdu)->msgType = mType;
/* // Delete 2006-05-11, by Wu jianjin.
((SJoyitApiHead *)pdu)->primType = primType; // Modify 2005-10-27, by Wujianjin.
((SJoyitApiHead *)pdu)->noie = IeCounter;
*/
// ((SJoyitApiHead *)pdu)->PktLength = pos;
// Modify 2006-05-11, by Wu jianjin.
((SInterApiHead *)pdu)->primType = primType;
((SInterApiHead *)pdu)->noie = IeCounter;
memcpy(pPdu, pdu, pos);
len = pos;
}
else
{ // Out of memory.
printf("Make up Joyit API out of memory. mType:0x%04X\n", mType);
}
}
return pPdu;
}
// ===========================================================================
//
// Description: Decompose Inter API message.
// Input:
// ptr Pointer point to Inter API message string.
// len Length of Inter API message. The message begin with message type.
// Output: Null
// Return: int
// >=0 Success.
// -1 Incompleted PDU.
// -2 Exceed data in PDU.
//
// ===========================================================================
/*
int CPduBase::DecomposeInterApi(char * ptr, UINT16 len)
{
int r = 0;
char *pPdu = ptr;
UINT8 noie;
UINT16 pos = 0; // Calculate the length of PDU.
if (len > sizeof(SInterApiHead))
{
// Store the PDU header.
LengthOfHeader = sizeof(SInterApiHead);
memcpy(Header, pPdu, sizeof(SInterApiHead));
pPdu += LengthOfHeader;
pos += LengthOfHeader;
// Get the message type and number of IEs.
// mType = ((SInterApiHead *)Header)->msgType;
primType = ((SInterApiHead *)Header)->primType;
noie = ((SInterApiHead *)Header)->noie;
// Get all IEs.
for (int i=0; i<noie; i++)
{
UINT8 ieId, ieLen;
char * pIedata;
ieId = *pPdu++;
ieLen = *pPdu++;
pIedata = pPdu;
pPdu += ieLen;
pos += (ieLen + 2);
if (pos > len)
{
r = -1; // Imcompleted PDU.
break;
}
else
{
PutIE(ieId, ieLen, pIedata);
if (PSG_IE_MSGTYPE == ieId) // Add 2005-10-27, by Wujianjin. Save the message type value.
{
mType = *((UINT16 *)pIedata);
}
}
}
if (pos < len)
{ // Exceed data in PDU.
r = -2; // Exceed data.
}
}
else
{
r = -1; // Imcompleted PDU.
}
return r;
}
*/
// ===========================================================================
//
// Description: Pack up IE into Inter API message.
// Input: Null
// Output:
// len Length of Inter API message.
// Return: char *
// NULL Failure.
// Other Pointer point to Inter API message.
//
// ===========================================================================
/*
char * CPduBase::ComposeInterApi(UINT16& len)
{
char * pPdu = NULL;
char pdu[MAX_MSGLEN] = { 0 };
UINT8 pos = 0;
UINT16 l;
int i;
// Make up API header.
memcpy(pdu, Header, sizeof(SInterApiHead));
pos += sizeof(SInterApiHead);
// Make up all IEs.
for (i=0; i<IeCounter; ++i)
{
pdu[pos++] = IE[i].id;
pdu[pos++] = IE[i].len;
if ((pos + IE[i].len) >= MAX_MSGLEN)
{ // Message too long.
printf("Inter API too long. mType:0x%04X\n", mType);
break;
}
memcpy(pdu+pos, IE[i].GetIeData(l), IE[i].len);
pos += IE[i].len;
}
// Allocate memory for this PDU.
if (i == IeCounter)
{
pPdu = new char[pos];
if (pPdu != NULL)
{
// ((SInterApiHead *)pdu)->msgType = mType;
((SInterApiHead *)pdu)->primType = primType;
((SInterApiHead *)pdu)->noie = IeCounter;
// ((SJoyitApiHead *)pdu)->PktLength = pos;
memcpy(pPdu, pdu, pos);
len = pos;
}
else
{ // Out of memory.
printf("Make up Inter API out of memory. mType:0x%04X\n", mType);
}
}
return pPdu;
}
*/
void CPduBase::ReconstructIndex( )
{ // Add 2005-11-04, by Wujianjin.
memset(Ieid2Index, IE_NOT_EXIST, MAX_IE*sizeof(UINT8));
for (UINT8 i=0; i<IeCounter; ++i)
{
if (IE_NOT_EXIST == Ieid2Index[IE[i].id])
{
Ieid2Index[IE[i].id] = i;
}
}
}
// ------------------------------------------------------------------------
//
// Revision list.
// ==============
//
// 1.0, 2005-08-02, Wu jianjin
// Initial version.
// 1.1, 2005-10-26, Wu jianjin.
// Add Inter API message compose and decompose function.
//
// ------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?