File "recv_accs.php"
Full path: /www/ansys/ttest/accmes/recv_accs.php
File size: 3.5 KiB (3585 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
// 自動でクラスを参照する
// 関数名 : __autoload()
// 備考 : 参照先は./class/XXX.phpとする
// 更新 : 2012/10/19 KMK-Teraoka
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
function __autoload($className)
{
$fPath = "./class/" . str_replace("_", "/", $className) . ".php";
require_once $fPath;
}
//===============================================
// DEBUG_MODE
// 備考 :
// 更新 : 2012/11/29 KMK-Teraoka
//===============================================
define("DEBUG_MODE", "1");
Debug::setMode(DEBUG_MODE);
if (DEBUG_MODE == 1)
{
Stopwatch::start();
}
//===============================================
// CommonUtilities
// 備考 :
// 更新 : 2012/11/29 KMK-Teraoka
//===============================================
$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$LOG_FILE = "./log/recv_positions.log";
try
{
$_log = new Log($LOG_FILE);
//===============================================
// POST、GETパラメータの受け取り
// 備考 :
// 更新 : 2012/11/29 KMK-Teraoka
//===============================================
if (DEBUG_MODE == 1)
{
extract($_POST);
extract($_GET);
Debug::writes($_POST);
}
$androidId = isset($_POST["android_id"]) ? htmlspecialchars($_POST["android_id"]) : "";
$gacc = isset($_POST["gacc"]) ? htmlspecialchars($_POST["gacc"]) : "";
$accs = isset($_POST["accs"]) ? htmlspecialchars($_POST["accs"]) : "";
$fname = isset($_POST["fname"]) ? htmlspecialchars($_POST["fname"]) : "";
$_log->write("ADNROID_ID->". $androidId. "\n");
$_log->write("GACC->". $gacc. "\n");
$_log->write("ACCS->". $accs. "\n");
$_log->write("FNAME->". $fname. "\n");
if (strcmp($androidId, "") == 0)
{
throw new Exception("管理IDが指定されていません");
}
//===============================================
// Positionsを項目毎に分割
// 備考 :
// 更新 : 2012/11/29 KMK-Teraoka
//===============================================
$accData = array();
$sepRow = explode("#", $accs);
$row = count($sepRow);
for($iCount = 0; $iCount < $row; $iCount++)
{
$sepColumn = explode(",", $sepRow[$iCount]);
$accData[$iCount]["x"] = floor($sepColumn[0] * 1000) / 1000;
$accData[$iCount]["y"] = floor($sepColumn[1] * 1000) / 1000;
$accData[$iCount]["z"] = floor($sepColumn[2] * 1000) / 1000;
//$accData[$iCount]["time"] = sprintf("%.3f", $sepColumn[3] / 1000.0);
$accData[$iCount]["time"] = $sepColumn[3];
}
Debug::writes($accData);
$dir = "./data/". $androidId;
if (!file_exists($dir))
{
mkdir($dir, 0777);
chmod($dir, 0777);
}
$fpath = $dir. "/". $fname;
$fp = fopen($fpath, "a");
if ($fp != null)
{
if (strcmp($gacc, "") != 0)
{
$sepGacc = explode(",", $gacc);
$gaccData["x"] = floor($sepGacc[0] * 1000) / 1000;
$gaccData["y"] = floor($sepGacc[1] * 1000) / 1000;
$gaccData["z"] = floor($sepGacc[2] * 1000) / 1000;
$gaccData["time"] = $sepGacc[3];
$buffer = "#". $gaccData["time"]. ",". $gaccData["x"]. ",". $gaccData["y"]. ",". $gaccData["z"]. "\r\n";
fputs($fp, $buffer);
}
for($iCount = 0; $iCount < $row; $iCount++)
{
//$msec = explode(".", $accData[$iCount]["time"]);
//$strTime = date("Y-m-d H:i:s", $accData[$iCount]["time"]). ".". $msec[1];
$buffer = "". $accData[$iCount]["time"]. ",". $accData[$iCount]["x"]. ",". $accData[$iCount]["y"]. ",". $accData[$iCount]["z"]. "\r\n";
fputs($fp, $buffer);
}
}
}
catch(Exception $exc)
{
$_log->write($exc->getMessage(). "\n");
}
?>