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

📄 path_switch.c

📁 单片机程序代码,经过很详细的测试.呵呵,硬件相关.
💻 C
📖 第 1 页 / 共 5 页
字号:
						path_switch_array[bportid2][timeid - 1][1] = port;
						path_switch_array[bportid2][timeid - 1][2] = 0xff;
						path_switch_array[bportid2][timeid - 1][3] = 0;
					}						
					break;
			case 2: path_switch_array[2][timeid - 1][0] = bportid;		//填写OTB光口1的供倒换光口
					path_switch_array[2][timeid - 1][1] = port;
					path_switch_array[2][timeid - 1][2] = bportid2;
					path_switch_array[2][timeid - 1][3] = 1;
					if (bportid != 0xff){
						path_switch_array[bportid][timeid - 1][0] = 2;
						path_switch_array[bportid][timeid - 1][1] = port;
						path_switch_array[bportid][timeid - 1][2] = 2;
						path_switch_array[bportid][timeid - 1][3] = 0;
					}
					else {
						path_switch_array[bportid2][timeid - 1][0] = 0xff;		//填写供倒换光口
						path_switch_array[bportid2][timeid - 1][1] = port;
						path_switch_array[bportid2][timeid - 1][2] = 0xff;
						path_switch_array[bportid2][timeid - 1][3] = 0;
					}						
					break;
			case 3: path_switch_array[3][timeid - 1][0] = bportid;
					path_switch_array[3][timeid - 1][1] = port;
					path_switch_array[3][timeid - 1][2] = bportid2;
					path_switch_array[3][timeid - 1][3] = 1;
					if (bportid != 0xff){
						path_switch_array[bportid][timeid - 1][0] = 3;
						path_switch_array[bportid][timeid - 1][1] = port;
						path_switch_array[bportid][timeid - 1][2] = 3;
						path_switch_array[bportid][timeid - 1][3] = 0;
					}
					else {
						path_switch_array[bportid2][timeid - 1][0] = 0xff;		//填写供倒换光口
						path_switch_array[bportid2][timeid - 1][1] = port;
						path_switch_array[bportid2][timeid - 1][2] = 0xff;
						path_switch_array[bportid2][timeid - 1][3] = 0;
					}						
					break;
			default: break;
		}

		return_value = 0;
		if (bportid2 >= 0 & bportid2 <= 3){
			if (bportid != 0xff){
				PTUN(bportid2,btimeid2 - 1) = port;
			}
			else PTUN(bportid2,btimeid2 - 1) = 0xff;
		}
	}
	else return_value = 2;

	if (!GetResRdyTbl(1))
		SetResRdyTbl(1); 
	return (return_value);
}


unsigned char run_path_switch(struct cmd_para_save *path_switch){
//C52运行通道倒换命令
unsigned char xdata boardid;
unsigned char xdata portid;
unsigned char xdata timeid;
unsigned char xdata sboard;
unsigned char xdata sport;
unsigned char xdata stime;
unsigned char xdata bport;
unsigned char xdata outport;
unsigned char xdata mode;
unsigned char xdata return_value;

	commandid = 0x00433532;
	boardid = path_switch -> path_swset_board;				//输出盘号
	portid = path_switch -> path_swset_port;				//输出端口号
	timeid = path_switch -> path_swset_slot;				//输出时隙号
	sboard = path_switch -> path_stset_board;
	sport = path_switch -> path_stset_port;
	stime = path_switch -> path_stset_slot;
	mode = path_switch -> path_swset_mode;					//倒换模式

	switch (sboard){										//得到源端端口在1K50上的端口值
		case 4: if (sport == 1){
   					sport = 2;
				}
				else sport = 3;
				break;
		case 5: if (sport == 1){
					sport = 0;
				}
				else sport = 1;
				break;
		default: break;
	}
	if (mode == 2){
		return_value = 0;
		path_switch_state[timeid - 1] = mode;				//保存倒换模式
	}
	else if ((mode == 1) & (sboard == 0)){	//由自动状态倒换到主用状态
		return_value = 0;
		path_switch_state[timeid - 1] = mode;				//保存倒换模式
	}
	else {													//强制倒换状态
		bport = path_switch_array[sport][timeid - 1][0];
		outport = path_switch_array[sport][timeid - 1][1];
		if (bport < 4){
			PTUN(outport,timeid - 1) = bport;
	//		return_value = path_switch_function(path_switch_array[sport][timeid - 1][0],timeid - 1,outport);
			//调用倒换函数
	//		if (return_value == 0){							//倒换成功更改当前输入表中的输入端口
			path_switch_array[sport][timeid - 1][3] = 0;
			path_switch_array[bport][timeid - 1][3] = 1;
			if (outport < 4){								//若是保护的是时隙,则要同时进行时隙的并发配置
				switch (outport){							//对光口进行并发配置
					case 0: PTUN(1,timeid - 1) = bport;
							//return_value = path_switch_function(0,timeid - 1,1);
							break;
					case 1: PTUN(0,timeid - 1) = bport;
							//return_value = path_switch_function(0,timeid - 1,0);
							break;
					case 2: PTUN(3,timeid - 1) = bport;
							//return_value = path_switch_function(0,timeid - 1,3);
							break;
					case 3: PTUN(2,timeid - 1) = bport;
							//return_value = path_switch_function(0,timeid - 1,2);
							break;
					default:break;
				}
			}
			return_value = 0;
			path_switch_state[timeid - 1] = mode;					//保存倒换模式
		}
		else return_value = 2;
	}
	if (!GetResRdyTbl(1))
		SetResRdyTbl(1); 
	return (return_value);
}



