logger_launcher.php 3.49 KB
Newer Older
Andrey Filippov's avatar
Andrey Filippov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<?php
/*!***************************************************************************
*! FILE NAME  : logger_launcher.php
*! DESCRIPTION: launches the event logger (IMU/GPS/External trigger/Other sensor) a dies
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*!  $Log: logger_launcher.php,v $
*!  Revision 1.6  2013/05/29 18:43:01  dzhimiev
*!  1. sync instead of unmount at stop
*!
*!  Revision 1.4  2012/10/10 22:44:52  dzhimiev
*!  1. added _help & _usage
*!
*!  Revision 1.3  2012/07/09 23:49:26  dzhimiev
*!  1. added mount/umount options
*!
*!  Revision 1.2  2012/04/13 00:49:59  dzhimiev
*!  1. added 'starting index' to logger
*!
*!
*!  Revision 1.1  2012/04/13 00:22:51  dzhimiev
*!  1. added logger_launcher.php
*!
*!
*/

include 'show_source.inc';

//default parameters
$cmd = "start";
$file = "/usr/html/CF/imu_log.log";
$index = 1;
$n = 5000000;
$mount_point = "/usr/html/CF";
$force_dev = false;


$xml = "<Document>\n";

//get parameters
if (isset($_GET['cmd'])) $cmd = $_GET['cmd'];

if (isset($_GET['file'])) $file = $_GET['file'];
if (isset($_GET['index'])) $index = $_GET['index'];
if (isset($_GET['n'])) $n = $_GET['n'];
if (isset($_GET['mount_point'])) $mount_point = $_GET['mount_point'];

if (isset($_GET['dev'])) {
   $dev = $_GET['dev'];
   $force_dev = true;
}

if ($cmd=="start") {

    if (!is_dir($mount_point)) mkdir($mount_point);

    //detect devices
    //$dev = "/dev/hda1";

    if (!$force_dev) {
	$hda1 = exec("cat /proc/diskstats | grep 'hda1'");
	$hdb1 = exec("cat /proc/diskstats | grep 'hdb1'");

	if      (strlen($hda1)>0) $dev = "/dev/hda1";
	else if (strlen($hdb1)>0) $dev = "/dev/hdb1";
	else {
	  $xml .= "\t<error>CF cards not found</error>\n";
	  send_response($xml);
	}
    }

    exec("mount $dev $mount_point");
    exec("/usr/local/bin/log_imu $file $index $n >/dev/null 2>&1 &");
    $xml .= "\t<result>ok</result>\n";
}

if ($cmd=="stop") {

    exec("killall -1 log_imu");
    //unmount
    //exec("umount $mount_point");
    exec("sync");
    $xml .= "\t<result>ok</result>\n";
}


$xml .= "</Document>";

send_response($xml);

function send_response($xml){
    header("Content-Type: text/xml");
    header("Content-Length: ".strlen($xml)."\n");
    header("Pragma: no-cache\n");
    printf("%s", $xml);
    flush();
}

function _help(){
    echo "<pre>\n";
    echo "Usage example: 'http://192.168.0.9/logger_launcher.php?file=/usr/html/CF/test.log&index=1&n=1000000&dev=/dev/hdb1', where\n";
    echo "'file'- log name (includes absolute path), '/usr/html/CF/' is the 'dev's mount point\n";
    echo "'index'- index added to the log name\n";
    echo "'n'- max number of records in a single log file\n";
    echo "'dev'- device name: '/dev/hda1' or '/dev/hdb1'\n";
}

function _usage(){
    _help();
}

?>