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

📄 ecm.c.bak

📁 有线电视系统前端设备复用器原代码。 用语接受卫星信号
💻 BAK
📖 第 1 页 / 共 5 页
字号:
				
				/*
				caSendLog(LOGTYPE_NORMAL,"cp%03d: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x  cp%03d: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",g_current_cp_number-1,g_CW_List_Backup[para*8 + 0],g_CW_List_Backup[para*8 + 1],g_CW_List_Backup[para*8 + 2],g_CW_List_Backup[para*8 + 3],g_CW_List_Backup[para*8 + 4],g_CW_List_Backup[para*8 + 5],g_CW_List_Backup[para*8 + 6],g_CW_List_Backup[para*8 + 7],g_current_cp_number,g_CW_List[para*8 + 0],g_CW_List[para*8 + 1],g_CW_List[para*8 + 2],g_CW_List[para*8 + 3],g_CW_List[para*8 + 4],g_CW_List[para*8 + 5],g_CW_List[para*8 + 6],g_CW_List[para*8 + 7]);
				*/
			}
			else if((g_ecmg_channel_status[ucCACount].lead_CW==1)&&(g_ecmg_channel_status[ucCACount].CW_per_msg==3))
			{/*一次发三个CW控制字*/
				pItemHead->parameter_type  =ECMG2SCS_CP_CW_Combination;
				pItemHead->parameter_length=10;

				*(unsigned short *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD))=g_current_cp_number-3;
				for(i=0;i<8;i++)
					*(unsigned char *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + 2 + i)=g_CW_List_Backup2[para*8 + i];

				pHead->message_length+=sizeof(CA_MESSAGE_ITEM_HEAD) + 10;

				pItemHead->parameter_type  =ECMG2SCS_CP_CW_Combination;
				pItemHead->parameter_length=10;

				*(unsigned short *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD))=g_current_cp_number-2;
				for(i=0;i<8;i++)
					*(unsigned char *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + 2 + i)=g_CW_List_Backup[para*8 + i];

				pHead->message_length+=sizeof(CA_MESSAGE_ITEM_HEAD) + 10;

				pItemHead=(CA_MESSAGE_ITEM_HEAD *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + 10);
				pItemHead->parameter_type  =ECMG2SCS_CP_CW_Combination;
				pItemHead->parameter_length=10;

				*(unsigned short *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD))= g_current_cp_number -1;
				for(i=0;i<8;i++)
					*(unsigned char *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + 2 + i)=g_CW_List[para*8 + i];

				pHead->message_length+=sizeof(CA_MESSAGE_ITEM_HEAD) + 10;
			}

/*
			pItemHead=(CA_MESSAGE_ITEM_HEAD *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + 10);
			pItemHead->parameter_type  =ECMG2SCS_CP_duration;
			pItemHead->parameter_length=2;
			*(unsigned short *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD))=g_ca_config.Para_Config.CP_Duration;
			pHead->message_length+=sizeof(CA_MESSAGE_ITEM_HEAD) + 2;
*/			

			if(Status_List->streamlist[para].access_criteria_transfer_mode)
			{/*插入ACDATA*/
				pItemHead=(CA_MESSAGE_ITEM_HEAD *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + pItemHead->parameter_length);
				pItemHead->parameter_type  =ECMG2SCS_access_criteria;
				acindex=Status_List->streamlist[para].ECM_stream_ID;

				pItemHead->parameter_length=g_ca_config.AC_Data_List[acindex].SubDataConfig[ucCACount].AC_Data_Length;			
				for(i=0;i<pItemHead->parameter_length;i++)
					*(unsigned char *)((char *)pItemHead + sizeof(CA_MESSAGE_ITEM_HEAD) + i)=g_ca_config.AC_Data_List[acindex].SubDataConfig[ucCACount].AC_Data[i];	

				pHead->message_length+=sizeof(CA_MESSAGE_ITEM_HEAD) + pItemHead->parameter_length;
			}

			Status_List->streamlist[para].waitresponse=1;

			caSendLog(LOGTYPE_NORMAL,"ecmg: Send a stream CW provision message,streamid=%d.",Status_List->streamlist[para].ECM_stream_ID);

			break;
		default:
			break;
	}
	MsgLen=pHead->message_length + 5;
	return ca_send(socket,EcmgSendBuf,MsgLen,Para_Config->Network_Delay);
}

