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

finisheshed daemon-control javascript

parent 620a1357
......@@ -4,13 +4,26 @@
<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
var pre_delay;// = 5.0;
var duration;// = 100;
var duration_eo;// = 100;
var ffc;// = false;
var ffc_period;// = 30;
var ffc_groups;// = 2;
var ffc_frames;// = 8;
var compressor_run;// = false;
var debug;// = 0;
var sequence_num;// = 0;
var last_ffc;// = 0;
var time_to_ffc;// = 0;
var capture_run;// = 0;
var want_run;
var request_num = 0;
var update_editable = true;
var apply_pending = false;
function parse_response(resp){
var result = "";
console.log(resp);
......@@ -41,134 +54,235 @@ function send_request(rq,callback){
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 sendStatusRequest(){
var url = "http://192.168.0.41/lwir16/lwir16.php?daemon=status";
if (apply_pending) {
var mod_pars = modParameters();
// console.log('mod_pars members:');
for(const p in mod_pars) {
url +="&"+p+"="+mod_pars[p];
}
update_editable = true; // will update edited fields
apply_pending = false;
}
send_request(url,parseStatusResponse);
}
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 sendRestartRequest(){
var url = "http://192.168.0.41/lwir16/lwir16.php?daemon=restart&cmd=STATUS";
send_request(url,parseStatusResponse);
}
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 parseStatusResponse(resp){
var result = "";
// console.log(resp);
if (update_editable) {
if (resp.getElementsByTagName("pre_delay").length!=0){
pre_delay = parseFloat(resp.getElementsByTagName("pre_delay")[0].childNodes[0].nodeValue);
document.getElementById("idpre_delay").value = pre_delay;
}
if (resp.getElementsByTagName("duration").length!=0){
duration = parseInt(resp.getElementsByTagName("duration")[0].childNodes[0].nodeValue);
document.getElementById("idduration").value = duration;
}
if (resp.getElementsByTagName("duration_eo").length!=0){
duration_eo = parseInt(resp.getElementsByTagName("duration_eo")[0].childNodes[0].nodeValue);
document.getElementById("idduration_eo").value = duration_eo;
}
}
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;
}
if (resp.getElementsByTagName("ffc").length!=0){
ffc = parseInt(resp.getElementsByTagName("ffc")[0].childNodes[0].nodeValue);
document.getElementById("idffc").checked = ffc > 0;
}
if (resp.getElementsByTagName("ffc_period").length!=0){
ffc_period = parseFloat(resp.getElementsByTagName("ffc_period")[0].childNodes[0].nodeValue);
document.getElementById("idffc_period").value = ffc_period;
}
if (resp.getElementsByTagName("ffc_groups").length!=0){
ffc_groups = parseInt(resp.getElementsByTagName("ffc_groups")[0].childNodes[0].nodeValue);
document.getElementById("idffc_groups").value = ffc_groups;
}
if (resp.getElementsByTagName("ffc_frames").length!=0){
ffc_frames = parseInt(resp.getElementsByTagName("ffc_frames")[0].childNodes[0].nodeValue);
document.getElementById("idffc_frames").value = ffc_frames;
}
function updateDuration(field_id){
var v=parseInt(document.getElementById(field_id).value);
if (isNaN(v)){
v = 100;
if (resp.getElementsByTagName("compressor_run").length!=0){
compressor_run = parseInt(resp.getElementsByTagName("compressor_run")[0].childNodes[0].nodeValue);
document.getElementById("idcompressor_run").checked = compressor_run > 0;
}
if (resp.getElementsByTagName("debug").length!=0){
debug = parseInt(resp.getElementsByTagName("debug")[0].childNodes[0].nodeValue);
document.getElementById("iddebug").value = debug;
}
}
if (resp.getElementsByTagName("sequence_num").length!=0){
sequence_num = parseInt(resp.getElementsByTagName("sequence_num")[0].childNodes[0].nodeValue);
document.getElementById("idsequence_num").value = sequence_num;
}
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;
if (resp.getElementsByTagName("last_ffc").length!=0){
last_ffc = parseFloat(resp.getElementsByTagName("last_ffc")[0].childNodes[0].nodeValue);
document.getElementById("idlast_ffc").value = last_ffc;
}
if (resp.getElementsByTagName("time_to_ffc").length!=0){
time_to_ffc = parseFloat(resp.getElementsByTagName("time_to_ffc")[0].childNodes[0].nodeValue);
document.getElementById("idtime_to_ffc").value = time_to_ffc;
}
if (resp.getElementsByTagName("capture_run").length!=0){
capture_run = parseInt(resp.getElementsByTagName("capture_run")[0].childNodes[0].nodeValue);
document.getElementById("idcapture_run").checked = capture_run > 0;
if (update_editable) {
document.getElementById("idStartStop").innerHTML=capture_run?"Stop":"Start";
document.getElementById("idStartStop").disabled = false;
want_run = capture_run;
}
}
if (update_editable) {
document.getElementById('idApply').innerHTML='Apply';
document.getElementById('idApply').disabled= false;
document.getElementById('idRestart').innerHTML='Restart';
document.getElementById('idRestart').disabled= false;
}
ffc_period = v;
document.getElementById(field_id).value=""+v;
request_num++;
document.getElementById("idrequest_num").value = request_num;
update_editable = false;
sendStatusRequest();
}
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 modParameters(){
var mod_pars={};
if (document.getElementById("idpre_delay").value != (""+pre_delay)){
mod_pars['pre_delay'] = document.getElementById("idpre_delay").value;
}
if (document.getElementById("idduration").value != (""+duration)){
mod_pars['duration'] = document.getElementById("idduration").value;
}
if (document.getElementById("idduration_eo").value != (""+duration_eo)){
mod_pars['duration_eo'] = document.getElementById("idduration_eo").value;
}
if (document.getElementById("idffc").checked != ffc){
mod_pars['ffc'] = document.getElementById("idffc").checked?"1":"0";
}
if (document.getElementById("idffc_period").value != (""+ffc_period)){
mod_pars['ffc_period'] = document.getElementById("idffc_period").value;
}
if (document.getElementById("idffc_groups").value != (""+ffc_groups)){
mod_pars['ffc_groups'] = document.getElementById("idffc_groups").value;
}
if (document.getElementById("idffc_frames").value != (""+ffc_frames)){
mod_pars['ffc_frames'] = document.getElementById("idffc_frames").value;
}
if (document.getElementById("idcompressor_run").checked != compressor_run){
mod_pars['compressor_run'] = document.getElementById("idcompressor_run").checked?"1":"0";
}
if (want_run != capture_run) {
mod_pars['cmd'] = want_run? "START":"STOP";
}
console.log('mod_pars members:');
for(const p in mod_pars) {
console.log (p, mod_pars[p]);
}
return mod_pars;
}
function setPending(){
document.getElementById('idApply').innerHTML='Pending';
document.getElementById('idApply').disabled= true;
document.getElementById("idStartStop").innerHTML="Pending";
document.getElementById("idStartStop").disabled = true;
document.getElementById("idRestart").innerHTML="Pending";
document.getElementById("idRestart").disabled = true;
apply_pending = true;
}
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);
function clickedRestart(){
setPending();
sendRestartRequest();
}
function clickedRun(){
want_run = !capture_run;
setPending();
}
function clickedApply(){
setPending();
}
</script>
</head>
<body onload='init_lwir()'>
<body onload='sendStatusRequest()'>
<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>
<button id="idStartStop" name = "nStartStop" onclick="clickedRun()" disabled="true">???</button>
</td><td>
<button id="idApply" name = "nApply" onclick="clickedApply()" disabled = "true">???</button>
</td><td>&nbsp;</td> <td>&nbsp;</td><td>&nbsp;</td>
<td><button id="idRestart" name = "nRestart" onclick="clickedRestart()" >Restart</button></td></tr>
<tr><td>Pre-capture delay</td><td>
<input id="idpre_delay" name="npre_delay" size="10" maxlength="10" value="?" type="text">
</td><td> sec</td><td>Sequence count</td><td>
<input id="idsequence_num" name="nsequence_num" size="10" maxlength="10" value="?" type="text" disabled >
</td><td>captured</td></tr>
<tr><td>Sequence length (@60Hz)</td><td>
<input id="idduration" name="nduration" size="10" maxlength="10" value="?" type="text">
</td><td>frames</td><td>Request count</td><td>
<input id="idrequest_num" name="nrequest_num" size="10" maxlength="10" value="?" type="text" disabled >
</td><td>&nbsp;</td></tr>
<tr><td>Sequence length (@10Hz)</td><td>
<input id="idduration_eo" name="nduration_eo" size="10" maxlength="10" value="?" type="text">
</td><td>frames</td><td>Capture run</td><td>
<input id="idcapture_run" name="ncapture_run" type="checkbox" disabled>
</td><td>&nbsp;</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>
<tr><td>FFC</td><td>
<input id="idffc" name="nffc" type="checkbox">
</td><td>&nbsp;</td><td>Last FFC</td><td>
<input id="idlast_ffc" name="nlast_ffc" size="10" maxlength="10" value="?" type="text" disabled >
</td><td>sec</td></tr>
<tr><td>FFC period</td><td>
<input id="idffc_period" name="nffc_period" size="10" maxlength="10" value="?" type="text">
</td><td>sec</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 groups</td><td>
<select id="idffc_groups" name="nffc_groups" value="?">
<option value="1">1</option>
<option value="2">2</option>
<option value="4" selected="selected">4</option>
</select>
</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>FFC frames</td><td>
<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>
<tr><td>Compress after Init</td><td>
<input id="idcompressor_run" name="ncompressor_run" type="checkbox">
</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Debug level</td><td>
<input id="iddebug" name="ndebug" size="10" maxlength="10" value="?" type="text">
</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</table>
</body>
</html>
ips = "192.168.0.41,192.168.0.42,192.168.0.43,192.168.0.44,192.168.0.45"
duration = 100
pre_delay = 5.0
ffc_period = 300.0
pre_delay = 3.0
ffc_period = 30.0
ffc_groups = 2
ffc_frames = 8
ffc = 1
......
......@@ -63,12 +63,14 @@
define('DAEMON_CTRL', 'daemon');
define('DAEMON_CTRL_CMDS', 'cmd'); //comma-separated commands to be sent to the daemon
// print_r($_GET); // magic
// exit(0); // magic
// initializations before reading lwir16.ini
$GLOBALS[COMPRESSOR_RUN] = 0;
$GLOBALS[DURATION] = 100;
$GLOBALS[PRE_DELAY] = 5.0; // seconds
$GLOBALS[FFC] = false; // perform FFC before starting a sequence (and before delay? reduce delay ?)
$GLOBALS[FFC] = 0; // perform FFC before starting a sequence (and before delay? reduce delay ?)
// $ffc = false;
$GLOBALS[FFC_GROUPS] = 2; // 1/2/4 - do not run FFC on all channels simultaneously (43 failed)
$GLOBALS[FFC_FRAMES] = 8; // read actual?
......@@ -108,7 +110,7 @@
} else if ($key == 'run'){
$GLOBALS[COMPRESSOR_RUN] = 2;
} else if ($key == 'ffc'){
$GLOBALS[FFC] = true;
$GLOBALS[FFC] = 1;
if ($value) { // string "0" will also be false
$v = (int) $value;
if (($v == 1) || ($v == 2) || ($v == 4)){
......@@ -117,6 +119,10 @@
}
}
}
// print_r($lswir16cmds);
// exit(0);
if (isset($duration) && !isset($duration_eo)){
$duration_eo = (int) ($duration/EO_DECIMATE + 1);
}
......@@ -124,7 +130,8 @@
if (isset($duration_eo)) $GLOBALS[DURATION_EO] = $duration_eo;
if ($GLOBALS[DURATION] < 1) $GLOBALS[DURATION] = 1;
if ($GLOBALS[DURATION_EO] < 1) $GLOBALS[DURATION_EO] = 1;
if (isset($lswir16cmds)){
$lwir_trig_dly = 0;
$eo_quality = 97;
......@@ -180,7 +187,7 @@
} else if ($cmd == 'capture'){
$results = runCapture($GLOBALS[FFC], $nowait); // runCapture($run_ffc, $nowait = 0, $debug=0)
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>");
$xml->addChild ('ffc', $GLOBALS[FFC] ? 'true':'false');
$xml->addChild ('ffc', $GLOBALS[FFC]);
$xml->addChild (FFC_GROUPS,$GLOBALS[FFC_GROUPS]);
$xml->addChild (FFC_FRAMES,$GLOBALS[FFC_FRAMES]);
for ($i = 0; $i<count($GLOBALS[IPS]); $i++){
......@@ -591,11 +598,9 @@ EOT;
$xml_state->addChild (trim($kv[0]),trim($kv[1]));
}
}
$xml->addChild (SECUENCE_NUM, $GLOBALS[SECUENCE_NUM]);
if ($GLOBALS[FFC]) {
$GLOBALS[TIME_TO_FFC] = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD] - time();
$xml->addChild (TIME_TO_FFC, $GLOBALS[TIME_TO_FFC]);
}
$GLOBALS[TIME_TO_FFC] = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD] - time();
$xml->addChild (SECUENCE_NUM, $GLOBALS[SECUENCE_NUM]);
$xml->addChild (TIME_TO_FFC, $GLOBALS[TIME_TO_FFC]);
$xml->addChild (IPS, implode(',',$GLOBALS[IPS]));
$xml->addChild (DURATION, $GLOBALS[DURATION]);
$xml->addChild (DURATION_EO, $GLOBALS[DURATION_EO]);
......@@ -652,7 +657,9 @@ EOT;
if ($GLOBALS[DEBUG]){
print_r($ini);
}
unset ($GLOBALS[DAEMON_CMD]);
unset ($GLOBALS[DAEMON_CMD]);
applyConf ($ini); // update $GLOBALS
$from_pipe = true;
if ($GLOBALS[DEBUG] > 1){
......@@ -726,7 +733,7 @@ EOT;
if (isset($arr[DAEMON_CMD])) $GLOBALS[DAEMON_CMD] = $arr[DAEMON_CMD];
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[FFC])) $GLOBALS[FFC] = $arr[FFC]?true:false; // only after INIT
if (isset($arr[FFC])) $GLOBALS[FFC] = $arr[FFC]?1:0;
}
/**
......@@ -736,41 +743,88 @@ EOT;
*/
function daemon_control($cmd)
{
/*
echo "<pre>\n";
print_r($_SERVER);
echo "</pre>\n";
exit(0);
*/
// echo "<pre>\n";
// print_r($_SERVER);
// echo "</pre>\n";
// exit(0);
// see if it already running
$debug = 0;
$max_wait = 10; // seconds
// $sript_name = substr($_SERVER['SCRIPT_NAME'], 1); // remove leading '/'
$sript_path = $_SERVER['SCRIPT_FILENAME'];
$sript_name = basename($sript_path);
$pids = getPIDByName($sript_name, 'php', $active_only = false);
// echo "<pre>0:\n";
// print_r($pids);
// echo "</pre>\n";
// Stop if needed
if ($pids && (($cmd == 'restart') || ($cmd == 'stop'))) {
$mode = 0600;
if (! file_exists(PIPE_CMD)) {
// create the pipe
umask(0);
posix_mkfifo(PIPE_CMD, $mode);
// below - does not work with non-blocking "w+", will take care later
/*
* $mode = 0600;
* if (! file_exists(PIPE_CMD)) {
* // create the pipe
* umask(0);
* posix_mkfifo(PIPE_CMD, $mode);
* }
* $f = fopen(PIPE_CMD, "w+"); // make it non-blocking as the receiver may be hang
* fwrite($f, "CMD=EXIT");
* fclose($f);
* for ($i = 0; $pids && ($i < $max_wait); $i ++) {
* sleep (1);
* $pids = getPIDByName($sript_name, 'php', $active_only = false);
* }
*/
// if(file_exists(PIPE_CMD)) unlink(PIPE_CMD); //delete pipe
// if(file_exists(PIPE_RESPONSE)) unlink(PIPE_RESPONSE); //delete pipe
// print_r($pids);
if ($debug) {
echo "<pre>1:\n";
print_r($pids);
echo "</pre>\n";
}
if ($pids) { // did not exit, ask politely
foreach ($pids as $proc) {
exec('kill ' . $proc['pid'], $output, $retval);
}
}
$f = fopen(PIPE_CMD, "w+"); // make it non-blocking as the receiver may be hang
fwrite($f, "CMD=EXIT");
fclose($f);
for ($i = 0; $i < $max_wait; $i ++) {
if ($debug) {
echo "<pre>2:\n";
print_r($pids);
echo "</pre>\n";
}
for ($i = 0; $pids && ($i < $max_wait); $i ++) {
sleep (1);
$pids = getPIDByName($sript_name, 'php', $active_only = false);
if (! $pid)
break;
}
if ($pids) { // did not exit
if ($debug) {
echo "<pre>3:\n";
print_r($pids);
echo "</pre>\n";
}
if ($pids) { // did not exit - just kill them
foreach ($pids as $proc) {
exec('kill -9 ' . $proc['pid'], $output, $retval);
}
}
$pids = getPIDByName($sript_name, 'php', $active_only = false);
if ($debug) {
echo "<pre>4\n";
print_r($pids);
echo "</pre>\n";
}
}
$pids = getPIDByName($sript_name, 'php', $active_only = false);
// print_r($pids);
if (!$pids && ($cmd != 'stop')) {
exec($sript_path . ' > /dev/null 2>&1 &'); // "> /dev/null 2>&1 &" makes sure it is really really run as a background job that does not wait for input
// wait it to run
......@@ -780,8 +834,16 @@ EOT;
}
}
/*
$exit_ps = ($cmd == 'stop') || !pids ; // nothing else to do if it is not running
if (($cmd == 'restart') || ($cmd == 'start')){
if (!isset ($_GET[DAEMON_CTRL_CMDS]) && !isset ($_GET[DAEMON_CMD])){ // no other commands (like "status")
$exit_ps = true;
}
}
*/
if (($cmd == 'restart') || ($cmd == 'start') || ($cmd == 'stop') || !pids) { // nothing else to do if it is not running
// just respond with $pids xml
// if ($exit_ps) { // nothing else to do if it is not running just respond with $pids xml
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><lwir16_daemon_status/>");
if ($pids) {
/*
......
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