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

📄 cbcfunction.c

📁 CBS(小区广播)程序实现手稿
💻 C
📖 第 1 页 / 共 5 页
字号:
		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].ilength=0;
		
		memcpy(&LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].s_CellReport[0].s_CellId.cCellId[0],LpCellId,CELLID_LEN);
		/* 初始状态为未知 */
		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].s_CellReport[0].cCellStatus=UNKNOW_STATUS;
		/* 初始完成次数为预定次数 */
		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].s_CellReport[0].iNoOfBroadcastsCompl=NoOfBroadcastReq;
		
		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].ilength++;

		LPs_ResponseCellList->cNumberOfBSC++;
	}
	else
	{
		return UNRECOGNIZED_BSC;
	}

	return SUCCESS;
}




/* 将不可用小区加到响应小区列表 */
int Process_Add_Failure_CellId_To_ResponseCellListBuf(unsigned char *LpCellId,CELLLIST_i *LPs_ResponseCellList,unsigned char *LPBSCID)
{
	int i;

	for(i=0;i<LPs_ResponseCellList->cNumberOfBSC;i++)
	{
		/* 比较BSCID */
		if(memcmp(&LPs_ResponseCellList->s_BSCCellList[i].BSCIdentifier[0],LPBSCID,BSC_INDENTIFIER_LEN)==0)
		{
			/* 列表是否满了 */
        	if (LPs_ResponseCellList->s_BSCCellList[i].ilength>=MAX_BSC_CELL_COUNT)
			{
		        return FAILURE;
			}
			memcpy(&LPs_ResponseCellList->s_BSCCellList[i].s_CellReport[LPs_ResponseCellList->s_BSCCellList[i].ilength].s_CellId.cCellId[0],
				LpCellId,CELLID_LEN);
			/* 失败原因 */
			LPs_ResponseCellList->s_BSCCellList[i].s_CellReport[LPs_ResponseCellList->s_BSCCellList[i].ilength].cCellStatus=PERMANENT_FAILURE;

			LPs_ResponseCellList->s_BSCCellList[i].ilength++;

			return SUCCESS;
		}

	}

	/* 没有该BSC小区列表 */
	if (LPs_ResponseCellList->cNumberOfBSC<MAX_BSC_CONNECT)
	{
		memcpy(&LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].BSCIdentifier[0],LPBSCID,BSC_INDENTIFIER_LEN);
		
		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].ilength=0;
		
		memcpy(&LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].s_CellReport[0].s_CellId.cCellId[0],LpCellId,CELLID_LEN);
		
		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].s_CellReport[0].cCellStatus=PERMANENT_FAILURE;

		LPs_ResponseCellList->s_BSCCellList[LPs_ResponseCellList->cNumberOfBSC].ilength++;

		LPs_ResponseCellList->cNumberOfBSC++;
	}
	else
	{
		return UNRECOGNIZED_BSC;
	}

	return SUCCESS;
}


