test.cpp
来自「ABis无线接口全套资料」· C++ 代码 · 共 1,598 行 · 第 1/3 页
CPP
1,598 行
//skip space
while(*end == '\t')
end++;
//bsic
begin = end;
while(*end != '\t')
end++;
strncpy(bsic, begin, end - begin);
//skip space
while(*end == '\t')
end++;
//cell_x
begin = end;
while(*end != '\t')
end++;
strncpy(cell_x, begin, end - begin);
//skip space
while(*end == '\t')
end++;
//cell_y
begin = end;
while(*end != '\n')
end++;
//strncpy(cell_y, begin, end - begin);
strncpy(cell_y, begin, end - begin - 1);/* Xiao Modify for correct fomat */
index = hash_index((unsigned char*)cell_cgi, strlen((const char *)cell_cgi));
if(cell_info_list[index] == NULL)
{
struct SCellInfo *newCell = NULL;
if((newCell = new SCellInfo) == NULL)
{
printf("read_cell_info_list:malloc newCell fail\n");
return ;
}
memset(newCell, 0, sizeof(SNeibhourInfo));
newCell->bcch = atol(bcch);
newCell->bsic = atol(bsic);
memcpy(newCell->cell_cgi, cell_cgi, sizeof(cell_cgi));
memcpy(newCell->cell_name, cell_name, sizeof(cell_name));
newCell->cell_x = atof(cell_x);
newCell->cell_y = atof(cell_y);
cell_info_list[index] = newCell;
}
else
{
struct SCellInfo *pCell = cell_info_list[index];
struct SCellInfo *newCell = NULL;
while(pCell->next != NULL)
{
pCell = pCell->next;
}
//Reach the end
if((newCell = new SCellInfo) == NULL)
{
printf("read_cell_info_list:malloc newCell fail\n");
return ;
}
memset(newCell, 0, sizeof(SNeibhourInfo));
newCell->bcch = atol(bcch);
newCell->bsic = atol(bsic);
memcpy(newCell->cell_cgi, cell_cgi, sizeof(cell_cgi));
memcpy(newCell->cell_name, cell_name, sizeof(cell_name));
newCell->cell_x = atof(cell_x);
newCell->cell_y = atof(cell_y);
pCell->next = newCell;
}
}
}
//说明: 如果程序刚启动还未收到BCCH INFO MESSAGE,则未分析出BA,那么返回-1
// 其他:直接返回数组中的值,可能有两种,
// 第一种:成功找到,返回>1, 第二种:未找到,返回0
void display_ba(bool isIdle, UINT8 pcm, UINT8 cell)
{
SBA* pBa = NULL;
if(isIdle)
pBa = &(gba[pcm][cell].BA0);
else
pBa = &(gba[pcm][cell].BA1);
printf("pcm%d cell%d ", pcm, cell);
for(int i=0; i<pBa->length; ++i)
{
printf("%d ", pBa->BA[i]);
}
printf("\n");
}
#if 0
int FindBcch(bool isIdle, UINT16 linkID, UINT8 tei, UINT8 bcch_freq_index)
{
SBA* pBa = NULL;
UINT8 pcm = linkID/64;
UINT16 bcch = 0;
if(isIdle)
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0);
else
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1);
if (0 == pBa->isInit)
return -1;
bcch = pBa->BA[bcch_freq_index];
//printf("****************************************\n");
//printf("bcch_freq_index = %d bcch = %d\n", bcch_freq_index, bcch);
//display_ba(isIdle, pcm, BtsTrx2Cell(pcm, tei-1));
//printf("****************************************\n");
return bcch;
};
#endif
void show_ba(void)
{
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
if(gba[i][j].BA1.isInit != 0)
{
printf("PCM:%d, CELL:%d\t",i, j);
for(int n = 0; n < 32; n++)
{
printf("%d ",gba[i][j].BA1.BA[n]);
}
printf("\n");
}
}
}
}
void UpdateBcch(CAbisPdu& pdu)
{
CIeBase* pIe = NULL;
UINT8 pcm = 0;
UINT16 linkid = 0; // nk ID
UINT8 tei = 0;
pIe = pdu.GetIE(ABIS_LK_IE_MSG_TYPE);
if(pIe == NULL)
return;
UINT32 pduType = pIe->GetIeData();
SMessageType msgType = (*(SMessageType*)&pduType);
/**********************************************************************/
//更新BA列表
//bacch info msg
//update ba
if( (msgType.TYPE != 17) // BCCH_INFORMATION
&&(msgType.TYPE != 26) // SACCH_FILLING
&&(msgType.TYPE != 52) )//SACCH_INFO_MODIFY
{
return;
}
//get link id
UINT32 data_linkid;
pIe = pdu.GetIE(ABIS_LK_IE_LINKNUMBER);
if(pIe != NULL)
{
UINT32 data = pIe->GetIeData();
data_linkid = pIe->GetIeData();
linkid = *((UINT16*)&data);
pcm = (UINT8)(linkid/64);
}
else
{
return;
}
//get tei
pIe = pdu.GetIE(ABIS_LK_IE_ADDRESS);
if(pIe != NULL)
{
UINT32 data = pIe->GetIeData();
SAddressField addr = *((SAddressField*)&data);
tei = addr.TEI;
}
else
{
return;
}
struct link_header joyit_header;
memcpy(&joyit_header, (char *)&data_linkid, sizeof(link_header));
link_info Link_Infomation;
//Link_Infomation.linknum = linknumber;
Link_Infomation.linknum = (joyit_header.E1_num) |((joyit_header.board_num&0x07)<<3);
//Link_Infomation.linknum = ((joyit_header.E1_num&0x06)>>1) |((joyit_header.board_num&0x07)<<2);
Link_Infomation.address_TEI = tei;
if(NULL == (pIe = pdu.GetIE(LAYER3INFO_IE_SYSTEM_TYPE)))
return;
//printf("pcm%d, cell%d ", pcm, BtsTrx2Cell(pcm, tei-1));
UINT8 type = pIe->GetIeData();
//printf("linkid = %d, pcm = %d ", linkid, pcm);
SBA* pBa = NULL;
switch(type)
{
case LAYER3INFO_MSG_SYSTEM_INFORMATION_TYPE2:
//printf("pcm%d cell%d linkid %d tei %d sys_info_type2\n", pcm, BtsTrx2Cell(pcm, tei-1),linkid,tei);
printf("pcm%d cell%d linknum %d tei %d sys_info_type2\n", pcm, BtsTrx2Cell(pcm, tei-1),Link_Infomation.linknum,tei);
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0);
gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0.isInit = 1;
gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0.length = 0; // 重新开始
break;
case LAYER3INFO_MSG_SYSTEM_INFORMATION_TYPE2BIS:
//printf("pcm%d cell%d linkid %d tei %d sys_info_type2bis\n", pcm, BtsTrx2Cell(pcm, tei-1),linkid,tei);
printf("pcm%d cell%d linknum %d tei %d sys_info_type2bis\n", pcm, BtsTrx2Cell(pcm, tei-1),Link_Infomation.linknum,tei);
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0);
if(0 == gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0.isInit)
return;
break;
case LAYER3INFO_MSG_SYSTEM_INFORMATION_TYPE2TER:
//printf("pcm%d cell%d linkid %d tei %d sys_info_type2ter\n", pcm, BtsTrx2Cell(pcm, tei-1),linkid,tei);
printf("pcm%d cell%d linknum %d tei %d sys_info_type2ber\n", pcm, BtsTrx2Cell(pcm, tei-1),Link_Infomation.linknum,tei);
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0);
if(0 == gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA0.isInit)
return;
break;
case LAYER3INFO_MSG_SYSTEM_INFORMATION_TYPE5:
//printf("pcm%d cell%d sys_info_type5\n", pcm, BtsTrx2Cell(pcm, tei-1));
//printf("pcm%d cell%d linkid %d tei %d sys_info_type5\n", pcm, BtsTrx2Cell(pcm, tei-1),linkid,tei);
printf("pcm%d cell%d linknum %d tei %d sys_info_type5\n", pcm, BtsTrx2Cell(pcm, tei-1),Link_Infomation.linknum,tei);
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1);
gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1.isInit = 1;
gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1.length = 0; // 重新开始
break;
case LAYER3INFO_MSG_SYSTEM_INFORMATION_TYPE5BIS:
//printf("pcm%d cell%d sys_info_type5bis\n", pcm, BtsTrx2Cell(pcm, tei-1));
//printf("pcm%d cell%d linkid %d tei %d sys_info_type5bis\n", pcm, BtsTrx2Cell(pcm, tei-1),linkid,tei);
printf("pcm%d cell%d linknum %d tei %d sys_info_type5bis\n", pcm, BtsTrx2Cell(pcm, tei-1),Link_Infomation.linknum,tei);
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1);
if(0 == gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1.isInit)
return;
break;
case LAYER3INFO_MSG_SYSTEM_INFORMATION_TYPE5TER:
//printf("pcm%d cell%d sys_info_type5ter\n", pcm, BtsTrx2Cell(pcm, tei-1));
//printf("pcm%d cell%d linkid %d tei %d sys_info_type5ter\n", pcm, BtsTrx2Cell(pcm, tei-1),linkid,tei);
printf("pcm%d cell%d linknum %d tei %d sys_info_type5ber\n", pcm, BtsTrx2Cell(pcm, tei-1),Link_Infomation.linknum,tei);
pBa = &(gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1);
if(0 == gba[pcm][BtsTrx2Cell(pcm, tei-1)].BA1.isInit)
return;
break;
}
if(NULL != (pIe = pdu.GetIE(LAYER3INFO_IE_BITMAP0)))
{
UINT16 len;
UINT8* pMap = (UINT8*)pIe->GetIeData(len);
for(int i=0; i<124; ++i)
{
if(pMap[i] != 0)
{
pBa->BA[pBa->length] = i+1;//+1 by chris ,very important
++(pBa->length);
printf("%d(%d) ", pBa->length,i+1);
}
}
printf("\n");
}
else if(NULL != (pIe = pdu.GetIE(LAYER3INFO_IE_VBITMAP)))
{
UINT16 len;
SVBitFormat* pVMap = (SVBitFormat*)pIe->GetIeData(len);
for(int i=0; i<111; ++i)
{
if(pVMap[i].rrfcn != 0)
{
pBa->BA[pBa->length] = pVMap[i].rrfcn;
++(pBa->length);
printf("%d(%d) ", pBa->length,pVMap[i].rrfcn);
}
}
printf("\n");
}
else
{
}
return;
//更新BA列表
}
extern unsigned char local_cgi [300][28];
extern unsigned char local_cgi_print [100][28];
extern int cgi_num;
extern int print_num;
int main(int argc, char **argv)
{
if (argc < 3)
{
Usage( );
return 0;
}
char filetmp[512];
char reportfile[8][512];
memset(filetmp, 0, sizeof(filetmp));
memset(reportfile, 0, sizeof(reportfile));
int filelen = strlen(argv[2]);
strncpy(filetmp, argv[2], filelen);
log = new LogFile[8];
for(int i=0; i<8; ++i)
{
sprintf(filetmp+filelen, ".pcm%d", i);
log[i].SetFileName(filetmp);
log[i].OpenFile();
}
xcpPtr = NULL;
FILE * fp;
fp = fopen(argv[1], "r");
if (NULL == fp)
{
fprintf(stderr, "Given file not noexist.\n");
return -1;
}
unsigned char byte;
char* pos = msubuf;
char endOfFile = 0;
SByte* pByte;
int neib_cnt = 0, cell_cnt = 0;
read_neibhbour_info();
read_cell_info_list();
for(int i = 0; i < MAX_NIBHOUR_LIST; i++)
{
struct SNeibhourInfo * p= nibhour_info_list[i];
struct SNeibhour *pNei ;
while(p != NULL)
{
pNei = p->neibhour;
while(pNei != NULL)
{
neib_cnt++;
pNei = pNei->next;
}
p = p->next;
}
}
printf("neib_cnt:%d\n",neib_cnt);
for(int i = 0; i < MAX_CELL_LIST; i++)
{
struct SCellInfo * p = cell_info_list[i];
while(p != NULL)
{
cell_cnt++;
p = p->next;
}
}
printf("cell_cnt:%d\n",cell_cnt);
while (! feof(fp)
&& (! endOfFile))
{
pos = msubuf;
msulen = 0;
memset(msubuf, '\0', sizeof(msubuf));
memset(msu, '\0', sizeof(msu));
memset(date, '\0', 10);
memset(time, '\0', 8);
if (NULL == fgets(msubuf, 1024, fp))
{
fprintf(stderr, "Reading file error.\n");
return -2;
}
memcpy(date, msubuf, 10);
memcpy(time, msubuf+11, 8);
pos += 20;
msulen = strlen(pos);
msulen += 1;
msulen = msulen/3;
for(int i=0; i<msulen;++i)
{
pByte = (SByte*)pos;
byte = Asci2Byte(pByte->high) << 4;
byte |= Asci2Byte(pByte->low);
msu[i] = byte;
pos += 3;
byte = 0;
}
CAbisPdu pdu;
pdu.Decode(msu, msulen);
UpdateBcch(pdu);
Output(pdu);
}
show_cellmap();
/*
//打印统计信息
for(int i=0; i<8; ++i)
{
printf("BTS%d total MR = %ld success_decode MR = %ld find_cgi MR = %ld\n",
i, gStatTab.BTS_MR_TOTAL[i], gStatTab.BTS_MR_SUCCESS_DECODE[i], gStatTab.BTS_MR_FIND_CGI[i]);
}
show_ba();
*/
return 0;
}
#if 0
int getCgi(int linkID, int tei, char * cgi)
{
for(unsigned int i = 0; i < sizeof(cell_name) / sizeof(SPCMCGI); i++)
{
if((cell_name[i].link_begin <= linkID) && (linkID <= cell_name[i].link_end))
{
if(cell_name[i].tei == tei)
{
memcpy(cgi , cell_name[i].cgi, sizeof(cell_name[i].cgi));
return strlen((const char *)cgi);
}
}
}
return 0;
}
#endif
void Usage( )
{
printf("\n\n");
printf("Copyright (C) 2003~2008, Joyit Communications\n");
printf(" test [input file name] [output file name]\n\n");
}
char Asci2Byte(char asci)
{
if((asci>='0')&&(asci<='9'))
return asci-0x30;
if((asci=='a') || (asci=='A'))
return 10;
if((asci=='b') || (asci=='B'))
return 11;
if((asci=='c') || (asci=='C'))
return 12;
if((asci=='d') || (asci=='D'))
return 13;
if((asci=='e') || (asci=='E'))
return 14;
if((asci=='f') || (asci=='F'))
return 15;
return 0xff;
}
void ConstructPduInfo(CAbisPdu& pdu)
{
}
UINT8 A2O(UINT8 onum)
{
#pragma pack(1)
struct STmp
{
UINT8 low:3;
UINT8 high:3;
UINT8 notuse:2;
}tmp;
#pragma pack(1);
tmp = *(STmp*)(&onum);
return tmp.high*10 + tmp.low;
}
char *get_neibhbour_cell_cgi(char *cell, int bsic, int bcch, char *neibhour)
{
struct SNeibhourInfo * pNeibhour = NULL;
struct SCellInfo *pCellInfo = NULL;
struct SCellInfo *fwest_distance_cell = NULL;
float distance = 0, fwest_distance = 0;
float local_cell_x = 0, local_cell_y = 0;
int index_neib = -1, index_cell = -1;
index_neib = hash_index((unsigned char*)cell, strlen((const char *)cell));
pNeibhour = nibhour_info_list[index_neib];
while(pNeibhour != NULL)
{
if (strncmp(pNeibhour->cell, cell, strlen(cell)) == 0)
{
struct SNeibhour *pNeibCell = pNeibhour->neibhour;
while(pNeibCell != NULL)
{
//找出一个邻居来匹配
//index_cell = hash_index((unsigned char*)pNeibCell->neibhour, strlen(pNeibCell->neibhour));
index_cell = hash_index((unsigned char*)(pNeibCell->neibhour), strlen((const char *)(pNeibCell->neibhour)));
pCellInfo = cell_info_list[index_cell];
while(pCellInfo != NULL)
{
//小区信息表中找出邻居信息
if (strncmp(pNeibCell->neibhour, pCellInfo->cell_cgi, strlen(pNeibCell->neibhour)) == 0)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?