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

intermediate working versio with debug enabled

parent 5d1ca452
...@@ -18,12 +18,16 @@ var debug;// = 0; ...@@ -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){ ...@@ -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(){ ...@@ -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);
} }
...@@ -144,13 +148,23 @@ function parseStatusResponse(resp){ ...@@ -144,13 +148,23 @@ function parseStatusResponse(resp){
time_to_ffc = parseFloat(resp.getElementsByTagName("time_to_ffc")[0].childNodes[0].nodeValue); time_to_ffc = parseFloat(resp.getElementsByTagName("time_to_ffc")[0].childNodes[0].nodeValue);
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(){ ...@@ -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(){ ...@@ -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(){ ...@@ -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,8 +299,11 @@ function clickedApply(){ ...@@ -277,8 +299,11 @@ 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">
</td><td>frames</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> </td><td>frames</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
......
...@@ -7,18 +7,24 @@ multicam_conf = "/etc/elphel393/multicamconf.xml" ...@@ -7,18 +7,24 @@ 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
ffc_groups = 2 eo_decimate_m1 = 5
ffc_frames = 8 duration = 500
ffc = 1 pre_delay = 2.0
tiff_telem = 1 ffc_period = 180.0
tiff_mn = 0 ffc_groups = 2
tiff_mx = 65535 ffc_frames = 8
ffc = 1
tiff_telem = 1
tiff_mn = 0
tiff_mx = 65535
tiff_bin_shift = 1 tiff_bin_shift = 1
tiff_auto = 0 tiff_auto = 0
debug = 1 frames_idle = 10
frames_wait = 20
debug = 1
output_log = /var/log/lwir16.log output_log = /var/log/lwir16.log
# no spaces around commas! # no spaces around commas!
CMD = INIT,START CMD = INIT,START
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*! FILE NAME : lwir.php *! FILE NAME : lwir.php
*! DESCRIPTION: Subcameras initialization and capturing of synchronized scene *! DESCRIPTION: Subcameras initialization and capturing of synchronized scene
* sequences * sequences
*! Copyright (C) 2021 Elphel, Inc *! Copyright (C) 2021-2023 Elphel, Inc
*! -----------------------------------------------------------------------------** *! -----------------------------------------------------------------------------**
*! *!
*! This program is free software: you can redistribute it and/or modify *! This program is free software: you can redistribute it and/or modify
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
define('CAM_PORT_SEP', '_'); // camera ip to port seperator define('CAM_PORT_SEP', '_'); // camera ip to port seperator
define('IPS', 'ips'); define('IPS', 'ips');
define('PORT_MASKS', 'port_masks'); define('PORT_MASKS', 'port_masks');
define('RUN_MODES', 'run_modes');
define('ALL_PORTS', 15); define('ALL_PORTS', 15);
define('IMGSRV_PORT0', 2323); define('IMGSRV_PORT0', 2323);
define('TIFF_TELEM', 'tiff_telem'); define('TIFF_TELEM', 'tiff_telem');
...@@ -55,31 +57,45 @@ ...@@ -55,31 +57,45 @@
define('FFC_PERIOD', 'ffc_period'); define('FFC_PERIOD', 'ffc_period');
define('FFC_GROUPS', 'ffc_groups'); define('FFC_GROUPS', 'ffc_groups');
define('FFC_FRAMES', 'ffc_frames'); define('FFC_FRAMES', 'ffc_frames');
define('FRAMES_IDLE', 'frames_idle'); // 10
define('FRAMES_WAIT', 'frames_wait'); // 20
define('LWIR_FPS', 'lwir_fps');
define('EO_DECIMATE_M1', 'eo_decimate_m1');
define('COMPRESSOR_RUN', 'compressor_run'); // after init define('COMPRESSOR_RUN', 'compressor_run'); // after init
define('I_AM_MASTER', 'i_am_naster');
define('DEBUG', 'debug'); define('DEBUG', 'debug');
define('DAEMON_RUN', 'daemon_run'); // not read through ini define('DAEMON_RUN', 'daemon_run'); // not read through ini
define('CAPTURE_RUN', 'capture_run'); // not read through ini define('CAPTURE_RUN', 'capture_run'); // not read through ini
define('CAPTURE_WAIT', 'capture_wait'); // wait notification from the camera that camture_run finished
define('LAST_FFC', 'last_ffc'); // not read through ini define('LAST_FFC', 'last_ffc'); // not read through ini
define('SECUENCE_NUM', 'sequence_num'); // not read through ini define('LEFT_CAPTURE', 'left_capture');
define('SEQUENCE_NUM', 'sequence_num'); // not read through ini
define('TIME_TO_FFC', 'time_to_ffc'); // not read through ini define('TIME_TO_FFC', 'time_to_ffc'); // not read through ini
define('DAEMON_CMD', 'CMD'); // command to be executed by a daemon define('DAEMON_CMD', 'CMD'); // command to be executed by a daemon
define('CMD_INIT', 'INIT'); // passed commands define('CMD_INIT', 'INIT'); // passed commands
define('CMD_START', 'START'); // passed commands define('CMD_START', 'START'); // passed commands
define('CMD_STOP', 'STOP'); // passed commands define('CMD_STOP', 'STOP'); // passed commands
define('CMD_ABORT', 'ABORT'); // STOP without waiting
define('CMD_CONTINUE', 'CONTINUE'); // notification from the camera (one ok?)
define('CMD_EXIT', 'EXIT'); // passed commands define('CMD_EXIT', 'EXIT'); // passed commands
define('CMD_STATUS', 'STATUS'); // passed commands define('CMD_STATUS', 'STATUS'); // passed commands
define('CMD_REBOOT', 'REBOOT'); // passed commands define('CMD_REBOOT', 'REBOOT'); // passed commands
define('CR_EXTRA', 2); // not currenly used - wait extra frames in capture_range define('CR_EXTRA', 2); // not currenly used - wait extra frames in THREADS_MODE > 0
// daemon control $_GET // daemon control $_GET
define('DAEMON_CTRL', 'daemon'); define('DAEMON_CTRL', 'daemon');
define('DAEMON_CTRL_CMDS', 'cmd'); //comma-separated commands to be sent to the daemon define('DAEMON_CTRL_CMDS', 'cmd'); //comma-separated commands to be sent to the daemon
define('OUTPUT_LOG', 'output_log'); // redirect daemon output define('OUTPUT_LOG', 'output_log'); // redirect daemon output
define('CAMERA_STATE', '/var/state/camera'); define('CAMERA_STATE', '/var/state/camera');
//07.03.2023
define('SCRIPT_CAPTURE_RANGE', 'capture_range.php');
// print_r($_GET); // magic // print_r($_GET); // magic
// exit(0); // magic // exit(0); // magic
// initializations before reading lwir16.ini // initializations before reading lwir16.ini
$GLOBALS[I_AM_MASTER] = 0; // later find it automatically
$GLOBALS[COMPRESSOR_RUN] = 0; $GLOBALS[COMPRESSOR_RUN] = 0;
$GLOBALS[DURATION] = 100; $GLOBALS[DURATION] = 100;
$GLOBALS[PRE_DELAY] = 5.0; // seconds $GLOBALS[PRE_DELAY] = 5.0; // seconds
...@@ -99,7 +115,15 @@ ...@@ -99,7 +115,15 @@
$ini = parse_ini_file(CONF_LWIR16); $ini = parse_ini_file(CONF_LWIR16);
applyConf($ini); applyConf($ini);
/*
echo '<pre>';
printf("--- ini: ---\n");
print_r($ini);
printf("--- GLOBALS: ---\n");
print_r($GLOBALS);
echo '</pre>';
exit (0);
*/
$ffc_wait_frames = 10; // extra wait after FFC finished (2xffc_frames) $ffc_wait_frames = 10; // extra wait after FFC finished (2xffc_frames)
$compressor_run = 0; // stop all $compressor_run = 0; // stop all
...@@ -117,6 +141,7 @@ ...@@ -117,6 +141,7 @@
unset($duration);unset($duration_eo); unset($duration);unset($duration_eo);
unset ($masks); unset ($masks);
unset ($run_modes);
foreach($_GET as $key=>$value) { foreach($_GET as $key=>$value) {
if (($key == 'ip') || ($key == 'ips')){ // multicamera operation if (($key == 'ip') || ($key == 'ips')){ // multicamera operation
$GLOBALS[IPS] = explode(',',$value); $GLOBALS[IPS] = explode(',',$value);
...@@ -124,6 +149,9 @@ ...@@ -124,6 +149,9 @@
} else if ($key == PORT_MASKS){ // } else if ($key == PORT_MASKS){ //
$masks = explode(',',$value); $masks = explode(',',$value);
unset ($GLOBALS[PORT_MASKS]); // invalidate unset ($GLOBALS[PORT_MASKS]); // invalidate
} else if ($key == RUN_MODES){ //
$run_modes = explode(',',$value);
unset ($GLOBALS[RUN_MODES]); // invalidate
} else if (($key == 'lwir16') || ($key == 'cmd')){ } else if (($key == 'lwir16') || ($key == 'cmd')){
$lswir16cmds = explode(',',$value); $lswir16cmds = explode(',',$value);
} else if ($key == 'pre_delay'){ } else if ($key == 'pre_delay'){
...@@ -162,6 +190,13 @@ ...@@ -162,6 +190,13 @@
$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]] = ALL_PORTS; $GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]] = ALL_PORTS;
// print ('<pre>'.$i."->".$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]."\n</pre>"); // print ('<pre>'.$i."->".$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]."\n</pre>");
} }
if (isset($run_modes) && (count($run_modes) > $i)){
$GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] = (int) ($run_modes[$i]);
} else {
$GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] = 0;
// print ('<pre>'.$i."->".$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]."\n</pre>");
}
} }
} }
// print_r($lswir16cmds); // print_r($lswir16cmds);
...@@ -235,7 +270,7 @@ ...@@ -235,7 +270,7 @@
printf($rslt); printf($rslt);
exit(0); exit(0);
} else if ($cmd == 'capture'){ } else if ($cmd == 'capture'){
$results = runCapture($GLOBALS[FFC], $nowait); // runCapture($run_ffc, $nowait = 0, $debug=0) $results = runCapture($GLOBALS[FFC], $nowait); // runCapture($run_ffc, $nowait = 0, $debug=0) // single-run?
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>"); $xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>");
$xml->addChild ('ffc', $GLOBALS[FFC]); $xml->addChild ('ffc', $GLOBALS[FFC]);
$xml->addChild (FFC_GROUPS,$GLOBALS[FFC_GROUPS]); $xml->addChild (FFC_GROUPS,$GLOBALS[FFC_GROUPS]);
...@@ -342,20 +377,23 @@ ...@@ -342,20 +377,23 @@
} }
} }
} else { // Just output usage? } else { // Just output usage?
echo <<<EOT // Be carefull watching that EOT; is not indented (after auto-indenting). That leads to errors such as (at much later line number)!
<pre> // Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE)
This script supports initialization of the LWIR16 camera (16 LWIR 640x512 sensors and 4 2592x1936 color ones) // or number (T_NUM_STRING) in /www/pages/capture_range.php on line 143
and capturing of short image sequences (100 frames fit into 64MB per-channel image buffer) for (relatively) echo <<<EOT
slow recording with camogm. Untill videocompression for 16-bit TIFFs is not implemented, recording is not fast <pre>
enough for continupous recording. This script should be launched in the 'master' subcamera only, it will This script supports initialization of the LWIR16 camera (16 LWIR 640x512 sensors and 4 2592x1936 color ones)
communidate with the other ones. and capturing of short image sequences (100 frames fit into 64MB per-channel image buffer) for (relatively)
slow recording with camogm. Untill videocompression for 16-bit TIFFs is not implemented, recording is not fast
URL parameters: enough for continupous recording. This script should be launched in the 'master' subcamera only, it will
<b>lwir16=init</b> - syncronize all 5 cameras, set acquisition parameters communidate with the other ones.
<b>lwir16=capture</b> - wait specified time, synchronously turn on compressors in each channel of each subcamera,
acquire specified number of frames in each channel (reduced, and turn compressors off. URL parameters:
<b>lwir16=init</b> - syncronize all 5 cameras, set acquisition parameters
</pre> <b>lwir16=capture</b> - wait specified time, synchronously turn on compressors in each channel of each subcamera,
acquire specified number of frames in each channel (reduced, and turn compressors off.
</pre>
EOT; EOT;
// Watch EOT w/o any spaces! // Watch EOT w/o any spaces!
} }
...@@ -415,16 +453,18 @@ EOT; ...@@ -415,16 +453,18 @@ EOT;
} }
// print_r($urls); print("<br/>"); // print_r($urls); print("<br/>");
// exit(0); // exit(0);
$trig_period = 100000000/$GLOBALS[LWIR_FPS];
for ($i = 0; $i < count($lwir_ips); $i ++) { for ($i = 0; $i < count($lwir_ips); $i ++) {
$urls[$i] .= '&TRIG_DELAY=' . $lwir_trig_dly . '&*TRIG_DELAY=15' . // apply to all ports $urls[$i] .= '&TRIG_DELAY=' . $lwir_trig_dly . '&*TRIG_DELAY=15' . // apply to all ports
'&BITS=16&*BITS=15' . '&COLOR=' . $COLOR_RAW . '&*COLOR=15' . '&WOI_HEIGHT=' . ($LWIR_HEIGHT + ($LWIR_TELEMETRY ? $LWIR_TELEMETRY_LINES : 0)) . '&*WOI_HEIGHT=15' . '&' . $REG_FFC_FRAMES . '=' . $FFC_FRAMES . '&*' . $REG_FFC_FRAMES . '=15'; // apply to all channels '&TRIG_PERIOD=' . $trig_period . '&*TRIG_PERIOD=15' .
'&BITS=16&*BITS=15' . '&COLOR=' . $COLOR_RAW . '&*COLOR=15' . '&WOI_HEIGHT=' . ($LWIR_HEIGHT + ($LWIR_TELEMETRY ? $LWIR_TELEMETRY_LINES : 0)) . '&*WOI_HEIGHT=15' . '&' . $REG_FFC_FRAMES . '=' . $FFC_FRAMES . '&*' . $REG_FFC_FRAMES . '=15'; // apply to all channels
$urls[$i] .= '&COMPRESSOR_RUN=2&*COMPRESSOR_RUN=15'; $urls[$i] .= '&COMPRESSOR_RUN=2&*COMPRESSOR_RUN=15';
} }
if ($debug) { if ($debug) {
print_r($GLOBALS[IPS]); print_r($GLOBALS[IPS]);
print_r($urls); print_r($urls);
} }
for ($chn = 0; $chn < 4; $chn ++) { for ($chn = 0; $chn < 4; $chn ++) { // last IP
$urls[count($GLOBALS[IPS]) - 1 + $chn] .= $urls[count($GLOBALS[IPS]) - 1 + $chn] .=
"&COLOR=" . $COLOR_JP4 . "&COLOR=" . $COLOR_JP4 .
"&QUALITY=" . $eo_quality . "&QUALITY=" . $eo_quality .
...@@ -442,6 +482,7 @@ EOT; ...@@ -442,6 +482,7 @@ EOT;
} }
if ($chn == 0) { if ($chn == 0) {
$urls[count($GLOBALS[IPS]) - 1] .= '&COMPRESSOR_RUN=2&*COMPRESSOR_RUN=15'; $urls[count($GLOBALS[IPS]) - 1] .= '&COMPRESSOR_RUN=2&*COMPRESSOR_RUN=15';
$urls[count($GLOBALS[IPS]) - 1] .= '&TRIG_DECIMATE='.$GLOBALS[EO_DECIMATE_M1] .'&*TRIG_DECIMATE=15';
} }
} }
if ($debug) { if ($debug) {
...@@ -533,26 +574,34 @@ EOT; ...@@ -533,26 +574,34 @@ EOT;
if ($run_ffc){ // may move after measuring time, but need to make sure it will be not too late if ($run_ffc){ // may move after measuring time, but need to make sure it will be not too late
runFFC($lwir_ips, $ffc_wait_frames, $debug); runFFC($lwir_ips, $ffc_wait_frames, $debug);
} }
if ($GLOBALS[I_AM_MASTER]) {
$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); // uses P_TRIG_PERIOD, so it should be master or set correctly
$timestamp = $this_timestamp + $GLOBALS[PRE_DELAY]; // this will be a delay between capture sequences $timestamp = $this_timestamp + $GLOBALS[PRE_DELAY]; // this will be a delay between capture sequences (default - 3s)
}
// $timestamp = $this_timestamp + $GLOBALS[PRE_DELAY]; // this will be a delay between capture sequences (default - 3s)
$urls = array(); $urls = array();
for ($i = 0; $i<count($GLOBALS[IPS]); $i++){ for ($i = 0; $i<count($GLOBALS[IPS]); $i++){
// $_SERVER[SCRIPT_NAME] STARTS WITH '/' // $_SERVER[SCRIPT_NAME] STARTS WITH '/'
$url = 'http://'.$GLOBALS[IPS][$i].'/capture_range.php?sensor_port='.$sensor_port; // $url = 'http://'.$GLOBALS[IPS][$i].'/'.SCRIPT_CAPTURE_RANGE.'?sensor_port='.$sensor_port; //
$url .= '&ts='.$timestamp; // &timestamp" -> ×tamp if ($GLOBALS[I_AM_MASTER]) {
$url .= '&ts='.$timestamp; // &timestamp" -> ×tamp
} else {
$url .= '&a='.$GLOBALS[PRE_DELAY]; // &timestamp" -> ×tamp
}
// $url .= '&port_mask=15'; // .$port_mask[$i]; // $url .= '&port_mask=15'; // .$port_mask[$i];
$url .= '&port_mask='.$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]; //indexed by IPs $url .= '&port_mask='.$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]; //indexed by IPs
$dur = ($i < 4) ? $GLOBALS[DURATION] : $GLOBALS[DURATION_EO]; $dur = ($i < 4) ? $GLOBALS[DURATION] : $GLOBALS[DURATION_EO]; // maybe turn on EO forever
$url .= '&duration='. $dur; $url .= '&duration='. $dur;
// $url .= '&maxahead='. $maxahead; // $url .= '&maxahead='. $maxahead;
// $url .= '&minahead='. $minahead; // $url .= '&minahead='. $minahead;
$url .= '&extra='. CR_EXTRA; // $extra; $url .= '&extra='. CR_EXTRA; // $extra;
if ($wait && ($i == (count($GLOBALS[IPS]) - 1))){ // addd to the last ip in a list //
/* disabling $wait
if ($wait && ($i == (count($GLOBALS[IPS]) - 1))){ // addd to the last ip in a list maybe to the first?
$url .= '&wait'; $url .= '&wait';
} }
*/
$urls[] = $url; $urls[] = $url;
} }
if ($debug) { if ($debug) {
...@@ -653,7 +702,7 @@ EOT; ...@@ -653,7 +702,7 @@ EOT;
return curl_multi_finish($curl_data, true, 0, $enable_echo); // Switch true -> false if errors are reported (other output damaged XML) return curl_multi_finish($curl_data, true, 0, $enable_echo); // Switch true -> false if errors are reported (other output damaged XML)
} }
function lwir16_daemon() { function lwir16_daemon() { // Gets here when callled from OS
// ini parameters are already read in // ini parameters are already read in
declare(ticks = 1); declare(ticks = 1);
set_time_limit(0); // no limit - run forever set_time_limit(0); // no limit - run forever
...@@ -663,14 +712,18 @@ EOT; ...@@ -663,14 +712,18 @@ EOT;
if(file_exists(PIPE_CMD)){ if(file_exists(PIPE_CMD)){
unlink(PIPE_CMD); //delete pipe if it was already there - waiting prevents signal handling! unlink(PIPE_CMD); //delete pipe if it was already there - waiting prevents signal handling!
} }
$GLOBALS[DAEMON_RUN] = 1; $url_wait_capture;
$GLOBALS[CAPTURE_RUN] = 0; // until command $GLOBALS[DAEMON_RUN] = 1;
$GLOBALS[CAPTURE_RUN] = 0; // until command
$GLOBALS[CAPTURE_WAIT] = 0;
$GLOBALS[LAST_FFC] = 0; // overdue $GLOBALS[LAST_FFC] = 0; // overdue
$GLOBALS[SECUENCE_NUM] = 0; $GLOBALS[SEQUENCE_NUM] = 0;
if ($GLOBALS[DEBUG] > 1) { // was if ($GLOBALS[DEBUG > 1]) { if ($GLOBALS[DEBUG] > 1) { // was if ($GLOBALS[DEBUG > 1]) {
printf("--- GLOBALS: ---\n"); printf("--- GLOBALS: ---\n");
print_r($GLOBALS); print_r($GLOBALS);
} }
$left_frames = 0;
$abort_sequence=0;
// exit(0); // exit(0);
$from_pipe = false; // first commands are form INI $from_pipe = false; // first commands are form INI
while ($GLOBALS[DAEMON_RUN]){ while ($GLOBALS[DAEMON_RUN]){
...@@ -692,8 +745,17 @@ EOT; ...@@ -692,8 +745,17 @@ EOT;
} }
} else if ($cmd == CMD_START){ } else if ($cmd == CMD_START){
$GLOBALS[CAPTURE_RUN] = 1; $GLOBALS[CAPTURE_RUN] = 1;
$GLOBALS[CAPTURE_WAIT] = 0;
$left_frames = 0;
} else if ($cmd == CMD_STOP){ } else if ($cmd == CMD_STOP){
$GLOBALS[CAPTURE_RUN] = 0; $GLOBALS[CAPTURE_RUN] = 0; // should continue waiting
$abort_sequence = 0;
} else if ($cmd == CMD_ABORT){
$GLOBALS[CAPTURE_RUN] = 0; // should continue waiting
$abort_sequence = 1;
} else if ($cmd == CMD_CONTINUE){
$GLOBALS[CAPTURE_WAIT] = 0;
$left_frames = 0;
} else if ($from_pipe && ($cmd == CMD_STATUS)){ // generate status data and send over response pipe } else if ($from_pipe && ($cmd == CMD_STATUS)){ // generate status data and send over response pipe
$state = file('/var/state/camera'); $state = file('/var/state/camera');
//TODO: add daemon status itself //TODO: add daemon status itself
...@@ -706,7 +768,7 @@ EOT; ...@@ -706,7 +768,7 @@ EOT;
} }
} }
$GLOBALS[TIME_TO_FFC] = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD] - time(); $GLOBALS[TIME_TO_FFC] = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD] - time();
$xml->addChild (SECUENCE_NUM, $GLOBALS[SECUENCE_NUM]); $xml->addChild (SEQUENCE_NUM, $GLOBALS[SEQUENCE_NUM]);
$xml->addChild (TIME_TO_FFC, $GLOBALS[TIME_TO_FFC]); $xml->addChild (TIME_TO_FFC, $GLOBALS[TIME_TO_FFC]);
$xml->addChild (IPS, implode(',',$GLOBALS[IPS])); $xml->addChild (IPS, implode(',',$GLOBALS[IPS]));
$xml->addChild (DURATION, $GLOBALS[DURATION]); $xml->addChild (DURATION, $GLOBALS[DURATION]);
...@@ -716,11 +778,19 @@ EOT; ...@@ -716,11 +778,19 @@ EOT;
$xml->addChild (FFC_PERIOD, $GLOBALS[FFC_PERIOD]); $xml->addChild (FFC_PERIOD, $GLOBALS[FFC_PERIOD]);
$xml->addChild (FFC_GROUPS, $GLOBALS[FFC_GROUPS]); $xml->addChild (FFC_GROUPS, $GLOBALS[FFC_GROUPS]);
$xml->addChild (FFC_FRAMES, $GLOBALS[FFC_FRAMES]); $xml->addChild (FFC_FRAMES, $GLOBALS[FFC_FRAMES]);
$xml->addChild (FRAMES_IDLE, $GLOBALS[FRAMES_IDLE]);
$xml->addChild (FRAMES_WAIT, $GLOBALS[FRAMES_WAIT]);
$xml->addChild (LWIR_FPS, $GLOBALS[LWIR_FPS]);
$xml->addChild (EO_DECIMATE_M1, $GLOBALS[EO_DECIMATE_M1]);
$xml->addChild (RUN_MODES, implode(',',$GLOBALS[RUN_MODES]));
$xml->addChild (COMPRESSOR_RUN, $GLOBALS[COMPRESSOR_RUN]); $xml->addChild (COMPRESSOR_RUN, $GLOBALS[COMPRESSOR_RUN]);
$xml->addChild (DEBUG, $GLOBALS[DEBUG]); $xml->addChild (DEBUG, $GLOBALS[DEBUG]);
$xml->addChild (DAEMON_RUN, $GLOBALS[DAEMON_RUN]); $xml->addChild (DAEMON_RUN, $GLOBALS[DAEMON_RUN]);
$xml->addChild (CAPTURE_RUN, $GLOBALS[CAPTURE_RUN]); $xml->addChild (CAPTURE_RUN, $GLOBALS[CAPTURE_RUN]);
$xml->addChild (CAPTURE_WAIT, $GLOBALS[CAPTURE_WAIT]);
$xml->addChild (LAST_FFC, $GLOBALS[LAST_FFC]); $xml->addChild (LAST_FFC, $GLOBALS[LAST_FFC]);
$xml->addChild (LEFT_CAPTURE, $left_frames);
$rslt=$xml->asXML(); $rslt=$xml->asXML();
if(!file_exists(PIPE_RESPONSE)) { if(!file_exists(PIPE_RESPONSE)) {
// create the pipe // create the pipe
...@@ -743,7 +813,7 @@ EOT; ...@@ -743,7 +813,7 @@ EOT;
exit(0); exit(0);
} }
} }
continue; // try read new commands befor capturing continue; // try read new commands before capturing
} }
// Read / execute commands // Read / execute commands
if(file_exists(PIPE_CMD)) { if(file_exists(PIPE_CMD)) {
...@@ -778,7 +848,52 @@ EOT; ...@@ -778,7 +848,52 @@ EOT;
if ($GLOBALS[DEBUG] > 1){ if ($GLOBALS[DEBUG] > 1){
printf("--- capture_run: ---%d \n",$GLOBALS[CAPTURE_RUN]); printf("--- capture_run: ---%d \n",$GLOBALS[CAPTURE_RUN]);
} }
if ($GLOBALS[CAPTURE_RUN]){ if ($GLOBALS[CAPTURE_WAIT]){// need to wait previous capture is over, even if $GLOBALS[CAPTURE_RUN] is false after stop
// make a faster stop with sending all cameras capture_range 'stop' command
// or maybe monitor one of the cameras until done?
// $skip = 1; // OK if more
// $rslt = skipFrames($ips0,$skip);
$url = 'http://'.$GLOBALS[IPS][0].'/'.SCRIPT_CAPTURE_RANGE.'?sensor_port=0&state&frame='.$GLOBALS[FRAMES_WAIT]; //
$resp = file_get_contents($url);
$spos = strpos($resp, '<left>')+strlen('<left>');
$epos = strpos($resp, '</left>', $spos);
$left_frames = intval(substr($resp,$spos,$epos-$spos));
if ($GLOBALS[DEBUG] > 0){
printf("--- capture_wait: --- url: %s, left=%d, abort_sequence=%d \n",$url, $left_frames, $abort_sequence);
}
if ($left_frames < 0) $left_frames = 0;
if ($left_frames <=0 ){
$GLOBALS[CAPTURE_WAIT] = 0;
}
if ($abort_sequence && $GLOBALS[CAPTURE_WAIT]) { // still not stopped
$urls = array();
for ($i = 0; $i<count($GLOBALS[IPS]); $i++){
// $_SERVER[SCRIPT_NAME] STARTS WITH '/'
$url = 'http://'.$GLOBALS[IPS][$i].'/'.SCRIPT_CAPTURE_RANGE.'?sensor_port='.$sensor_port; //
$url .= '&port_mask='.$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]; //indexed by IPs
$url .= '&frame=0&duration=0'; // immediately stop compressors, do not use daemon
$urls[] = $url;
}
if ($GLOBALS[DEBUG] > 0){
printf("--- aborting runCapture: URLs:\n");
print_r($urls);
}
$curl_data = curl_multi_start ($urls);
$enable_echo = false;
$results = curl_multi_finish($curl_data, true, 0, $enable_echo); // Switch true -> false if errors are reported (other output damaged XML)
if ($GLOBALS[DEBUG] > 0){
printf("--- capture_run: ---\n");
print_r($result);
}
}
if ($left_frames > 0) {
// skip some frames as there is nothing to do
$rslt = skipFrames(array($GLOBALS[IPS][0]),$GLOBALS[FRAMES_IDLE]);// just master camera IP
}
} else if ($GLOBALS[CAPTURE_RUN]){ // run next cycle
$ffc_due = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD]; $ffc_due = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD];
$run_ffc = false; $run_ffc = false;
$now = time(); $now = time();
...@@ -786,20 +901,18 @@ EOT; ...@@ -786,20 +901,18 @@ EOT;
$run_ffc = true; $run_ffc = true;
$GLOBALS[LAST_FFC] = $now; $GLOBALS[LAST_FFC] = $now;
} }
// $result = runCapture($run_ffc, false, $GLOBALS[$GLOBALS[DEBUG]]);
$result = runCapture($run_ffc, false, $GLOBALS[DEBUG]); $result = runCapture($run_ffc, false, $GLOBALS[DEBUG]);
$GLOBALS[SECUENCE_NUM]++; $GLOBALS[SEQUENCE_NUM]++;
if ($GLOBALS[DEBUG] > 1){ if ($GLOBALS[DEBUG] > 0){
printf("--- capture_run: ---\n"); printf("--- capture_run: ---\n");
print_r($result); print_r($result);
} }
$GLOBALS[CAPTURE_WAIT] = 1;
} else { } else {
// jusrt skip a frame // skip some frames as there is nothing to do
$ips0 = array($GLOBALS[IPS][0]); // just master camera IP $rslt = skipFrames(array($GLOBALS[IPS][0]),$GLOBALS[FRAMES_IDLE]);// just master camera IP
$skip = 10; // OK if more
$rslt = skipFrames($ips0,$skip);
} }
} }
if ($GLOBALS[DEBUG]){ if ($GLOBALS[DEBUG]){
printf("--- Exiting ...\n"); printf("--- Exiting ...\n");
...@@ -809,7 +922,7 @@ EOT; ...@@ -809,7 +922,7 @@ EOT;
} }
} }
function signal_handler($signal) { function signal_handler($signal) { // to control daemon
switch($signal) { switch($signal) {
case SIGTERM: case SIGTERM:
print "Caught SIGTERM\n"; print "Caught SIGTERM\n";
...@@ -833,35 +946,48 @@ EOT; ...@@ -833,35 +946,48 @@ EOT;
if (isset ($arr[PORT_MASKS])){ if (isset ($arr[PORT_MASKS])){
$masks = explode(',',$arr[PORT_MASKS]); $masks = explode(',',$arr[PORT_MASKS]);
} }
// Add port masks incdexed by IPs. Changing IPs resets masks if (isset ($arr[RUN_MODES])){
$run_modes = explode(',',$arr[RUN_MODES]);
}
// Add port masks indexed by IPs. Changing IPs resets masks
$GLOBALS[PORT_MASKS] = array(); $GLOBALS[PORT_MASKS] = array();
$GLOBALS[RUN_MODES] = array();
for ($i = 0; $i < count($GLOBALS[IPS]); $i++){ for ($i = 0; $i < count($GLOBALS[IPS]); $i++){
if (isset($masks) && (count($masks) > $i)){ if (isset($masks) && (count($masks) > $i)){
$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]] = (int) $masks[$i]; $GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]] = (int) $masks[$i];
} else { } else {
$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]] = ALL_PORTS; $GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]] = ALL_PORTS;
} }
if (isset($run_modes) && (count($run_modes) > $i)){
$GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] = (int) $run_modes[$i];
} else {
$GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] = 0;
}
} }
} }
if (isset($arr[DURATION])){ if (isset($arr[DURATION])){
$GLOBALS[DURATION] = (int) $arr[DURATION]; $GLOBALS[DURATION] = (int) $arr[DURATION];
$GLOBALS[DURATION_EO] = (int) ($GLOBALS[DURATION]/EO_DECIMATE+1); $GLOBALS[DURATION_EO] = (int) ($GLOBALS[DURATION]/EO_DECIMATE+1);
} }
if (isset($arr[DURATION_EO])) $GLOBALS[DURATION_EO] = (int) $arr[DURATION_EO]; if (isset($arr[DURATION_EO])) $GLOBALS[DURATION_EO] = (int) $arr[DURATION_EO];
if (isset($arr[PRE_DELAY])) $GLOBALS[PRE_DELAY] = (double) $arr[PRE_DELAY]; if (isset($arr[PRE_DELAY])) $GLOBALS[PRE_DELAY] = (double) $arr[PRE_DELAY];
if (isset($arr[FFC_PERIOD])) $GLOBALS[FFC_PERIOD] = (double) $arr[FFC_PERIOD]; if (isset($arr[FFC_PERIOD])) $GLOBALS[FFC_PERIOD] = (double) $arr[FFC_PERIOD];
if (isset($arr[FFC_GROUPS])) $GLOBALS[FFC_GROUPS] = (int) $arr[FFC_GROUPS]; if (isset($arr[FFC_GROUPS])) $GLOBALS[FFC_GROUPS] = (int) $arr[FFC_GROUPS];
if (isset($arr[FFC_FRAMES])) $GLOBALS[FFC_FRAMES] = (int) $arr[FFC_FRAMES]; if (isset($arr[FFC_FRAMES])) $GLOBALS[FFC_FRAMES] = (int) $arr[FFC_FRAMES];
if (isset($arr[DAEMON_CMD])) $GLOBALS[DAEMON_CMD] = $arr[DAEMON_CMD]; if (isset($arr[DAEMON_CMD])) $GLOBALS[DAEMON_CMD] = $arr[DAEMON_CMD];
if (isset($arr[DEBUG])) $GLOBALS[DEBUG] = (int) $arr[DEBUG]; if (isset($arr[DEBUG])) $GLOBALS[DEBUG] = (int) $arr[DEBUG];
if (isset($arr[COMPRESSOR_RUN])) $GLOBALS[COMPRESSOR_RUN] = (int) $arr[COMPRESSOR_RUN]; // only after INIT if (isset($arr[COMPRESSOR_RUN])) $GLOBALS[COMPRESSOR_RUN] = (int) $arr[COMPRESSOR_RUN]; // only after INIT
if (isset($arr[FFC])) $GLOBALS[FFC] = $arr[FFC]?1:0; if (isset($arr[FFC])) $GLOBALS[FFC] = $arr[FFC]?1:0;
if (isset($arr[TIFF_TELEM])) $GLOBALS[TIFF_TELEM] = (int) $arr[TIFF_TELEM]; if (isset($arr[TIFF_TELEM])) $GLOBALS[TIFF_TELEM] = (int) $arr[TIFF_TELEM];
if (isset($arr[TIFF_MN])) $GLOBALS[TIFF_MN] = (int) $arr[TIFF_MN]; if (isset($arr[TIFF_MN])) $GLOBALS[TIFF_MN] = (int) $arr[TIFF_MN];
if (isset($arr[TIFF_MX])) $GLOBALS[TIFF_MX] = (int) $arr[TIFF_MX]; if (isset($arr[TIFF_MX])) $GLOBALS[TIFF_MX] = (int) $arr[TIFF_MX];
if (isset($arr[TIFF_BIN_SHIFT])) $GLOBALS[TIFF_BIN_SHIFT] = (int) $arr[TIFF_BIN_SHIFT]; if (isset($arr[TIFF_BIN_SHIFT])) $GLOBALS[TIFF_BIN_SHIFT] = (int) $arr[TIFF_BIN_SHIFT];
if (isset($arr[TIFF_AUTO])) $GLOBALS[TIFF_AUTO] = (int) $arr[TIFF_AUTO]; if (isset($arr[TIFF_AUTO])) $GLOBALS[TIFF_AUTO] = (int) $arr[TIFF_AUTO];
if (isset($arr[OUTPUT_LOG])) $GLOBALS[OUTPUT_LOG] = $arr[OUTPUT_LOG]; if (isset($arr[OUTPUT_LOG])) $GLOBALS[OUTPUT_LOG] = $arr[OUTPUT_LOG];
if (isset($arr[FRAMES_IDLE])) $GLOBALS[FRAMES_IDLE] = (int) $arr[FRAMES_IDLE];
if (isset($arr[FRAMES_WAIT])) $GLOBALS[FRAMES_WAIT] = (int) $arr[FRAMES_WAIT];
if (isset($arr[LWIR_FPS])) $GLOBALS[LWIR_FPS] = (double) $arr[LWIR_FPS];
if (isset($arr[EO_DECIMATE_M1])) $GLOBALS[EO_DECIMATE_M1] = (int) $arr[EO_DECIMATE_M1];
} }
/** /**
......
...@@ -16,6 +16,7 @@ PHP_SCRIPTS=i2c.php \ ...@@ -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 \
......
...@@ -26,6 +26,7 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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,12 +69,15 @@ ...@@ -64,12 +69,15 @@
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
and timestamp are specified - return last compressed frame number and timestamp.</p> and timestamp are specified - return last compressed frame number and timestamp.</p>
<p>Uses TRIG_PERIOD (in 10ns increments) for calculations.</p> <p>Uses TRIG_PERIOD (in 10ns increments) for calculations.</p>
<p>sensor_port=0..3 - specify which sensor port to use, default is sensor_port=0</p> <p>sensor_port=0..3 - specify which sensor port to use, default is sensor_port=0</p>
USAGE; USAGE;
exit (0); exit (0);
} }
...@@ -78,6 +86,8 @@ USAGE; ...@@ -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; ...@@ -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,9 +121,66 @@ USAGE; ...@@ -109,9 +121,66 @@ 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);
$timestamp = $this_timestamp + $ahead_now; $timestamp = $this_timestamp + $ahead_now;
...@@ -189,48 +258,60 @@ USAGE; ...@@ -189,48 +258,60 @@ 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;
if (isset($port_mask)){ // start or stop compressor $use_daemon = ($frame != 0);
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
if (!isset($duration)) { if (! isset($duration)) {
$duration = 0; $duration = 0;
} }
// kill CLI mode if it was running (e.g. waiting for 100 years) // kill CLI mode if it was running (e.g. waiting for 100 years)
exec("killall capture_range.php", $output, $retval); exec("killall capture_range.php", $output, $retval);
// spawn CLI program in background duration <0 - start only, ==0 - stop only, >0 - start+stop // spawn CLI program in background duration <0 - start only, ==0 - stop only, >0 - start+stop
// $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) {
// $f = fopen ( "/var/log/capture_range.log", 'a' ); // $xml->addChild ('notify_url', $notify_url); // urlencode($notify_url)); // dry run, do nothing
// fwrite($f,"DONE exec\n"); // } else {
// fclose ( $f ); if ($use_daemon) {
if ($duration > 0){ exec("/www/pages/capture_range.php $sensor_port $port_mask $frame $duration '$notify_url'> /dev/null 2>&1 &");
$frame += $duration; // xml will contain end frame // }
} // $f = fopen ( "/var/log/capture_range.log", 'a' );
if ($wait){ // fwrite($f,"DONE exec\n");
elphel_wait_frame_abs($sensor_port, $frame + 1); // fclose ( $f );
if ($duration > 0) {
$frame += $duration; // xml will contain end frame
}
file_put_contents(CAPTURE_RANGE_STATE, "end_frame = $frame\n");
if ($wait) {
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) {
$timestamp = elphel_frame2ts($sensor_port,0); $timestamp = elphel_frame2ts($sensor_port, 0);
$frame = elphel_ts2frame($sensor_port,0.0); $frame = elphel_ts2frame($sensor_port, 0.0);
} }
} }
$xml->addChild ('retval', $retval); $xml->addChild ('retval', $retval);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment