⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statistic.c

📁 CBS(小区广播)程序实现手稿
💻 C
📖 第 1 页 / 共 5 页
字号:
	}
	/* 保存统计定时器在进程区尾部 */
	memcpy(&ProcessData[s_Pid.iProcessId][LPCB_DATA_SIZE-sizeof(int)],&iReturnValue,sizeof(int));
	
	return s_Pid.iProcessId;
}

 
/* 处理X25链路统计
 * <0:返回错误, >=0:返回Pid
 */
int Process_Statistic_X25(CBEMESSAGE_t *LpCBEMessage)
{
	X25_STATISTIC_t                *LpX25Statistic;  
	int                            iReturnValue;
	PID_t                          s_Pid;
	int                            Tid;
	struct x25lnkstats lnkbuf;	/*  buffer to contain statistics */
    struct x25pktstats pktbuf;	/*  buffer to contain statistics */

	s_Pid.cFunctionId=MODULEID;
    s_Pid.cFunctionId=FUNCTIONID;

	/* 分配一个统计进程 */
    s_Pid.cFunctionId=FUNCTIONID;
    s_Pid.cModuleId=MODULEID;
	s_Pid.iProcessId=alloc_pid((char *)&s_Pid);
	if ( s_Pid.iProcessId < 0 )
	{
		printf("Creat Process Error\n");
		return FAILURE;
	}


	memset(&ProcessData[s_Pid.iProcessId][0],0,LPCB_DATA_SIZE);

	memcpy(&ProcessData[s_Pid.iProcessId][0],LpCBEMessage,LpCBEMessage->iLen+2);
	LpX25Statistic=(X25_STATISTIC_t *)&ProcessData[s_Pid.iProcessId][0];

	memcpy(&LpX25Statistic->s_StatMessageHead.s_ReceiverPid,
    	&s_Pid,sizeof(PID_t));

	Tid=GetTid(&LpX25Statistic->BSCIdentifier[0]);
	if (Tid<0)
	{
		return UNRECOGNIZED_BSC;
	}


	
	switch(LpX25Statistic->ParaId)
	{
	case X25PACK_CNT:/* x.25包层通信统计 */
		{
			memset(&pktbuf,0,sizeof(struct x25pktstats));
            if(LpX25Statistic->IfUplink)
			{
				x25packetstats (PORT, s_BscConnectInfo[Tid].X25UpLinkHandle, &pktbuf, XST_CONT, X25NULLFN);
			}
			else
			{
				x25packetstats (PORT, s_BscConnectInfo[Tid].X25DownlinkHandle, &pktbuf, XST_CONT , X25NULLFN);
			}
			memcpy(&ProcessData[s_Pid.iProcessId][sizeof(X25_STATISTIC_t)],&pktbuf,sizeof(struct x25pktstats));
		}
		break;      
	case X25LINK_CNT:/* x.25链路层通信统计 */ 
		{
			memset(&lnkbuf,0,sizeof(struct x25lnkstats));
            if(LpX25Statistic->IfUplink)
			{
				x25linkstats (PORT,s_BscConnectInfo[Tid].X25UpLinkHandle , &lnkbuf, XST_CONT , X25NULLFN);
			}
			else
			{
				x25linkstats (PORT, s_BscConnectInfo[Tid].X25DownlinkHandle, &lnkbuf, XST_CONT , X25NULLFN);
			}
			memcpy(&ProcessData[s_Pid.iProcessId][sizeof(X25_STATISTIC_t)],&lnkbuf,sizeof(struct x25lnkstats));
		}
		break;
	}

	/* 创建统计定时器 */
	iReturnValue=create_timer(LpX25Statistic->StatTimeLength*1000,
		STATISTIC_TIMER,(char *)&s_Pid,NULL);
	/* 创建定时器失败 */
	if (iReturnValue<0)
	{
		printf("Create timer Error!\n");
		/* 结束统计进程 */
		free_pid((char *)&s_Pid);

		return iReturnValue;
	}

	/* 保存统计定时器在进程区尾部 */
	memcpy(&ProcessData[s_Pid.iProcessId][LPCB_DATA_SIZE-sizeof(int)],&iReturnValue,sizeof(int));

	return s_Pid.iProcessId;
}

/* 处理统计定时器到时
 * 返回
 *    END         结束进程
 *    CONTINUANCE 继续
 */
int Process_Statistic_timer_Expired(PID_t s_Pid)
{
	MESSAGE_STATISTIC_t            *LpMessageStatistic;
	int                            iReturnValue;

	LpMessageStatistic=(MESSAGE_STATISTIC_t *)&ProcessData[s_Pid.iProcessId][0];


    iReturnValue=is_busy_pid((char *)&s_Pid);
	/* 统计已被取消 */
	if(iReturnValue==-1)
	{
		return FAILURE;
	}

	switch(LpMessageStatistic->ParaCategory)
	{
	case STATISTIC_CBSE: /* 服务元素的统计 */
		{			
			iReturnValue=Process_Statistic_Cbse_TimeExpired(s_Pid);
		}
		break;
	case STATISTIC_RESET_AND_FAIL:  /* 统计小区广播失败和重新复位的次数 */
		{
			iReturnValue=Process_Statistic_FailAndReset_TimeExpired(s_Pid);			
		}
		break;
	case STATISTIC_X25:  /* X25链路统计 */
		{
			iReturnValue=Process_Statistic_X25_TimeExpired(s_Pid);			
		}
		break;
	}
	
	return iReturnValue;
}


/* 处理Cbse统计定时器到时
 * 返回
 *   END         统计结束
 *   CONTINUANCE 统计继续
 */
