packages/web/353/php_top/tuneseq.php

Go to the documentation of this file.
00001 <?php
00002 /*!*******************************************************************************
00003 *! FILE NAME  : tuneseq.php
00004 *! DESCRIPTION: Run-time adjustmet of the camera core sequencer
00005 *! Copyright (C) 2008 Elphel, Inc
00006 *! -----------------------------------------------------------------------------**
00007 *!
00008 *!  This program is free software: you can redistribute it and/or modify
00009 *!  it under the terms of the GNU General Public License as published by
00010 *!  the Free Software Foundation, either version 3 of the License, or
00011 *!  (at your option) any later version.
00012 *!
00013 *!  This program is distributed in the hope that it will be useful,
00014 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *!  GNU General Public License for more details.
00017 *!
00018 *!  You should have received a copy of the GNU General Public License
00019 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *! -----------------------------------------------------------------------------**
00021 *!  $Log: tuneseq.php,v $
00022 *!  Revision 1.1.1.1  2008/11/27 20:04:03  elphel
00023 *!
00024 *!
00025 *!  Revision 1.7  2008/11/17 23:42:04  elphel
00026 *!  changed myval() to accept numbers in ""
00027 *!
00028 *!  Revision 1.6  2008/11/02 00:33:45  elphel
00029 *!  fixed bug introduced while renaming constants
00030 *!
00031 *!  Revision 1.5  2008/10/31 18:26:32  elphel
00032 *!  Adding support for constants like SENSOR_REGS32 (defined constant plus 32 to simplify referencing sensor registers from PHP
00033 *!
00034 *!  Revision 1.4  2008/10/15 22:28:56  elphel
00035 *!  snapshot 8.0.alpha2
00036 *!
00037 *!  Revision 1.3  2008/10/13 04:48:48  elphel
00038 *!  added some help to the page
00039 *!
00040 *!  Revision 1.2  2008/10/12 22:17:56  elphel
00041 *!  snapshot
00042 *!
00043 */
00044 
00045 function myval ($s) {
00046   $s=trim($s,"\" ");
00047   if (strtoupper(substr($s,0,2))=="0X")   return intval(hexdec($s));
00048   else return intval($s);
00049 }
00050 
00051 function read_latencies() {
00052    global $elp_const;
00053    $elphel_onchange=           'ELPHEL_ONCHANGE_';
00054    $elphel_onchange_len=strlen('ELPHEL_ONCHANGE_');
00055    $l_iarr=array(
00056           'CALLNASAP'=>elphel_get_P_value(ELPHEL_CALLNASAP),
00057           'CALLNEXT1'=>elphel_get_P_value(ELPHEL_CALLNEXT+1),
00058           'CALLNEXT2'=>elphel_get_P_value(ELPHEL_CALLNEXT+2),
00059           'CALLNEXT3'=>elphel_get_P_value(ELPHEL_CALLNEXT+3),
00060           'CALLNEXT4'=>elphel_get_P_value(ELPHEL_CALLNEXT+4));
00061 /*
00062    echo "<pre>\n";
00063    echo "As GETed:\n";
00064    var_dump($l_iarr);
00065    echo "</pre>\n";
00066 */
00067 
00068    $larr=array();
00069    for ($i=0;$i<32;$i++) {
00070      $lat=0;
00071      if ($l_iarr['CALLNEXT1'] & (1<<$i)) $lat++;
00072      if ($l_iarr['CALLNEXT2'] & (1<<$i)) $lat++;
00073      if ($l_iarr['CALLNEXT3'] & (1<<$i)) $lat++;
00074      if ($l_iarr['CALLNEXT4'] & (1<<$i)) $lat++;
00075      $larr[$i]=array('name'=>'','seqen'=>($l_iarr['CALLNASAP'] & (1<<$i))?true:false,'latency'=>$lat);
00076    }
00077    foreach ($elp_const as $key=>$value)  if (substr($key,0,$elphel_onchange_len)==$elphel_onchange) {
00078        $larr[$value]['name']=substr($key,$elphel_onchange_len);
00079    }
00080    return $larr;
00081 }
00082 
00083 function apply_latencies() {
00084    $l_iarr=array(
00085           'CALLNASAP'=>0,
00086           'CALLNEXT1'=>0,
00087           'CALLNEXT2'=>0,
00088           'CALLNEXT3'=>0,
00089           'CALLNEXT4'=>0);
00090    for ($i=0;$i<32;$i++) {
00091      if ($_POST["seqen_".$i]) $l_iarr['CALLNASAP'] |= (1 << $i);
00092      switch ($_POST["latency_".$i]) { 
00093        case "4":
00094         $l_iarr['CALLNEXT4'] |= (1 << $i);
00095        case "3":
00096         $l_iarr['CALLNEXT3'] |= (1 << $i);
00097        case "2":
00098         $l_iarr['CALLNEXT2'] |= (1 << $i);
00099        case "1":
00100         $l_iarr['CALLNEXT1'] |= (1 << $i);
00101      }
00102    }
00103    elphel_set_P_value(ELPHEL_CALLNASAP,   $l_iarr['CALLNASAP'], 0, ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO); 
00104    elphel_set_P_value(ELPHEL_CALLNEXT+1,  $l_iarr['CALLNEXT1'], 0, ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO); 
00105    elphel_set_P_value(ELPHEL_CALLNEXT+2,  $l_iarr['CALLNEXT2'], 0, ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO); 
00106    elphel_set_P_value(ELPHEL_CALLNEXT+3,  $l_iarr['CALLNEXT3'], 0, ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO); 
00107    elphel_set_P_value(ELPHEL_CALLNEXT+4,  $l_iarr['CALLNEXT4'], 0, ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO); 
00108 /*
00109    echo "<pre>\n";
00110    echo "As POSTed:\n";
00111    var_dump($l_iarr);
00112    echo "</pre>\n";
00113 */
00114 }
00115 
00116 function print_latencies() {
00117    $larr=read_latencies();
00118    printf ("<form action=\"$self\" method=\"post\">");
00119    printf ("<table border='1'><thead><td>bit#</td><td>Name</td><td>Enable<br/>sequencer</td><td>Latency</td></thead><tbody>\n");
00120    for ($i=0;$i<32;$i++) {
00121      printf ("<tr><td>%d</td><td>%s</td><td> <input type=\"checkbox\" name=\"seqen_%d\" value=\"1\" %s />  </td><td><input name=\"latency_%d\" type=\"text\" size=\"1\" value=\"%s\"/></td></tr>\n",
00122                                                $i,$larr[$i]['name']?$larr[$i]['name']:'&nbsp;',
00123                                                $i, $larr[$i]['seqen']?'checked':'',$i,$larr[$i]['latency']);
00124    }
00125    printf ("</tbody></table>\n");
00126    printf ("<input type=\"submit\" value=\"Apply\"/></form>\n");
00127 }
00128 
00129 
00130 function read_triggers() {
00131    global $elp_const;
00132    $elphel_onchange=           'ELPHEL_ONCHANGE_';
00133    $elphel_onchange_len=strlen('ELPHEL_ONCHANGE_');
00134    $elphel_lseek=              'ELPHEL_LSEEK_';
00135    $elphel_lseek_len=   strlen('ELPHEL_LSEEK_');
00136    $elphel_const=              'ELPHEL_CONST_'; 
00137    $elphel_const_len=   strlen('ELPHEL_CONST_');
00138 //   $elphel_=                   'ELPHEL_';
00139    $elphel_len=         strlen('ELPHEL_');
00140 
00141    $fp_raw=elphel_framepars_get_raw(-1);
00142    $fp_raw_ul=unpack('V*',$fp_raw); 
00143    $p_params=array_fill  ( 0, 927, array('name'=>"",'value'=>0));
00144    for ($i=0;$i<927;$i++) $p_params[$i]['value']=$fp_raw_ul[$i+1];
00146    foreach ($elp_const as $key=>$value) {
00147      if ((substr($key,0,$elphel_onchange_len)!=$elphel_onchange) &&
00148           (substr($key,0,$elphel_lseek_len)!=$elphel_lseek) &&
00149           (substr($key,0,$elphel_const_len)!=$elphel_const)) {
00150        if (($value>=0) && ($value<count($p_params))) {
00151          if (!$p_params[$value]['name'] ) $p_params[$value]['name']=substr($key,$elphel_len);
00152        }
00153      }
00154    }
00155    for ($i=0; $i <ELPHEL_SENSOR_NUMREGS; $i++ ) !$p_params[ELPHEL_SENSOR_REGS+$i]['name']="SENSOR_REGS".$i;
00156    return $p_params;
00157 }
00158 
00159 
00160 function print_triggers_head($names) { 
00161    printf ("<td>Num</td><td>Hex</td><td>Name</td><td>Value</td>\n");
00162    for ($i=0;$i<32;$i++) {
00163      printf("<td>");
00164      if ( count($names[$i])) foreach ($names[$i] as $char) printf("%s<br/>",$char);
00165      else                                                      printf("&nbsp;");
00166      printf("</td>");
00167    }
00168 
00169 }
00170 
00171 
00172 function print_triggers($filter=0,$minnum=0, $maxnum=926, $rephead=50) { 
00173    global $elp_const;
00174    $elphel_onchange=           'ELPHEL_ONCHANGE_';
00175    $elphel_onchange_len=strlen('ELPHEL_ONCHANGE_');
00176 //   $bit_names=array(0);
00177 //   for ($i=0;$i<32;$i++) $bit_names[$i]="";
00178    $bit_names=array_fill  ( 0, 32, "");
00179    foreach ($elp_const as $key=>$value)  if (substr($key,0,$elphel_onchange_len)==$elphel_onchange) {
00180        $bit_names[$value]=substr($key,$elphel_onchange_len);
00181    }
00182    for ($i=0;$i<32;$i++) $bit_names[$i]=str_split($bit_names[$i]);
00183 //   $larr=read_triggers();
00184 
00185    $pars=read_triggers();
00186 /*
00187    echo "<pre>\n";
00188    var_dump($pars[0]);
00189    var_dump($pars[1]);
00190    var_dump($pars[2]);
00191    var_dump($pars[3]);
00192    echo "</pre>\n";
00193 */
00194 
00195    printf ("<form action=\"$self\" method=\"post\">");
00196    printf ("<table border='1'><thead>\n");
00197    print_triggers_head($bit_names);
00198    printf ("<tbody>\n");
00199    $tohead=$rephead;
00200    if ($maxnum>926) $maxnum=926;
00201    for ($parnum=$minnum;$parnum<=$maxnum;$parnum++) {
00202      if ((!($filter & 1) || ($pars[$parnum]['name'])) && (!($filter & 2) || ($pars[$parnum]['value']))) {
00203        printf ("<tr>\n");
00204        printf ("<td><input type=\"hidden\" name=\"par_%d\" value=\"%d\"/>%d</td><td>0x%x</td><td>%s</td><td>%08x</td>",$parnum,$parnum,$parnum,$parnum,($pars[$parnum]['name'])?($pars[$parnum]['name']):"&nbsp;",$pars[$parnum]['value']);
00205        for ($b=0;$b<32;$b++) {
00206          printf ("<td><input type=\"checkbox\" name=\"trig_%d_%d\" value=\"1\" %s /></td>",$parnum,$b,($pars[$parnum]['value'] & (1 << $b))?'checked':'');
00207        }
00208        printf ("</tr>\n");
00209        if (($tohead--)<=0) { 
00210          printf ("<tr>\n");
00211          print_triggers_head($bit_names);
00212          printf ("</tr>\n");
00213          $tohead=$rephead;
00214        }
00215      }
00216    }
00217    printf ("</tbody></table>\n");
00218 
00219    printf ("<input type=\"submit\" value=\"Apply\"/></form>\n");
00220 }
00221 //   <input type="hidden" name="is_post" value="it_is">
00222 
00223 function apply_triggers() {
00224   $pars=array();
00225   foreach ($_POST as $key=>$value) if (substr($key,0,4)=="par_") $pars[$value]=0;
00226 
00227   foreach ($_POST as $key=>$value) if (substr($key,0,5)=="trig_") {
00228        list ($s,$i,$j)= split('_',$key);
00229        $pars[$i] |= (1<<$j);
00230   }
00231   foreach ($pars as $key=>$value) {
00232     elphel_set_P_value(intval($key), intval($value), 0, ELPHEL_CONST_FRAMEPAIR_FRAME_FUNC); 
00233   }
00234 /*
00235    echo "<pre>\n";
00236    var_dump($pars);
00237    echo "</pre>\n";
00238 */
00239 }
00240 
00242 //main
00243    $elp_const=get_defined_constants(true);
00244    $elp_const=$elp_const["elphel"];
00245    
00246    switch ($_GET["mode"]) {
00247      case "triggers":
00248      case "functions":
00249      $filter=0;
00250      $minnum=0; //927
00251      $maxnum=512; //927
00252      $rephead=50;
00253      if ($_GET["filter"]) {
00254         $filter=$_GET["filter"];
00255      }
00256      if ($_GET["min"]) {
00257         $minnum=$_GET["min"];
00258      }
00259      if ($_GET["max"]) {
00260         $maxnum=$_GET["max"];
00261      }
00262      if ($_GET["rephead"]) {
00263         $rephead=$_GET["rephead"];
00264      }
00265     
00266 
00267        if ($_SERVER["REQUEST_METHOD"]=="POST") {
00268          apply_triggers();
00269        }
00270        print_triggers($filter, $minnum, $maxnum,$rephead);
00271      exit (0);
00272      case "latency":
00273      case "latencies":
00274        if ($_SERVER["REQUEST_METHOD"]=="POST") {
00275          apply_latencies();
00276        }
00277        print_latencies();
00278      exit (0);
00279      default:
00280 
00281       echo <<<USAGE
00282    <p>This page allows to tune camera sequencer at run time, those adjustments to be applied to C headers of the drivers:
00283    <a href="http://elphel.cvs.sourceforge.net/viewvc/elphel/elphel353-7.2/os/linux-2.6-tag--devboard-R2_10-4/arch/cris/arch-v32/drivers/elphel/param_depend.h?view=markup">latency.h</a> and
00284    <a href="http://elphel.cvs.sourceforge.net/viewvc/elphel/elphel353-7.2/os/linux-2.6-tag--devboard-R2_10-4/arch/cris/arch-v32/drivers/elphel/param_depend.h?view=markup">param_depend.h</a></p>
00285    <p>First mode is used to specify latency (in frames) for different actions, additionally it specifies which actions can use hardware sequencer (some, like writing gamma tables to FPGA
00286       can only be performed in "ASAP" mode, bypassing the sequencer)</p>
00287    <h4> <a href="$self?mode=latency">mode=latency</a></h4>
00288    <p>The second one can be used to specify which functions are triggered by chnage in which parameters (either from user program or sometimes by actions of other functions).</p>
00289    <h4> <a href="$self?mode=triggers">mode=triggers</a></h4>
00290    <p>This mode can generate large tables, so it is possible to limit number of parameters shown,/p>
00291    <ul>
00292     <li><b>filter=N</b> (N=0..3), where 1 means "ignore unnamed parameters", 2 - "ignore parameters with a value 0", 3 - ignore both and 0 - show all<b></li>
00293     <li><b>min=N</b> - start with parameter number <b>N</b></li>
00294     <li><b>max=N</b> - end with parameter number <b>N</b></li>
00295     <li><b>rephead=N</b> - repeat table header each <b>N</b> lines.</li>
00296   </ul>
00297   <p>Example: <a href="$self?mode=triggers&filter=1&min=40&max=60">?mode=triggers&filter=1&min=40&max=60</a></p>
00298 USAGE;
00299        exit (0);
00300    } 
00301 
00302 ?>

Generated on Fri Nov 28 00:06:25 2008 for elphel by  doxygen 1.5.1