Commit 25585ef8 authored by Andrey Filippov's avatar Andrey Filippov

added multicamera sync and initialization of the LWIR16 camera

parent 5751116b
# Runs 'make', 'make install', and 'make clean' in specified subdirectories
SUBDIRS := src/php_top src/python_tests src/debugfs-webgui src/jp4-canvas src/update src/eyesis4pi src/index src/pointers src/snapshot src/jp4-viewer src/photofinish src/multicam src/diagnostics # src1
SUBDIRS := src/php_top src/python_tests src/debugfs-webgui src/jp4-canvas src/update src/eyesis4pi \
src/index src/pointers src/snapshot src/jp4-viewer src/photofinish src/multicam src/diagnostics src/lwir16 # src1
INSTALLDIRS = $(SUBDIRS:%=install-%)
CLEANDIRS = $(SUBDIRS:%=clean-%)
......
DOCUMENTROOT=$(DESTDIR)/www/pages/lwir16
OWN = -o root -g root
INSTDOCS = 0644
INSTALL = install
DOCS= index.html \
lwir16.php
all:
@echo "make all in src"
install:
@echo "make install in src"
$(INSTALL) $(OWN) -d $(DOCUMENTROOT)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(DOCS) $(DOCUMENTROOT)
clean:
@echo "make clean in src"
<html><head><title>Running LWIR16 sequences</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta content="">
<style></style>
<script language="JavaScript">
var initialized = false;
var seq_counter = 0;
var duration = 100;
var pre_delay = 5.0;
var ffc_period = 30;
var run = true;
var want_run = true;
var next_ffc_sec = 0; // will be overdue
function parse_response(resp){
var result = "";
console.log(resp);
if (resp.getElementsByTagName("result").length!=0){
result = resp.getElementsByTagName("result")[0].childNodes[0].nodeValue;
}else if (resp.getElementsByTagName("reboot").length!=0){
result = resp.getElementsByTagName("reboot")[0].childNodes[0].nodeValue;
}else if (resp.getElementsByTagName("error").length!=0){
result = resp.getElementsByTagName("error")[0].childNodes[0].nodeValue;
}else{
result = "Error";
}
document.getElementById("btn_response").innerHTML = result;
}
function send_request(rq,callback){
var request = new XMLHttpRequest();
request.open('GET', rq, true);
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var resp = this.responseXML;
callback(resp);
}
};
request.onerror = function() {
console.log("request error");
};
request.send();
}
function init_lwir(){
send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=init",init_response);
document.getElementById('idpre_delay').value= ""+pre_delay;
document.getElementById('idduration').value= ""+duration;
document.getElementById('idffc_period').value= ""+ffc_period;
}
function init_response(resp){
initialized = true;
// alert ("LWIR16 initialized");
document.getElementById('idStartStop').innerHTML= run? 'STOP': 'START';
console.log("LWIR16 initialized");
want_run = run;
captureSet();
}
function capture_response(resp){
document.getElementById('idcount').value=""+seq_counter;
// document.getElementById('idcount').innerHTML=""+seq_counter;
//id="idcount"
seq_counter++;
if (want_run) {
run = true;
// send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=capture&duration="+duration+"&pre_delay="+pre_delay,capture_response);
captureSet();
} else {
run = false;
document.getElementById('idStartStop').innerHTML='START';
}
}
function updatePreDelay(field_id){
var v=parseDouble(document.getElementById(field_id).value);
if (isNaN(v)){
v = 5.0;
}
pre_delay = v;
document.getElementById(field_id).value=""+v;
}
function updateDuration(field_id){
var v=parseInt(document.getElementById(field_id).value);
if (isNaN(v)){
v = 100;
}
duration = v;
document.getElementById(field_id).value=""+v;
}
function updateFFCPeriod(field_id){
var v=parseInt(document.getElementById(field_id).value);
if (isNaN(v)){
v = 100;
}
ffc_period = v;
document.getElementById(field_id).value=""+v;
}
function clickedRun(field_id){
want_run = !run;
// alert("want_run="+want_run);
if (want_run){
run = true;
document.getElementById(field_id).innerHTML='STOP';
captureSet();
// send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=capture&duration="+duration+"&pre_delay="+pre_delay,init_response);
}
}
function captureSet(){
var now_sec = 0.001 * ((new Date()).getTime());
var ffc_cmd = "";
if (now_sec > next_ffc_sec) {
ffc_cmd = "&ffc";
next_ffc_sec = now_sec + ffc_period;
document.getElementById("idffc").value="NOW";
} else {
document.getElementById('idffc').value=""+ (0.01 * Math.round(100*(next_ffc_sec - now_sec)));
}
send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=capture&duration="+duration+"&pre_delay="+pre_delay+ffc_cmd,capture_response);
}
</script>
</head>
<body onload='init_lwir()'>
<table>
<tr>
<td>Pre-capture delay</td><td>
<input id="idpre_delay" name="npre_delay" size="10" maxlength="10" value="?" onchange="updatePreDelay('idpre_delay')" type="text">
</td>
<td><button id="idStartStop" name = "nStartStop" onclick="clickedRun('idStartStop')">???</button></td>
</tr>
<tr>
<td>Sequence length (@60Hz)</td><td>
<input id="idduration" name="nduration" size="10" maxlength="10" value="?" onchange="updateDuration('idduration')" type="text">
</td>
<td>frames</td>
</tr>
<tr>
<td>FFC period</td><td>
<input id="idffc_period" name="nffc_period" size="10" maxlength="10" value="?" onchange="updateFFCPeriod('idffc_period')" type="text">
</td>
<td>sec</td>
</tr>
<tr>
<td>Sequence count</td><td>
<input id="idcount" name="ncount" size="10" maxlength="10" value="?" type="text" disabled >
</td>
<td>captured</td>
</tr>
<tr>
<td>Time to ffc</td><td>
<input id="idffc" name="ncount" size="10" maxlength="10" value="?" type="text" disabled >
</td>
<td>sec</td>
</tr>
</table>
</body>
</html>
This diff is collapsed.
......@@ -26,7 +26,9 @@
*! -----------------------------------------------------------------------------**
*!
*/
// TODO set include path, like in set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'include/show_source_include.php';
include "include/elphel_functions_include.php"; // includes curl functions
$minahead = 2;
$PARS_FRAMES = 16;
$maxahead = $PARS_FRAMES - 4; // 3;
......@@ -83,24 +85,64 @@ USAGE;
foreach($_GET as $key=>$value) {
if ($key == 'sensor_port'){
$sensor_port = (integer) $value;
} else if (($key == 'a') || ($key == 'ahead')){ // will overwrite timestamp with this value (in seconds) from now
$ahead_now = (double) $value;
} else if (($key == 'ts') || ($key == 'timestamp')){
$timestamp = (double) $value;
} else if (($key == 'f') || ($key == 'frame')){
$frame = (integer) $value;
} else if (($key == 'm') || ($key == 'port_mask')){
$port_mask = (integer) $value;
// $port_mask = (integer) $value;
$masklist = $value;
} else if (($key == 'd') || ($key == 'duration')){
$duration = (integer) $value;
// TODO: make durations optionally a list, same as port mask (for EO - different)
// wait - apply to the first IP in a list? or to the last?
// $duration = (integer) $value;
$duration_list = $value;
} else if (($key == 'mxa') || ($key == 'maxahead')){
$maxahead = (integer) $value;
} else if (($key == 'mna') || ($key == 'minahead')){
$minahead = (integer) $value;
} else if (($key == 'w') || ($key == 'wait')){ // wait all done
$wait = true;
} else if (($key == 'e') || ($key == 'extra')){ // wait all done
$extra = (integer) $value;
} else if (($key == 'e') || ($key == 'extra')){
$extra = (integer) $value; // not used?
} else if (($key == 'ip') || ($key == 'ips')){ // multicamera operation
$ips = explode(',',$value);
}
}
if (isset($ahead_now)){
$this_frame=elphel_get_frame($sensor_port);
$this_timestamp=elphel_frame2ts($sensor_port,$this_frame);
$timestamp = $this_timestamp + $ahead_now;
}
// if ips are provided, treat port mask as commaseparated list
// $port_mask = (integer) $value;
if (isset($ips)){
$pml = explode(',', $masklist);
$port_mask = array ();
for ($i = 0; $i<count($ips); $i++){
if ($i < count($pml)){
$port_mask[] = (integer) $pml[$i];
} else {
$port_mask[] = 15; // default - all sensors
}
}
$durl = explode(',', $duration_list);
$duration = array();
for ($i = 0; $i<count($ips); $i++){
if ($i < count($durl)){
$duration[] = (integer) $durl[$i];
} else {
$duration[] = $duration[0]; // at least one duration should be provided
}
}
} else {
$port_mask = (integer) $masklist; // single valude
$duration = (integer) $duration_list; // single valude
}
// convert provided timestamp to even number of frame timestamp
if (($frame !=0) || ($timestamp !=0.0)) {
if (($frame <=0) && ($timestamp > 0.0)){
$frame = elphel_ts2frame($sensor_port,$timestamp);
......@@ -108,6 +150,44 @@ USAGE;
$timestamp = elphel_frame2ts($sensor_port,$frame); // update, even if provided to fit better integer number of frames
}
if (isset($ips)){ // start parallel requests to all cameras ($ips should include this one too), collect responses and exit
// prepare URLs
$urls = array();
for ($i = 0; $i<count($ips); $i++){
// $_SERVER[SCRIPT_NAME] STARTS WITH '/'
$url = 'http://'.$ips[$i].$_SERVER[SCRIPT_NAME].'?sensor_port='.$sensor_port; //
$url .= '&ts='.$timestamp; // &timestamp" -> ×tamp
$url .= '&port_mask='.$port_mask[$i];
$url .= '&duration='. $duration[$i];
$url .= '&maxahead='. $maxahead;
$url .= '&minahead='. $minahead;
$url .= '&extra='. $extra;
if ($wait && ($i == (count($ips) - 1))){ // addd to the last ip in a list
$url .= '&wait';
}
$urls[] = $url;
}
// print_r($urls);
// exit(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)
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>");
for ($i = 0; $i<count($ips); $i++){
$xml_ip = $xml->addChild ('ip_'.$ips[$i]);
foreach ($results[$i] as $key=>$value){
$xml_ip->addChild($key,$value);
}
}
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
printf($rslt);
exit(0);
}
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>");
$flags = 0;
if (isset($port_mask)){ // start or stop compressor
......
......@@ -162,6 +162,8 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false, $with_h
do {
$curl_mrc = curl_multi_exec ($curl_mh, $curl_active);
} while ($curl_mrc == CURLM_CALL_MULTI_PERFORM );
} else {
break; // all activity was over before call to curl_multi_finish()
}
if ($echo) echo colorize("$curl_active ",'YELLOW',1);
$nrep++;
......
This diff is collapsed.
......@@ -22,7 +22,9 @@
*! -----------------------------------------------------------------------------**
*!
*/
include 'include/show_source_include.php';
// TODO set include path, like in set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'include/show_source_include.php';
include "include/elphel_functions_include.php"; // includes curl functions
$frame = -1; // positive - wait absolute frame number for the master port, negative - skip frame(s)
$sensor_port = 0;
foreach($_GET as $key=>$value) {
......@@ -30,8 +32,34 @@
$sensor_port = (integer) $value;
} else if (($key == 'f') || ($key == 'frame')){
$frame = (integer) $value;
} else if (($key == 'ip') || ($key == 'ips')){ // multicamera operation
$ips = explode(',',$value);
}
}
if (isset ($ips)){
$urls = array();
for ($i = 0; $i<count($ips); $i++){
// $_SERVER[SCRIPT_NAME] STARTS WITH '/'
$url = 'http://'.$ips[$i].$_SERVER[SCRIPT_NAME].'?frame='.$frame; //
$urls[] = $url;
}
$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)
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><wait_frames/>");
for ($i = 0; $i<count($ips); $i++){
$xml_ip = $xml->addChild ('ip_'.$ips[$i]);
foreach ($results[$i] as $key=>$value){
$xml_ip->addChild($key,$value);
}
}
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
printf($rslt);
exit(0);
}
if ($frame < 0) {
elphel_skip_frames($sensor_port, -$frame);
} else if ($frame > 0) {
......
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