Commit 3ed8b3eb authored by Andrey Filippov's avatar Andrey Filippov
Browse files

intermediate working versio with debug enabled

parent 5d1ca452
Loading
Loading
Loading
Loading
+43 −18
Original line number Original line Diff line number Diff line
@@ -18,12 +18,16 @@ var debug;// = 0;
var sequence_num;//  = 0;
var sequence_num;//  = 0;
var last_ffc;//  =     0;
var last_ffc;//  =     0;
var time_to_ffc;//  =  0;
var time_to_ffc;//  =  0;
var left_capture;
var capture_run;//  =  0;
var capture_run;//  =  0;
var capture_wait;// wait sequence end to stop
var capture_wait_was = 0;

var want_run;
var want_run;
var request_num = 0;
var request_num = 0;
var update_editable = true;
var update_editable = true;
var apply_pending = false;
var apply_pending = false;

console.log("self.location.host="+self.location.host);
function parse_response(resp){
function parse_response(resp){
  var result = "";
  var result = "";
  console.log("parse_response(), resp="+resp);
  console.log("parse_response(), resp="+resp);
@@ -58,7 +62,7 @@ function send_request(rq,callback){


function sendStatusRequest(){
function sendStatusRequest(){
    console.log("sendStatusRequest()");
    console.log("sendStatusRequest()");
    var url = "http://192.168.0.41/lwir16/lwir16.php?daemon=status";
    var url = "http://"+self.location.host+"/lwir16/lwir16.php?daemon=status";
    if (apply_pending) {
    if (apply_pending) {
        console.log("sendStatusRequest(), apply_pending");
        console.log("sendStatusRequest(), apply_pending");
        var mod_pars =   modParameters();
        var mod_pars =   modParameters();
@@ -74,7 +78,7 @@ function sendStatusRequest(){


function sendRestartRequest(){
function sendRestartRequest(){
    console.log("sendRestartRequest()");
    console.log("sendRestartRequest()");
    var url = "http://192.168.0.41/lwir16/lwir16.php?daemon=restart&cmd=STATUS";
    var url = "http://"+self.location.host+"/lwir16/lwir16.php?daemon=restart&cmd=STATUS";
    send_request(url,parseStatusResponse);
    send_request(url,parseStatusResponse);
}
}


@@ -145,12 +149,22 @@ function parseStatusResponse(resp){
  	document.getElementById("idtime_to_ffc").value = time_to_ffc;
  	document.getElementById("idtime_to_ffc").value = time_to_ffc;
  }
  }


  if (resp.getElementsByTagName("left_capture").length!=0){
	  left_capture = parseFloat(resp.getElementsByTagName("left_capture")[0].childNodes[0].nodeValue);
	  	document.getElementById("idleft_capture").value = left_capture;
  }
  
  if (resp.getElementsByTagName("capture_run").length!=0){
  if (resp.getElementsByTagName("capture_run").length!=0){
  	capture_run = parseInt(resp.getElementsByTagName("capture_run")[0].childNodes[0].nodeValue);
  	capture_run = parseInt(resp.getElementsByTagName("capture_run")[0].childNodes[0].nodeValue);
  	document.getElementById("idcapture_run").checked = capture_run > 0;
    if (resp.getElementsByTagName("capture_wait").length!=0){
  	if (update_editable) {
    	capture_wait_was = capture_wait;
        document.getElementById("idStartStop").innerHTML=capture_run?"Stop":"Start";
      	capture_wait = parseInt(resp.getElementsByTagName("capture_wait")[0].childNodes[0].nodeValue);
        document.getElementById("idStartStop").disabled = false;
    }  	
  	document.getElementById("idcapture_run").checked = (capture_run > 0) || (capture_wait > 0); // still waiting
//  	if (update_editable || (want_run != capture_run)) {
   	if (update_editable || (capture_wait_was && !capture_wait)) {
        document.getElementById("idStartStop").innerHTML=capture_run?"Stop":(capture_wait?"Waiting":"Start");
        document.getElementById("idStartStop").disabled = capture_wait; //false;
        want_run = capture_run;
        want_run = capture_run;
  	}
  	}
  }
  }
@@ -227,6 +241,13 @@ function clickedApply(){
    setPending();
    setPending();
}
}


function clickedAbort(){
    setPending();
    want_run=false;
    console.log("sendAbortRequest()");
    var url = "http://"+self.location.host+"/lwir16/lwir16.php?daemon=status&cmd=ABORT";
    send_request(url,parseStatusResponse);
}
</script>
</script>
  </head>
  </head>
  
  
@@ -236,6 +257,7 @@ function clickedApply(){
  
  
  <tr><td>
  <tr><td>
  <button id="idStartStop" name = "nStartStop" onclick="clickedRun()" disabled="true">???</button>
  <button id="idStartStop" name = "nStartStop" onclick="clickedRun()" disabled="true">???</button>
  <button id="idAbort" name = "nAbort" onclick="clickedAbort()">Abort</button>
  </td><td>
  </td><td>
    <button id="idApply" name = "nApply" onclick="clickedApply()"      disabled = "true">???</button>
    <button id="idApply" name = "nApply" onclick="clickedApply()"      disabled = "true">???</button>
</td><td>&nbsp;</td> <td>&nbsp;</td><td>&nbsp;</td>
</td><td>&nbsp;</td> <td>&nbsp;</td><td>&nbsp;</td>
@@ -249,26 +271,26 @@ function clickedApply(){


  <tr><td>Sequence length (@60Hz)</td><td>
  <tr><td>Sequence length (@60Hz)</td><td>
        <input id="idduration" name="nduration" size="10" maxlength="10" value="?" type="text">
        <input id="idduration" name="nduration" size="10" maxlength="10" value="?" type="text">
  </td><td>frames</td><td>Request count</td><td>
  </td><td>frames</td><td>Frames left</td><td>
       <input id="idrequest_num" name="nrequest_num" size="10" maxlength="10" value="?" type="text" disabled >
       <input id="idleft_capture" name="nleft_capture" size="10" maxlength="10" value="?" type="text" disabled >
  </td><td>&nbsp;</td></tr>
  </td><td>&nbsp;</td></tr>


  <tr><td>Sequence length (@10Hz)</td><td>
  <tr><td>Sequence length (@10Hz)</td><td>
        <input id="idduration_eo" name="nduration_eo" size="10" maxlength="10" value="?"  type="text">
        <input id="idduration_eo" name="nduration_eo" size="10" maxlength="10" value="?"  type="text">
  </td><td>frames</td><td>Capture run</td><td>
  </td><td>frames</td><td>Request count</td><td>
        <input id="idcapture_run" name="ncapture_run" type="checkbox" disabled>
       <input id="idrequest_num" name="nrequest_num" size="10" maxlength="10" value="?" type="text" disabled >
  </td><td>&nbsp;</td></tr>
  </td><td>&nbsp;</td></tr>
  
  
  <tr><td>FFC</td><td>
  <tr><td>FFC</td><td>
        <input id="idffc" name="nffc" type="checkbox">
        <input id="idffc" name="nffc" type="checkbox">
  </td><td>&nbsp;</td><td>Last FFC</td><td>
  </td><td>&nbsp;</td><td>Capture run</td><td>
       <input id="idlast_ffc" name="nlast_ffc" size="10" maxlength="10" value="?" type="text" disabled >
        <input id="idcapture_run" name="ncapture_run" type="checkbox" disabled>
  </td><td>sec</td></tr>
  </td><td>&nbsp;</td></tr>


  <tr><td>FFC period</td><td>
  <tr><td>FFC period</td><td>
        <input id="idffc_period" name="nffc_period" size="10" maxlength="10" value="?" type="text">
        <input id="idffc_period" name="nffc_period" size="10" maxlength="10" value="?" type="text">
  </td><td>sec</td><td>Time to FFC</td><td>
  </td><td>sec</td><td>Last FFC</td><td>
       <input id="idtime_to_ffc" name="ntime_to_ffc" size="10" maxlength="10" value="?" type="text" disabled >
       <input id="idlast_ffc" name="nlast_ffc" size="10" maxlength="10" value="?" type="text" disabled >
  </td><td>sec</td></tr>
  </td><td>sec</td></tr>


  <tr><td>FFC groups</td><td>
  <tr><td>FFC groups</td><td>
@@ -277,7 +299,10 @@ function clickedApply(){
        <option value="2">2</option>
        <option value="2">2</option>
        <option value="4" selected="selected">4</option>
        <option value="4" selected="selected">4</option>
        </select>
        </select>
  </td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  </td><td>&nbsp;</td>
  <td>Time to FFC</td><td>
       <input id="idtime_to_ffc" name="ntime_to_ffc" size="10" maxlength="10" value="?" type="text" disabled >
  </td><td>sec</td></tr>
  
  
  <tr><td>FFC frames</td><td>
  <tr><td>FFC frames</td><td>
        <input id="idffc_frames" name="nffc_frames" size="10" maxlength="10" value="?" type="text">
        <input id="idffc_frames" name="nffc_frames" size="10" maxlength="10" value="?" type="text">
+17 −11
Original line number Original line Diff line number Diff line
@@ -7,9 +7,13 @@ multicam_conf = "/etc/elphel393/multicamconf.xml"


ips =        "192.168.0.41,192.168.0.42,192.168.0.43,192.168.0.44,192.168.0.45"
ips =        "192.168.0.41,192.168.0.42,192.168.0.43,192.168.0.44,192.168.0.45"
port_masks=  "15,15,15,15,15"
port_masks=  "15,15,15,15,15"
duration =   100
#1 - run/stop, 2 - continuous, 0 do not use
pre_delay =  3.0
run_modes =  "1,1,1,1,2"
ffc_period = 30.0
lwir_fps =      59.98
eo_decimate_m1 = 5
duration =     500
pre_delay =      2.0
ffc_period =   180.0
ffc_groups =     2
ffc_groups =     2
ffc_frames =     8
ffc_frames =     8
ffc =            1
ffc =            1
@@ -18,6 +22,8 @@ tiff_mn = 0
tiff_mx =    65535
tiff_mx =    65535
tiff_bin_shift = 1
tiff_bin_shift = 1
tiff_auto =      0
tiff_auto =      0
frames_idle =   10
frames_wait =   20
debug =          1
debug =          1
output_log = /var/log/lwir16.log
output_log = /var/log/lwir16.log
 # no spaces around commas!
 # no spaces around commas!
+191 −65

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@ PHP_SCRIPTS=i2c.php \
            ccam.php \
            ccam.php \
            diag_utils.php \
            diag_utils.php \
            framepars.php \
            framepars.php \
            frame_to_ts.php \
            parsedit.php \
            parsedit.php \
            phpinfo.php \
            phpinfo.php \
            raw.php \
            raw.php \
+114 −33
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
*! -----------------------------------------------------------------------------**
*! -----------------------------------------------------------------------------**
*!
*!
*/
*/
   define('CAPTURE_RANGE_STATE',        '/var/state/capture_range.state');
   set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
   set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
   include 'show_source_include.php';
   include 'show_source_include.php';
   include "elphel_functions_include.php"; // includes curl functions
   include "elphel_functions_include.php"; // includes curl functions
@@ -41,6 +42,7 @@
       $port_mask =   $argv[2];
       $port_mask =   $argv[2];
       $frame =       $argv[3]; // absolute frame to start compressor
       $frame =       $argv[3]; // absolute frame to start compressor
       $duration =    $argv[4]; // number of frames to run compressor
       $duration =    $argv[4]; // number of frames to run compressor
       $notify =      $argv[5]; // double-quoted URL 
       
       
       if ($frame > 0){
       if ($frame > 0){
           $frame +=1; // seem there is a bug - actual compressed frames numbers (and last compressed frame number) are 1 less than expected
           $frame +=1; // seem there is a bug - actual compressed frames numbers (and last compressed frame number) are 1 less than expected
@@ -53,6 +55,9 @@
       elphel_capture_range($sensor_port, $port_mask, $frame, $duration);
       elphel_capture_range($sensor_port, $port_mask, $frame, $duration);
//       $f = fopen ( "/var/log/capture_range.log", 'a' );
//       $f = fopen ( "/var/log/capture_range.log", 'a' );
//       fwrite($f,"elphel_capture_range DONE\n");
//       fwrite($f,"elphel_capture_range DONE\n");
       if ($notify){ // complete url with http://
           file_get_contents($notify);
       }
//       fclose ( $f );
//       fclose ( $f );
       exit(0);
       exit(0);
   }
   }
@@ -64,6 +69,9 @@
   
   
   if (count($_GET) < 1) {
   if (count($_GET) < 1) {
       print ("CGI mode");
       print ("CGI mode");
       // Be carefull watching that USAGE is not indented (after auto-indenting). That leads to errors such as (at much later line number)!
       // Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE)
       // or number (T_NUM_STRING) in /www/pages/capture_range.php on line 143
       echo <<<USAGE
       echo <<<USAGE
<p>This script returns the timestamp for specified frame (frame=?) or expected frame number
<p>This script returns the timestamp for specified frame (frame=?) or expected frame number
  when the specified timestamp (timestamp = ?.?) will be reached. If none of the frame number
  when the specified timestamp (timestamp = ?.?) will be reached. If none of the frame number
@@ -78,6 +86,8 @@ USAGE;
    $timestamp = 0.0;
    $timestamp = 0.0;
    $PARS_FRAMES = 16;
    $PARS_FRAMES = 16;
    $minahead = 2;
    $minahead = 2;
    $notify_args=array();
    $notify_url="";
//    $port_mask = 15; // not set - same as ts2frame.php
//    $port_mask = 15; // not set - same as ts2frame.php
//    $duration =  1; // not set - end, set - start 
//    $duration =  1; // not set - end, set - start 
//    $wait = false;
//    $wait = false;
@@ -85,6 +95,8 @@ USAGE;
    foreach($_GET as $key=>$value) {
    foreach($_GET as $key=>$value) {
        if ($key == 'sensor_port'){
        if ($key == 'sensor_port'){
            $sensor_port = (integer) $value;
            $sensor_port = (integer) $value;
        } else if (($key == 'state')) {
            $read_state = 1; // all other parameters will not be used, maybe in the future - use multi request and combine responses?
        } else if (($key == 'a')  || ($key == 'ahead')){ // will overwrite timestamp with this value (in seconds) from now
        } else if (($key == 'a')  || ($key == 'ahead')){ // will overwrite timestamp with this value (in seconds) from now
            $ahead_now = (double) $value;
            $ahead_now = (double) $value;
        } else if (($key == 'ts')  || ($key == 'timestamp')){
        } else if (($key == 'ts')  || ($key == 'timestamp')){
@@ -109,8 +121,65 @@ USAGE;
            $extra = (integer) $value; // not used?
            $extra = (integer) $value; // not used?
        } else if (($key == 'ip') || ($key == 'ips')){ //  multicamera operation
        } else if (($key == 'ip') || ($key == 'ips')){ //  multicamera operation
            $ips = explode(',',$value);
            $ips = explode(',',$value);
        } else if (substr($key,0,7) == "notify_") {
            $nk = substr($key,7);
            if ($nk == 'cmd'){
                $notify_cmd=$value;
            } else if (substr($nk,0,3) == 'key') {
                $ni = intval(substr($nk,3));
                if (!isset($notify_args[$ni])) $notify_args[$ni]=array();
                $notify_args[$ni][0] = $value;
            } else if (substr($nk,0,3) == 'val') {
                $ni = intval(substr($nk,3));
                if (!isset($notify_args[$ni])) $notify_args[$ni]=array();
                $notify_args[$ni][1] = $value;
            }
        }
    }
    //capture_range.php?sensor_port=0&state&frame=20 # will respond and block if there are fewer than 20 frames
    if (isset($read_state)) { // if $frame >0 wait if less frames are left
        $xml = new SimpleXMLElement("<?xml version='1.0'  standalone='yes'?><capture_range/>");
        // does the state file exist?
        $this_frame = 0;
        $left =       0;
        if (file_exists(CAPTURE_RANGE_STATE)) {
           $ini =  parse_ini_file(CAPTURE_RANGE_STATE);
           $end_frame = intval($ini['end_frame']); 
           $this_frame=elphel_get_frame($sensor_port);
           $left = $end_frame - $this_frame;
           if (($frame > 0) && ($left > 0) && ($left < $frame)){
               elphel_wait_frame_abs($sensor_port, $end_frame); // wait and block client
           }
           }
           $this_frame=elphel_get_frame($sensor_port);
           $left = $end_frame - $this_frame;
        }
        }
        $xml->addChild ('frame',$this_frame);
        $xml->addChild ('end_frame',$end_frame);
        $xml->addChild ('left',$left);
        $rslt=$xml->asXML();
        header("Content-Type: text/xml");
        header("Content-Length: ".strlen($rslt)."\n");
        header("Pragma: no-cache\n");
        printf($rslt);
        exit(0);
    }
    if (isset($notify_cmd)){ 
        $wait = false;
        $notify_url='http://'.$notify_cmd; // $notify_cmd includes full url
        $i=0;
        foreach ($notify_args as $kv) {
            if (isset($kv[0])) {
                $notify_url .= ($i ? '&' : '?');
//                $notify_url .= ($i ? '&amp;' : '?');
                $notify_url .= $kv[0];
                if (isset($kv[1])) {
                    $notify_url .= '=' . $kv[1];
                }
                $i ++;
            }
        }
    }
    
    if (isset($ahead_now)){  
    if (isset($ahead_now)){  
        $this_frame=elphel_get_frame($sensor_port);
        $this_frame=elphel_get_frame($sensor_port);
        $this_timestamp=elphel_frame2ts($sensor_port,$this_frame);
        $this_timestamp=elphel_frame2ts($sensor_port,$this_frame);
@@ -190,20 +259,21 @@ USAGE;
    
    
    $xml = new SimpleXMLElement("<?xml version='1.0'  standalone='yes'?><capture_range/>");
    $xml = new SimpleXMLElement("<?xml version='1.0'  standalone='yes'?><capture_range/>");
        $flags = 0;
        $flags = 0;
    $use_daemon = ($frame != 0);
    if (isset($port_mask)) { // start or stop compressor
    if (isset($port_mask)) { // start or stop compressor
        $this_frame = elphel_get_frame($sensor_port);
        $this_frame = elphel_get_frame($sensor_port);
        if ($frame == 0){ // e.g. to stop ASAP
        if (! $use_daemon) { // e.g. to stop ASAP $frame=0, $duration !=0 - start ASAP
            if (isset($duration)) {
            if (isset($duration)) {
                elphel_compressor_run($sensor_port, 0, $flags, $port_mask); // turn on ASAP
                elphel_compressor_run($sensor_port, 0, $flags, $port_mask); // turn on ASAP
                $xml->addChild('compressor', 1);
                $xml->addChild('compressor', 1);
            } else {
            } else { // frame = 0; duration ==0 - stop ASAP
                elphel_compressor_stop($sensor_port, 0, $flags, $port_mask); // turn off ASAP
                elphel_compressor_stop($sensor_port, 0, $flags, $port_mask); // turn off ASAP
                $xml->addChild('compressor', 0);
                $xml->addChild('compressor', 0);
            }
            }
            $frame = $this_frame + $minahead;
            $frame = $this_frame + $minahead;
        }
        }
        $ahead = $frame - $this_frame;
        $ahead = $frame - $this_frame;
        if ($ahead < $minahead) {
        if ($use_daemon && ($ahead < $minahead)) {
            $xml->addChild('error', 'TOO LATE');
            $xml->addChild('error', 'TOO LATE');
            $xml->addChild('ahead', $ahead);
            $xml->addChild('ahead', $ahead);
        } else { // OK, enough time to program
        } else { // OK, enough time to program
@@ -216,16 +286,27 @@ USAGE;
            // $f = fopen ( "/var/log/capture_range.log", 'a' );
            // $f = fopen ( "/var/log/capture_range.log", 'a' );
            // fwrite($f,"exec(/www/pages/capture_range.php $sensor_port $port_mask $frame $duration > /dev/null 2>&1 &\n");
            // fwrite($f,"exec(/www/pages/capture_range.php $sensor_port $port_mask $frame $duration > /dev/null 2>&1 &\n");
            // fclose ( $f );
            // fclose ( $f );
            exec("/www/pages/capture_range.php $sensor_port $port_mask $frame $duration > /dev/null 2>&1 &");
            // if ($notify_url) {
            // $xml->addChild ('notify_url', $notify_url); // urlencode($notify_url)); // dry run, do nothing
            // } else {
            if ($use_daemon) {
                exec("/www/pages/capture_range.php $sensor_port $port_mask $frame $duration '$notify_url'> /dev/null 2>&1 &");
                // }
                // $f = fopen ( "/var/log/capture_range.log", 'a' );
                // $f = fopen ( "/var/log/capture_range.log", 'a' );
                // fwrite($f,"DONE exec\n");
                // fwrite($f,"DONE exec\n");
                // fclose ( $f );
                // fclose ( $f );
                if ($duration > 0) {
                if ($duration > 0) {
                    $frame += $duration; // xml will contain end frame
                    $frame += $duration; // xml will contain end frame
                }
                }
                file_put_contents(CAPTURE_RANGE_STATE, "end_frame = $frame\n");
                if ($wait) {
                if ($wait) {
                    elphel_wait_frame_abs($sensor_port, $frame + 1);
                    elphel_wait_frame_abs($sensor_port, $frame + 1);
                }
                }
            } else {
                if (file_exists(CAPTURE_RANGE_STATE)) {
                    unlink(CAPTURE_RANGE_STATE);
                }
            }
        }
        }
    } else { // just ts2frame.php mode
    } else { // just ts2frame.php mode
        if ($frame == 0) {
        if ($frame == 0) {