unsigned char get_path_state(struct cmd_para_save *path_switch){
//C53查询当前通道运行状态
unsigned char xdata boardid;
unsigned char xdata portid;
unsigned char xdata timeid;
unsigned char xdata mport;
unsigned char xdata return_value;

	boardid = path_switch -> path_stat_swget_board;				//输出盘号
	portid = path_switch -> path_stat_swget_port;				//输出端口
	timeid = path_switch -> path_stat_swget_slot;				//输出时隙

	mport = get_solt_working(boardid,portid,timeid);			//得到所保护的输出时隙的输入
	switch (mport){
		case 0: mboardid = 5;
				mportid = 1;
				return_value = 0;
				break;
		case 1: mboardid = 5;
				mportid = 2;
				return_value = 0;
				break;
		case 2: mboardid = 4;
				mportid = 1;
				return_value = 0;
				break;
		case 3: mboardid = 4;
				mportid = 2;
				return_value = 0;
				break;
		default: return_value = 2;
				 break;
	}
	if (!GetResRdyTbl(22))
		SetResRdyTbl(22); 
	return (return_value);
}


void report_path_stat(unsigned char value,unsigned char board,unsigned port){
//C53回应函数
	tx_buf[0] = '$';
	tx_buf[1] = '2';
	tx_buf[2] = '1';
	tx_buf[3] = 0x43;
	tx_buf[4] = 0x35;
	tx_buf[5] = 0x33;
	tx_buf[6] = '0';
	tx_buf[7] = '0';
	tx_buf[8] = '0';
	tx_buf[9] = '5';
	tx_buf[10] = value + 0x30;	
	tx_buf[11] = board + 0x30;
	if (board == 5){
		tx_buf[12] = '1';
	}
	else tx_buf[12] = '4';
	tx_buf[13] = '0';
	tx_buf[14] = port + 0x30;
	tx_buf[15] = '*';
	tx_buf_pointer = 0;	
	while(tx_buf[tx_buf_pointer] != '*'){
		SBUF = tx_buf[tx_buf_pointer];
		while(tx_done == 0);
		tx_done = 0;
		tx_buf_pointer++;
	}
	SBUF = tx_buf[tx_buf_pointer];          //发送最后一个字符'*'
	while(tx_done == 0);
	tx_done = 0;

}


/*以下为自动倒换函数*/
unsigned char xdata init_flg[2][4];
unsigned char xdata init_recover[4] = {0,0,0,0};

