var restoreCompleteState=0;
ReloadingRestoreData();
$('#backupContClose').on('click',function(){
	$('#backupCont').hide();
});
$('#RestoreContClose').on('click',function(){
	$('#RestoreCont').hide();
});
var _firmwareUpdateJsonDataArrtimer;
var _BackupFileType=0;
$('#BackupFile').on('click',function() {
	if ($('.connectionToServerBtn').html()=='CONNECT') {
		$('#DisplayErrorContent .DeviceSendReceiveInfraredContText').html("Must be Connected!");
		$('#DisplayErrorContent').show();
		return;
	}
	clearInterval(BackupFileTimer);
	_BackupFileType=1;
	var _i=0;
	// var _filename = $('#BackupAndRestoreSaveFileNameDisplay').val();
	// var _location = $('#BackupAndRestoreSelectPath').html();
	// if (_filename==''||_location=='') {
	// 	$('#DisplayErrorContent .DeviceSendReceiveInfraredContText').html("Error!");
	// 	$('#DisplayErrorContent').show();
	// 	return
	// }
	$('#backupCont').show();
	$('.backuploadingInput').css('width','0px');
	$('.backuptoFiling').show();
	_firmwareUpdateJsonDataArrtimer = setInterval(function(){
		$('.backuploadingInput').css('width',(_i*10+1)+'px');
		_i++;
		if (firmwareUpdateJsonDataArr!='') {	
			$.ajax({
		      	type: 'POST',
		      	url: "/common/BackupAndRestore.php",
		      	data: "backupToFile=1&backupdata="+firmwareUpdateJsonDataArr,
		      	datatype: 'json',
		      	async: false,
		      	success: function(rst) {      		
		      		if (rst=='success') {
		      			clearInterval(_firmwareUpdateJsonDataArrtimer);
		      			$('.backuploadingInput').css('width','201px');
		      			$('.backuptoFiling').hide();
		      			$('.backuptoFileFinish').show();
		      			$('#iframeExp').attr('src','/backup/downloadFile.php');
		      		}      		
		      	}
		  	});			
		}

	},200);
	SystemLogWriteToFileAnother('Backup And Restore','Backup File');
});
// 模拟文件选择控件点击
$('#SelectFileBtn').on('click',function(){
	// $('#SelectFileChangeBox').click();
});
// $('#Browse').on('click',function(){
// 	$('#SelectFileChangeBox').click();
// });
// 当文件控件值变化时
$('#RestoreSelectFileChangeBox').on('change',function(){
	var name = document.getElementById("RestoreSelectFileChangeBox").files[0].name;
	// console.log(document.getElementById("SelectFileChangeBox").files[0]);
	$('#RestoreBrowseFileNameDisplay').html(name);
});
$('#RestoreBrowseBtn').on('click',function(){
	$('#RestoreSelectFileChangeBox').click();
});
$('#Restore').on('click',function(){
	var formData = new FormData();
	if(document.getElementById("RestoreSelectFileChangeBox").files[0]==null){
		$('#DisplayErrorContent .DeviceSendReceiveInfraredContText').html("Invalid Value!");
		$('#DisplayErrorContent').show();
		return;
	}
    
	formData.append("BackupFile", document.getElementById("RestoreSelectFileChangeBox").files[0]);
    setTimeout(function(){
    	$.ajax({
	        url: "common/BackupAndRestore.php",
	        type: "POST",
	        data: formData,
	        /**
	        *必须false才会自动加上正确的Content-Type
	        */
	        contentType: false,
	        /**
	        * 必须false才会避开jQuery对 formdata 的默认处理
	        * XMLHttpRequest会对 formdata 进行正确的处理
	        */
	        processData: false,
	        success: function (data) {
	        	
	        	var _i=0;
				$('#RestoreCont').show();
				$('#RestoreCont .backuploadingInput').css('width','0px');
				$('#RestoreCont .backuptoFiling').show();
				if (data.indexOf('=|=')>=0) {
					data = data.split('=|=');
					RestoreDataFromFile(data[0]);
					RestoreGroupSettingDataFromFile(data[1]);
				}
				else
	        		RestoreDataFromFile(data);
	        	var _timer = setInterval(function(){
					$('#RestoreCont .backuploadingInput').css('width',(_i*10+1)+'px');
					if (_i<190) {
						_i++;
					}
					
					if (restoreCompleteState!=0) {
						$('#RestoreCont .backuploadingInput').css('width','190px');
		      			$('#RestoreCont .backuptoFiling').hide();
		      			$('#RestoreCont .backuptoFileFinish').show();
					}
				},200);
	        	SystemLogWriteToFileAnother('Backup And Restore','Restore From File');
	        },
	        error: function () {

	        }
      	});
    },1000);    
});
// 还原备份数据
function RestoreDataFromFile(data){
	var _jsonArr = eval('('+data+')');
	console.log(1,_jsonArr.status);
	if (_jsonArr.status == 'SUCCESS') {
		RestoreDataBackupFile(_jsonArr);
		console.log(2,_jsonArr.status);
	}
	else {
		RestoreDataOfflineModeBackupFile(_jsonArr);
		console.log(3,_jsonArr.status);
	}
}
// 组别设备信息数据还原 
function RestoreGroupSettingDataFromFile(data){
	var dataTmp = data.split('=');
	for (var i = 0; i < dataTmp.length; i++) {
		(function(ii){
			var pagetype='';
			if (dataTmp[i]!='') {
				if (dataTmp[ii].indexOf(',')>=0) {
					var _dataTmpArr = dataTmp[ii].split(',');
					for (var j = 0; j < _dataTmpArr.length; j++) {
						if (_dataTmpArr[j]!='') {
							var _dataTmp = _dataTmpArr[j].split(':');
							var _name = _dataTmp[0]+_dataTmp[1]+'_'+_dataTmp[3];
							RestoreGroupSettingDataFromFileAjax(_name,dataTmp[ii]);
							
							var _devicesIDArr = '';
							for (var k = 0; k < _dataTmpArr.length; k++) {
								if (_dataTmpArr[k]!='') {
									var _dataTmpListArr = _dataTmpArr[k].split(':');
									_devicesIDArr += _dataTmpListArr[5] + '|';
								}
							}
							_devicesIDArr = _devicesIDArr.substr(0,_devicesIDArr.length-1);

							if (_dataTmp[1]=='Decode') 
								var devicetype = 'rx';
							else if (_dataTmp[1]=='Encode') 
								var devicetype = 'tx';
							switch(_dataTmp[0].toLocaleLowerCase()){
							case 'video':
								pagetype = 'videoswitching';
							break;
							case 'videowall':
								pagetype = 'videowall';
							break;
							case 'hdmiaudio':
								pagetype = 'hdmi_audio';
							break;
							case 'analogaudio':
								pagetype = 'analog_audio';
							break;
							case 'rs232':
								pagetype = 'rs232';
							break;
							case 'infrared':
								pagetype = 'infrared';
							break;
							}
							if ('Default'!=_dataTmp[3]) {			
								//alert(pagetype,_devicesIDArr);					
								var data = 'type=12&GroupID='+_dataTmp[3]+'&pagetype='+pagetype+'&devicetype='+devicetype+'&listnum=1&name='+_dataTmp[4]+'&devicelist='+_devicesIDArr.replace(/\|/g,',').replace(/_/g,':');
					            $.ajax({
								    type: 'POST',
								    url: 'common/MySqlCommon.php',
								    data: data,
								    datatype: 'json',
								    async: true,
								    success: function(rst) {
								        	
								    } 
								});
							}							
							
						}
					}
				}
				else {
					var _dataTmp = dataTmp[ii].split(':');
					var _name = _dataTmp[0]+_dataTmp[1]+'_'+_dataTmp[3];
					RestoreGroupSettingDataFromFileAjax(_name,dataTmp[ii]);				
					if (1) {
						if (_dataTmp[1]=='Decode') 
							var devicetype = 'rx';
						else if (_dataTmp[1]=='Encode') 
							var devicetype = 'tx';

						switch(_dataTmp[0].toLocaleLowerCase()){
						case 'video':
							pagetype = 'videoswitching';
						break;
						case 'videowall':
							pagetype = 'videowall';
						break;
						case 'hdmiaudio':
							pagetype = 'hdmi_audio';
						break;
						case 'analogaudio':
							pagetype = 'analog_audio';
						break;
						case 'rs232':
							pagetype = 'rs232';
						break;
						case 'infrared':
							pagetype = 'infrared';
						break;
						}
						if ('Default'!=_dataTmp[3]) {
							
							var data = 'type=12&GroupID='+_dataTmp[3]+'&pagetype='+pagetype+'&devicetype='+devicetype+'&listnum=1&name='+_dataTmp[4]+'&devicelist='+_dataTmp[5].replace(/_/g,':');
			            	$.ajax({
						        type: 'POST',
						        url: 'common/MySqlCommon.php',
						        data: data,
						        datatype: 'json',
						        async: true,
						        success: function(rst) {
						        	
						        } 
						    });
						}	
							
					}
				}
			}
				
				
			
		})(i);
	}
}
function CheckFileIsExists(name){
	var SendData = 'CheckFileExist='+name;
	$.ajax({
        type: 'POST',
        url: 'common/GroupSaveSetting.php',
        data: SendData,
        datatype: 'json',
        async: true,
        success: function(rst) {
        	if (rst=='1')
        		return true;
        	else 
        		return false;
        } 
    });
}
function RestoreGroupSettingDataFromFileAjax(name,data){
	var SendData = 'GroupSaveSettingName='+name+'&FileData='+data;
    $.ajax({
        type: 'POST',
        url: 'common/GroupSaveSetting.php',
        data: SendData,
        datatype: 'json',
        async: true,
        success: function(rst) {
        } 
    });
}
// 在线模式备份的数据还原
function RestoreDataBackupFile(_jsonArr){
	if(_jsonArr.result.devices.length>0){
		for (var i = 0; i < _jsonArr.result.devices.length; i++) {			
			if (_jsonArr.result.devices[i].identity.is_receiver) {
				var AnalogAudioOutputCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','ANALOG_AUDIO_OUTPUT','inputs[0].configuration.source.value');
				
				var HDMIAudioOutputCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','inputs[1].configuration.source.value');
				var deviceEDIDCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_MONITOR','status.edid');
				var hostnameCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.hostname');
				var modeCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mode');
				var addressCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');
				var maskCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mask');
				var gatewayCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.gateway');

				var baud_rateCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.baud_rate','index',1);
				var data_bitsCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.data_bits','index',1);
				var stop_bitsCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.stop_bits','index',1);
				var parityCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.parity','index',1);	
				
				var display_modeCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','FRAME_BUFFER','configuration.display_mode');
				var widthCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','status.video.width');
				var heightCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','status.video.height');
				var frames_per_secondCopyData = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','status.video.frames_per_second');
				
				var Multicastaddress = checkReceiveJsonDataToString(_jsonArr.result.devices[i].subscriptions,'subscriptions','type','HDMI','configuration.address');
				var HdmiAudioMulticastaddress = checkReceiveJsonDataToString(_jsonArr.result.devices[i].subscriptions,'subscriptions','type','HDMI_AUDIO','configuration.address');
				var AnalogAudioMulticastaddress = checkReceiveJsonDataToString(_jsonArr.result.devices[i].subscriptions,'subscriptions','type','AUDIO','configuration.address');
				
				var receiveDataToCheckOb = eval('('+receiveDataToCheck+')');
				for (var j = 0; j < receiveDataToCheckOb.result.devices.length; j++) {
					var device_id = receiveDataToCheckOb.result.devices[j].device_id;
					if (_jsonArr.result.devices[i].device_id==device_id) {
						var AnalogAudioOutputCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','ANALOG_AUDIO_OUTPUT','inputs[0].configuration.source.value');
						if (AnalogAudioOutputCopyData!=AnalogAudioOutputCopyDataRec) {
							if (AnalogAudioOutputCopyData == 2) {
								sendCommand('data=set '+device_id+' property nodes[ANALOG_AUDIO_OUTPUT:0].inputs[main:0].configuration.source.value 2');
							}
							else if (AnalogAudioOutputCopyData == 3) {
								sendCommand('data=set '+device_id+' property nodes[ANALOG_AUDIO_OUTPUT:0].inputs[main:0].configuration.source.value 3');
							}
						}
						// console.log(AnalogAudioOutputCopyData+':'+AnalogAudioOutputCopyDataRec);
						var HDMIAudioOutputCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','inputs[1].configuration.source.value');
						if (HDMIAudioOutputCopyData!=HDMIAudioOutputCopyDataRec) {
							if (HDMIAudioOutputCopyData == 2) {
								sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 2');
							}
							else if (HDMIAudioOutputCopyData == 3) {
								sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 3');
							}
							else if (HDMIAudioOutputCopyData == 6) {
								sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 6');
							}
							else if (HDMIAudioOutputCopyData == 7) {
								sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 7');
							}
						}
						var deviceEDIDCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_MONITOR','status.edid');
						var hostnameCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.hostname');
						if (hostnameCopyData!=hostnameCopyDataRec) {
							sendCommand('data=set '+device_id+' property configuration.device_name '+hostnameCopyData);
						}
						var modeCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mode');
						var addressCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');
						var maskCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mask');
						var gatewayCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.gateway');
						if (modeCopyData!=modeCopyDataRec) {
							if (modeCopyData == 'DHCP') {
								sendCommand('data=set '+device_id+' ip mode DHCP');
							}
							else{
								sendCommand('data=set '+device_id+' ip mode MANUAL address '+addressCopyData+' mask '+maskCopyData+' gateway '+gatewayCopyData);
							}
						}
						var baud_rateCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.baud_rate','index',1);
						if (baud_rateCopyData!=baud_rateCopyDataRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.baud_rate '+baud_rateCopyData);
						}
						var data_bitsCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.data_bits','index',1);
						if (data_bitsCopyData!=data_bitsCopyDataRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.data_bits '+data_bitsCopyData);
						}
						var stop_bitsCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.stop_bits','index',1);
						if (stop_bitsCopyData!=stop_bitsCopyDataRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.stop_bits '+stop_bitsCopyData);
						}
						var parityCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.parity','index',1);
						if (parityCopyData!=parityCopyDataRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.parity '+parityCopyData);
						}

						// 分辨率
						// video page
						var display_modeCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','FRAME_BUFFER','configuration.display_mode');
						var widthCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','status.video.width');
						var heightCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','status.video.height');
						var frames_per_secondCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','status.video.frames_per_second');
						if (widthCopyData!=widthCopyDataRec||
							heightCopyData!=heightCopyDataRec||
							frames_per_secondCopyData!=frames_per_secondCopyDataRec||
							display_modeCopyData!=display_modeCopyDataRec) {
							if (display_modeCopyData == 'FAST_SWITCHED') {
								sendCommand('data=set '+device_id+' video fastswitch size '+widthCopyData+' '+heightCopyData+' fps '+frames_per_secondCopyData);
							}
							else if (display_modeCopyData == 'FAST_SWITCHED_STRETCH') {
								sendCommand('data=set '+device_id+' video fastswitch stretch size '+widthCopyData+' '+heightCopyData+' fps '+frames_per_secondCopyData);
							}
							else if (display_modeCopyData == 'FAST_SWITCHED_CROP') {
								sendCommand('data=set '+device_id+' video fastswitch crop size '+widthCopyData+' '+heightCopyData+' fps '+frames_per_secondCopyData);
							} 
							else if (display_modeCopyData == 'GENLOCK_SCALING') {
								sendCommand('data=set '+device_id+' video genlock_scaling size '+widthCopyData+' '+heightCopyData+' fps '+frames_per_secondCopyData); 
							}
						}
						// video连接关系还原
						var MulticastaddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].subscriptions,'subscriptions','type','HDMI','configuration.address');
						if (Multicastaddress!=MulticastaddressRec&&Multicastaddress!='0.0.0.0') {
							for (var k = 0; k < _jsonArr.result.devices.length; k++) {
								(function(kk){
									if (_jsonArr.result.devices[kk].identity.is_transmitter) {
										var TxMulticastaddressRec = checkReceiveJsonDataToString(_jsonArr.result.devices[kk].streams,'streams','type','HDMI','configuration.address');
										if (Multicastaddress==TxMulticastaddressRec) {
											sendCommand('data=join ' + _jsonArr.result.devices[kk].device_id + ':HDMI:0 ' + device_id + ':HDMI:0');
										}
									}
								})(k);								
							}
						}
						// hdmi audio连接关系还原
						var HdmiAudioMulticastaddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].subscriptions,'subscriptions','type','HDMI_AUDIO','configuration.address');
						if (HdmiAudioMulticastaddress!=HdmiAudioMulticastaddressRec&&HdmiAudioMulticastaddress!='0.0.0.0') {
							for (var k = 0; k < _jsonArr.result.devices.length; k++) {
								(function(kk){
									if (_jsonArr.result.devices[kk].identity.is_transmitter) {
										var TxMulticastaddressRec = checkReceiveJsonDataToString(_jsonArr.result.devices[kk].streams,'streams','type','HDMI_AUDIO','configuration.address');
										if (HdmiAudioMulticastaddress==TxMulticastaddressRec) {
											sendCommand('data=join ' + _jsonArr.result.devices[kk].device_id + ':HDMI_AUDIO:0 ' + device_id + ':HDMI_AUDIO:0');
										}
									}
								})(k);								
							}
						}
						// analog audio连接关系还原
						var AnalogAudioMulticastaddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].subscriptions,'subscriptions','type','HDMI_AUDIO','configuration.address');
						if (AnalogAudioMulticastaddress!=AnalogAudioMulticastaddressRec&&AnalogAudioMulticastaddress!='0.0.0.0') {
							for (var k = 0; k < _jsonArr.result.devices.length; k++) {
								(function(kk){
									if (_jsonArr.result.devices[kk].identity.is_transmitter) {
										var TxMulticastaddressRec = checkReceiveJsonDataToString(_jsonArr.result.devices[kk].streams,'streams','type','AUDIO','configuration.address');
										if (AnalogAudioMulticastaddress==TxMulticastaddressRec) {
											sendCommand('data=join ' + _jsonArr.result.devices[kk].device_id + ':AUDIO:0 ' + device_id + ':AUDIO:0');
										}
									}
								})(k);								
							}
						}
						var Rs232Address = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','RS232','configuration.address');
						var InfraredAddress = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','INFRARED','configuration.address');
				
						// rs232 连接对应关系
						var Rs232MulticastAddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','RS232','configuration.address');
						if (Rs232Address!=Rs232MulticastAddressRec&&Rs232Address!='0.0.0.0') {
							for (var k = 0; k < receiveDataToCheckOb.result.devices.length; k++) {
								(function(kk){
									var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[kk].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');					
									if (Rs232Address == addressRec) {
										sendCommand('data=switch ' + device_id + ':RS232:1 ' + receiveDataToCheckOb.result.devices[kk].device_id + ':RS232:1');
									}
									
								})(k);
							}
							if (Rs232Address=='255.255.255.255') {
								sendCommand('data=switch ' + device_id + ':RS232:1 all:RS232:1');
							}
							if (Rs232Address==$('.connectionIP').val()) {
								sendCommand('data=switch ' + device_id + ':RS232:1 '+$('.connectionIP').val());
							}
						}
						else if (Rs232Address=='0.0.0.0') {
							sendCommand('data=stop ' + device_id + ':RS232:1');
						}
						// infrared 连接对应关系
						var InfraredMulticastAddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','INFRARED','configuration.address');
						if (InfraredAddress!=InfraredMulticastAddressRec&&InfraredAddress!='0.0.0.0') {
							for (var k = 0; k < receiveDataToCheckOb.result.devices.length; k++) {
								(function(kk){
									var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[kk].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');					
									if (InfraredAddress == addressRec) {
										sendCommand('data=switch ' + device_id + ':INFRARED:0 ' + receiveDataToCheckOb.result.devices[kk].device_id + ':INFRARED:0');
									}
									
								})(k);
							}
							if (InfraredAddress=='255.255.255.255') {
								sendCommand('data=switch ' + device_id + ':INFRARED:0 all:INFRARED:0');
							}
							if (InfraredAddress==$('.connectionIP').val()) {
								sendCommand('data=switch ' + device_id + ':INFRARED:0 '+$('.connectionIP').val());
							}							
						}
						else if (InfraredAddress=='0.0.0.0') {
							sendCommand('data=stop ' + device_id + ':INFRARED:0');
						}
					}
				}
			}
			else if(_jsonArr.result.devices[i].identity.is_transmitter){
				var hdcp_support = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.hdcp_support_enable');
				var hdcp22_support = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.hdcp_22_support_disable');
				var deviceEDID = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.edid');
				var hostname = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.hostname');
				var mode = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mode');
				var address = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');
				var mask = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mask');
				var gateway = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.gateway');

				var baud_rate = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.baud_rate','index',1);
				var data_bits = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.data_bits','index',1);
				var stop_bits = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.stop_bits','index',1);
				var parity = checkReceiveJsonDataToString(_jsonArr.result.devices[i].nodes,'nodes','type','UART','configuration.parity','index',1);
				var state = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','HDMI','status.state');

				var AudioState = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','HDMI_AUDIO','status.state');
				var AnalogAudioState = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','AUDIO','status.state');
				var Rs232Address = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','RS232','configuration.address');
				var InfraredAddress = checkReceiveJsonDataToString(_jsonArr.result.devices[i].streams,'streams','type','INFRARED','configuration.address');
				
				var receiveDataToCheckOb = eval('('+receiveDataToCheck+')');
				for (var j = 0; j < receiveDataToCheckOb.result.devices.length; j++) {
					var device_id = receiveDataToCheckOb.result.devices[j].device_id;
					if (_jsonArr.result.devices[i].device_id==device_id) {
						var hdcp_supportRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.hdcp_support_enable');
						if (hdcp_support!=hdcp_supportRec) {
							if (hdcp_support) {
								sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_support_enable ENABLE');
							}
							else{
								sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_support_enable DISABLE');
							}
						}
						var hdcp22_supportRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.hdcp_22_support_disable');
						if (hdcp22_support!=hdcp22_supportRec) {
							if (hdcp22_support) {
								sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_22_support_disable True');
							}
							else{
								sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_22_support_disable False');
							}
						}
						var deviceEDIDRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.edid');
						if (deviceEDID!=deviceEDIDRec) {
							sendCommand('data=set '+device_id+' edid ' + deviceEDID);
						}
						var hostnameRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.hostname');
						if (hostname!=hostnameRec) {
							sendCommand('data=set '+device_id+' property configuration.device_name '+hostname);
						}
						var modeRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mode');
						var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');
						var maskRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mask');
						var gatewayRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.gateway');
						if (mode!=modeRec) {
							if (mode=='DHCP') {
								sendCommand('data=set '+device_id+' ip mode DHCP');
							}
							else {
								sendCommand('data=set '+device_id+' ip mode MANUAL address '+address+' mask '+mask+' gateway '+gateway);
							}
						}
						var baud_rateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.baud_rate','index',1);
						if (baud_rate!=baud_rateRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.baud_rate '+baud_rate);
						}
						var data_bitsRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.data_bits','index',1);
						if (data_bits!=data_bitsRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.data_bits '+data_bits);
						}
						var stop_bitsRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.stop_bits','index',1);
						if (stop_bits!=stop_bitsRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.stop_bits '+stop_bits);
						}
						var parityRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.parity','index',1);
						if (parity!=parityRec) {
							sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.parity '+parity);
						}

						// 对应关系、start/stop状态
						//  video
						var stateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','HDMI','status.state');
						if (state!=stateRec) {
							if (state == 'STREAMING') {
								sendCommand('data=start '+device_id+':HDMI:0');
							}
							else if (state == 'STOPPED') {
								sendCommand('data=stop '+device_id+':HDMI:0');
							}
						}
						// hdmi audio
						var AudioStateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','HDMI_AUDIO','status.state');
						if (AudioState!=AudioStateRec) {
							if (state == 'STREAMING') {
								sendCommand('data=start '+device_id+':HDMI_AUDIO:0');
							}
							else if (state == 'STOPPED') {
								sendCommand('data=stop '+device_id+':HDMI_AUDIO:0');
							}
						}
						// analog audio
						var AnalogAudioStateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','AUDIO','status.state');
						if (AnalogAudioState!=AnalogAudioStateRec) {
							if (AnalogAudioState == 'STREAMING') {
								sendCommand('data=start '+device_id+':AUDIO:0');
							}
							else if (AnalogAudioState == 'STOPPED') {
								sendCommand('data=stop '+device_id+':AUDIO:0');
							}
						}
						// rs232 连接对应关系
						var Rs232MulticastAddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','RS232','configuration.address');
						if (Rs232Address!=Rs232MulticastAddressRec&&Rs232Address!='0.0.0.0') {
							for (var k = 0; k < receiveDataToCheckOb.result.devices.length; k++) {
								(function(kk){
									var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[kk].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');					
									if (Rs232Address == addressRec) {
										sendCommand('data=switch ' + device_id + ':RS232:1 ' + receiveDataToCheckOb.result.devices[kk].device_id + ':RS232:1');
									}
									
								})(k);
							}
							if (Rs232Address=='255.255.255.255') {
								sendCommand('data=switch ' + device_id + ':RS232:1 all:RS232:1');
							}
							if (Rs232Address==$('.connectionIP').val()) {
								sendCommand('data=switch ' + device_id + ':RS232:1 '+$('.connectionIP').val());
							}							
						}
						else if (Rs232Address=='0.0.0.0') {
							sendCommand('data=stop ' + device_id + ':RS232:1');
						}
						// infrared 连接对应关系
						var InfraredMulticastAddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].streams,'streams','type','INFRARED','configuration.address');
						if (InfraredAddress!=InfraredMulticastAddressRec&&InfraredAddress!='0.0.0.0') {
							for (var k = 0; k < receiveDataToCheckOb.result.devices.length; k++) {
								(function(kk){
									var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[kk].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');					
									if (InfraredAddress == addressRec) {
										sendCommand('data=switch ' + device_id + ':INFRARED:0 ' + receiveDataToCheckOb.result.devices[kk].device_id + ':INFRARED:0');
									}
									
								})(k);
							}
							if (InfraredAddress=='255.255.255.255') {
								sendCommand('data=switch ' + device_id + ':INFRARED:0 all:INFRARED:0');
							}
							if (InfraredAddress==$('.connectionIP').val()) {
								sendCommand('data=switch ' + device_id + ':INFRARED:0 '+$('.connectionIP').val());
							}
							
						}
						else if (InfraredAddress=='0.0.0.0') {
							sendCommand('data=stop ' + device_id + ':INFRARED:0');
						}
					}
				}
			}			
		}
	}
	restoreCompleteState = 1;
}
// 离线模式备份的数据还原
function RestoreDataOfflineModeBackupFile(_jsonArr){
	var receiveDataToCheckOb = eval('('+receiveDataToCheck+')');
	for (var j = 0; j < receiveDataToCheckOb.result.devices.length; j++) {
		var device_id = receiveDataToCheckOb.result.devices[j].device_id;
		var _jsonArrRx = _jsonArr.rx.split(':');
		var _jsonArrTx = _jsonArr.tx.split(':');
		if (receiveDataToCheckOb.result.devices[j].identity.is_receiver) {
			for (var i = 0; i < _jsonArrRx.length; i++) {
				var _jsonArrRxDetail = _jsonArrRx[i].split(',');				
				if (_jsonArr.result.devices[i].device_id==device_id) {
					var AnalogAudioOutputCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','ANALOG_AUDIO_OUTPUT','inputs[0].configuration.source.value');
					if (_jsonArrRxDetail[1]!=AnalogAudioOutputCopyDataRec) {
						if (AnalogAudioOutputCopyData == 2) {
							sendCommand('data=set '+device_id+' property nodes[ANALOG_AUDIO_OUTPUT:0].inputs[main:0].configuration.source.value 2');
						}
						else if (AnalogAudioOutputCopyData == 3) {
							sendCommand('data=set '+device_id+' property nodes[ANALOG_AUDIO_OUTPUT:0].inputs[main:0].configuration.source.value 3');
						}
					}
					// console.log(AnalogAudioOutputCopyData+':'+AnalogAudioOutputCopyDataRec);
					var HDMIAudioOutputCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_ENCODER','inputs[1].configuration.source.value');
					if (_jsonArrRxDetail[2]!=HDMIAudioOutputCopyDataRec) {
						if (_jsonArrRxDetail[2] == 2) {
							sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 2');
						}
						else if (_jsonArrRxDetail[2] == 3) {
							sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 3');
						}
						else if (_jsonArrRxDetail[2] == 6) {
							sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 6');
						}
						else if (_jsonArrRxDetail[2] == 7) {
							sendCommand('data=set '+device_id+' property nodes[HDMI_ENCODER:0].inputs[audio:0].configuration.source.value 7');
						}
					}
					var deviceEDIDCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_MONITOR','status.edid');
					var hostnameCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.hostname');
					if (_jsonArrRxDetail[3]!=hostnameCopyDataRec) {
						sendCommand('data=set '+device_id+' property configuration.device_name '+_jsonArrRxDetail[3]);
					}
					var modeCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mode');
					var addressCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');
					var maskCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mask');
					var gatewayCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.gateway');
					if (_jsonArrRxDetail[4]!=modeCopyDataRec) {
						if (_jsonArrRxDetail[4] == 'DHCP') {
							sendCommand('data=set '+device_id+' ip mode DHCP');
						}
						else{
							sendCommand('data=set '+device_id+' ip mode MANUAL address '+_jsonArrRxDetail[5]+' mask '+_jsonArrRxDetail[6]+' gateway '+_jsonArrRxDetail[7]);
						}
					}
					var baud_rateCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.baud_rate','index',1);
					if (_jsonArrRxDetail[8]!=baud_rateCopyDataRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.baud_rate '+_jsonArrRxDetail[8]);
					}
					var data_bitsCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.data_bits','index',1);
					if (_jsonArrRxDetail[9]!=data_bitsCopyDataRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.data_bits '+_jsonArrRxDetail[9]);
					}
					var stop_bitsCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.stop_bits','index',1);
					if (_jsonArrRxDetail[10]!=stop_bitsCopyDataRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.stop_bits '+_jsonArrRxDetail[10]);
					}
					var parityCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.parity','index',1);
					if (_jsonArrRxDetail[11]!=parityCopyDataRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.parity '+_jsonArrRxDetail[11]);
					}
					// // 分辨率
					// // video page
					// var display_modeCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'nodes','type','FRAME_BUFFER','configuration.display_mode');
					// var widthCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'nodes','type','HDMI_ENCODER','status.video.width');
					// var heightCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'nodes','type','HDMI_ENCODER','status.video.height');
					// var frames_per_secondCopyDataRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'nodes','type','HDMI_ENCODER','status.video.frames_per_second');
					// if (widthCopyData!=widthCopyDataRec||
					// 	heightCopyData!=heightCopyDataRec||
					// 	frames_per_secondCopyData!=frames_per_secondCopyDataRec||
					// 	display_modeCopyData!=display_modeCopyDataRec) {
					// 	if (display_modeCopyData == 'FAST_SWITCHED') {
					// 		sendCommand('data=set '+device_id+' video fastswitch size '+widthCopyData+' '+heightCopyDataRec+' fps '+frames_per_secondCopyData);
					// 	}
					// 	else if (display_modeCopyData == 'FAST_SWITCHED_STRETCH') {
					// 		sendCommand('data=set '+device_id+' video fastswitch stretch size '+widthCopyData+' '+heightCopyDataRec+' fps '+frames_per_secondCopyData);
					// 	}
					// 	else if (display_modeCopyData == 'FAST_SWITCHED_CROP') {
					// 		sendCommand('data=set '+device_id+' video fastswitch crop size '+widthCopyData+' '+heightCopyDataRec+' fps '+frames_per_secondCopyData);
					// 	} 
					// 	else if (display_modeCopyData == 'GENLOCK_SCALING') {
					// 		sendCommand('data=set '+device_id+' video genlock_scaling size '+widthCopyData+' '+heightCopyDataRec+' fps '+frames_per_secondCopyData); 
					// 	}
					// }
					// // video连接关系还原
					// var MulticastaddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'subscriptions','type','HDMI','configuration.address');
					// if (Multicastaddress!=MulticastaddressRec&&Multicastaddress!='0.0.0.0') {
					// 	for (var k = 0; k < _jsonArr.result.devices.length; k++) {
					// 		(function(kk){
					// 			if (_jsonArr.result.devices[kk].identity.is_transmitter) {
					// 				var TxMulticastaddressRec = checkReceiveJsonDataToString(_jsonArr.result.devices[kk],'streams','type','HDMI','configuration.address');
					// 				if (Multicastaddress==TxMulticastaddressRec) {
					// 					sendCommand('data=join ' + _jsonArr.result.devices[kk].device_id + ':HDMI:0 ' + device_id + ':HDMI:0');
					// 				}
					// 			}
					// 		})(k);								
					// 	}
					// }
					// // hdmi audio连接关系还原
					// var HdmiAudioMulticastaddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'subscriptions','type','HDMI_AUDIO','configuration.address');
					// if (HdmiAudioMulticastaddress!=HdmiAudioMulticastaddressRec&&HdmiAudioMulticastaddress!='0.0.0.0') {
					// 	for (var k = 0; k < _jsonArr.result.devices.length; k++) {
					// 		(function(kk){
					// 			if (_jsonArr.result.devices[kk].identity.is_transmitter) {
					// 				var TxMulticastaddressRec = checkReceiveJsonDataToString(_jsonArr.result.devices[kk],'streams','type','HDMI_AUDIO','configuration.address');
					// 				if (HdmiAudioMulticastaddress==TxMulticastaddressRec) {
					// 					sendCommand('data=join ' + _jsonArr.result.devices[kk].device_id + ':HDMI_AUDIO:0 ' + device_id + ':HDMI_AUDIO:0');
					// 				}
					// 			}
					// 		})(k);								
					// 	}
					// }
					// // analog audio连接关系还原
					// var AnalogAudioMulticastaddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'subscriptions','type','HDMI_AUDIO','configuration.address');
					// if (AnalogAudioMulticastaddress!=AnalogAudioMulticastaddressRec&&AnalogAudioMulticastaddress!='0.0.0.0') {
					// 	for (var k = 0; k < _jsonArr.result.devices.length; k++) {
					// 		(function(kk){
					// 			if (_jsonArr.result.devices[kk].identity.is_transmitter) {
					// 				var TxMulticastaddressRec = checkReceiveJsonDataToString(_jsonArr.result.devices[kk],'streams','type','AUDIO','configuration.address');
					// 				if (AnalogAudioMulticastaddress==TxMulticastaddressRec) {
					// 					sendCommand('data=join ' + _jsonArr.result.devices[kk].device_id + ':AUDIO:0 ' + device_id + ':AUDIO:0');
					// 				}
					// 			}
					// 		})(k);								
					// 	}
					// }
				}
			}				
		}
		else if(receiveDataToCheckOb.result.devices[j].identity.is_transmitter){			
			for (var j = 0; j < receiveDataToCheckOb.result.devices.length; j++) {
				var _jsonArrTxDetail = _jsonArrTx[i].split(',');	
				if (_jsonArr.result.devices[i].device_id==device_id) {
					var hdcp_supportRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.hdcp_support_enable');
					if (_jsonArrRxDetail[1]!=hdcp_supportRec) {
						if (hdcp_support) {
							sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_support_enable ENABLE');
						}
						else{
							sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_support_enable DISABLE');
						}
					}
					var hdcp22_supportRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.hdcp_22_support_disable');
					if (_jsonArrRxDetail[2]!=hdcp22_supportRec) {
						if (hdcp22_support) {
							sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_22_support_disable True');
						}
						else{
							sendCommand('data=set '+device_id+' property nodes[HDMI_DECODER:0].configuration.Hdcp_22_support_disable False');
						}
					}
					var deviceEDIDRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','HDMI_DECODER','configuration.edid');
					if (_jsonArrRxDetail[3]!=deviceEDIDRec) {
						sendCommand('data=set '+device_id+' edid ' + _jsonArrRxDetail[3]);
					}
					var hostnameRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.hostname');
					if (_jsonArrRxDetail[4]!=hostnameRec) {
						sendCommand('data=set '+device_id+' property configuration.device_name '+_jsonArrRxDetail[4]);
					}
					var modeRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mode');
					var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.address');
					var maskRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.mask');
					var gatewayRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','NETWORK_INTERFACE','configuration.ip.gateway');
					if (_jsonArrRxDetail[5]!=modeRec) {
						if (mode=='DHCP') {
							sendCommand('data=set '+device_id+' ip mode DHCP');
						}
						else {
							sendCommand('data=set '+device_id+' ip mode MANUAL address '+_jsonArrRxDetail[6]+' mask '+_jsonArrRxDetail[7]+' gateway '+_jsonArrRxDetail[8]);
						}
					}
					var baud_rateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.baud_rate','index',1);
					if (_jsonArrRxDetail[9]!=baud_rateRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.baud_rate '+_jsonArrRxDetail[9]);
					}
					var data_bitsRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.data_bits','index',1);
					if (_jsonArrRxDetail[10]!=data_bitsRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.data_bits '+_jsonArrRxDetail[10]);
					}
					var stop_bitsRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.stop_bits','index',1);
					if (_jsonArrRxDetail[11]!=stop_bitsRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.stop_bits '+_jsonArrRxDetail[11]);
					}
					var parityRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i].nodes,'nodes','type','UART','configuration.parity','index',1);
					if (_jsonArrRxDetail[12]!=parityRec) {
						sendCommand('data=set '+device_id+' property nodes[UART:1].configuration.parity '+_jsonArrRxDetail[12]);
					}

					// // 对应关系、start/stop状态
					// //  video
					// var stateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'streams','type','HDMI','status.state');
					// if (state!=stateRec) {
					// 	if (state == 'STREAMING') {
					// 		sendCommand('data=start '+device_id+':HDMI:0');
					// 	}
					// 	else if (state == 'STOPPED') {
					// 		sendCommand('data=stop '+device_id+':HDMI:0');
					// 	}
					// }
					// // hdmi audio
					// var AudioStateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'streams','type','HDMI_AUDIO','status.state');
					// if (AudioState!=AudioStateRec) {
					// 	if (state == 'STREAMING') {
					// 		sendCommand('data=start '+device_id+':HDMI_AUDIO:0');
					// 	}
					// 	else if (state == 'STOPPED') {
					// 		sendCommand('data=stop '+device_id+':HDMI_AUDIO:0');
					// 	}
					// }
					// // analog audio
					// var AnalogAudioStateRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'streams','type','AUDIO','status.state');
					// if (AnalogAudioState!=AnalogAudioStateRec) {
					// 	if (AnalogAudioState == 'STREAMING') {
					// 		sendCommand('data=start '+device_id+':AUDIO:0');
					// 	}
					// 	else if (AnalogAudioState == 'STOPPED') {
					// 		sendCommand('data=stop '+device_id+':AUDIO:0');
					// 	}
					// }
					// // rs232 连接对应关系
					// var Rs232MulticastAddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'streams','type','RS232','configuration.address');
					// if (Rs232Address!=Rs232MulticastAddressRec&&Rs232Address!='0.0.0.0') {
					// 	for (var k = 0; k < receiveDataToCheckOb.result.devices.length; k++) {
					// 		(function(kk){
					// 			var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'nodes','type','NETWORK_INTERFACE','configuration.ip.address');					
					// 			if (Rs232Address == addressRec) {
					// 				sendCommand('data=switch ' + device_id + ':RS232:0 ' + receiveDataToCheckOb.result.devices[i].device_id + ':RS232:0');
					// 			}
					// 		})(k);
					// 	}
					// }
					// // infrared 连接对应关系
					// var InfraredMulticastAddressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'streams','type','INFRARED','configuration.address');
					// if (InfraredAddress!=InfraredMulticastAddressRec&&InfraredAddress!='0.0.0.0') {
					// 	for (var k = 0; k < receiveDataToCheckOb.result.devices.length; k++) {
					// 		(function(kk){
					// 			var addressRec = checkReceiveJsonDataToString(receiveDataToCheckOb.result.devices[i],'nodes','type','NETWORK_INTERFACE','configuration.ip.address');					
					// 			if (InfraredAddress == addressRec) {
					// 				sendCommand('data=switch ' + device_id + ':INFRARED:0 ' + receiveDataToCheckOb.result.devices[i].device_id + ':INFRARED:0');
					// 			}
					// 		})(k);
					// 	}
					// } 
				}
			}
		}
		
	}
}
// 4s预加载
function ReloadingRestoreData(){
	$('#reloadingGetData').show();
	$('.backuploadingInput').css('width','0px');
	$('.backuptoFiling').show();	
	var _i=0;
	var _timer = setInterval(function(){
		$('.backuploadingInput').css('width',_i+'px');
		_i+=5;
		if (_i>=201) {
			clearInterval(_timer);
		    $('#reloadingGetData').hide();
		}
	},100);
}
/*Timeout,please login again!

一群嗜血的蚂蚁 被腐肉所吸引   我面无表情 看孤独的风景

失去你 爱恨开始分明   失去你 还有什么事好关心

当鸽子不再象征和平    我终于被提醒

广场上喂食的是秃鹰   我用漂亮的押韵

形容被掠夺一空的爱情    啊 乌云开始遮蔽 夜色不干净

公园里 葬礼的回音 在漫天飞行   送你的白色玫瑰

在纯黑的环境凋零    乌鸦在树枝上诡异的很安静

静静听 我黑色的大衣    想温暖你日渐冰冷的回忆

走过的 走过的 生命   啊 四周弥漫雾气

我在空旷的墓地    老去后还爱你

为你弹奏肖邦的夜曲    纪念我死去的爱情

跟夜风一样的声音    心碎的很好听

手在键盘敲很轻    我给的思念很小心

你埋葬的地方叫幽冥    为你弹奏肖邦的夜曲

纪念我死去的爱情    而我为你隐姓埋名

在月光下弹琴    对你心跳的感应

还是如此温热亲近    怀念你那鲜红的唇印

那些断翅的蜻蜓 散落在这森林    而我的眼睛 没有丝毫同情

失去你 泪水混浊不清    失去你 我连笑容都有阴影

风在长满青苔的屋顶    嘲笑我的伤心

像一口没有水的枯井    我用凄美的字型

描绘后悔莫及的那爱情   为你弹奏肖邦的夜曲

纪念我死去的爱情    跟夜风一样的声音

心碎的很好听    手在键盘敲很轻

我给的思念很小心    你埋葬的地方叫幽冥

为你弹奏肖邦的夜曲    纪念我死去的爱情

而我为你隐姓埋名    在月光下弹琴

对你心跳的感应    还是如此温热亲近

怀念你那鲜红的唇印    一群嗜血的蚂蚁 被腐肉所吸引

我面无表情 看孤独的风景   失去你 爱恨开始分明

失去你 还有什么事好关心   当鸽子不再象征和平

我终于被提醒    广场上喂食的是秃鹰

我用漂亮的押韵    形容被掠夺一空的爱情


感受停在我发端的指尖
如何瞬间 冻结时间
记住望着我坚定的双眼
也许已经 没有明天
面对浩瀚的星海
我们微小得像尘埃
漂浮在 一片无奈
缘份让我们相遇乱世以外 
命运却要我们危难中相爱
也许未来遥远在光年之外
我愿守候未知里为你等待
我没想到 为了你 我能疯狂到
山崩海啸 没有你 根本不想逃
我的大脑 为了你 已经疯狂到
脉搏心跳 没有你 根本不重要
一双围在我胸口的臂弯
足够抵挡 天旋地转
一种执迷不放手的倔强
足以点燃 所有希望
宇宙磅礴而冷漠
我们的爱微小却闪烁
颠簸 却如此忘我
缘份让我们相遇乱世以外
命运却要我们危难中相爱
也许未来遥远在光年之外
我愿守候未知里为你等待
我没想到 为了你 我能疯狂到
山崩海啸 没有你 根本不想逃
我的大脑 为了你 已经疯狂到
脉搏心跳 没有你 根本不重要
也许航道以外 是醒不来的梦
乱世以外 是纯粹的相拥
我没想到 为了你 我能疯狂到
山崩海啸 没有你 根本不想逃
我的大脑 为了你 已经疯狂到
脉搏心跳 没有你 根本不重要
相遇乱世以外 危难中相爱
相遇乱世以外 危难中相爱
我没想到


如果华陀再世 崇洋都被医治
外邦来学汉字 激发我民族意识
马钱子 决明子 苍耳子 还有莲子
黄药子 苦豆子 川楝子 我要面子
用我的方式 改写一部历史
没什么别的事 跟着我 念几个字
山药 当归 枸杞 GO 山药 当归 枸杞 GO
看我抓一把中药 服下一帖骄傲
我表情悠哉 跳个大概
动作轻松自在 你学不来
霓虹的招牌 调整好状态
在华丽的城市 等待醒来
我表情悠哉 跳个大概
用书法书朝代 内力传开
豪气挥正楷 给一拳对白
结局平躺下来 看谁厉害
练成什么丹 揉成什么丸
鹿茸切片不能太薄
老师傅的手法不能这样乱抄
龟苓膏 云南白药 还有冬虫夏草
自己的音乐 自己的药 份量刚刚好
听我说中药苦 抄袭应该更苦
快翻开本草纲目 多看一些善本书
蟾苏 地龙 已翻过江湖
这些老祖宗的辛苦 我们一定不能输
就是这个光 就是这个光 一起唱
(就是这个光 就是这个光 嘿)
让我来调个偏方 专治你媚外的内伤
已扎根千年的汉方 有别人不知道的力量
我表情悠哉 跳个大概
动作轻松自在 你学不来
霓虹的招牌 调整好状态
在华丽的城市 等待醒来
我表情悠哉 跳个大概
用书法书朝代 内力传开
豪气挥正楷 给一拳对白
结局平躺下来 看谁厉害
蹲 小僵尸蹲 小僵尸蹲
又蹲 小僵尸蹲 暗巷点灯
又蹲 小僵尸蹲 钻萝卜坑
又蹲 小僵尸蹲 念咒语哼
蹲 小僵尸蹲 小僵尸蹲
又蹲 小僵尸蹲 暗巷点灯
又蹲 小僵尸蹲 钻萝卜坑
又蹲 小僵尸蹲 念咒语哼

这街上太拥挤
太多人有秘密
玻璃上有雾气在被隐藏起过去
你脸上的情绪
在还原那场雨
这巷弄太过弯曲走不回故事里
这日子不再绿
又斑驳了几句
剩下搬空回忆的我在大房子里
电影院的座椅
隔遥远的距离
感情没有对手戏你跟自己下棋
还来不及仔仔细细写下你的关于
描述我如何爱你
你却微笑的离我而去
这感觉 已经不对
我努力在挽回
一些些应该体贴的感觉我没给
你嘟嘴许的愿望很卑微在妥协
是我忽略 你不过要人陪
这感觉已经不对
我最后才了解
一页页不忍翻阅的情节你好累
你默背为我掉过几次泪多憔悴
而我心碎你受罪你的美我不配
★ 张琪 制作
这街上太拥挤
太多人有秘密
玻璃上有雾气在被隐藏起过去
你脸上的情绪
在还原那场雨
这巷弄太过弯曲走不回故事里
这日子不再绿
又斑驳了几句
剩下搬空回忆的我在大房子里
电影院的座椅
隔遥远的距离
感情没有对手戏你跟自己下棋
还来不及仔仔细细写下你的关于
描述我如何爱你
你却微笑的离我而去
这感觉 已经不对
我努力在挽回
一些些应该体贴的感觉我没给
你嘟嘴许的愿望很卑微在妥协
是我忽略 你不过要人陪
这感觉已经不对
我最后才了解
一页页不忍翻阅的情节你好累
你默背为我掉过几次泪多憔悴
而我心碎你受罪你的美我不配
★ 张琪 制作
这感觉 已经不对
我努力在挽回
一些些应该体贴的感觉我没给
你嘟嘴许的愿望很卑微在妥协
是我忽略 你不过要人陪
这感觉已经不对
我最后才了解
一页页不忍翻阅的情节你好累
你默背为我掉过几次泪多憔悴
而我心碎你受罪你的美我不配

 */