<!DOCTYPE html>
<% language=javascript %>
<html>
<head lang="en">
    <meta charset="GB2312">
    <title></title>
    <link href="css/style.css" title="style" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.6.3.min.js"></script>

</head>
<body style="background: #F3F3F3">
<div class='type1796 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-airc.png" style="width: 40%;text-align: center;"></td>
    <td>
    <table width='100%'>
        <tr><td style='border: none'> <h1>空调监测</h1></td></tr>
        <tr><td style='width: 200px;'>基本信息</td><td>SID:<span class='SID1796'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr1796'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port1796'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd1796'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State1796'> </span></td></tr>
    </table>
    <table width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>温度(监测量)</h1></td></tr>
        <tr><td >温度:<span class='Tem1796'></span></td><td>监测量状态:<span class='iTem1796'></span></td></tr>
        <tr id='IHum'><td >湿度:<span class='Hum1796'></span></td><td>监测量状态:<span class='iHum1796'></span></td></tr>
        <tr id='IRun1'><td >空调1状态:<span class='Run11796'></span></td><td><span class='iRun11796'></span></td></tr>
        <tr id='IRun2'><td >空调2状态:<span class='Run21796'></span></td><td><span class='iRun21796'></span></td></tr>
    </table>
    <table width='100%' style='margin-top: 30px' class="ofBTN">
        <tr><td style='border: none'> <h1>空调控制</h1></td></tr>
        <tr><td style='width: 180px;'><span id='IFunc'>遥控命令号:</span> <select id="functions" style="width:80px" onchange="OnFuncChange()"></select></td>
			<td style='width: 250px;'><span id='IProbes'>发射探头:</span> <select id="probes" style="width:150px"></select></td>
			<td><a href='javascript:aircRemoteCtrl()' id='relayctrlon' class='yel'>发送</a></td></tr>
    </table>
    <table width='100%' style='margin-top: 0px'>
        <tr><td style='color: #FF0000;'>发送空调遥控前，必须先按照说明书对原空调遥控器进行自学习，然后按学习的遥控码及探头进行控制</td></tr>
    </table>
    </td>
    </tr>
  </table>
	<br>
	<br>
	<br>
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
</div>
<script>
var itype=1796;
var tescape= 5000,time;
  
<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var tag1=<% write(db_QryInt("select tag1 from tbSM where SID="+sid,1)); %>;
var json=<% db_QryAdv("select * from tbAircIACRx0 where SID="+sid,0);%>;
<% db_Close(); %>
	
if (tag1==1)
{
	$("#IHum").hide();
	$("#IRun1").hide();
	$("#IRun2").hide();
    $("#IFunc").html("组别：");
    $("#IProbes").html("功能：");
}
else if (tag1==2)
{
    $("#IFunc").html("组别：");
    $("#IProbes").html("功能：");
}
	
$(function(){
   time=setInterval(ajax,tescape)
});
function ajax(){
    $.ajax({
        type: "POST",
        url: "omdev/smdat0.asp",
        data: "itype="+itype+"&sid="+sid,
        dataType:"json",
        success: function(msg){
            list3(msg); 
			
        }
    });
}

listFunctions();
function listFunctions()
{
	var stbl = "";
	if (tag1==1)
	{
			stbl+=" <option value=\"1\">开关机</option>";
			stbl+=" <option value=\"2\">制冷</option>";
			stbl+=" <option value=\"3\">制热</option>";
			stbl+=" <option value=\"4\">除湿</option>";
			stbl+=" <option value=\"5\">自动</option>";
		$("#functions").html(stbl);
	
		stbl = "";
		stbl+=" <option value=\"1\">开机</option>";
		stbl+=" <option value=\"2\">关机</option>";
		$("#probes").html(stbl);
	}
	else if (tag1==2)
	{
			stbl+=" <option value=\"1\">开关机</option>";
			stbl+=" <option value=\"2\">制冷</option>";
			stbl+=" <option value=\"3\">制热</option>";
			stbl+=" <option value=\"4\">除湿</option>";
			stbl+=" <option value=\"5\">送风</option>";
		$("#functions").html(stbl);
	
		stbl = "";
		stbl+=" <option value=\"0\">开机</option>";
		stbl+=" <option value=\"63\">关机</option>";
		$("#probes").html(stbl);
	}
	else
	{
		for (var i=0; i<64; i++){
			stbl+=" <option value=\""+i+"\">"+i+"</option>";
		}
		$("#functions").html(stbl);
	
		stbl = "";
		stbl+=" <option value=\"1\">探头1输出</option>";
		stbl+=" <option value=\"2\">探头2输出</option>";
		stbl+=" <option value=\"3\">探头1、2同时输出</option>";
		$("#probes").html(stbl);
	}
}

