<!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='type793 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-ups.png" style="width: 50%;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='SID793'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr793'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port793'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd793'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State793'> </span></td></tr>
    </table>

    <table width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>运行参数</h1></td></tr>
        <tr class="trtime" id="trtime" style='display: none'><td>UPS当前时间:</span>&nbsp;</td><td><span class='Time793'> </td><td></td></tr>
		<tr><td>输入电压:<span class='VinA793'> </span>&nbsp;<span class='VinB793'> </span>&nbsp;<span class='VinC793'> </span></td><td>输出电压:<span class='VoutA793'> </span>&nbsp;<span class='VoutB793'> </span>&nbsp;<span class='VoutC793'> </span></td><td>旁路电压:<span class='VBA793'> </span>&nbsp;<span class='VBB793'> </span>&nbsp;<span class='VBC793'> </span></td></tr>
		<tr><td>输入频率:<span class='FinA793'> </span>&nbsp;<span class='FinB793'> </span>&nbsp;<span class='FinC793'> </span></td><td>输出频率:<span class='FoutA793'> </span>&nbsp;<span class='FoutB793'> </span>&nbsp;<span class='FoutC793'> </span></td><td>旁路频率:<span class='FBA793'> </span>&nbsp;<span class='FBB793'> </span>&nbsp;<span class='FBC793'> </span></td></tr>
		<tr><td>输入电流:<span class='IinA793'> </span>&nbsp;<span class='IinB793'> </span>&nbsp;<span class='IinC793'> </span></td><td>输出电流:<span class='IoutA793'> </span>&nbsp;<span class='IoutB793'> </span>&nbsp;<span class='IoutC793'> </span></td><td>旁路电流:<span class='IBA793'> </span>&nbsp;<span class='IBB793'> </span>&nbsp;<span class='IBC793'> </span></td></tr>
        <tr><td>电池电压:<span class='Vbatt793'> </span></td><td>电池容量:<span class='Pbatt793'> </span></td><td>电池温度:<span class='Tem793'> </span></td></tr>
		<tr><td>电池剩于时间:<span class='Mbatt793'> </span></td><td> 工作模式:<span class='v1793'> </span></td><td> <span class='xx793'> </span></td></tr>

    </table>
    <table class="workstate" style='display: none' width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>工作状态</h1></td></tr>
        <tr><td >充电器故障:<span class='b15793'> </span></td><td> 电池晶闸管故障:<span class='b14793'> </span></td><td>初始化故障:<span class='b13793'> </span></td><td >母线电压异常:<span class='b12793'> </span></td></tr>
        <tr><td >熔丝断:<span class='b11793'> </span></td><td> 旁路晶闸管故障:<span class='b10793'> </span></td><td>逆变晶闸管故障:<span class='b9793'> </span></td><td >输入晶闸管故障:<span class='b8793'> </span></td></tr>
        <tr><td >风扇故障:<span class='b7793'> </span></td><td> 辅助电源故障:<span class='b6793'> </span></td><td>逆变器故障:<span class='b5793'> </span></td><td >整流器故障:<span class='b4793'> </span></td></tr>
        <tr><td >整流器限流:<span class='b3793'> </span></td><td> 整流器状态:<span class='b2793'> </span></td><td>电池充电:<span class='b1793'> </span></td><td >电池自检:<span class='b0793'> </span></td></tr>
    </table>
    <table class='kttable ktaircpowtable' id="trea89iictrl" width='100%' style='margin-top: 10px;display: none'>
        <tr><td style='border: none'> <h1>UPS时间同步</h1></td></tr>
        <tr>
			<td style='width: 25%;'>同步时间: </td>
			<td style='width: 20%;'> <a  href='javascript:upsTimeSync(1)' id='aircPowCtrlon' class='redd'>同步时间</a></td>
			<td style='width: 100%;'></td>
		</tr>
    </table>
    </td>
    </tr>
  </table>
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
    </div>
<script>
var itype=793;
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 tbUpsEx where SID="+sid,0); %>;
<% db_Close(); %>
$(function(){
	if (tag1 == 3)
	{
		$("#trtime").show();
		$("#trea89iictrl").show();
	}
    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)
        }
    });
}
list3(json);
function list3(data){
    $.each(data.recs,function(i,n){
        $(".SID793").html(n.SID);
        $(".Addr793").html(n.Addr);
        $(".Port793").html(n.Port%256);
        $(".DateUpd793").html(n.DateUpd);
        $(".State793").html(window.parent.parseState(n.State));

        $(".VinA793").html(n.Vin1/10+"V");
		$(".VinB793").html(n.Vin2/10+"V");
		$(".VinC793").html(n.Vin3/10+"V");
		
        $(".VoutA793").html(n.Vout1/10+"V");
		$(".VoutB793").html(n.Vout2/10+"V");
		$(".VoutC793").html(n.Vout3/10+"V");
		
        $(".VBA793").html(n.VB1/10+"V");
		$(".VBB793").html(n.VB2/10+"V");
		$(".VBC793").html(n.VB3/10+"V");
		
		if ((n.Iin1==0) && (n.Iin2==0) && (n.Iin3==0))
		{
			$(".IinA793").html("NA");
			$(".IinB793").html("NA");
			$(".IinC793").html("NA");
		}
		else
		{
			$(".IinA793").html(n.Iin1/10+"A");
			$(".IinB793").html(n.Iin2/10+"A");
			$(".IinC793").html(n.Iin3/10+"A");
		}
		
		if ((n.IB1==0) && (n.IB2==0) && (n.IB3==0))
		{
			$(".IBA793").html("NA");
			$(".IBB793").html("NA");
			$(".IBC793").html("NA");
		}
		else
		{
			$(".IBA793").html(n.IB1/10+"A");
			$(".IBB793").html(n.IB2/10+"A");
			$(".IBC793").html(n.IB3/10+"A");
		}
		
		$(".IoutA793").html(n.Iout1/10+"A");
		$(".IoutB793").html(n.Iout2/10+"A");
		$(".IoutC793").html(n.Iout3/10+"A");
		
		$(".FinA793").html(n.Fin1/10+"Hz");
		$(".FinB793").html(n.Fin2/10+"Hz");
		$(".FinC793").html(n.Fin3/10+"Hz");
		
		$(".FoutA793").html(n.Fout1/10+"Hz");
		$(".FoutB793").html(n.Fout2/10+"Hz");
		$(".FoutC793").html(n.Fout3/10+"Hz");
		
		$(".FBA793").html(n.FB1/10+"Hz");
		$(".FBB793").html(n.FB2/10+"Hz");
		$(".FBC793").html(n.FB3/10+"Hz");
		
        $(".Vbatt793").html(n.Vbatt/10+"V");            
		$(".Pbatt793").html(n.Pbatt/10+"%");
		if ((tag1==0) || (tag1==1)) 
			$(".Tem793").html(n.Tem/10+"℃");  
		else
			$(".Tem793").html("NA"); 
		$(".Mbatt793").html(n.Mbatt/10+"min"); 
		
		if ((tag1==0) || (tag1==1))
			$(".v1793").html(GetWorkState(n.v1)); 
		else
			$(".v1793").html("NA"); 
		
		if ((tag1==0) || (tag1==1))
		{
			$(".workstate").show();
			$(".b15793").html(n.b15 ? "告警" : "正常");
			$(".b14793").html(n.b14 ? "告警" : "正常");
			$(".b13793").html(n.b13 ? "告警" : "正常");
			$(".b12793").html(n.b12 ? "告警" : "正常");
			$(".b11793").html(n.b11 ? "告警" : "正常");
			$(".b10793").html(n.b10 ? "告警" : "正常");
			$(".b9793").html(n.b9 ? "告警" : "正常");
			$(".b8793").html(n.b8 ? "告警" : "正常");
			$(".b7793").html(n.b7 ? "告警" : "正常");
			$(".b6793").html(n.b6 ? "告警" : "正常");
			$(".b5793").html(n.b5 ? "告警" : "正常");
			$(".b4793").html(n.b4 ? "告警" : "正常");
			$(".b3793").html(n.b3 ? "告警" : "正常");
			$(".b2793").html(n.b2 ? "告警" : "正常");
			$(".b1793").html(n.b1 ? "告警" : "正常");
			$(".b0793").html(n.b0 ? "告警" : "正常");
		}
		else if (tag1 == 3)
		{
			//n.v3 = (year << 9) | (mouth << 5) | (day);
			//n.v4 = (hour << 9) | (min << 5) | (sece);
			var year, mouth, day, hour, min, sece;
			year = (n.v3 >> 9) ;
			mouth =  (n.v3 >> 5) & 0x0f;
			day =  (n.v3)& 0x1f;
			hour =  (n.v4 >> 9)& 0x1f;
			min =  (n.v4 >> 5)& 0x3f;
			sece =  (n.v4)& 0x3f;
			$(".Time793").html(year+"."+mouth+"."+day+" "+hour+":"+min+":"+sece);
		}

    })
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
    $("span:contains('正常')").addClass("ger").removeClass("red");
}

//1：待机模式 2：旁路模式 3：市电模式 4：电池模式 5：电池自检 6：故障模式 7：变频模式 8：紧急关机模式 9：关机模式
function GetWorkState(st)
{
    switch(st){
    case 1: return "待机模式";
    case 2: return "旁路模式";
    case 3: return "市电模式";
    case 4: return "电池模式";
    case 5: return "电池自检";
    case 6: return "故障模式";
    case 7: return "变频模式";
    case 8: return "紧急关机模式";
    case 9: return "关机模式";
    }
    return "未知模式";
}

function upsTimeSync(state)
{
	var wParam = 0x060000; //[32:16]功能码，[15:0]寄存器地址
	var year, mouth, day, hour, min, sece;
	var secc = 1;
	
	var list=new Date();
	year = list.getFullYear();
	mouth = list.getMonth()+1;
	day = list.getDate();
	hour = list.getHours();
	min = list.getMinutes();
	sece = list.getSeconds();

	var s="是否需要同步UPS时间？\n同步时间："+year+"."+mouth+"."+day+" "+hour+":"+min+":"+sece;
	if(!confirm(s)) return;
	//年
	var lParam = (sid << 16) | (year & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        success: function(msg){
            //if (msg != "OK")
				secc = 0;
        }
    });
	//月
	lParam = (sid << 16) | (mouth & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        success: function(msg){
            //if (msg != "OK")
				secc = 0;
        }
    });
	//日
	lParam = (sid << 16) | (day & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        success: function(msg){
            //if (msg != "OK")
				secc = 0;
        }
    });
	//时
	var lParam = (sid << 16) | (hour & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        success: function(msg){
            //if (msg != "OK")
				secc = 0;
        }
    });
	//分
	lParam = (sid << 16) | (min & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        success: function(msg){
            //if (msg != "OK")
				secc = 0;
        }
    });
	//秒
	lParam = (sid << 16) | (sece & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        success: function(msg){
            //if (msg != "OK")
				secc = 0;
        }
    });
	
	if (secc)
        alert("指令发送成功!");
	else
        alert("指令发送失败!");
}

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