/******************************************************************************************************/
void path_switch_recover(void){
//每秒查询是否信号恢复,进行通道倒换函数

unsigned char xdata temp;
unsigned char xdata tport;
unsigned char xdata outport;
unsigned char xdata value;
unsigned char xdata *valueid;
unsigned char xdata quotient;
unsigned char xdata residue;

	if (((Ia0_a & 0xD0) | (Ia2_a & 0xE0) | (Ia3_a & 0x80)) == 0){			//MCB A口全0
   		if (init_recover[0] == 1){
	 		for (temp = 0; temp <= 62; temp++){
				if (path_switch_state[temp] == 2){							//如果处于自动倒换状态
					for (tport = 1; tport <= 3; tport++){					//轮循查找哪个光口的备用光口是MCB光口1
						if (path_switch_array[tport][temp][0] == 0){
							quotient = temp >> 3;							//得到该时隙所在的字节值(同timeid / 8运算)
							residue = temp & 0x07;							//同timeid % 8运算
							residue = 7 - residue;                      	//得到该时隙所在的bit位
							outport = path_switch_array[tport][temp][1];
//				    		value = path_switch_function(0,temp,outport);	//进行该时隙的通道倒换
							switch(tport){
//								case 0: valueid = (quotient + 0x88A6);
//						    	        value = ((*valueid) >> residue) & 0x01;       	//如果该时隙出现AIS
//										if (value != 0){                                //该时隙不能倒换
//						            		PTUN(outport,temp) = 0;
//										   	value = 0;
//										}
//										else{
//							            	value = 2; 
//						    	        }
//										break;
							    case 1: valueid = (quotient + 0x8AA6);
						            	value = ((*valueid) >> residue) & 0x01;
						    	        if (value != 0){
						    	        	PTUN(outport,temp) = 0;
						        	    	value = 0;
										}
							            else{
						        	    	value = 2;
						            	}
										break;
						    	case 2: value = f2rc7860_rd(quotient + 0x00A6);
										value = (value >> residue) & 0x01;
						        	    if (value != 0){
						        	    	PTUN(outport,temp) = 0;
						            	   	value = 0;
										}
						    	        else{
						            		value = 2; 
							            }
										break;
							    case 3: value = f2rc7860_rd(quotient + 0x02A6);
										value = (value >> residue) & 0x01;
						    	        if (value != 0){
						    	        	PTUN(outport,temp) = 0;
						        	       	value = 0;
										}
							            else{
						        	    	value = 2;
						            	}
										break;                    
							   default: value = 2;
						   				break;
						   }
							if ((value == 0) & (outport < 4)){				//光口处于时隙的保换倒换状态
								switch (outport){							//对光口进行并发配置
									case 0: value = PTUN(1,temp) = 0;
//													path_switch_function(0,temp,1);
											break;
//									case 1: value = path_switch_function(0,temp,0);
//											break;
									case 2: value = PTUN(3,temp) = 0;
//													path_switch_function(0,temp,3);
											break;
									case 3: value = PTUN(2,temp) = 0;
//													path_switch_function(0,temp,2);
											break;
									default:break;
								}
							}
							if (value == 0){								//如果倒换成功
								path_switch_array[tport][temp][3] = 0;		//倒换成功改写当前时隙所用端口
								path_switch_array[0][temp][3] = 1;
							}
						}
					}
				}
			}
			init_recover[0] = 0;
		}
//   		if (init_recover[0] == 2){
//			init_recover[0] = 1;
//		}
//		SetExtRdyTbl(15);											//改写2M盘的AIS速率
	}

	if ((Ia0_b & 0xD0 | Ia2_b & 0xE0 | Ia3_b & 0x80) == 0){			//MCB B口全0
   		if (init_recover[1] == 1){
			for (temp = 0; temp <= 62; temp++){
				if (path_switch_state[temp] == 2){							//如果处于自动倒换状态
					for (tport = 0; tport <= 3; tport++){					//轮循查找哪个光口的备用光口是MCB光口2
						if (tport != 1){
						if (path_switch_array[tport][temp][0] == 1){
							quotient = temp >> 3;							//得到该时隙所在的字节值(同timeid / 8运算)
							residue = temp & 0x07;							//同timeid % 8运算
							residue = 7 - residue;                      	//得到该时隙所在的bit位
							outport = path_switch_array[tport][temp][1];
//				    		value = path_switch_function(1,temp,outport);	//进行该时隙的通道倒换
							switch(tport){
								case 0: valueid = (quotient + 0x88A6);
						    	        value = ((*valueid) >> residue) & 0x01;       	//如果该时隙出现AIS
										if (value != 0){                                //该时隙不能倒换
						            		PTUN(outport,temp) = 1;
										   	value = 0;
										}
										else{
							            	value = 2; 
						    	        }
										break;
//							    case 1: valueid = (quotient + 0x8AA6);
//						            	value = ((*valueid) >> residue) & 0x01;
//						    	        if (value != 0){
//						    	        	PTUN(outport,temp) = 1;
//						        	    	value = 0;
//										}
//							            else{

⌨️ 快捷键说明

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