<?php
require("../../inc/lib.inc");

$DEBUG=0;
$db="OMC_PUB";
$sql = "SELECT detailStat,updateTime FROM sysStat WHERE sysTypeNo='311' AND sysNo='$subSysNo' AND subSysNo='0'"; 
//echo "$sql";
if($DEBUG)echo "<br>sql=$sql";
$res=mysqli_query($pubConn,$sql);
$row=@mysqli_fetch_array($res);
//echo mysqli_error($pubConn);

if(!$row)
{
	echo 2;
	echo "###";
	echo 2;
	exit();
}

$due_date	= date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-$heatbeat_overtime,date("m"),date("d"),date("Y")));

$ove_date	= date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")+$heatbeat_overtime,date("m"),date("d"),date("Y")));

$hex_mes=$row[detailStat];
$refresh_time=$row[updateTime];
//echo $heatbeat_overtime;
if(!($refresh_time > $due_date && $refresh_time < $ove_date))
{
	echo 0;
	echo "###";
	echo 0;
	exit();
}
$bin_mes='';
for($i=0;$i<strlen($hex_mes);$i++)
{
	$sig_hex_mes=substr($hex_mes,$i,1);
	$sig_dec_mes=HexDec($sig_hex_mes);
	$sig_bin_mes=DecBin($sig_dec_mes);
	$sig_bin_mes=omc_keep_length($sig_bin_mes,0,4);
	$bin_mes.=$sig_bin_mes;
}
if($DEBUG)echo "<br>bin_mes=$bin_mes";
$stt_e0		=	21; //E1 #0 status (bit 0: 0/1 not in used / in used; bit 1: 0/1 link not ok / link ok)
$stt_e1		=	22; //E1 #1 status
	
//E1#0 status (bit 0: 0/1 not in used / in used; bit 1: 0/1 link not ok / link ok)
for($i=0;$i<2;$i++){
	$binSttE0=substr($bin_mes,$stt_e0*8+7-$i,1);
	$sttE0[$i]=BinDec($binSttE0);
	if($DEBUG)echo "<br>sttE0[$i]=$sttE0[$i]";
}

if(!$sttE0[0]){
	$sttE0[1] = 2;
}

//E1#1 status
for($i=0;$i<2;$i++){
	$binSttE1=substr($bin_mes,$stt_e1*8+7-$i,1);
	$sttE1[$i]=BinDec($binSttE1);
	if($DEBUG)echo "<br>sttE1[$i]=$sttE1[$i]";
}

if(!$sttE1[0]){
	$sttE1[1] = 2;
}



echo $sttE0[1];
echo "###";
echo $sttE1[1];
?>
