<!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='type1027 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-batt.png" style="width: 70%;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='SID1027'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr1027'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port1027'> </span>&nbsp;&nbsp;&nbsp;说明:<span class='Note1027'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd1027'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State1027'> </span></td></tr>
    </table>
	<div class="batt_grub0"></div>
	<div class="batt_grub1"></div>
	<div class="batt_grub2"></div>
	<div class="batt_grub3"></div>
	<div class="batt_grub4"></div>
    </td>
    </tr>
  </table>
</div>
<a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
<script>
var itype=1027;
var tescape= 5000,time;
  
<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var jbase=<% db_QryAdv("select SID,Type,Tag1,Name,Note,SerDef,SerAddr,Ext1 from tbSM where SID="+sid,0); %>;
var json=<% db_QryAdv("select * from tbBattRTVS where SID="+sid,0); %>;
var BRT=0,BR1=0,BR2=0,BR3=0,BR4=0;

if (jbase.reccnt>0) {
  BR1=(jbase.recs[0].Ext1 & 0xff);
  BR2=(jbase.recs[0].Ext1 >> 8) & 0xff;
  BR3=(jbase.recs[0].Ext1 >> 16) & 0xff;
  BR4=(jbase.recs[0].Ext1 >> 24) & 0xff;
}
BRT=BR1+BR2+BR3+BR4;

$(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){
    //var q="BRT="+BRT+",BR1="+BR1+",BR2="+BR2+",BR3="+BR3+",BR4="+BR4;
    var q0='';
    var q1='';
    var q2='';
    var q3='';
    var q4='';
	var id = 0;
	var R1,T1,T2,V1,S1,TV;
	var I0, I1;
	var cb1 = 0;
	var cb2 = 0;
	var cb3 = 0;
	var cb4 = 0;
	
	//模块电流
    q0 += "<table width='100%' style='margin-top: 30px'>"
    q0 += "<tr><td style='border: none'> <h1>模块电流(监测量)</h1></td></tr>"
	
	//通道1
    q1 += "<table width='100%' style='margin-top: 30px'>"
    q1 += "<tr><td style='border: none'> <h1>通道1(监测量)</h1></td></tr>"
	
	//通道2
    q2 += "<table width='100%' style='margin-top: 20px'>"
    q2 += "<tr><td style='border: none'> <h1>通道2(监测量)</h1></td></tr>"
	
	//通道3
    q3 += "<table width='100%' style='margin-top: 20px'>"
    q3 += "<tr><td style='border: none'> <h1>通道3(监测量)</h1></td></tr>"
	
	//通道4
    q4 += "<table width='100%' style='margin-top: 20px'>"
    q4 += "<tr><td style='border: none'> <h1>通道4(监测量)</h1></td></tr>"
	
    $.each(data.recs,function(i,n){
		if (i==0)
		{
			$(".SID1027").html(n.SID);
			$(".Addr1027").html(n.Addr);
			$(".Port1027").html(n.Port%256);
			if (jbase.reccnt>0)
			  $(".Note1027").html(jbase.recs[0].Name);
			$(".DateUpd1027").html(n.DateUpd);
			$(".State1027").html(parseState(n.State));
			
			I0 = n.TI1/10;
			I1 = n.TI2/10;
			q0 += "<tr><td style='width: 200px;'>电流通道1:&nbsp;"+I0+"A</td><td>电流通道2:&nbsp;"+I1+"A</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td></tr>"
		}
		else
		{
		    if (n.GlobalId == 0) return true;
			R1=n.R1/10;
			T1=n.T1;
			T2=n.T2;
			V1=n.V1/10;
			S1=n.S1;			
			if (n.GlobalId <= BR1)//通道1
			{
				id=n.GlobalId;
				if (cb1 == 0)
				{
					TV = n.TV/10;
					q1 += "<tr><td style='width: 100px;'>通道总电压:</td><td>&nbsp;"+TV+"V</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td></tr>"
					q1 += "<tr><td style='width: 100px;'>序号</td><td>测量地址</td><td>内阻(单位: mΩ) </td><td>模块CPU温度(单位: ℃)</td><td>电池表面温度(单位: ℃)</td><td>电压(单位: V)</td><td>鼓包状态</td><td>工作状态</td></tr>"
					cb1 = 1;
				}
				q1 += "<tr><td>"+id+"</td><td>"+n.MAddr+"</td><td>"+R1+"</td><td>"+T1+"</td><td>"+T2+"</td><td>"+V1+"</td><td>"+pumpState(S1)+"</td><td>"+parseState(n.State)+"</td>"
			}
			else if (n.GlobalId <= (BR1+BR2))//通道2
			{
				id = (n.GlobalId-BR1);
				if (cb2 == 0)
				{
					TV = n.TV/10;
					q2 += "<tr><td style='width: 100px;'>通道总电压:</td><td>&nbsp;"+TV+"V</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td></tr>"
					q2 += "<tr><td style='width: 100px;'>序号</td><td>测量地址</td><td>内阻(单位：mΩ)</td><td>模块CPU温度(单位: ℃)</td><td>电池表面温度(单位: ℃)</td><td>电压(单位: V)</td><td>鼓包状态</td><td>工作状态</td></tr>"
					cb2 = 1;
				}
				q2 += "<tr><td>"+id+"</td><td>"+n.MAddr+"</td><td>"+R1+"</td><td>"+T1+"</td><td>"+T2+"</td><td>"+V1+"</td><td>"+pumpState(S1)+"</td><td>"+parseState(n.State)+"</td>"
			}
			else if (n.GlobalId <= (BR1+BR2+BR3))//通道3
			{
				id = (n.GlobalId-BR1-BR2);
				if (cb3 == 0)
				{
					TV = n.TV/10;
					q3 += "<tr><td style='width: 100px;'>通道总电压:</td><td>&nbsp;"+TV+"V</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td></tr>"
					q3 += "<tr><td style='width: 100px;'>序号</td><td>测量地址</td><td>内阻(单位：mΩ)</td><td>模块CPU温度(单位: ℃)</td><td>电池表面温度(单位: ℃)</td><td>电压(单位: V)</td><td>鼓包状态</td><td>工作状态</td></tr>"
					cb3 = 1;
				}
				q3 += "<tr><td>"+id+"</td><td>"+n.MAddr+"</td><td>"+R1+"</td><td>"+T1+"</td><td>"+T2+"</td><td>"+V1+"</td><td>"+pumpState(S1)+"</td><td>"+parseState(n.State)+"</td>"
			}
			else if (n.GlobalId <= (BRT))//通道4
			{
				id = (n.GlobalId-BR1-BR2-BR3);
				if (cb4 == 0)
				{
					TV = n.TV/10;
					q4 += "<tr><td style='width: 100px;'>通道总电压:</td><td>&nbsp;"+TV+"V</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td></tr>"
					q4 += "<tr><td style='width: 100px;'>序号</td><td>测量地址</td><td>内阻(单位：mΩ)</td><td>模块CPU温度(单位: ℃)</td><td>电池表面温度(单位: ℃)</td><td>电压(单位: V)</td><td>鼓包状态</td><td>工作状态</td></tr>"
					cb4 = 1;
				}
				q4 += "<tr><td>"+id+"</td><td>"+n.MAddr+"</td><td>"+R1+"</td><td>"+T1+"</td><td>"+T2+"</td><td>"+V1+"</td><td>"+pumpState(S1)+"</td><td>"+parseState(n.State)+"</td>"
			}
		}
    });
	q0 += "</table>";
	q1 += "</table>";
	q2 += "</table>";
	q3 += "</table>";
	q4 += "</table>";
    $(".batt_grub0").html(q0);
    $(".batt_grub1").html(q1);
    $(".batt_grub2").html(q2);
    $(".batt_grub3").html(q3);
    $(".batt_grub4").html(q4);
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
    $("span:contains('正常')").addClass("ger").removeClass("red");
}

function pumpState(st)
{
	var state = "告警";
	if (0 == st)
		state = "正常";
	return state;
}

function parseState(st)
{
	var state = "故障";
	if (0 == st)
		state = "正常";
	else if (1 == st)
		state = "告警";
	return state;
}
</script>
</body>
</html>