<!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>
    <style>
        i{font-style:normal}
        .kaiguanTD td{text-align: left;}
    </style>

</head>
<body style="background: #F3F3F3">
<div class='type2317 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img id ="imginit" src="" style="width: 100%;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='SID2317'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr2317'> </span>&nbsp;&nbsp;&nbsp;端口:<span class='Port2317'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd2317'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State2317'> </span></td></tr>
    </table>

    <h1 style='margin:30px 10px 10px 10px;'>测量值</h1>
    <table width='100%' class="kaiguanTD">
        <tr><td style='width: 200px;'>显示值:</td><td><span class="ADC"></span>&nbsp;<span class="Unit"></span></td></tr>
    </table>
    </td>
    </tr>
  </table>

    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
    </div>
<script>
var itype=2317;
var tescape=5000,time;
<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var tag1=<% write(tag1);%>;
var isubsys=<%write(subsys);%>;
<%var val=db_QryInt("select SerType from tbSM where SID="+sid,1);%>
var Val=<% write(val);%>;
<% db_Close(); %>

<% db_Open("/NandFlash/dbCfg.db3"); %>
var unit1=<%db_QryAdv("select Unit from tbAIDef where Type="+type,0);%>
var jfxy =<%db_QryAdv("select * from tbAICfg where Type ="+type+" order by Xval",0);%>
var unit=unit1.recs[0].Unit;
<%var Sid1=db_QryInt("select SID from tbPort where Val="+val,1);%>
var ssid=<% write(Sid1);%>;
<% db_Close(); %>

<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var json=<% db_QryAdv("select * from tbDio where SID="+Sid1,0); %>
var jaidata=<%db_QryAdv("select d.*,s.Name,s.Tag1,s.KName,s.TName,s.SerType,s.SerDef,s.SerAddr,b.Brief from tbSubSysDetail d left join tbSM s on s.SID=d.SID left join tbSMBrief b on b.SID=d.SID where d.SID="+sid,0);%>
<% db_Close(); %>	
//var unit = "mA";
//if ((tag1 % 10) >= 1)
//	unit = "V";
listimg();
function listimg()
{
  $("#imginit").attr('src',subsysicon(isubsys)); 
  //$("#imgId").attr('src',path); 
}

    $(function(){
        if (tescape>0)
        {
            time=setInterval(ajax,tescape);
        }
    });
    function ajax(){
        $.ajax({
            type: "POST",
            url: "omdev/smdat0.asp",
            data: "itype="+itype+"&sid="+ssid,
            dataType:"json",
            success: function(msg){
               list3(msg);		
            }
        });
    }
	function calfy(xval)
	{  
	  var ydx=0;var xdx = 0;var k = 0;var b =0 ; var fy =0;
	  var dat = xval/100;
	  if(jfxy.reccnt>=3)
	  {
	     for(var i=0;i < jfxy.reccnt;i++)
	    {
			 if( dat<jfxy.recs[0].Xval)
			 {
			   xdx = jfxy.recs[1].Xval-jfxy.recs[0].Xval;
			   ydx =jfxy.recs[1].Yval-jfxy.recs[0].Yval;
			   k =ydx/xdx;
			   b =jfxy.recs[0].Yval-k*jfxy.recs[0].Xval;
			
			 }
			 else if ( dat > jfxy.recs[jfxy.reccnt-1].Xval)
			 {
			   xdx = jfxy.recs[jfxy.reccnt-1].Xval-jfxy.recs[jfxy.reccnt-2].Xval;
			   ydx =jfxy.recs[jfxy.reccnt-1].Yval-jfxy.recs[jfxy.reccnt-2].Yval;
			   k =ydx/xdx;
			   b =jfxy.recs[jfxy.reccnt-1].Yval-k*jfxy.recs[jfxy.reccnt-1].Xval;
			   
			 }
			 else
			 {
			   if(jfxy.recs[i].Xval<=dat && jfxy.recs[i+1].Xval>=dat)
			   {
				  xdx = jfxy.recs[i+1].Xval-jfxy.recs[i].Xval;
				  ydx =jfxy.recs[i+1].Yval-jfxy.recs[i].Yval;
				  k =ydx/xdx;
				  b =jfxy.recs[i].Yval-k*jfxy.recs[i].Xval;
				  
			   }
			 }     
	    }
	  }
	  else if(jfxy.reccnt==2)
	  {
	   xdx = jfxy.recs[1].Xval-jfxy.recs[0].Xval;
	   ydx =jfxy.recs[1].Yval-jfxy.recs[0].Yval;
	   k =ydx/xdx;
	   b =jfxy.recs[0].Yval-k*jfxy.recs[0].Xval;	   
	  }
	  else 
	  {
	    return dat;
	  }	  
      fy =k*dat+b;	  
	  return fy;	  
	}
function subsysicon(st){
    switch(st)
	{
    case 1: return "img/ico-elec.png";
    case 2: return "img/ico-elecsw.png";
    case 3: return "img/ico-ups.png";
    case 4: return "img/ico-batt.png";
    case 5: return "img/ico-envir.png";
    case 6: return "img/ico-leak.png";
    case 7: return "img/ico-airc.png";
    case 8: return "img/ico-cyber.png";
    case 9: return "img/ico-smoke.png";
    case 10: return "img/ico-infrared.png";
    }
    //return "img/ico-unknow-small.png";
   return "img/ico-infrared.png";
}
   list3(json);
    function list3(data){
        $.each(data.recs,function(i,n){
            $(".SID2317").html(jaidata.recs[0].SID);
            $(".Addr2317").html(0);
            $(".Port2317").html("AI"+(Val-ssid*256));
            $(".DateUpd2317").html(n.DateUpd);
            $(".State2317").html(window.parent.parseState(jaidata.recs[0].State));
              switch(Val-ssid*256)
			  {
				case 1: $(".ADC").html((calfy(n.D06)).toFixed(2));break;
				case 2: $(".ADC").html((calfy(n.D07)).toFixed(2));break;
				default:break;
			  } 
            $(".Unit").html(unit);			  
        });
		$("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
		$("span:contains('正常')").addClass("ger").removeClass("red");
    }
</script>
</body>
</html>