📄 cfpcooperatedch.cpp
字号:
#include "StdAfx.h"
#include "CfpFp.h"//#include "CFpCooperateDch.h"
CString ConvertToHexStr(BYTE *pFirst,int length,bool order)
{
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
CString str,tempStr;
str.Empty();
for(int n=0;n<length;n++)//读字符串
{
tempStr.Format("%02X",*pFirst);
if(order==TRUE)
str.operator +=(tempStr+" ");
else
str.Insert(0, tempStr+" ");
pFirst++;
}//for
const char *pccHex = str;
return str;
}
CFpCooperateDch::CFpCooperateDch()
{
pFirstTB=NULL;
pFirstTFI=NULL;
pMsgHead=NULL;
}
CFpCooperateDch::~CFpCooperateDch()
{
if (DCHPduArray.GetCount()!=0)
{
int num=DCHPduArray.GetCount();
for(;num>0;num--)
{
CFpMacDch *p;
p=DCHPduArray.GetHead();
DCHPduArray.RemoveHead();
delete p;
}
}
if (CFPPduArray.GetCount()!=0)
{
int num=CFPPduArray.GetCount();
for(;num>0;num--)
{
CFp *p;
p=CFPPduArray.GetHead();
CFPPduArray.RemoveHead();
delete p;
}
}
if (CHTBStructArray.GetCount()!=0)
{
int num=CHTBStructArray.GetCount();
for(;num>0;num--)
{
TBSstruct *p;
p=CHTBStructArray.GetHead();
CHTBStructArray.RemoveHead();
delete p;
}
}
if (RLCPduArray.GetCount()!=0)
{
int num=RLCPduArray.GetCount();
for(;num>0;num--)
{
CFpRlc *p;
p=RLCPduArray.GetHead();
RLCPduArray.RemoveHead();
delete p;
}
}
if (pFirstTB!=NULL)
{
delete pFirstTB;
}
if (pFirstTFI!=NULL)
{
delete pFirstTFI;
}
/* 雒江涛 2006-3-29
if (pMsgHead!=NULL)
{
delete pMsgHead;
}
*/
}
TBSstruct::TBSstruct()
{
pFirstTB=NULL;
}
TBSstruct::~TBSstruct()
{
// 雒江涛 删除 2006-3-29
}
WORD CFpCooperateDch::Initial(const FPPARA_ARRAY &FpConfigInf)
{
int Num=FpConfigInf.GetSize();
if(Num>0)
{
ConfigInfArray.Copy(FpConfigInf);
for(int i=0;i<Num;i++)
{
CFpMacDch *p = new CFpMacDch;
p->Initialize(ConfigInfArray[i].m_MapLChSet);
p->SetTrCh(ConfigInfArray[i].eTrChType);
p->SetDir(ConfigInfArray[i].nDirection);
DCHPduArray.AddToRear(p);
}
}
cfp.SetDir(ConfigInfArray[0].nDirection);
return 0;
}
WORD CFpCooperateDch::Decode(CString &res)
{
pMsgHead = GetHeadPointer();
PduLength=GetBitLength();
FTbyte *pFTbyteSruct;
pFTbyteSruct=(FTbyte *)pMsgHead;
if ((*pFTbyteSruct).FT==1)//控制桢
{//1
DCHControlFrameDecode(pMsgHead,PduLength,res);
return 0;
}//1
else//数据桢
{//2
WORD CHNumber;
CHNumber=ConfigInfArray.GetSize();//(得到AAL2类链接上承载的传输信道数目)
if (ConfigInfArray[0].nDirection==UpLink)
{//2.1
WORD ULDecodestate;
ULDecodestate=DCHULCooperdecode(pMsgHead,PduLength,res);
if(ULDecodestate==0)
{
WORD TBNumber;//一个传输信道内的TB块数量
int i=0;//第几个传输信道,在CFpMacDch对象链表中,第几个CFpMacDch对象就对应第几个传输信道,也等同于第几个TBS块。
for(;CHNumber>=1;)
{//2.1.1
TBNumber=(CHTBStructArray.GetAt(i)->TBSByteLength)/(CHTBStructArray.GetAt(i)->TBByteLenth);
DWORD nBitLength;
nBitLength=CHTBStructArray.GetAt(i)->TBbitLength;
BYTE *pPduData;
pPduData=(BYTE *)CHTBStructArray.GetAt(i)->pFirstTB;
int LogIDNum=ConfigInfArray[i].m_MapLChSet.GetSize();//一个传输信道所有可能映射的逻辑信道的ID的数目
for(int i=0;i<LogIDNum;i++)//由于是多个传输信道协同,所以将RLCPduArray的初始化放在这里。
{//2.1.1.1
CFpRlc *p = new CFpRlc;
p->SetDir(ConfigInfArray[i].nDirection);
p->SetTrCh(ConfigInfArray[i].eTrChType);
p->SetTBSeg(TBNumber);
RLCPduArray.AddToRear(p);
}//2.1.1.1
int j=1;//add by QiYing
for(;TBNumber>=1;)
{//2.1.1.2
DCHPduArray.GetAt(i)->Create(nBitLength, pPduData);
BYTE CHid;
WORD MacULDecodeState;
CString str;//
str.Format(_T("⑴Transport Block"));//
res+=str;//增加新的格式 2006年4月12日
MacULDecodeState=DCHPduArray.GetAt(i)->Decode(res, CHid);
if(MacULDecodeState!=0)
{
res+=TrailStr;//4.13新的输出格式
TrailStr.Empty();
return 1;
}
DCHPduArray.GetAt(i)->GetSdu(*RLCPduArray.GetAt(CHid));
WORD RlcULDecodeState;
RlcULDecodeState=RLCPduArray.GetAt(CHid)->Decode(res);
if(RlcULDecodeState!=0)
{
res+=TrailStr;//4.13新的输出格式
TrailStr.Empty();
return 1;
}
WORD rrcpduState=2;//rrcpduState先定义值为2,目的是进入下边for循环内。
for(;(rrcpduState!=1)&&(rrcpduState!=0);)
{//2.1.1.2.1
rrcpduState=RLCPduArray.GetAt(CHid)->GetSdu(cfp);
if (rrcpduState!=1)
{//2.1.1.2.1.1
CFp *pCFP=new CFp;
*pCFP=cfp;
CFPPduArray.AddToRear(pCFP);
}//2.1.1.2.1.1
}//2.1.1.2.1
// str.Format(_T("⑴Padding"));///
// res+=Pad;///
res+=PadStr[j];///
j++;
TBNumber--;
pPduData= pPduData+ CHTBStructArray.GetAt(i)->TBByteLenth;//指针移到下一个TB块开始位置。
}//2.1.1.2
res+=TrailStr;//4.13新的输出格式
TrailStr.Empty();
CHNumber--;
i++;
}//2.1.1
// res+=TrailStr;
return 0;
}
else
{
return 1;
}
}//2.1
else
{//2.2
WORD DLDecodestate;
DLDecodestate=DCHDLCooperdecode(pMsgHead,PduLength,res);
if(DLDecodestate==0)
{
WORD TBNumber;//一个传输信道内的TB块数量
int i=0;//第几个传输信道,在CFpMacDch对象链表中,第几个CFpMacDch对象就对应第几个传输信道,也等同于第几个TBS块。
for(;CHNumber>=1;)
{//2.2.1
TBNumber=(CHTBStructArray.GetAt(i)->TBSByteLength)/(CHTBStructArray.GetAt(i)->TBByteLenth);
DWORD nBitLength;
nBitLength=CHTBStructArray.GetAt(i)->TBbitLength;
BYTE *pPduData;
pPduData=(BYTE *)CHTBStructArray.GetAt(i)->pFirstTB;
int LogIDNum=ConfigInfArray[i].m_MapLChSet.GetSize();//一个传输信道所有可能映射的逻辑信道的ID的数目
for(int i=0;i<LogIDNum;i++)//由于是多个传输信道协同,所以将RLCPduArray的初始化放在这里。
{//2.2.1.1
CFpRlc *p = new CFpRlc;
p->SetDir(ConfigInfArray[i].nDirection);
p->SetTrCh(ConfigInfArray[i].eTrChType);
p->SetTBSeg(TBNumber);
RLCPduArray.AddToRear(p);
}//2.2.1.1
int j=1;//add by QiYing
for(;TBNumber>=1;)
{//2.2.1.2
DCHPduArray.GetAt(i)->Create(nBitLength, pPduData);
BYTE CHid;
WORD MacDLDecodeState;
CString str;//
str.Format(_T("⑴Transport Block"));
res+=str;//增加新的格式 2006年4月12日
MacDLDecodeState=DCHPduArray.GetAt(i)->Decode(res, CHid);
if(MacDLDecodeState!=0)
{
res+=TrailStr;//4.13新的输出格式
TrailStr.Empty();
return 1;
}
DCHPduArray.GetAt(i)->GetSdu(*RLCPduArray.GetAt(CHid));
WORD RlcDLDecodeState;
RlcDLDecodeState=RLCPduArray.GetAt(CHid)->Decode(res);
if(RlcDLDecodeState!=0)
{
res+=TrailStr;//4.13新的输出格式
TrailStr.Empty();
return 1;
}
WORD rrcpduState=2;//rrcpduState先定义值为2,目的是进入下边for循环内。
for(;(rrcpduState!=1)&&(rrcpduState!=0);)
{//2.2.1.2.1
rrcpduState=RLCPduArray.GetAt(CHid)->GetSdu(cfp);
if (rrcpduState!=1)
{//2.2.1.2.1.1
CFp *pCFP=new CFp;
*pCFP=cfp;
CFPPduArray.AddToRear(pCFP);
}//2.2.1.2.1.1
}//2.2.1.2.1
// str.Format(_T("⑴Padding"));
// res+=str;
// res+=Pad;
res+=PadStr[j];
j++;
// PadStr.Empty();
TBNumber--;
pPduData= pPduData+ CHTBStructArray.GetAt(i)->TBByteLenth;//指针移到下一个TB块开始位置。
}//2.2.1.2
res+=TrailStr;//4.13新的输出格式
TrailStr.Empty();
CHNumber--;
i++;
}//2.2.1
return 0;
}
else
{
return 1;
}
}//2.2
}//2
return 0;
}
WORD CFpCooperateDch::GetSdu(CFp &sdu)
{
int n;
n=CFPPduArray.GetCount();
if(n>0)
{
CFp *k = CFPPduArray.GetHead();
sdu = *k;
CFPPduArray.RemoveHead();
delete k;
if (n==1)
{
return 0;
}
else
{
return 2;
}
}
else
{
return 1;
}
}
/*{
int n;
n=CFPPduArray.GetCount();
CFp *k = CFPPduArray.GetHead();
sdu = *k;
CFPPduArray.RemoveHead();
delete k;
if (n==1)
{
return 0;
}
else
{
return 2;
}
}*/
WORD CFpCooperateDch::DCHDLCooperdecode(BYTE *pMsg, WORD Length, CString &res)
{
CString str;
BYTE *temp=pMsg;
WORD PDULength;//3月15日晚间修改
PDULength=GetBitLength();//3月15日晚间修改
int PDUByteLength;
PDUByteLength=PDULength/8;
PDUByteLength=PDUByteLength-2-ConfigInfArray.GetSize()-(ConfigInfArray[0].wCrcBitSize/8);//如果PDULength在减去FP帧的帧头和帧尾以后小于0,那么不解码,返回解码错误信息。
if(PDUByteLength>0)
{//11 3月15日,修改增加程序健壮性。
str.Format(_T("#FP DCH: Data"));// Modify on 4/12 by QiYing
res+=str;
str.Format(_T("⑴Header"));// Modify on 4/12 by QiYing
res+=str;
str.Format(_T("@Header CRC|%X|帧头CRC"),(*temp&0xfe)>>1);
res+=str;
temp++;
str.Format(_T("@FT(Frame Type)|%X|数据帧"),*temp&0x01);
res+=str;
str.Format(_T("@CFN(Connection Frame Number)|%X|连接帧号"),*temp);
res+=str;
temp++;
str.Format(_T("⑵TFI(Transport Format Indicator)"));// Modify on 4/12 by QiYing
res+=str;
int Num=ConfigInfArray.GetSize();
int a[50];
for(int i=0;i<Num;i++)
{
a[i]=*temp&0x1f;
str.Format(_T("@DCH %d TFI|%X|"),i+1,a[i]);
res+=str;
temp++;
PadStr[i+1].Empty();
}
int sum=0;//计算总TBS长度
for(i=0;i<Num;i++)
{
pFirstTB=temp;
TBSstruct* tempstruct=new TBSstruct;
tempstruct->pFirstTB=temp;
tempstruct->TFIvalue=a[i];
if(ConfigInfArray[i].m_Tfs[a[i]].wNumOfTb!=0)
{
tempstruct->TBbitLength=ConfigInfArray[i].m_Tfs[a[i]].wTbsSize/ConfigInfArray[i].m_Tfs[a[i]].wNumOfTb;
if(tempstruct->TBbitLength%8)
{
int c;
tempstruct->TBByteLenth=tempstruct->TBbitLength/8+1;
tempstruct->TBSByteLength=ConfigInfArray[i].m_Tfs[a[i]].wNumOfTb*tempstruct->TBByteLenth;
for(int n=1;n<=ConfigInfArray[i].m_Tfs[a[i]].wNumOfTb;n++)
{
c=tempstruct->TBbitLength%8;
temp+=tempstruct->TBByteLenth-1;//pointing to the last byte of the current TB
int b[50];
b[n]=*temp&(255>>c);
temp++;
// PadStr.Format(_T("@Padding|%X|填充"),b[n]);
str.Format(_T("⑴Padding"));
PadStr[n]+=str;
str.Format(_T("@Padding|%X|填充"),b[n]);
PadStr[n]+=str;
}
}
else
{
tempstruct->TBByteLenth=tempstruct->TBbitLength/8;
tempstruct->TBSByteLength=ConfigInfArray[i].m_Tfs[a[i]].wNumOfTb*tempstruct->TBByteLenth;
temp+=tempstruct->TBSByteLength;
}
CHTBStructArray.AddToRear(tempstruct);
sum+=tempstruct->TBSByteLength;
}
else
{
str.Format(_T("@第 %d 个传输信道TB块个数为0"),i);
res+=str;
}
}
PDUByteLength=PDUByteLength-sum;// 3月15日,修改增加程序健壮性。
if(PDUByteLength==0)//判断数据中实际的TB长度减去TFI指示的传输格式长度是否大于或等于0(因为考虑到CRCI的存在所以条件为大于等于0),符合的话进行TB块解码,否则报错返回。
{//4 3月15日,修改增加程序健壮性。
str.Format(_T("⑴Trailer"));
TrailStr+=str;
WORD payloadCRCbitlength;
payloadCRCbitlength=ConfigInfArray[0].wCrcBitSize;
str.Format(_T("@Payload CRC|%s|净荷CRC"),ConvertToHexStr(temp,payloadCRCbitlength/8,TRUE));//Modify on 4/12 by QiYing
TrailStr+=str;
return 0;
}
else
{//000
str.Format(_T("数据与传输格式集不符!"));
res+=str;
return 1;
}//000
}
else
{//111
str.Format(_T("待解码数据错误!"));
res+=str;
return 1;
}//111
}
WORD CFpCooperateDch::DCHULCooperdecode(BYTE *pMsg, WORD Length, CString &res)
{
CString str;
BYTE *temp=pMsg;
WORD PDULength;//3月15日晚间修改
PDULength=GetBitLength();//3月15日晚间修改
int PDUByteLength;
PDUByteLength=PDULength/8;
PDUByteLength=PDUByteLength-3-ConfigInfArray.GetSize()-(ConfigInfArray[0].wCrcBitSize/8);//如果PDULength在减去FP帧的帧头和帧尾以后小于0,那么不解码,返回解码错误信息。
if(PDUByteLength>0)
{//11 3月15日,修改增加程序健壮性。
str.Format(_T("#FP DCH: Data"));// Modify on 4/12 by QiYing
res+=str;
str.Format(_T("⑴Header"));//
res+=str;
str.Format(_T("@Header CRC|%X|帧头CRC"),(*temp&0xfe)>>1);
res+=str;
temp++;
str.Format(_T("@FT(Frame Type)|%X|数据帧"),*temp&0x01);
res+=str;
str.Format(_T("@CFN|%X|连接帧号"),*temp);
res+=str;
temp++;
str.Format(_T("⑵TFI(Transport Format Indicator)"));
res+=str;
int Num=ConfigInfArray.GetSize();
int a[50];
int b[50];//used for saving Padding fields
for(int i=0;i<Num;i++)
{
a[i]=*temp&0x1f;
str.Format(_T("@DCH %d TFI|%X|"),i+1,a[i]);
res+=str;
temp++;
PadStr[i+1].Empty();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -