<!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='empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-smoke-small.png" style="width: 60%;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='BaseSID'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='BaseAddr'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='BasePort'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd'> </span></td></tr>
        <tr><td style='width: 200px;'>监测状态</td><td><span class='State'> </span></td></tr>
    </table>
    <table width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>运行参数</h1></td></tr>
		<tr><td><span class='NV40004'></span>:&nbsp;<span class='V40004'></span></td></tr>
    </table>


	
    </td>
    </tr>
  </table>
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
</div>
<script>
var itype=5001;
var tescape=1000,time;
var sport=<%write('"'+port+'"');%>;
 
<% db_Open("/NandFlash/tmp/dbDat0"+port+".db3"); %>
var sid=<% write(sid);%>;
var json0=<% db_QryAdv("select * from tbModbus where SID="+sid,0,1);%>;
var json=<% db_QryAdv("select * from tbModbusDat where SID="+sid,0);%>;
var jname = <% db_QryAdv("select Name from tbSM where SID="+sid,0); %>
<% db_Close(); %>
	
$(".smName").html(jname.recs[0].Name);

var jsCfg = "";

$(function(){
  if (LoadJsConfig())
  {
  }
	ajax();
  time=setInterval(ajax, tescape);
});

function ajax(){
    $.ajax({
        type: "POST",
        url: "omdev/smdat0.asp",
        data: "port="+sport+"&itype="+itype+"&sid="+sid,
        dataType:"json",
		async: false,
        success: function(msg){
            list3(msg); 
        }
    });
}

function LoadJsConfig(){

	var url = "../jsn/A3-"+itype+".js"
	$.ajax({
		type: "POST",
		url: url,
		async: false,
		dataType: "text",
		error: function(e) {
			console.log("Get ../jsn/A3-"+itype+".js error");
		},
		complete: function(){
			//console.log("Get ../jsn/A3-"+itype+".js complete");
		},
		success: function(msg){
			jscfg=eval("("+msg+")");
			console.log("Get ../jsn/A3-"+itype+".js success");
			//console.log("Js Conf: "+"\""+msg+"\"");
			//console.log("Js Conf: "+JSON.parse(msg));
		}
	});
	
	if (jscfg=="")
	{
        alert("数据未支持，请检查数据配置是否正确！");
		return false;
	}
	return true;
}

list0(json0);
function list0(data){ // 基本配置信息
    $.each(data.recs,function(i,n){
        $(".BaseSID").html(n.SID);
        $(".BaseAddr").html(n.Addr);
        $(".BasePort").html(sport);
        $(".DateUpd").html(n.DateUpd);
        $(".State").html(parseState(n.State));
    });
}

//list3(json);
function list3(data)// 展示数据
{
	if (data.qry == "ok")
	{
		$.each(data.recs,function(i,n){
			for (var key in jscfg)
			{
				$(".N"+key).html(jscfg[key].title);
				if (jscfg[key].vType==0)
					$("."+key).html(n[key] / jscfg[key].vFactor + jscfg[key].unit);
				else if (jscfg[key].vType==1)
					$("."+key).html(jscfg[key].vStatus[n.State]);
				else //if (jscfg[key].vType==2)
					$("."+key).html(n[key]);
			}
		});
	}
	else
	{
			for (var key in jscfg)
			{
				$(".N"+key).html(jscfg[key].title);
				$("."+key).html("NAN&nbsp;"+jscfg[key].unit);
			}
	}

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

function parseAlm(istate){
    if(istate==0) return "正常";
    else   if(istate==1) return "告警";
    else return "无效";
}
function parseState(istate){
    if(istate==0) return "正常";
    else   if(istate==1) return "告警";
    else return "故障";
}

</script>

</body>
</html>