int Process_Statistic_Cbse_TimeExpired(PID_t s_Pid)
{
	MESSAGE_STATISTIC_t            *LpMessageStatistic;
	int                            i,j,k;
	int                            iReturnValue;
	CBSE_STATISTIC_RESULT_t        s_CBSEStatisticResult;
	int                            Tid;
	CELL_CBSE_STATISTIC_RESULT_t   s_CellCBSEStatisticResult;
	CBEMESSAGE_t                   s_CBEMessage;
	int                            ilen;/* 固定值 */
	unsigned char                  IfCellExist;/* 小区是否存在 */

	ilen=sizeof(MESSAGE_STATISTIC_t)-sizeof(unsigned short)-sizeof(MESSAGE_HEAD_t);

	LpMessageStatistic=(MESSAGE_STATISTIC_t *)&ProcessData[s_Pid.iProcessId][0];

	switch(LpMessageStatistic->ParaId)
	{
	case CBCPROXY_CBSE_CNT: /* CBCProxy业务请求次数 */
		{
			memcpy(&s_CBSEStatisticResult,&ProcessData[s_Pid.iProcessId][sizeof(MESSAGE_STATISTIC_t)],
				sizeof(CBSE_STATISTIC_RESULT_t));

			/* 有6种业务的统计 */
			i=0;
	        /* 写入 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=WRITE_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount=
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyWriteReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;

            /* 替换 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=REPLACE_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount=
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyReplaceReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount ;
			i++;
			/* 删除 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=KILL_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyKillReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;
            /* 消息状态查询查询 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=QUERY_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyMsgQueryCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;
            /* 小区信道负荷查询 */ 
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=CBCH_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyCBCHReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;

            /* 小区重启 */ 
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=RESET_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyResetCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;
			
			s_CBSEStatisticResult.cNumber=i;			

			/* 返回一次统计结果 */
			memset(&s_CBEMessage,0,sizeof(CBEMESSAGE_t));
			s_CBEMessage.s_MessageHead.iMessageAreaId=C;
			memcpy(&s_CBEMessage.s_MessageHead.s_ReceiverPid,&LpMessageStatistic->s_StatMessageHead.s_SenderPid,sizeof(PID_t));
			memcpy(&s_CBEMessage.s_MessageHead.s_SenderPid,&s_Pid,sizeof(PID_t));
			s_CBEMessage.s_MessageHead.iMessageType=LpMessageStatistic->s_StatMessageHead.iMessageType;
			s_CBEMessage.s_MessageHead.iMessageLength=i*sizeof(STATTYPE_COUNT_t)+1+ilen;
			s_CBEMessage.iLen=s_CBEMessage.s_MessageHead.iMessageLength+sizeof(MESSAGE_HEAD_t);			
			
			/* 将统计请求也返回 */
			if (LpMessageStatistic->StatCounter==0)
			{
				LpMessageStatistic->StatCounter=255;
    			memcpy(&s_CBEMessage.cMessage[0],&LpMessageStatistic->StatSerialId[0],ilen);
				LpMessageStatistic->StatCounter=0;
			}
			else
			{
    			memcpy(&s_CBEMessage.cMessage[0],&LpMessageStatistic->StatSerialId[0],ilen);
			}

			memcpy(&s_CBEMessage.cMessage[ilen],&s_CBSEStatisticResult,s_CBEMessage.s_MessageHead.iMessageLength-ilen);

			AppendCBESendMessage(&s_CBEMessage);

			/* 是否结束统计 */
			if (LpMessageStatistic->StatCounter>0)
			{
				LpMessageStatistic->StatCounter--;
				if (LpMessageStatistic->StatCounter==0)
				{
					return END;
				}
			}

			/* 开始下一次统计 */
    
			i=0;
	        /* 写入 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=WRITE_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount=
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyWriteReqCnt ;
			i++;

            /* 替换 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=REPLACE_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount=
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyReplaceReqCnt ;
			i++;
			/* 删除 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=KILL_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyKillReqCnt;
			i++;
            /* 消息状态查询查询 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=QUERY_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyMsgQueryCnt;
			i++;
            /* 小区信道负荷查询 */ 
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=CBCH_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyCBCHReqCnt;
			i++;

            /* 小区重启 */ 
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=RESET_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_CbcProxyReqCnt.iCBCProxyResetCnt;
			i++;

			s_CBSEStatisticResult.cNumber=i;

			memcpy(&ProcessData[s_Pid.iProcessId][sizeof(MESSAGE_STATISTIC_t)],&s_CBSEStatisticResult,s_CBSEStatisticResult.cNumber*sizeof(STATTYPE_COUNT_t)+1);

			/* 创建统计定时器 */
			iReturnValue=create_timer(LpMessageStatistic->StatTimeLength*1000,
				STATISTIC_TIMER,(char *)&s_Pid,NULL);
			/* 创建定时器失败 */
			if (iReturnValue<0)
			{
				printf("Create timer Error!\n");
				/* 结束统计进程 */
				return END;
			}
			memcpy(&ProcessData[s_Pid.iProcessId][LPCB_DATA_SIZE-sizeof(int)],&iReturnValue,sizeof(int));
		}
		break;
	case BSC_CBSE_CNT:      /* 对各个BSC业务请求次数 */
		{
			Tid=GetTid(&LpMessageStatistic->BSCIdentifier[0]);
			if (Tid<0)
			{
				return END;//UNRECOGNIZED_BSC;
			}

			memcpy(&s_CBSEStatisticResult,&ProcessData[s_Pid.iProcessId][sizeof(MESSAGE_STATISTIC_t)],
				sizeof(CBSE_STATISTIC_RESULT_t));

			/* 有6种业务的统计 */
    
			i=0;

	        /* 写入 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=WRITE_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount=
				s_CBSECount.s_ReqBSCCnt[Tid].iCBCProxyWriteReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount ;
			i++;
            /* 替换 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=REPLACE_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount=
				s_CBSECount.s_ReqBSCCnt[Tid].iCBCProxyReplaceReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount ;
			i++;
			/* 删除 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=KILL_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_ReqBSCCnt[Tid].iCBCProxyKillReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;
            /* 消息状态查询查询 */
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=QUERY_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_ReqBSCCnt[Tid].iCBCProxyMsgQueryCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;
            /* 小区信道负荷查询 */ 
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=CBCH_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_ReqBSCCnt[Tid].iCBCProxyCBCHReqCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;

            /* 小区重启 */ 
			s_CBSEStatisticResult.s_StattypeCount[i].cStatisticType=RESET_STATISTIC;
			s_CBSEStatisticResult.s_StattypeCount[i].iCount= 
				s_CBSECount.s_ReqBSCCnt[Tid].iCBCProxyResetCnt-s_CBSEStatisticResult.s_StattypeCount[i].iCount;
			i++;

			s_CBSEStatisticResult.cNumber=i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -