Commit 9389820e authored by Andrey Filippov's avatar Andrey Filippov

more debugging

parent 3ed8b3eb
......@@ -270,7 +270,7 @@
printf($rslt);
exit(0);
} else if ($cmd == 'capture'){
$results = runCapture($GLOBALS[FFC], $nowait); // runCapture($run_ffc, $nowait = 0, $debug=0) // single-run?
$results = runCapture($GLOBALS[FFC], $nowait, true, $GLOBALS[DEBUG]); // runCapture($run_ffc, $nowait = 0, $debug=0) // single-run?
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>");
$xml->addChild ('ffc', $GLOBALS[FFC]);
$xml->addChild (FFC_GROUPS,$GLOBALS[FFC_GROUPS]);
......@@ -533,7 +533,7 @@ EOT;
return $results;
}
function runCapture($run_ffc, $nowait = 0, $debug=0) { // works, but the main script hangs
function runCapture($run_ffc, $nowait = 0, $first_run = 0, $debug=0) { // works, but the main script hangs
// TODO: use lwir16.ini
// $eo_quality = 97;
// $exposure = 1000; // 1 ms
......@@ -581,7 +581,7 @@ EOT;
}
// $timestamp = $this_timestamp + $GLOBALS[PRE_DELAY]; // this will be a delay between capture sequences (default - 3s)
$urls = array();
for ($i = 0; $i<count($GLOBALS[IPS]); $i++){
for ($i = 0; $i<count($GLOBALS[IPS]); $i++) if ($GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] > 0){ // 0 - do not use this camera at all
// $_SERVER[SCRIPT_NAME] STARTS WITH '/'
$url = 'http://'.$GLOBALS[IPS][$i].'/'.SCRIPT_CAPTURE_RANGE.'?sensor_port='.$sensor_port; //
if ($GLOBALS[I_AM_MASTER]) {
......@@ -592,6 +592,16 @@ EOT;
// $url .= '&port_mask=15'; // .$port_mask[$i];
$url .= '&port_mask='.$GLOBALS[PORT_MASKS][$GLOBALS[IPS][$i]]; //indexed by IPs
$dur = ($i < 4) ? $GLOBALS[DURATION] : $GLOBALS[DURATION_EO]; // maybe turn on EO forever
if ($GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] == 2) {// continuous run mode
/*
if ($first_run) {
$dur = -1; // start only, no stop
} else {
continue; // nothing to do for this camera, it is supposed to already be running. Or just enable compressor anyway?
}
*/
$dur = -1; // start only, no stop
}
$url .= '&duration='. $dur;
// $url .= '&maxahead='. $maxahead;
// $url .= '&minahead='. $minahead;
......@@ -724,6 +734,7 @@ EOT;
}
$left_frames = 0;
$abort_sequence=0;
$need_service = 0; // set by commands START, STOP, ABORT, reset when served
// exit(0);
$from_pipe = false; // first commands are form INI
while ($GLOBALS[DAEMON_RUN]){
......@@ -747,13 +758,16 @@ EOT;
$GLOBALS[CAPTURE_RUN] = 1;
$GLOBALS[CAPTURE_WAIT] = 0;
$left_frames = 0;
$need_service = 1;
} else if ($cmd == CMD_STOP){
$GLOBALS[CAPTURE_RUN] = 0; // should continue waiting
$abort_sequence = 0;
$need_service = 1;
} else if ($cmd == CMD_ABORT){
$GLOBALS[CAPTURE_RUN] = 0; // should continue waiting
$abort_sequence = 1;
} else if ($cmd == CMD_CONTINUE){
// $need_service = 1;
} else if ($cmd == CMD_CONTINUE){ // not used, designed for notification from capture_range.php
$GLOBALS[CAPTURE_WAIT] = 0;
$left_frames = 0;
} else if ($from_pipe && ($cmd == CMD_STATUS)){ // generate status data and send over response pipe
......@@ -867,8 +881,10 @@ EOT;
$GLOBALS[CAPTURE_WAIT] = 0;
}
if ($abort_sequence && $GLOBALS[CAPTURE_WAIT]) { // still not stopped
$sensor_port = 0;
$urls = array();
for ($i = 0; $i<count($GLOBALS[IPS]); $i++){
// stop all started cameras, including started-only, but not inactive. TODO - add inactive to skip initialization?
for ($i = 0; $i<count($GLOBALS[IPS]); $i++) if ($GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] > 0){ // 0 - do not use this camera at all
// $_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
......@@ -884,14 +900,16 @@ EOT;
$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");
printf("--- aborting runCapture result: ---\n");
print_r($result);
}
}
/// if (($left_frames > 0) && !$abort_sequence){
if ($left_frames > 0) {
// skip some frames as there is nothing to do
// skip some frames as there is nothing to do
$rslt = skipFrames(array($GLOBALS[IPS][0]),$GLOBALS[FRAMES_IDLE]);// just master camera IP
}
$abort_sequence = 0;
} else if ($GLOBALS[CAPTURE_RUN]){ // run next cycle
$ffc_due = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD];
......@@ -902,7 +920,8 @@ EOT;
$GLOBALS[LAST_FFC] = $now;
}
// $result = runCapture($run_ffc, false, $GLOBALS[$GLOBALS[DEBUG]]);
$result = runCapture($run_ffc, false, $GLOBALS[DEBUG]);
$result = runCapture($run_ffc, false, $need_service, $GLOBALS[DEBUG]);
$need_service = 0;
$GLOBALS[SEQUENCE_NUM]++;
if ($GLOBALS[DEBUG] > 0){
printf("--- capture_run: ---\n");
......@@ -910,6 +929,39 @@ EOT;
}
$GLOBALS[CAPTURE_WAIT] = 1;
} else {
if ($GLOBALS[DEBUG] > 0){
printf("--- idle: need_service=$need_service: ---\n");
}
if ($need_service) { // need to stop those that were continuously running. FIXME: now will not wor if all are continuously running
$sensor_port = 0;
$urls = array();
// stop all continuously run cameras, but not inactive. TODO - add inactive to skip initialization?
for ($i = 0; $i<count($GLOBALS[IPS]); $i++) if ($GLOBALS[RUN_MODES][$GLOBALS[IPS][$i]] ==2) { // only continuously running
// $_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("--- stopping continuously running cameras: URLs:\n");
print_r($urls);
}
if (count($urls) > 0) {
$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_stop_continuously_running: ---\n");
print_r($result);
}
} else {
if ($GLOBALS[DEBUG] > 0){
printf("--- No continuously runnong cameras to stop ---\n");
}
}
$need_service = 0;
}
// skip some frames as there is nothing to do
$rslt = skipFrames(array($GLOBALS[IPS][0]),$GLOBALS[FRAMES_IDLE]);// just master camera IP
}
......
......@@ -16,7 +16,6 @@ PHP_SCRIPTS=i2c.php \
ccam.php \
diag_utils.php \
framepars.php \
frame_to_ts.php \
parsedit.php \
phpinfo.php \
raw.php \
......
......@@ -52,6 +52,13 @@
// $f = fopen ( "/var/log/capture_range.log", 'a' );
// fwrite($f,"elphel_capture_range($sensor_port, $port_mask, $frame, $duration);\n");
// fclose ( $f );
/**
* Program multiple channels (according to 'port_mask') to start compressor at absolute (or relative) 'frame', run it for 'duration' frames
* and then stop. If 'duration'==0 - just stop compressor, if 'duration' <0 - only start.
* This function is intended to be executed in a background process (such as in capture_range.php) not to hold http client
* BUG: frame number after stop is 2 less than expected (ahead applied in wrong place?)
*/
elphel_capture_range($sensor_port, $port_mask, $frame, $duration);
// $f = fopen ( "/var/log/capture_range.log", 'a' );
// fwrite($f,"elphel_capture_range DONE\n");
......@@ -211,7 +218,7 @@ USAGE;
$duration = (integer) $duration_list; // single valude
}
// convert provided timestamp to even number of frame timestamp
// convert provided timestamp to integer number of frame timestamp
if (($frame !=0) || ($timestamp !=0.0)) {
if (($frame <=0) && ($timestamp > 0.0)){
$frame = elphel_ts2frame($sensor_port,$timestamp);
......@@ -263,7 +270,7 @@ USAGE;
if (isset($port_mask)) { // start or stop compressor
$this_frame = elphel_get_frame($sensor_port);
if (! $use_daemon) { // e.g. to stop ASAP $frame=0, $duration !=0 - start ASAP
if (isset($duration)) {
if ($duration < 0) {
elphel_compressor_run($sensor_port, 0, $flags, $port_mask); // turn on ASAP
$xml->addChild('compressor', 1);
} else { // frame = 0; duration ==0 - stop ASAP
......@@ -271,12 +278,12 @@ USAGE;
$xml->addChild('compressor', 0);
}
$frame = $this_frame + $minahead;
}
}
$ahead = $frame - $this_frame;
if ($use_daemon && ($ahead < $minahead)) {
if ($use_daemon && ($ahead < $minahead) && (!isset($ahead_now))) {
$xml->addChild('error', 'TOO LATE');
$xml->addChild('ahead', $ahead);
} else { // OK, enough time to program
} else { // OK, enough time to program or no-daemon mode, or ASAP
if (! isset($duration)) {
$duration = 0;
}
......@@ -290,6 +297,9 @@ USAGE;
// $xml->addChild ('notify_url', $notify_url); // urlencode($notify_url)); // dry run, do nothing
// } else {
if ($use_daemon) {
if (isset($ahead_now) && ($ahead_now == 0)){
$frame = 0; // ASAP
}
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' );
......
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