<?php
$gett = $_GET["q"];//获取数据
$selectTimeMin = $_GET['selectTimeMin'];
$selectTimeMax = $_GET['selectTimeMax'];
ini_set("precision", "4");  //浮点数小数位数
   class MyDB extends SQLite3
   {
      function __construct()
      {
         //$this->open('SL651.sqlite.db3');
		 $this->open('C:/Users/Administrator/Desktop/workFile/HlsPrj/河流_50888/DB/SL651.sqlite.db3');
      }
   }
   $con = new MyDB();
   if(!$con){
      echo $con->lastErrorMsg();
   } 
   
// 选择数据库
$sql="SELECT * FROM motorInfo WHERE dataTime > '$selectTimeMin' and dataTime < '$selectTimeMax' and devID = '".$gett."' ORDER by `dataTime`;";
$result = $con->query($sql);
//echo $sql;
if (!$result) {
    printf("Error: SELECT DB ERR\n");
	$con->close();
    exit();
}


echo "<table border='1'>
<tr>
<th>序号</th>
<th>采集时间</th>
<th>上报时间</th>
<th>设备ID</th>
<th>驱动器状态</th>
<th>指令状态</th>
<th>电机控制步骤</th>
<th>运行状态</th>
<th>当前告警</th>
<th>当前电压</th>
<th>当前电流</th>
<th>电机位置</th>
<th>电机推算位置</th>
<th>压力传感器位置</th>
<th>传感器目标位置</th>
<th>每层间隔距离</th>
<th>运动模式路径</th>
<th>位置H</th>
<th>位置L</th>
<th>电机运行速度</th>
<th>加速时间</th>
<th>减速时间</th>
<th>接近开关</th>
<th>Prx运行</th>
<th>告警解析</th>
</tr>";
//SELECT 操作
while($row = $result->fetchArray(SQLITE3_ASSOC) )
{
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['dataTime'] . "</td>";
    echo "<td>" . $row['reportTime'] . "</td>";
	echo "<td>" . $row['devID'] . "</td>";
	echo "<td>" . $row['iDevOnline'] . "</td>";
	echo "<td>" . $row['iDevCmdState'] . "</td>";
	echo "<td>" . $row['iMotorCtrStep'] . "</td>";
	echo "<td>" . $row['iDevState'] . "</td>";
	echo "<td>" . $row['iDevAlarm'] . "</td>";
	echo "<td>" . $row['iVol']/1000 . "</td>";
	echo "<td>" . $row['iCur'] . "</td>";
	echo "<td>" . $row['fPosition'] . "</td>";
	echo "<td>" . $row['i32MoterClcPosition'] . "</td>";
	echo "<td>" . $row['i32SensorPosition'] . "</td>";
	echo "<td>" . $row['iTargetPosition'] . "</td>";
	echo "<td>" . $row['iIntervalDis'] . "</td>";
	echo "<td>" . $row['iWordMode'] . "</td>";
	echo "<td>" . $row['iPositionH'] . "</td>";
	echo "<td>" . $row['iPositionL'] . "</td>";
	echo "<td>" . $row['iSpeed'] . "</td>";
	echo "<td>" . $row['iAccelerationTime'] . "</td>";
	echo "<td>" . $row['iDecelerationTime'] . "</td>";
	echo "<td>" . $row['iRes1'] . "</td>";
	echo "<td>" . $row['iPRx'] . "</td>";
	$DevAlarm = $row['iDevAlarm'];
	$DevAlarmStr = "";
	if($DevAlarm&1)
	{
		$DevAlarmStr = "Switch ";
	}
	if($DevAlarm&2)
	{
		$DevAlarmStr = $DevAlarmStr."OverCur ";
	}

	if($DevAlarm&4)
	{
		$DevAlarmStr = $DevAlarmStr."OverVol ";
	}

	if($DevAlarm&8)
	{
		$DevAlarmStr = $DevAlarmStr."LineNotMove ";
	}

	if($DevAlarm&16)
	{
		$DevAlarmStr = $DevAlarmStr."PosErr ";
	}

	if($DevAlarm&32)
	{
		$DevAlarmStr = $DevAlarmStr."StallErr ";
	}

	if($DevAlarm&64)
	{
		$DevAlarmStr = $DevAlarmStr."CurColErr ";
	}

	if($DevAlarm&128)
	{
		$DevAlarmStr = $DevAlarmStr."LockShaftErr ";
	}

	if($DevAlarm&256)
	{
		$DevAlarmStr = $DevAlarmStr."sensorOutline ";
	}

	if($DevAlarm&512)
	{
		$DevAlarmStr = $DevAlarmStr."motorOutline ";
	}

	if($DevAlarm&1024)
	{
		$DevAlarmStr = $DevAlarmStr."McuResetErr ";
	}

	echo "<td>" . $DevAlarmStr . "</td>";
    echo "</tr>";
}
echo "</table>";
$con->close();
 ?>