function OnFuncChange()
{
	var stbl = "";
	var ifunc=$("#functions").val();//遥控命令号
	if (tag1==1)
	{
		if (ifunc == 1)
		{
			stbl+=" <option value=\"1\">开机</option>";
			stbl+=" <option value=\"2\">关机</option>";
			$("#probes").html(stbl);
		}
		else
		{
			for (var i=1; i<=12; i++){
				stbl+=" <option value=\""+i+"\">"+(i+16)+"℃</option>";
			}
			$("#probes").html(stbl);
		}
	}
	else if (tag1==2)
	{
		if (ifunc == 1)
		{
			stbl+=" <option value=\"0\">开机</option>";
			stbl+=" <option value=\"63\">关机</option>";
			$("#probes").html(stbl);
		}
		else
		{
			for (var i=1; i<=15; i++){
				stbl+=" <option value=\""+((ifunc-2)*15+i)+"\">"+(i+15)+"℃</option>";
			}
			$("#probes").html(stbl);
		}
	}
}

list3(json);
function list3(data){
    $.each(data.recs,function(i,n){
        $(".SID1796").html(n.SID);
        $(".Addr1796").html(n.Addr);
        $(".Port1796").html(n.Port%256);
        $(".DateUpd1796").html(n.DateUpd);
        $(".State1796").html(window.parent.parseState(n.State));
		
        if(n.iTem==0){n.iTem="正常";}
        else if(n.iTem==1){n.iTem="告警";}
        else{n.iTem="故障";}
		
        if(n.iHum==0){n.iHum="正常";}
        else if(n.iHum==1){n.iHum="告警";}
        else{n.iHum="故障";}
		
        $(".Tem1796").html(n.Tem/10.0+"℃");
        $(".iTem1796").html(n.iTem);
        $(".Hum1796").html(n.Hum/10.0+"％");
        $(".iHum1796").html(n.iHum);
        $(".Run11796").html(n.RunState1 ? "开机" : "关机");
		$(".Run21796").html(n.RunState2 ? "开机" : "关机");
	})
	$("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");    $("span:contains('正常')").addClass("ger").removeClass("red");
}
function aircRemoteCtrl(){
	var ifunc=$("#functions").val();//遥控命令号
	var iprobes=$("#probes").val();//发射探头号
	var wParam = 0x050000 | (ifunc & 0xffff); //[32:16]功能码，[15:0]寄存器地址
	var lParam = (sid << 16) | 0xff00 | (iprobes & 0xFF);//[32:16]SID，[15:0]控制信息数据
	if (tag1==1)
	{
		wParam = 0x060000; //[32:16]功能码，[15:0]寄存器地址
		lParam = (sid << 16) | ((ifunc<<8) & 0xff00) | (iprobes & 0xFF);//[32:16]SID，[15:8]组别，[7:0]键值
	}
	else if (tag1==2)
	{
		wParam = 0x050000 | (iprobes & 0xffff); //[32:16]功能码，[15:0]寄存器地址
		lParam = (sid << 16) | 0xff01;//[32:16]SID，[15:0]控制信息数据
	}
	
    $.ajax({
		type: "POST",
		url: "action/doctrl",
		data: "op="+wParam+"&value="+lParam+"",
		dataType: "json",
		success: function(msg){
			alert("ok!");
		}    
	});
}

</script>
</body>
</html>