/*-------------------------------------------------------------------------*/
/* switch cw when no ecmg connection                                       */
/* added by johnnyling 2004-02-17                                          */
/*-------------------------------------------------------------------------*/
/*
void ca_switch_CW()
{
	int    i;
	static cp=0;
	unsigned char buf[256];

	ca_write_reg(CA_EVEN_ODD_CONTROL_ADDRESS,cp&0x0003);

	ca_write_reg(CA_READ_CW_CONTROL_ADDRESS,(cp+1)&0x0003);

	NIB_ADDRESS_LOW_REG =0x0E;
	NIB_ADDRESS_HIGH_REG=0;

	for(i=0;i<256;i++)
		*(buf+i)=NIB_ACTION_REG;

	for(i=0;i<64;i++)
		*(buf + i*4 + 3)=*(buf + i*4) + *(buf + i*4 + 1) + *(buf + i*4 + 2);

	cp++;
}
*/

void ca_Get_CW(unsigned char *buf)
{
	int i;

	ca_write_reg(CA_EVEN_ODD_CONTROL_ADDRESS,g_current_cp_number&0x0003);

	ca_write_reg(CA_READ_CW_CONTROL_ADDRESS,(g_current_cp_number+1)&0x0003);

	NIB_ADDRESS_LOW_REG =0x0E;
	NIB_ADDRESS_HIGH_REG=0;

	for(i=0;i<256;i++)
		*(buf+i)=NIB_ACTION_REG;

	for(i=0;i<64;i++)
		*(buf + i*4 + 3)=*(buf + i*4) + *(buf + i*4 + 1) + *(buf + i*4 + 2);

	if(g_current_cp_number >= 255)
		g_current_cp_number = 0;
	else
		g_current_cp_number++;


}

/*CWG中断*/
#if 1
void ca_CW_int_Handle(void)
{
	int				i;
	unsigned long	Msg[4]; 

	/*当通道和流未建立时不需要获得控制字*/

	if(((g_has_valid_ca_config)&&(g_ecmg_connected[0]==0))||
	    ((g_has_valid_ca1_config)&&(g_ecmg_connected[1]==0))||
	     ((g_has_valid_ca2_config)&&(g_ecmg_connected[2]==0)))
	{
             return;
	}
	
#if 1	 /*add by fpx 20060528*/
	if(g_ecmg_channel_status[0].lead_CW==1)
	{
/*		g_current_cp_number=0;*/
/*		if(g_first_CW == 0)*/
/*				ca_Get_CW(g_CW_List);*/
             

		g_first_CW         =1;

		g_wanted_cp_number[0]=1;
		g_wanted_cp_number[1] = 1;
		g_wanted_cp_number[2] = 1;
		
		if(g_ecmg_channel_status[0].CW_per_msg==2)
		{
				for(i=0;i<32*8;i++)
					g_CW_List_Backup[i]=g_CW_List[i];

				ca_Get_CW(g_CW_List);		
		}
	
		if(g_ecmg_stream_status_list[0].streamcount != 0 && !g_ecmg_waitcommand[0])
		{
			Msg[0]=1;
			SendQueue("QONE",Msg);
		}
		if(g_ecmg_stream_status_list[1].streamcount != 0 && !g_ecmg_waitcommand[1])
		{
			Msg[0] = 1;
			SendQueue("QSEC",Msg);
		}
		if(g_ecmg_stream_status_list[2].streamcount != 0 && !g_ecmg_waitcommand[2])
		{
			Msg[0] = 1;
			SendQueue("QTHI",Msg);
		}
	}
#endif

#if 0	 /*rmv by fpx 20060528	*/
	{
		if(!g_first_CW)
		{
			ca_Get_CW(g_CW_List);
			g_first_CW=1;
		}
		if(g_first_CW ==1)
		{
			for(i=0;i<32*8;i++)
				g_CW_List_Backup[i]=g_CW_List[i];

			ca_Get_CW(g_CW_List);

		       g_first_CW++;
		}
		/*----------------------------------------------*/
		/*get all the CW                                */
		/*----------------------------------------------*/
		for(i=0;i<32*8;i++)
			g_CW_List_Backup2[i]=g_CW_List_Backup[i];

		for(i=0;i<32*8;i++)
			g_CW_List_Backup[i]=g_CW_List[i];

		ca_Get_CW(g_CW_List);

		if(g_ecmg_stream_status_list[0].streamcount != 0 && !g_ecmg_waitcommand[0])
		{
			Msg[0]=1;
			SendQueue("QONE",Msg);
		}
		if(g_ecmg_stream_status_list[1].streamcount != 0 && !g_ecmg_waitcommand[1])
		{
			Msg[0] = 1;
			SendQueue("QSEC",Msg);
		}
		if(g_ecmg_stream_status_list[2].streamcount != 0 && !g_ecmg_waitcommand[2])
		{
			Msg[0] = 1;
			SendQueue("QTHI",Msg);
		}
	}
#endif
}
#endif