//处理从Bsc来的响应
/*
int Process_Response(int Tid)
{
	int                     iReturnValue;
	WRITEREPLACE_REQUEST_t  *LPWriteReplaceRequest;
	REPORTSUCCESS_t         s_Report;
	CBEMESSAGE_t            s_CBEMessage;
	CBEMESSAGE_t            s_CBCProxyMessage;
	CELLLIST_t              s_CellList;  
	int                     i;
	PID_t                   s_SelectedPid;

	memset(&s_Report,0,sizeof(REPORTSUCCESS_t));
	memset(&s_CBEMessage,0,sizeof(CBEMESSAGE_t));
	
	if ((CBCBSC_Unpack.p_MessageIdentifier.bFlag!=EXIST)
		||(CBCBSC_Unpack.p_Serialnumber.bFlag!=EXIST))
	{
		printf("Parameter needed in Bsc Response! \n");
		return FAILURE;
	}

	memcpy(&s_Report.p_MessageIdentifier,&CBCBSC_Unpack.p_MessageIdentifier,sizeof(MESSAGEIDENTIFIER_t));
	memcpy(&s_Report.p_Serialnumber,&CBCBSC_Unpack.p_Serialnumber,sizeof(SERIALNUMBER_t));

	if (CBCBSC_Unpack.p_NoofBroadcastComlList.bFlag==EXIST)
		memcpy(&s_Report.p_NoofBroadcastComlList,&CBCBSC_Unpack.p_NoofBroadcastComlList,sizeof(NOOFBROADCASTSCOMLLIST_t));

	if (CBCBSC_Unpack.p_FailureReportList.bFlag==EXIST)
	{
		memcpy(&s_Report.p_FailureReportList,&CBCBSC_Unpack.p_FailureReportList,sizeof(FAILURELIST_t));
*/	
/*		
		//如果是Write_Replace且不是超时状态,重发
		if ((s_BscConnectInfo[Tid].cResendTimes<MAX_RESEND_TIMES)
			&&(s_BscConnectInfo[Tid].MessageType==CBSE_WRITE_REPLACE))
		{
			memset(&s_CellList,0,sizeof(CELLLIST_t));

			LPWriteReplaceRequest=(WRITEREPLACE_REQUEST_t *)&s_BscConnectInfo[Tid].OriginalMessageBuf[(sizeof(MESSAGE_HEAD_t)+sizeof(short))];
			
			for(i=0;i<s_Report.p_FailureReportList.iLength;i++)
			{
				//基站系统负荷超载	(7),
				//小区内存溢出		(8),
				//基站系统内存溢出	(9),
				if ((s_Report.p_FailureReportList.s_FailureReason[i].cCause==BSS_CAPACITY_EXCEEDED)||
					(s_Report.p_FailureReportList.s_FailureReason[i].cCause==CELL_MEMORY_EXCEEDED)||
					(s_Report.p_FailureReportList.s_FailureReason[i].cCause==BSS_MEMORY_EXCEEDED))
				{
					s_CellList.cCellIdDisc=2;
					memcpy(&s_CellList.s_CellList[s_CellList.iLength].cCellId[0],
						&s_Report.p_FailureReportList.s_FailureReason[i].s_Cellid.cCellId[0],4);
					s_CellList.iLength++;
				}	
			}
			if (s_CellList.iLength>0)
			{
				s_CellList.bFlag=EXIST;
			

				memcpy(&LPWriteReplaceRequest->p_CellList,&s_CellList,sizeof(CELLLIST_t));
					
				//创建进程
				s_SelectedPid.cModuleId=MODULEID;     
				s_SelectedPid.cFunctionId=FUNCTIONID; 
				s_SelectedPid.iProcessId=alloc_pid((char *)&s_SelectedPid);
				if ( s_SelectedPid.iProcessId >= 0 )
				{
					//创建定时器
					iReturnValue=create_timer(RESEND_PERIOD,SCHEDULED_RESEND,(char *)&s_SelectedPid,NULL);
       				if (iReturnValue<0)
					{
	        			printf("Create timer Error!\n");
						//释放进程
						free_pid((char *)&s_SelectedPid);
					}
					else
					{
						 //复制次数 
						memcpy(&s_BscConnectInfo[Tid].OriginalMessageBuf[(sizeof(MESSAGE_HEAD_t)+sizeof(short)+sizeof(WRITEREPLACE_REQUEST_t ))],
							&s_BscConnectInfo[Tid].cResendTimes,sizeof(int));
						//复制Tid
						memcpy(&s_BscConnectInfo[Tid].OriginalMessageBuf[(sizeof(MESSAGE_HEAD_t)+sizeof(short)+sizeof(WRITEREPLACE_REQUEST_t)+sizeof(int))],
							&Tid,sizeof(int));
   					  //拷贝进程数据区
						memcpy(&ProcessData[s_SelectedPid.iProcessId][0],&s_BscConnectInfo[Tid].OriginalMessageBuf[0],LPCB_DATA_SIZE);
					}
				}
				else
				{
					printf("Creat Process Error\n");						
				}
			}
		}
		else
		{
        //不重发设为永久失败
			for(i=0;i<s_Report.p_FailureReportList.iLength;i++)
			{
				//基站系统负荷超载	(7),
				//小区内存溢出		(8),
				//基站系统内存溢出	(9),
				if ((s_Report.p_FailureReportList.s_FailureReason[i].cCause==BSS_CAPACITY_EXCEEDED)||
					(s_Report.p_FailureReportList.s_FailureReason[i].cCause==CELL_MEMORY_EXCEEDED)||
					(s_Report.p_FailureReportList.s_FailureReason[i].cCause==BSS_MEMORY_EXCEEDED))
				{
					s_Report.p_FailureReportList.s_FailureReason[i].cCause=PERMANENT_FAILURE;
				}
			}
		}
			
*/
/*		
	}

	if (CBCBSC_Unpack.p_ChannelIndicator.bFlag==EXIST)
	{
		memcpy(&s_Report.p_ChannelIndicator,&CBCBSC_Unpack.p_ChannelIndicator,sizeof(CHANNELINDICATOR_t));
	}
*/
/*	char cHandToHandSingnal[8];
	int  iMessageAreaId;
	PID_t s_ReceiverPid;
	PID_t s_SenderPid;
	int  iMessageType;
	int  iMessageLength;
	short           iProcessId;
	unsigned char   cFunctionId;
	unsigned char   cModuleId;	
*/

