<!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='type1310 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-envir.png" style="width: 50%;text-align: center;"></td>
    <td>
    <table width='100%'>
        <tr><td style='border: none'> <h1 class='smName'></h1></td></tr>
        <tr><td style='width: 200px;'>基本信息</td><td>SID:<span class='SID1310'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr1310'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port1310'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd1310'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State1310'> </span></td></tr>
    </table>
    <table width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>车位锁状态(监测量)</h1></td></tr>
        <tr><td >车位锁状态:<span class='Lock1310'></span></td><td>监测量状态:<span class='iLock1310'></span></td></tr>
    </table>
    <table width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>电量(监测量)</h1></td></tr>
        <tr><td >电量:<span class='Pow1310'></span></td><td>监测量状态:<span class='iPow1310'></span></td></tr>
    </table>
    <table class='tabcsb' width='100%' style='margin-top: 30px;display: none'>
        <tr><td style='border: none'> <h1>车辆传感器状态(监测量)</h1></td></tr>
        <tr><td >车辆传感器状态:<span class='Csb1310'></span></td><td>监测量状态:<span class='iCsb1310'></span></td></tr>
    </table>
    <table class='tabbeep' width='100%' style='margin-top: 30px;display: none'>
        <tr><td style='border: none'> <h1>蜂鸣器状态(监测量)</h1></td></tr>
        <tr><td >蜂鸣器状态:<span class='BEEP1310'></span></td><td>监测量状态:<span class='iBEEP1310'></span></td></tr>
    </table>
    <table id='tabcarlock' class='kttable ktaircpowtable' width='100%' style='margin-top: 10px;display: none'>
        <tr><td style='border: none'> <h1>车位锁控制</h1></td></tr>
        <tr>
			<td style='width: 20%;'>车位锁控制: </td>
			<td style='width: 20%;'> <a  href='javascript:CarLockCtrl(25, 256)' id='aircPowCtrlon' class='gray'>降锁</a></td>
			<td style='width: 20%;'><a href='javascript:CarLockCtrl(26, 256)' id='aircPowCtrloff' class='gray'>升锁</a></td>
			<td style='width: 100%;'></td>
		</tr>
    </table>
    <table id='tabcarbees' class='kttable ktaircpowtable' width='100%' style='margin-top: 10px;display: none'>
        <tr><td style='border: none'> <h1>蜂鸣器控制</h1></td></tr>
        <tr>
			<td style='width: 20%;'>蜂鸣器控制: </td>
			<td style='width: 20%;'> <a  href='javascript:CarLockCtrl(22,1)' id='aircPowCtrlon' class='gray'>打开</a></td>
			<td style='width: 20%;'><a href='javascript:CarLockCtrl(22,0)' id='aircPowCtrloff' class='gray'>关闭</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=1310;
var tescape= 5000,time;
  
<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var json=<% db_QryAdv("select * from tbEnvirCPL where SID="+sid,0);%>;
var jname = <% db_QryAdv("select Name from tbSM where SID="+sid,0); %>
var tag1=<% write(db_QryInt("select Tag1 from tbSM where SID="+sid,1));%>;
<% db_Close(); %>
	
$(".smName").html(jname.recs[0].Name);

if (tag1==1)
{
	$(".tabcsb").show();
	$(".tabbeep").show();
	$("#tabcarlock").show();
	$("#tabcarbees").show();
}
	
$(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);
        }
    });
}
list3(json);
function list3(data){
    $.each(data.recs,function(i,n){
        if(n.iLock==0){n.iLock="正常";}
        else if(n.iLock==1){n.iLock="告警";}
        else if(n.iLock<0||n.iLock>1){n.iLock="故障";}
		
        if(n.iPow==0){n.iPow="正常";}
        else if(n.iPow==1){n.iPow="告警";}
        else if(n.iPow<0||n.iPow>1){n.iPow="故障";}
		
        if(n.iCsb==0){n.iCsb="正常";}
        else if(n.iCsb==1){n.iCsb="告警";}
        else if(n.iCsb<0||n.iCsb>1){n.iCsb="故障";}
		
        if(n.iBEEP==0){n.iBEEP="正常";}
        else if(n.iBEEP==1){n.iBEEP="告警";}
        else if(n.iBEEP<0||n.iBEEP>1){n.iBEEP="故障";}
		
        $(".SID1310").html(n.SID);
        $(".Addr1310").html(n.Addr);
        $(".Port1310").html(n.Port%256);
        $(".DateUpd1310").html(n.DateUpd);
        $(".State1310").html(window.parent.parseState(n.State));

		if (tag1==1)
		{
			if (n.Lock==0)
				n.Lock = "上升状态";
			else if (n.Lock==1)
				n.Lock = "下降状态";
			else if (n.Lock==2)
				n.Lock = "中间状态";
			else if (n.Lock==3)
				n.Lock = "上升遇阻后恢复";
			else if (n.Lock==0x88)
				n.Lock = "运动状态";
			else //if (n.Lock==3)
				n.Lock = "未知";
			$(".Lock1310").html(n.Lock);
			
			if (n.Pow==0)
				n.Pow = "没电";
			else if (n.Pow==1)
				n.Pow = "低电";
			else if (n.Pow==2)
				n.Pow = "中间状态";
			else if (n.Csb==3)
				n.Pow = "满电";
			$(".Pow1310").html(n.Pow);

			if (n.Csb==0)
				n.Csb = "无车";
			else if (n.Csb==1)
				n.Csb = "有车";
			else if (n.Csb==2)
				n.Csb = "变化中";
			else //if (n.Csb==0)
				n.Csb = "未知";
			$(".Csb1310").html(n.Csb);
			
			if (n.BEEP==0)
				n.BEEP = "关闭";
			else //if (n.BEEP==1)
				n.BEEP = "打开";
			$(".BEEP1310").html(n.BEEP);
			
			$(".iCsb1310").html(n.iCsb);
			$(".iBEEP1310").html(n.iBEEP);
		}
		else
		{
			if (n.Lock==1)
				n.Lock = "上升状态";
			else if (n.Lock==6)
				n.Lock = "运动状态";
			else if (n.Lock==8)
				n.Lock = "初始状态";
			else //if (n.Lock==0)
				n.Lock = "下降状态";
			$(".Lock1310").html(n.Lock);
			$(".Pow1310").html(n.Pow+"%");
		}
        
		
        $(".iLock1310").html(n.iLock);
        $(".iPow1310").html(n.iPow);
    })
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
    $("span:contains('正常')").addClass("ger").removeClass("red");
}


function CarLockCtrl(ifunc, val)
{
	var secc = 0;
	var wParam = (ifunc << 16) | 0x0000; //[32:16]功能码，[15:0]寄存器地址
	var lParam = (sid << 16) | (val & 0xFFFF);//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        async: false,
        complete: function(msg){
            console.log("CarLockCtrl complete.");
        },
        error: function(msg){
            console.log("CarLockCtrl error.");
			secc = 0;
        },
        success: function(msg){
            console.log("CarLockCtrl success.");
			secc = 1;
        }
    });
	if (secc)
        alert("指令发送成功!");
	else
        alert("指令发送失败!");
}


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