unsigned char get_continue_counter(unsigned short pid,unsigned char ucCACount)
{
	int i;
	unsigned char continue_counter;

	continue_counter=0;
	for(i=0;i<g_ecmg_stream_status_list[ucCACount].streamcount;i++)
	{
		if(g_ecmg_stream_status_list[ucCACount].streamlist[i].pid==pid)
		{
			continue_counter=g_ecmg_stream_status_list[ucCACount].streamlist[i].continue_counter;
			if(continue_counter==15)
				g_ecmg_stream_status_list[ucCACount].streamlist[i].continue_counter=0;
			else
				g_ecmg_stream_status_list[ucCACount].streamlist[i].continue_counter++;
			break;
		}
	}
	return continue_counter;
}

/*发送TS包到FIFO中*/
void ts_send(char *buf)
{
	int i;
	int rc;
	unsigned long int delay ;
	rc = mu_lock(ulMultEMM, MU_WAIT, 0);
	if(rc)
		Display("Lock Error!");
	
	for(i=0;i<188;i++)
		USER_DATA_WRITE_FIFO_REG=*(buf + i);

	USER_DATA_FRAME_END_REG=0xFF;
	
	rc = mu_unlock(ulMultEMM);
}

/*将ECM信息写到FIFO中*/
void send_ecm(char *buf,int buflen,unsigned short pid,char datatype,unsigned char unCACount)
{
	int             i;
	int             tsnum;
	TS_TAG          *pTsHead;
	char            *pSection;
	short           offset;
	char            *pts;
	char            tspkt[188];
	short           rst;
	int             first;
	
	if(datatype)
	{/* ts packet */
		tsnum= buflen / 188;
		for(i=0;i<tsnum;i++)
		{
			pts= buf + i*188;
			pTsHead=(TS_TAG *)pts;
			pTsHead->PID=pid;	
			pTsHead->Continuity_counter=get_continue_counter(pid,unCACount);
			ts_send(pts);
		}				
	}
	else
	{/*section*/		
		pSection=buf;
		offset=0;

		rst=buflen;
		first=1;
		while(rst>0)
		{
			pTsHead=(TS_TAG *)tspkt;
			MemSet(tspkt,188,0xFF);

			pTsHead->Sync_byte                   =0x47;
			pTsHead->Transport_err_indicator     =0;
			
			if(first)			
				pTsHead->Payload_unit_start_indicator=1;
			else
				pTsHead->Payload_unit_start_indicator=0;

			pTsHead->Transport_priority          =0;
			pTsHead->PID                         =pid;
			pTsHead->Transport_scambling_control =0;
			pTsHead->Adaption_field_control      =1;
			pTsHead->Continuity_counter          =get_continue_counter(pid,unCACount);

			if(first)			
			{
				*(char *)((char *)pTsHead + sizeof(TS_TAG))=0; /* pointer field */
				if(rst<=(188 - 1 - sizeof(TS_TAG)))
				{
					MemCopy((char *)pTsHead + sizeof(TS_TAG) + 1,buf + offset,rst);
					offset+=rst;
					ts_send(tspkt);
					break;
				}
				else
				{
					MemCopy((char *)pTsHead + sizeof(TS_TAG) + 1,buf + offset,188-1-sizeof(TS_TAG));
					offset+=188-1-sizeof(TS_TAG);
					ts_send(tspkt);
					rst-=188 - 1 - sizeof(TS_TAG);
				}

				first=0;
			}
			else
			{
				if(rst<=(188 - sizeof(TS_TAG)))
				{
					MemCopy((char *)pTsHead + sizeof(TS_TAG),buf + offset,rst);
					offset+=rst;
					ts_send(tspkt);
					break;
				}
				else
				{
					MemCopy((char *)pTsHead + sizeof(TS_TAG),buf + offset,188 - sizeof(TS_TAG));
					offset+=188 - sizeof(TS_TAG);
					ts_send(tspkt);
					rst-=188 - sizeof(TS_TAG);
				}
			}
		}
	}
}

/*
int  ecmg_check_response(void)
{
	int i;
	for(i=0;i<g_ecmg_stream_status_list[0].streamcount;i++)
	{
		if(g_ecmg_stream_status_list[0].streamlist[i].waitresponse)
			return 0;
	}
	return 1;
}
*/

int ecmg_close_channel(int socket,unsigned char ucCACount)
{
	ecmgSend(socket,ECMG2SCS_CHANNEL_CLOSE,0,ucCACount);
	return 0;
}

/*关闭所有流,并关闭通道*/
int ecmg_close_all(int socket,unsigned char ucCACount)
{
	int i;

/*
	for(i=0;i<g_ecmg_stream_status_list[0].streamcount;i++)

⌨️ 快捷键说明

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