/*	
	s_CBEMessage.s_MessageHead.iMessageAreaId=A;
	//CBSE_REPORT_SUCCESS
	s_CBEMessage.s_MessageHead.iMessageType=3;

	s_CBEMessage.s_MessageHead.s_SenderPid.cFunctionId=FUNCTIONID;
	s_CBEMessage.s_MessageHead.s_SenderPid.cModuleId=MODULEID;


	//for reduce the SocketBag's length 
	if ((CBCBSC_Unpack.p_NoofBroadcastComlList.bFlag!=EXIST)&&
		(CBCBSC_Unpack.p_FailureReportList.bFlag!=EXIST)&&
		(CBCBSC_Unpack.p_ChannelIndicator.bFlag!=EXIST))
	{
		//All optional Parameters are not existent
		s_CBEMessage.s_MessageHead.iMessageLength=sizeof(MESSAGEIDENTIFIER_t)+sizeof(SERIALNUMBER_t);
	}else
	{
		s_CBEMessage.s_MessageHead.iMessageLength=sizeof(REPORTSUCCESS_t);
	}

	s_CBEMessage.iLen=sizeof(MESSAGE_HEAD_t)+s_CBEMessage.s_MessageHead.iMessageLength;
	memcpy(&s_CBEMessage.cMessage[0],(char *)&s_Report,s_CBEMessage.s_MessageHead.iMessageLength);
//	s_CBEMessage.SocketHandle=s_BscConnectInfo[Tid].SocketHandle;

    memset(&s_CBCProxyMessage,0,sizeof(CBEMESSAGE_t));
    //压缩列表参数
	Convert_Response(&s_CBEMessage,&s_CBCProxyMessage);	
	AppendCBESendMessage(&s_CBCProxyMessage);
	return SUCCESS;
}
*/


/* 处理从BSC来的响应 */
int Process_Response(int Tid)
{
	PID_t                             s_Pid;
	unsigned char                     ResponseType;
	WRITEREPLACE_PROCESS_DATA_STRUCT  *LPs_WriteReplaceProcessDataStruct;
	KILL_PROCESS_DATA_STRUCT          *LPs_KillProcessDataStruct;

    REPORTSUCCESS_t                   m_Report; 
	int                               i,j;
	unsigned char                     cNeedResend;
	int                               iBscPosi;  /* BSC在响应列表中的偏移量 */
	int                               iReturnValue;



	cNeedResend=0;

	memset(&m_Report,0,sizeof(REPORTSUCCESS_t));
	
    memcpy(&s_Pid,&s_BscConnectInfo[Tid].s_Pid,sizeof(PID_t));



	memcpy(&m_Report.p_MessageIdentifier,&CBCBSC_Unpack.p_MessageIdentifier,sizeof(MESSAGEIDENTIFIER_t));
	memcpy(&m_Report.p_Serialnumber,&CBCBSC_Unpack.p_Serialnumber,sizeof(SERIALNUMBER_t));

	/* 完成列表 */
	if (CBCBSC_Unpack.p_NoofBroadcastComlList.bFlag==EXIST)
	{
		memcpy(&m_Report.p_NoofBroadcastComlList,&CBCBSC_Unpack.p_NoofBroadcastComlList,sizeof(NOOFBROADCASTSCOMLLIST_t));
	}
    
	/* 失败报告 */
	if (CBCBSC_Unpack.p_FailureReportList.bFlag==EXIST)
	{
		memcpy(&m_Report.p_FailureReportList,&CBCBSC_Unpack.p_FailureReportList,sizeof(FAILURELIST_t));

	}
    
	/* 信道指示 */
	if (CBCBSC_Unpack.p_ChannelIndicator.bFlag==EXIST)
	{
		memcpy(&m_Report.p_ChannelIndicator,&CBCBSC_Unpack.p_ChannelIndicator,sizeof(CHANNELINDICATOR_t));
	}

	/* 是CBC内部发的删除 */
	if ((s_Pid.iProcessId==0)&&(s_Pid.cFunctionId==0)&&
	    (s_Pid.cModuleId==0))
	{
		return FAILURE;				
	}

	
	/* 进程是否存在 */
	if (is_busy_pid((char *)&s_Pid)<0)
	{
		return FAILURE;
	}
   
	/* 考虑到删除消息 */
	ResponseType=ProcessData[s_Pid.iProcessId][sizeof(CBEMESSAGE_t)];

	switch (ResponseType)
	{

	case CBCPROXY_REPORT_WRITE :           /* 写入消息报告 */
		{

			if(m_Report.p_NoofBroadcastComlList.bFlag==EXIST)
			{
				/* 小区WRITE成功次数加一 */
				for(i=0;i<m_Report.p_NoofBroadcastComlList.ilength;i++)
				{
#ifdef  OPEN_STATISTIC
					Update_Cell_Statistic_Count(&m_Report.p_NoofBroadcastComlList.s_NoOfBroadcastComl[i].s_Cellid.cCellId[0],Tid,WRITE_STATISTIC,1,0);
#endif
				}
			}

			LPs_WriteReplaceProcessDataStruct=(WRITEREPLACE_PROCESS_DATA_STRUCT *)&ProcessData[s_Pid.iProcessId][0];

			
			/* 找到对应的BSC */
			for(i=0;i<LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.cNumberOfBSC;i++)
			{

				if (memcmp(&s_BscConnectInfo[Tid].BscIdentifier[0],
					&LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[i].BSCIdentifier[0],
					BSC_INDENTIFIER_LEN)==0)
				{
					break;
				}
			}	
				
			iBscPosi=i;

			if (iBscPosi==LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.cNumberOfBSC)
			{/* 非法响应 */
				return FAILURE;
			}

			/* 收到响应置1 */
			LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].bReceiveRespons=1;

			/* 置相应的小区状态 */
			if (m_Report.p_FailureReportList.bFlag==1)
			{
				/* 小区匹配,考虑小区识别器为1或2,只匹配小区识别码 */
				for (i=0;i<m_Report.p_FailureReportList.iLength;i++)
				{
					for(j=0;j<LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].ilength;j++)
					{
						if(memcmp(&m_Report.p_FailureReportList.s_FailureReason[i].s_Cellid.cCellId[2],
							&LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].s_CellReport[j].s_CellId.cCellId[2]
							,2)==0)
						{
							LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].s_CellReport[j].cCellStatus=
								m_Report.p_FailureReportList.s_FailureReason[i].cCause;

							/* 是否要重发 
					  			基站系统负荷超载	(7),
					   			小区内存溢出		(8),
					   			基站系统内存溢出	(9),
							*/
							if ((m_Report.p_FailureReportList.s_FailureReason[i].cCause==BSS_CAPACITY_EXCEEDED)||
								(m_Report.p_FailureReportList.s_FailureReason[i].cCause==CELL_MEMORY_EXCEEDED)||
								(m_Report.p_FailureReportList.s_FailureReason[i].cCause==BSS_MEMORY_EXCEEDED))
							{
#ifdef  OPEN_STATISTIC	
								/* 失败次数加一 */
								Update_Cell_Statistic_Count(&m_Report.p_FailureReportList.s_FailureReason[i].s_Cellid.cCellId[0],Tid
									,WRITE_STATISTIC, 2,m_Report.p_FailureReportList.s_FailureReason[i].cCause);
#endif
								LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].s_CellReport[j].cCellStatus=TEMP_FAILURE;
								cNeedResend=1;
							}
							else/* 置永久失败 */
							{
								LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].s_CellReport[j].cCellStatus=PERMANENT_FAILURE;
							}
							break;												
						}
					}
				}
						
			}




			LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.bFlag=1;

			/* 是否是重发消息的响应 */
			if (LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].bResendFlag==1)
			{/* 是重发消息的响应 */
				LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].bResendFlag=0;

				/* 返回单条响应 */
	            Process_WriteReturnSingleResponseToCBCProxy(&s_Pid,iBscPosi);			
 				
				/* 要重发 */
				if (cNeedResend==1)
				{
					/* 重发次数<3 */
					if (LPs_WriteReplaceProcessDataStruct->s_ResponseCellList.s_BSCCellList[iBscPosi].cResendTimes<3)
					{
						/* 重发定时器 */
						iReturnValue=create_timer(RESEND_PERIOD,SCHEDULED_RESEND,(char *)&s_Pid,&s_BscConnectInfo[Tid].BscIdentifier[0]);
       					if (iReturnValue<0)
						{
	        				printf("Create Resend timer Error!\n");
							return END;
						}

						/* 生命定时器 */
						if (LPs_WriteReplaceProcessDataStruct->iLifeTimerId>=0)
						{
							kill_timer(LPs_WriteReplaceProcessDataStruct->iLifeTimerId,(char *)&s_Pid);						
						}
						
						iReturnValue=create_timer((RESEND_PERIOD+WAIT_RESPONSE_TIME),LIFE_PERIOD,(char *)&s_Pid,NULL);
       					if (iReturnValue<0)
						{
	        				printf("Create Resend timer Error!\n");
							return END;
						}
						LPs_WriteReplaceProcessDataStruct->iLifeTimerId=iReturnValue;
						
						/* 重发标志置1 */

⌨️ 快捷键说明

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