packages/web/353/php_top/framepars.php

Go to the documentation of this file.
00001 <?php
00002 /*!*******************************************************************************
00003 *! FILE NAME  : framepars.php
00004 *! DESCRIPTION: Provides control of FPGA compressor/image acquisition
00005 *!              to the circular buffer (circbuf)
00006 *! Copyright (C) 2007-2008 Elphel, Inc
00007 *! -----------------------------------------------------------------------------**
00008 *!
00009 *!  This program is free software: you can redistribute it and/or modify
00010 *!  it under the terms of the GNU General Public License as published by
00011 *!  the Free Software Foundation, either version 3 of the License, or
00012 *!  (at your option) any later version.
00013 *!
00014 *!  This program is distributed in the hope that it will be useful,
00015 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 *!  GNU General Public License for more details.
00018 *!
00019 *!  You should have received a copy of the GNU General Public License
00020 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 *! -----------------------------------------------------------------------------**
00022 *!  $Log: framepars.php,v $
00023 *!  Revision 1.1.1.1  2008/11/27 20:04:03  elphel
00024 *!
00025 *!
00026 *!  Revision 1.26  2008/11/27 09:29:22  elphel
00027 *!  new file - diag_utils.php that includes somewhat cleaned-up version of utilities from framepars.php. That file installation  is moved to attic
00028 *!
00029 *!  Revision 1.25  2008/11/17 23:42:04  elphel
00030 *!  changed myval() to accept numbers in ""
00031 *!
00032 *!  Revision 1.24  2008/11/13 05:40:45  elphel
00033 *!  8.0.alpha16 - modified histogram storage, profiling
00034 *!
00035 *!  Revision 1.23  2008/11/04 17:45:08  elphel
00036 *!  added interface for testing new functions: elphel_gamma(), elphel_reverse_gamma(), elphel_histogram(), elphel_reverse_histogram(); links to individual gamma pages in the cache from "framepars.php?gamma_structure"
00037 *!
00038 *!  Revision 1.22  2008/10/31 18:26:32  elphel
00039 *!  Adding support for constants like SENSOR_REGS32 (defined constant plus 32 to simplify referencing sensor registers from PHP
00040 *!
00041 *!  Revision 1.21  2008/10/29 04:18:28  elphel
00042 *!  v.8.0.alpha10 made a separate structure for global parameters (not related to particular frames in a frame queue)
00043 *!
00044 *!  Revision 1.20  2008/10/28 07:03:03  elphel
00045 *!  reports error when wrong constant name is entered (before in silently used 0)
00046 *!
00047 *!  Revision 1.19  2008/10/23 18:26:15  elphel
00048 *!  Fixed percentile calculations in histograms
00049 *!
00050 *!  Revision 1.18  2008/10/23 08:11:58  elphel
00051 *!  support for histograms testing
00052 *!
00053 *!  Revision 1.17  2008/10/22 03:47:45  elphel
00054 *!  minor
00055 *!
00056 *!  Revision 1.16  2008/10/21 21:29:15  elphel
00057 *!  using support fro xml output in imgsrv
00058 *!
00059 *!  Revision 1.15  2008/10/21 04:22:57  elphel
00060 *!  XTRA_FPGA=1000 is included in cmd=init
00061 *!
00062 *!  Revision 1.14  2008/10/19 07:01:24  elphel
00063 *!  updated to use  elphel_skip_frames();
00064 *!
00065 *!  Revision 1.13  2008/10/18 06:16:49  elphel
00066 *!  changing test modes, init does not start compressor
00067 *!
00068 *!  Revision 1.12  2008/10/15 22:28:56  elphel
00069 *!  snapshot 8.0.alpha2
00070 *!
00071 *!  Revision 1.11  2008/10/13 16:57:18  elphel
00072 *!  switched to ELPHEL_* defined constants from locally defined ones
00073 *!
00074 *!  Revision 1.10  2008/10/13 04:48:25  elphel
00075 *!  added sample gamma initialization to cmd=init
00076 *!
00077 *!  Revision 1.8  2008/10/11 18:46:07  elphel
00078 *!  snapshot
00079 *!
00080 *!  Revision 1.7  2008/10/10 17:06:59  elphel
00081 *!  just a snapshot
00082 *!
00083 *!  Revision 1.6  2008/10/06 08:31:08  elphel
00084 *!  snapshot, first images
00085 *!
00086 *!  Revision 1.5  2008/10/05 05:13:33  elphel
00087 *!  snapshot003
00088 *!
00089 *!  Revision 1.4  2008/10/04 16:10:12  elphel
00090 *!  snapshot
00091 *!
00092 *!  Revision 1.3  2008/09/28 00:31:57  elphel
00093 *!  snapshot
00094 *!
00095 *!  Revision 1.2  2008/09/25 00:58:12  elphel
00096 *!  snapshot
00097 *!
00098 *!  Revision 1.1  2008/09/22 22:55:50  elphel
00099 *!  snapshot
00100 *!
00101 */
00102 
00103 function myval ($s) {
00104   $s=trim($s,"\" ");
00105   if (strtoupper(substr($s,0,2))=="0X")   return intval(hexdec($s));
00106   else return intval($s);
00107 }
00108    $imgsrv="http://".$_SERVER['SERVER_ADDR'].":8081";
00109    if (count($_GET)==0) {
00110          echo <<<USAGE
00111    <p>This is a collection of tools for the 8.0 software development/testing, you can provide parameters in HTTP GET request.</p>
00112    <p>At this alpha stage very few programs/pages are working, among them:</p>
00113    <ul>
00114     <li><a href="tuneseq.php">tuneseq.php</a> - run-time tuning of sequencer latencies;</li>
00115     <li><a href="$imgsrv">imgsrv</a> getting images from the camera internal buffer (you have to acquire them there first)</li>
00116     <li><a href="var/klog.txt">var/klog.txt</a> - read kernel messages (you first need to telnet to the camera and run "printk_mod &amp;" and enable some of the DEBUG bits)</li>
00117    </ul>
00118    <h4>Make sure to run "printk_mod &amp;" before enabling debug bits - some are from interrupt service routine, and default printk() output to console can really mess up things.</h4>
00119    <p>Here are some of the current options</p>
00120    <ul>
00121     <li><b>cmd=</b> - execute one of the following commands:
00122        <ul>
00123          <li><a href="?cmd=init">init</a> - initialize camera, detect sensor, put some gamma-table, start compressor. After that you may acquire image with
00124              <a href="$imgsrv/img">$imgsrv/img</a></li>
00125          <li><a href="?cmd=constants">constants</a> - list all Elphel-defined constants available in PHP scripts </li>
00126          <li><a href="?cmd=gamma">gamma</a> - change gamma table (no gamma settings yet)</li>
00127          <li><a href="?cmd=0">0</a> - show current frame (sensor frame - it is incrementead even if compressor is off), frame8 - hardware modulo 8 sequencer counter</li>
00128          <li><a href="?cmd=jpegheader">jpegheader</a> - show current frame JPEG header</li>
00129       </ul>
00130       <p> There are some other options left out in the code, but they are not needed anymore - some others may be added
00131     </li>
00132     <li><b>a=A&amp;d=D&amp;=N[&amp;frame=F[&amp;flags=G]]</b> - Set parameter <b>A</b> with data<b>D</b> (hex data may be used).
00133                Address can also use defined constant names (w/o "ELPHEL_" prefix). <b>F</b> - absolute frame number (most likely will fail) or one of
00134                <b>this</b>, <b>next</b>, <b>next2</b>, <b>next3</b>, <b>next4</b>, <b>next5</b>, <b>next6</b> (next4 is usually safe to use). <G> - flags/modifiers - numeric value or "s" - static/not frame-related parameter or "n" - new parameter (force to be treated as new even if the value is the same as was before) </li>
00135     <li><b>na=A&amp;d=D&amp;=N[&amp;frame=F[&amp;test=1]]</b> - shortcut for the previous command with the flag "n" (force new).      test=1 - show a series of images around test command, i.e. <a href="?na=WOI_WIDTH&d=0xa20&frame=next3&test=1">na=WOI_WIDTH&amp;d=0xa20&amp;frame=next3&amp;test=1</a> would run compressor, skip 2 frames, change WOI_WIDTH 3 frames in the future, wait 4 frames and stop compressor. Then show last acquired images in a table.</li>
00136     <li><b>sa=A&amp;d=D&amp;=N</b> -  shortcut with the flag "s" (static), i.e. <a href="?sa=DEBUG&d=0">sa=DEBUG&amp;d=0</a> - turn debug logging off<br/></li>
00137     <li><b>frame=F</b> - Print raw frame parameters data for frame <b>F</b>. Valid values 0..7 and -1 (that will show function triggers instead of the parameter values). Frame 0 also hold "static" parameters - when written with "s" flags they only go there other parameters propagate to the future frames during frame interrupts.</li>
00138     <li><b>"gamma_structure</b> - show structure of the gamma tables cache. Gamma cache consists of 255 pages and index one, based on linked lists. It is designed to minimize floating point calcualions (made outside of the kernel) and facilitate scaling (integer) needed fro white balancing. So the "prototype" (non-scaled curves are cached in the top list with connected lists of scaled derivatives. For each table there are several sub-tables that can be requested (and cached after that) - reverse table (for histogram processing) and FPGA table (formatted to be written to the FPGA). Each gamma "type" is marked with a 16-bit hash, by default calculated as gamma value (in percents, 8 bits) and black level shift (fat zero), but it is possible to load arbitrary table and mark it with unique 16-bit hash16. When the curve is loaded it can be send to any of the 4 color channels with arbitrary 16-bit scale (0x400 is 1.0) by writing to one of GTAB_R, GTAB_G, GTAB_GB or GTAB_B registers (16 higher bits - hash16, lower 16 - scale, it is possible to change any set of bytes of the 32-bit word adding byte masks to the flags     ELPHEL_CONST_FRAMEPAIR_BYTE0, ELPHEL_CONST_FRAMEPAIR_BYTE1, ELPHEL_CONST_FRAMEPAIR_BYTE2, ELPHEL_CONST_FRAMEPAIR_BYTE3, ELPHEL_CONST_FRAMEPAIR_WORD0,FRAMEPAIR_WORD1.</li>
00139     <li><b>"gamma=G</b> - show raw data of the gamma page <b>G</b> (page 0 is a root)</li>
00140   </ul>
00141 USAGE;
00142        exit (0);
00143 }
00144 //$_SERVER["SERVER_ADDR"] . ":8081
00145     $address="";
00146     $data="";
00147     $frame="";
00148     $gamma_page="";
00149     $flags=0;
00150     $elp_const=get_defined_constants(true);
00151     $elp_const=$elp_const["elphel"];
00152     $test=0;
00153     $hist_needed=0;
00154      foreach($_GET as $key=>$value) {
00155        switch($key) {
00156        case "profile":
00157 $num_entries=myval($value);
00158 //echo "<pre>";
00159  $prof_template=array(
00160                  "PROFILE00"=>0,"PROFILE01"=>0,
00161                  "PROFILE02"=>0,"PROFILE03"=>0,
00162                  "PROFILE04"=>0,"PROFILE05"=>0,
00163                  "PROFILE06"=>0,"PROFILE07"=>0,
00164                  "PROFILE08"=>0,"PROFILE09"=>0,
00165                  "PROFILE10"=>0,"PROFILE11"=>0,
00166                  "PROFILE12"=>0,"PROFILE13"=>0,
00167                  "PROFILE14"=>0,"PROFILE15"=>0
00168 );
00169  $now=elphel_get_frame()-2; 
00170  $time_start=elphel_get_fpga_time();
00171  $prof_raw=array();
00172  for ($i=$now-$num_entries-1;$i<=$now;$i++) {
00173    $prof_raw[$i]=elphel_get_P_arr($prof_template,$i);
00174  }
00175 $time_end=elphel_get_fpga_time();
00176  $prof=array();
00177  for ($i=$now-$num_entries;$i<=$now;$i++) {
00178    $prof[$i]=array ( "dt0"=>($prof_raw[$i]["PROFILE00"]-$prof_raw[$i-1]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE01"]-$prof_raw[$i-1]["PROFILE01"]),
00179                      "dt1"=>($prof_raw[$i]["PROFILE02"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE03"]-$prof_raw[$i]["PROFILE01"]),
00180                      "dt2"=>($prof_raw[$i]["PROFILE04"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE05"]-$prof_raw[$i]["PROFILE01"]),
00181                      "dt3"=>($prof_raw[$i]["PROFILE06"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE07"]-$prof_raw[$i]["PROFILE01"]),
00182                      "dt4"=>($prof_raw[$i]["PROFILE08"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE09"]-$prof_raw[$i]["PROFILE01"]),
00183                      "dt5"=>($prof_raw[$i]["PROFILE10"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE11"]-$prof_raw[$i]["PROFILE01"]),
00184                      "dt6"=>($prof_raw[$i]["PROFILE12"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE13"]-$prof_raw[$i]["PROFILE01"]),
00185                      "dt7"=>($prof_raw[$i]["PROFILE14"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE15"]-$prof_raw[$i]["PROFILE01"]));
00186    foreach ($prof[$i] as $key=>$value) if ($prof[$i][$key]<0)$prof[$i][$key]="";
00187  }
00188 
00189  echo <<<CAPTION
00190 <p>reading profile time start=$time_start </p>
00191 <p>reading profile time end=$time_end </p>
00192 <ol>Profiling interrupt/tasklet execution time in microseconds, starting from the start of the frame
00193   <li>after updating frame pointers, Exif, parameters structures (IRQ service)</li>
00194   <li>start of the tasklet</li>
00195   <li>after Y histogram (G1) load from the FPGA (if enabled)</li>
00196   <li>after processing parameters (actions triggered by the parameter changes), </li>
00197   <li>after C histograms (R,G2,B) load from the FPGA (if enabled)</li>
00198   <li>When parameters are started to be written by appliaction(s) - overwritten if several calls take place during the same frame</li>
00199   <li>When parameters are finished to be written by appliaction(s) (may be  overwritten)</li>
00200 </oul>
00201 <br/><br/>
00202 CAPTION;
00203 
00204  printf ("<table border='1'><tr><td>Frame</td><td>(hex)</td><td>Period</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>\n");
00205  for ($i=$now-$num_entries;$i<=$now;$i++) {
00206    printf("<tr style='align:right'><td>%d</td><td>%08x</td><td>%d</td>",$i,$i,$prof[$i]["dt0"]);
00207    for ($j=1;$j<8;$j++) {
00208      if ($prof[$i]["dt".$j]) printf("<td>%d</td>",$prof[$i]["dt".$j]);
00209      else                    printf("<td>&nbsp;</td>");
00210    }
00211    printf("</tr>\n");
00212  }
00213  printf("</table>");
00214 //echo "<pre>";print_r($prof_raw);echo"</pre>\n";
00215 
00216          exit (0);
00217        case "histogram_direct":
00218        case "histogram_reverse":
00219        case "gamma_direct":
00220        case "gamma_reverse":
00221           $xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
00222           $value=floatval($value);
00223           switch($key) {
00224             case "histogram_direct":
00225               $xml->addChild ('histogram_direct_r', elphel_histogram(0,$value));
00226               $xml->addChild ('histogram_direct_g', elphel_histogram(1,$value));
00227               $xml->addChild ('histogram_direct_gb',elphel_histogram(2,$value));
00228               $xml->addChild ('histogram_direct_b', elphel_histogram(3,$value));
00229               break;
00230             case "histogram_reverse":
00231               $xml->addChild ('histogram_reverse_r', elphel_reverse_histogram(0,$value));
00232               $xml->addChild ('histogram_reverse_g', elphel_reverse_histogram(1,$value));
00233               $xml->addChild ('histogram_reverse_gb',elphel_reverse_histogram(2,$value));
00234               $xml->addChild ('histogram_reverse_b', elphel_reverse_histogram(3,$value));
00235               break;
00236             case "gamma_direct":
00237               $xml->addChild ('gamma_direct_r', elphel_gamma(0,$value));
00238               $xml->addChild ('gamma_direct_g', elphel_gamma(1,$value));
00239               $xml->addChild ('gamma_direct_gb',elphel_gamma(2,$value));
00240               $xml->addChild ('gamma_direct_b', elphel_gamma(3,$value));
00241               break;
00242             case "gamma_reverse":
00243               $xml->addChild ('gamma_reverse_r', elphel_reverse_gamma(0,$value));
00244               $xml->addChild ('gamma_reverse_g', elphel_reverse_gamma(1,$value));
00245               $xml->addChild ('gamma_reverse_gb',elphel_reverse_gamma(2,$value));
00246               $xml->addChild ('gamma_reverse_b', elphel_reverse_gamma(3,$value));
00247               break;
00248           }
00249          $rslt=$xml->asXML();
00250          header("Content-Type: text/xml");
00251          header("Content-Length: ".strlen($rslt)."\n");
00252          header("Pragma: no-cache\n");
00253          printf($rslt);
00254          exit (0);
00255        case "cmd":
00256        case "seek":
00257        case "fseek":
00258        case "lseek":
00259          $xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
00260          if (!$value) {
00261            $xml->addChild ('frame',elphel_get_frame());
00262            $xml->addChild ('frame8',elphel_fpga_read(0x16) & 7);
00263          } else if ($value=="time"){
00264            $xml->addChild ('fpga_time',elphel_get_fpga_time());
00265          } else if ($value=="irqoff"){
00266            $framepars_file=fopen("/dev/frameparsall","r");
00267            $xml->addChild ('irqoff_result',fseek($framepars_file,ELPHEL_LSEEK_INTERRUPT_OFF,SEEK_END)); //#define      LSEEK_INTERRUPT_OFF  0x23 /// disable camera interrupts
00268            fclose($framepars_file);
00269          } else if ($value=="irqon"){
00271            while (elphel_fpga_read(0x16) & 7) usleep (1000); 
00272            $framepars_file=fopen("/dev/frameparsall","r");
00273            $xml->addChild ('irqon_result',fseek($framepars_file,ELPHEL_LSEEK_INTERRUPT_ON,SEEK_END)); //#define      LSEEK_INTERRUPT_ON   0x24 /// enable camera interrupts
00274            fclose($framepars_file);
00275          } else if ($value=="init"){
00276            $framepars_file=fopen("/dev/frameparsall","r");
00277            $xml->addChild ('LSEEK_FRAMEPARS_INIT',fseek($framepars_file,ELPHEL_LSEEK_FRAMEPARS_INIT,SEEK_END));
00278            $xml->addChild ('elphel_set_P_value',  elphel_set_P_value(ELPHEL_SENSOR, 0x00, 0, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC));
00279            $xml->addChild ('LSEEK_SENSORPROC',    fseek($framepars_file,ELPHEL_LSEEK_SENSORPROC,    SEEK_END));
00280            $frame=0;
00281 // gets half-frame
00282 /*
00283            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00284            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00285            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00286            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00287            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00288            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00289 */
00290 /*
00291 //works
00292            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00293            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00294            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00295            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00296            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00297            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00298 */
00299 /*
00300 wrong
00301            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00302            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00303            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00304            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00305            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00306            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00307 
00308            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00309            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00310            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00311            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00312            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00313            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00314 
00315 */
00316 /*
00317            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00318            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00319            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00320            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00321            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00322            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+5, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00323 */
00324 
00325            elphel_set_P_value(ELPHEL_MAXAHEAD,               2, 0, 8); 
00326 
00327            elphel_set_P_value(ELPHEL_FPGA_XTRA,                  1000, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC); 
00328            elphel_set_P_value(ELPHEL_EARLY_TIMESTAMP,        1, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC); 
00329 
00331 
00332            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00333            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00334            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00335            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00336            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00337            elphel_set_P_value(ELPHEL_BAYER,                  0, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00338            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00339            elphel_set_P_value(ELPHEL_COMPRESSOR_RUN,         2, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC); 
00340 
00341 /*
00342            elphel_set_P_value(ELPHEL_BITS,                   8, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00343            elphel_set_P_value(ELPHEL_QUALITY,               80, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00344            elphel_set_P_value(ELPHEL_COLOR,                  1, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00345            elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00346            elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00347            elphel_set_P_value(ELPHEL_SENSOR_RUN,             2, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
00348 */
00349 
00350            fclose($framepars_file);
00351 /*
00352          } else if ($value=="gamma1"){
00353 */
00354            $gamma=57;
00355            $black=10;
00356            $scale_r= (int) (1.0 * 1024);
00357            $scale_g= (int) (0.9 * 1024);
00358            $scale_b= (int) (1.1 * 1024);
00359            $scale_gb=(int) (0.9 * 1024);
00360            elphel_gamma_add (0.01*$gamma, $black);
00361 #define P_GTAB_R         138 // combines (P_PIXEL_LOW<<24) | (P_GAMMA <<16) and 16-bit (6.10) scale for gamma tables, individually for each color.
00362                              //  16Msbs are also "hash16" and do not need to be black level/gamma, just uniqualy identify the table for applications
00363            $gamma_pars=array("GTAB_R"   => ($black<<24) | ($gamma << 16) | ($scale_r  & 0xffff),
00364                              "GTAB_G"   => ($black<<24) | ($gamma << 16) | ($scale_g  & 0xffff),
00365                              "GTAB_B"   => ($black<<24) | ($gamma << 16) | ($scale_b  & 0xffff),
00366                              "GTAB_GB"  => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
00367            $frame=elphel_get_frame(); //0
00368            elphel_set_P_arr ($gamma_pars, $frame+3,0);
00369          } else if ($value=="gamma57"){
00370            $gamma=57;
00371            $black=10;
00372            $scale_r= (int) (1.0 * 1024);
00373            $scale_g= (int) (1.0 * 1024);
00374            $scale_b= (int) (1.0 * 1024);
00375            $scale_gb=(int) (1.0 * 1024);
00376            elphel_gamma_add (0.01*$gamma, $black);
00377 #define P_GTAB_R         138 // combines (P_PIXEL_LOW<<24) | (P_GAMMA <<16) and 16-bit (6.10) scale for gamma tables, individually for each color.
00378                              //  16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
00379            $gamma_pars=array("GTAB_R"   => ($black<<24) | ($gamma << 16) | ($scale_r  & 0xffff),
00380                              "GTAB_G"   => ($black<<24) | ($gamma << 16) | ($scale_g  & 0xffff),
00381                              "GTAB_B"   => ($black<<24) | ($gamma << 16) | ($scale_b  & 0xffff),
00382                              "GTAB_GB"  => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
00383            $frame=elphel_get_frame(); //0
00384            elphel_set_P_arr ($gamma_pars, $frame+3,0);
00385          } else if ($value=="gamma"){
00386            $gamma=60;
00387            $black=10;
00388            $scale_r= (int) (1.0 * 1024);
00389            $scale_g= (int) (0.9 * 1024);
00390            $scale_b= (int) (1.1 * 1024);
00391            $scale_gb=(int) (0.9 * 1024);
00392            elphel_gamma_add (0.01*$gamma, $black);
00393 #define P_GTAB_R         138 // combines (P_PIXEL_LOW<<24) | (P_GAMMA <<16) and 16-bit (6.10) scale for gamma tables, individually for each color.
00394                              //  16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
00395            $gamma_pars=array("GTAB_R"   => ($black<<24) | ($gamma << 16) | ($scale_r  & 0xffff),
00396                              "GTAB_G"   => ($black<<24) | ($gamma << 16) | ($scale_g  & 0xffff),
00397                              "GTAB_B"   => ($black<<24) | ($gamma << 16) | ($scale_b  & 0xffff),
00398                              "GTAB_GB"  => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
00399            $frame=elphel_get_frame(); //0
00400            elphel_set_P_arr ($gamma_pars, $frame+3,0);
00401          } else if ($value=="linear"){
00402            $gamma=100;
00403            $black=0;
00404            $scale_r= (int) (1.0 * 1024);
00405            $scale_g= (int) (1.0 * 1024);
00406            $scale_b= (int) (1.0 * 1024);
00407            $scale_gb=(int) (1.0 * 1024);
00408            elphel_gamma_add (0.01*$gamma, $black);
00409 #define P_GTAB_R         138 // combines (P_PIXEL_LOW<<24) | (P_GAMMA <<16) and 16-bit (6.10) scale for gamma tables, individually for each color.
00410                              //  16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
00411            $gamma_pars=array("GTAB_R"   => ($black<<24) | ($gamma << 16) | ($scale_r  & 0xffff),
00412                              "GTAB_G"   => ($black<<24) | ($gamma << 16) | ($scale_g  & 0xffff),
00413                              "GTAB_B"   => ($black<<24) | ($gamma << 16) | ($scale_b  & 0xffff),
00414                              "GTAB_GB"  => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
00415            $frame=elphel_get_frame(); //0
00416            elphel_set_P_arr ($gamma_pars, $frame+3,0);
00417          } else if ($value=="initgamma"){
00418            $gammas_file=fopen("/dev/gamma_cache","r");
00419            $xml->addChild ('LSEEK_GAMMA_INIT',fseek($gammas_file,ELPHEL_LSEEK_GAMMA_INIT,SEEK_END));
00420            fclose($gammas_file);
00421          } else if ($value=="jpegheader"){
00422            $circbuf_file=fopen("/dev/circbuf","r");
00423            fseek($circbuf_file,ELPHEL_LSEEK_CIRC_LAST,SEEK_END);
00424            $jpeg_start=ftell($circbuf_file);
00425            $xml->addChild ('circbuf_pointer',sprintf("0x%x (0x%x)",$jpeg_start,$jpeg_start>>2));
00426            fclose($circbuf_file);
00427            $header_file=fopen("/dev/jpeghead","r");
00429            fseek($header_file,$jpeg_start+1,SEEK_END); 
00430            fseek($header_file,0,SEEK_END);   
00431            $header_size=ftell($header_file); 
00432            $xml->addChild ('header_size',$header_size);
00433            fseek($header_file,0,SEEK_SET);   
00434            $header=fread ($header_file,8192);
00435            $xml->addChild ('header_read_length',strlen($header));
00436            fclose($header_file);
00437            $aheader=unpack('C*',$header);
00438            for ($i=0; $i<count($aheader) ;$i+=16){
00439              $d="";
00440              for ($j=$i; ($j<$i+16) && ($j<count($aheader)); $j++)  $d.=sprintf(" %02x",$aheader[$j+1]);
00441              $xml->addChild (sprintf('header%03x',$i),$d);
00442            }
00443          } else if ($value=="reset"){
00444            $framepars_file=fopen("/dev/frameparsall","r");
00445            $xml->addChild ('LSEEK_DMA_STOP',  fseek($framepars_file,ELPHEL_LSEEK_DMA_STOP,SEEK_END));
00446            $xml->addChild ('LSEEK_DMA_INIT',  fseek($framepars_file,ELPHEL_LSEEK_DMA_INIT,SEEK_END));
00447            $xml->addChild ('COMPRESSOR_RESET',  fseek($framepars_file,ELPHEL_COMPRESSOR_RESET,SEEK_END));
00448            fclose($framepars_file);
00449          } else if  ($value=="constants"){
00450            echo "<pre>\n";
00451            print_r($elp_const);
00452            echo "</pre>\n";
00453            exit(0);
00454          } else {
00455            $framepars_file=fopen("/dev/frameparsall","r");
00456            $xml->addChild ('lseek_'.$value,fseek($framepars_file,$value,SEEK_END));
00457            fclose($framepars_file);
00458          }
00459 
00460 
00461          $rslt=$xml->asXML();
00462          header("Content-Type: text/xml");
00463          header("Content-Length: ".strlen($rslt)."\n");
00464          header("Pragma: no-cache\n");
00465          printf($rslt);
00466          exit (0);
00467        case "a": 
00468        case "adr":
00469        case "na": 
00470        case "sa": 
00471          $address=myval ($value);
00472          if (($address==0) && (strlen($value)>3)) { // suspect constant
00473            $address=$elp_const["ELPHEL_".$value];
00474          }
00475          switch ($key){
00476            case "na": 
00477               $address |= ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC;;
00478               break;
00479            case "sa":
00480               $address |= ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO;
00481               break;
00482          }
00483          if (($address & 0xffff) ==0) { 
00484            $xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
00485            $xml->addChild ('ERROR','"Wrong address==0, probably misspelled constant: \''.$value.'\'"' );
00486            $rslt=$xml->asXML();
00487            header("Content-Type: text/xml");
00488            header("Content-Length: ".strlen($rslt)."\n");
00489            header("Pragma: no-cache\n");
00490            printf($rslt);
00491            exit (0);
00492          }
00493          break;
00494        case "d":
00495        case "data":
00496          $data=myval ($value);
00497          break;
00498        case "hist_raw":
00499          $hist_needed++;
00500        case "hist":
00501        case "histogram":
00502          $hist_needed++; 
00503        case "f":
00504        case "frame":
00505          $current_frame=elphel_get_frame();
00506          switch ($value) {
00507            case "this": $frame=$current_frame;
00508               break;
00509            case "next": $frame=$current_frame+1;
00510               break;
00511            case "next2": $frame=$current_frame+2;
00512               break;
00513            case "next3": $frame=$current_frame+3;
00514               break;
00515            case "next4": $frame=$current_frame+4;
00516               break;
00517            case "next5": $frame=$current_frame+5;
00518               break;
00519            case "next6": $frame=$current_frame+6;
00520               break;
00521               break;
00522            case "prev": $frame=$current_frame-1;
00523               break;
00524            case "prev2": $frame=$current_frame-2;
00525               break;
00526            case "prev3": $frame=$current_frame-3;
00527               break;
00528            case "prev4": $frame=$current_frame-4;
00529               break;
00530            case "prev5": $frame=$current_frame-5;
00531               break;
00532            case "prev6": $frame=$current_frame-6;
00533               break;
00534            default:
00535              $frame=myval ($value);
00536          }
00537          break;
00538        case "flags": 
00539        case "flag":
00540          switch ($value) {
00541           case "z":
00542           case "zero":
00543           case "s":
00544           case "static":
00545             $flags=ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO;
00546             break;
00547           case "n":
00548           case "new":
00549             $flags=ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC;
00550             break;
00551           default:
00552           $flags=myval ($value);
00553          }
00554          break;
00555        case "t":
00556        case "test":
00557          $test=myval ($value);
00558          break;
00559        case "gamma":
00560        case "gamma_page":
00561          $gamma_page=myval ($value);
00562          break;
00563        case "gamma_structure":
00565          printGammaStructure();
00566 /*         echo "<pre>\n";
00567          var_dump(getGammaStructure());
00568          echo "</pre>\n";*/
00569          exit (0);
00570       }
00571     }
00572     if ($address==="") {
00573       if ($frame==="") {
00574         if ($gamma_page==="") {
00575         echo <<<USAGE
00576    <p>read/fwrite frame parameters, execute commands</p>
00577    <ul>
00578     <li><b>framepars.php?cmd=<i>command number</i></b> -  execute <i>register_address</i></li>
00579     <li><b>framepars.php?a[dr]=<i>register_address</i>[&f[rame]=<i>frame_number</i>]</b> -  read frame parameter <i>register_address</i> from <i>frame_number</i></li>
00580     <li><b>framepars.php?a[dr]=<i>register_address</i>&d[ata]=<i>register_data</i>[&f[rame]=<i>frame_number</i>][&flag[s]=<i>flags</i>]</b> -  write frame parameter <i>register_address</i> with data <i>register_data</i> to frame <i>frame_number</i>, optionally use <i>flags</i></li>
00581   </ul>
00582 USAGE;
00583         exit (0);
00584         } else {
00586           printRawGamma($gamma_page);
00587           exit (0);
00588 
00589         }
00590       } else { 
00591         switch ($hist_needed) {
00592           case 2:
00593             printRawHistogram(0xfff,$frame);
00594             exit (0);
00595           case 1:
00596             printHistogram($frame);
00597             exit (0);
00598           default:
00600             printRawFrame($frame);
00601             exit (0);
00602         }
00603       }
00604     }
00605     $xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
00606     $xml->addChild ('frame',$frame);
00607     $xml->addChild ('hex_frame',sprintf("0x%x",$frame));
00608     $xml->addChild ('address',$address);
00609     $xml->addChild ('hex_address',sprintf("0x%x",$address));
00610     if ($data==="") {
00611        if ($frame==='') $data=elphel_get_P_value($address);
00612        else             $data=elphel_get_P_value($address, $frame);
00613        $xml->addChild ('read',$data);
00614        $xml->addChild ('hex_read',sprintf("0x%x",$data));
00615     } else {
00616        if (($frame==='') && flags) $frame =0; 
00617        $xml->addChild ('frame_was',$frame);
00619        if ($test>0) {
00620      ob_flush();  flush();
00621 
00622          elphel_set_P_value(ELPHEL_COMPRESSOR_RUN | ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC, ELPHEL_CONST_COMPRESSOR_RUN_CONT, $current_frame+2);
00623          $frame+=2;
00624          $current_frame+=2;
00625          elphel_skip_frames(2);
00626        }
00627        if ($frame==='') elphel_set_P_value($address, $data);
00628        else             elphel_set_P_value($address, $data, $frame, $flags);
00629        if ($test>0) {
00630          printf ("<p><a href=\"%s/prev/prev/prev/prev/prev/prev/prev/prev/meta/next/meta/next/meta/next/meta/next/meta/next/meta/next/meta/next/meta/next/meta\">meta data for the last 9 frames</a></p>\n", $imgsrv);
00631          ob_flush();  flush(); 
00632          $circbuf_file=fopen("/dev/circbuf","r");
00633          $current_frame=$frame;
00634          printf ("<p>frame=%d (0x%x), time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00635          elphel_skip_frames(2);
00636          printf ("<p>target frame=%d (0x%x) frame=%d(0x%x), time=%d </p>\n",$frame, $frame, elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00637 //         printf ("<p>start_frame2=0x%x</p>\n",$current_frame);
00638 
00639          elphel_set_P_value(ELPHEL_COMPRESSOR_RUN | ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC, ELPHEL_CONST_COMPRESSOR_RUN_STOP, $current_frame+4);
00640          printf ("<p>frame=%d (0x%x), time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00641          $current_frame+=6; 
00642          for ($i=0;$i<6;$i++) {
00643            elphel_skip_frames(1);
00644            printf ("<p>skipped 1 frame - frame=%d (0x%x), time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00645          }
00646 //         elphel_skip_frames(6);
00647 //         printf ("<p>after skip 6 frames - frame=0x%x, time=%d </p>\n",elphel_get_frame(),time());  ob_flush();  flush();
00648          fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
00650          printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00651          elphel_skip_frames(1);
00652          fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
00653          printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00654          elphel_skip_frames(1);
00655          fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
00656          printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00657          elphel_skip_frames(1);
00658          fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
00659          printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time());  ob_flush();  flush();
00660 
00662 //         printf ("<p>end_frame2=0x%x</p>\n",elphel_get_frame());
00663          fclose($circbuf_file);
00664 
00665          image_table8 ();
00666          exit (0); 
00667          $xml->addChild ('test',$test);
00668        }
00669        $xml->addChild ('frame',$frame);
00670        $xml->addChild ('written',$data);
00671        $xml->addChild ('hex_written',sprintf("0x%x",$data));
00672        $xml->addChild ('flags',sprintf("0x%x",$flags));
00673     }
00674     $rslt=$xml->asXML();
00675     header("Content-Type: text/xml");
00676     header("Content-Length: ".strlen($rslt)."\n");
00677     header("Pragma: no-cache\n");
00678     printf($rslt);
00679     exit (0);
00680 function printGammaStructure() {
00681   $gammaStructure=getGammaStructure();
00682    printf("<table \"border=1\">\n");
00683    printf(       "<tr><td>oldest_non_scaled</td><td><b>%d</b></td></tr>\n"
00684                 ."<tr><td>newest_non_scaled</td><td><b>%d</b></td></tr>\n"
00685                 ."<tr><td>oldest_all</td><td><b>%d</b></td></tr>\n"
00686                 ."<tr><td>newest_all</td><td><b>%d</b></td></tr>\n"
00687                 ."<tr><td>non_scaled_length</td><td><b>%d</b></td></tr>\n"
00688                 ."<tr><td>num_locked</td><td><b>%d</b></td></tr>\n"
00689                 ."<tr><td>locked_col 0</td><td><b>%d</b></td>\n"
00690                 ."<tr><td>locked_col 1</td><td><b>%d</b></td>\n"
00691                 ."<tr><td>locked_col 2</td><td><b>%d</b></td>\n"
00692                 ."<tr><td>locked_col 3</td><td><b>%d</b></td>\n"
00693                 ."</table>\n",
00694                 $gammaStructure["oldest_non_scaled"],
00695                 $gammaStructure["newest_non_scaled"],
00696                 $gammaStructure["oldest_all"],
00697                 $gammaStructure["newest_all"],
00698                 $gammaStructure["non_scaled_length"],
00699                 $gammaStructure["num_locked"],
00700                 $gammaStructure["locked_col"][0],
00701                 $gammaStructure["locked_col"][1],
00702                 $gammaStructure["locked_col"][2],
00703                 $gammaStructure["locked_col"][3]
00704 );
00705     printf("<br/><br/>\n");
00706 
00707     printf("<table \"border=1\">\n");
00708 //    printf("<tr><td>index           </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["index"]);printf("</tr>\n");
00709     printf("<tr><td>index           </td>\n"); foreach ($gammaStructure["entries"] as $entry)
00710        printf ("<td><a href='?gamma_page=%d'><b>%d</b></a></td>",$entry["index"],$entry["index"]);printf("</tr>\n");
00711 
00712     printf("<tr><td>hash32           </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%08x</b></td>",$entry["hash32"]);printf("</tr>\n");
00713     printf("<tr><td>scale           </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%01.3f</b></td>",$entry["scale"]);printf("</tr>\n");
00714     printf("<tr><td>gamma           </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%01.3f</b></td>",$entry["gamma"]);printf("</tr>\n");
00715     printf("<tr><td>black           </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["black"]);printf("</tr>\n");
00716     printf("<tr><td>valid           </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>0x%x</b></td>",$entry["valid"]);printf("</tr>\n");
00717     printf("<tr><td>locked          </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>0x%8x</b></td>",$entry["locked"]);printf("</tr>\n");
00718     printf("<tr><td>this_non_scaled </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["this_non_scaled"]);printf("</tr>\n");
00719     printf("<tr><td>newer_non_scaled</td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newer_non_scaled"]);printf("</tr>\n");
00720     printf("<tr><td>older_non_scaled</td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["older_non_scaled"]);printf("</tr>\n");
00721     printf("<tr><td>newer_all       </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newer_all"]);printf("</tr>\n");
00722     printf("<tr><td>older_all       </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["older_all"]);printf("</tr>\n");
00723     printf("<tr><td>oldest_scaled   </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["oldest_scaled"]);printf("</tr>\n");
00724     printf("<tr><td>newest_scaled   </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newest_scaled"]);printf("</tr>\n");
00725     printf("<tr><td>newer_scaled    </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newer_scaled"]);printf("</tr>\n");
00726     printf("<tr><td>older_scaled    </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["older_scaled"]);printf("</tr>\n");
00727     printf("</table>\n");
00728   }
00729 
00730 function getGammaStructure() {
00731         $gammas_file=fopen("/dev/gamma_cache","r");
00732         fseek($gammas_file,0,SEEK_END);
00733         $numberOfEntries=ftell($gammas_file);
00734         fclose($gammas_file);
00735         $gammaStructure=array();
00736         $g_raw=elphel_gamma_get_raw(0);
00737         $g_raw_ul=unpack('V*',$g_raw);
00738         $gammaStructure["oldest_non_scaled"]=$g_raw_ul[5];
00739         $gammaStructure["newest_non_scaled"]=$g_raw_ul[6];
00740         $gammaStructure["oldest_all"]=       $g_raw_ul[7];
00741         $gammaStructure["newest_all"]=       $g_raw_ul[8];
00742         $gammaStructure["non_scaled_length"]=$g_raw_ul[9];
00743         $gammaStructure["num_locked"]=       $g_raw_ul[10];
00744         $gammaStructure["locked_col"]=  array ($g_raw_ul[11],$g_raw_ul[12],$g_raw_ul[13],$g_raw_ul[14]);
00745         $gammaStructure["entries"]=  array ();
00746         for ($i=1; $i<$numberOfEntries; $i++) {
00747           $g_raw=elphel_gamma_get_raw($i);
00748           $g_raw_ul=unpack('V*',$g_raw);
00749           if ($g_raw_ul[ 4]>=0) { 
00750             $hash32= $g_raw_ul[1];
00751             $gammaStructure["entries"][$i]=  array (
00752               "index" =>                 $i,
00753               "hash32"=>                 $hash32,
00754               "scale" =>                 ($hash32 & 0xffff)/1024.0,
00755               "gamma" =>                 (($hash32 >> 16) & 0xff)/100.0,
00756               "black" =>                 (($hash32 >> 24) & 0xff),
00757               "valid" =>                 $g_raw_ul[ 2], 
00758               "locked" =>                $g_raw_ul[ 3], 
00759               "this_non_scaled" =>       $g_raw_ul[ 4], 
00760 
00761               "newer_non_scaled" =>      $g_raw_ul[ 5], 
00762               "older_non_scaled" =>      $g_raw_ul[ 6], 
00763 
00764               "newer_all" =>             $g_raw_ul[ 7], 
00765               "older_all" =>             $g_raw_ul[ 8], 
00766 
00767               "oldest_scaled" =>         $g_raw_ul[ 9], 
00768               "newest_scaled" =>         $g_raw_ul[10], 
00769               "newer_scaled" =>          $g_raw_ul[ 9], 
00770               "older_scaled" =>          $g_raw_ul[10] 
00771               );
00772             }
00773           }
00774           return $gammaStructure;
00775         }
00776 
00777 function printRawGamma($page=0) {
00778         $g_raw=elphel_gamma_get_raw($page);
00779 //var_dump()
00780         $g_raw_ul=unpack('V*',$g_raw);
00781         echo "<pre>\n";
00782         printf ("Gamma cache page %d, length=%d\n",$page, strlen($g_raw));
00783         $a=1; 
00784         $hash32= $g_raw_ul[$a++];
00785         $scale= ($hash32 & 0xffff)/1024.0;
00786         $gamma= (($hash32 >> 16) & 0xff)/100.0;
00787         $black= (($hash32 >> 24) & 0xff);
00788         printf ("hash32= %08x (scale=%f gamma=%f black=%d)\n",$hash32,$scale,$gamma,$black);
00789         $valid= $g_raw_ul[$a++];
00790         printf ("valid=%d, locked=%d\n",$valid & 1, $valid & 2);
00791 
00792         $locked= $g_raw_ul[$a++];
00793         printf ("locked= 0x%x (for frame=%d/color=%d)\n",$locked, $locked & 7, ($locked>>3) & 3);
00794 
00795         $this_non_scaled=$g_raw_ul[$a++]; 
00796         printf ("this_non_scaled=%d\n",$this_non_scaled);
00797         if ($page==0) {
00798           printf ("oldest_non_scaled=%d\n",$g_raw_ul[$a++]);
00799           printf ("newest_non_scaled=%d\n",$g_raw_ul[$a++]);
00800         } else {
00801           printf ("newer_non_scaled=%d\n",$g_raw_ul[$a++]);
00802           printf ("older_non_scaled=%d\n",$g_raw_ul[$a++]);
00803         }
00804 
00805         if ($page==0) {
00806           printf ("oldest_all=%d\n",$g_raw_ul[$a++]);
00807           printf ("newest_all=%d\n",$g_raw_ul[$a++]);
00808         } else {
00809           printf ("newer_all=%d\n",$g_raw_ul[$a++]);
00810           printf ("older_all=%d\n",$g_raw_ul[$a++]);
00811         }
00812 
00813         if ($page==0) {
00814           printf ("non_scaled_length=%d\n",$g_raw_ul[$a++]); 
00815           printf ("num_locked=%d\n",$g_raw_ul[$a++]);        
00816         } else if ($this_non_scaled==0){
00817           printf ("oldest_scaled=%d\n",$g_raw_ul[$a++]);
00818           printf ("newest_scaled=%d\n",$g_raw_ul[$a++]);
00819         } else {
00820           printf ("newer_scaled=%d\n",$g_raw_ul[$a++]);
00821           printf ("older_scaled=%d\n",$g_raw_ul[$a++]);
00822         }
00824         if ($page==0) {
00825           printf ("\nTable of locked indexes\n");
00826           for ($color=0;$color<4; $color++) {
00827 //            for ($frame=0;$frame<8; $frame++) {
00828               printf (" %4d",$g_raw_ul[$a++]);
00829 //            }
00830 //            printf ("\n");
00831           }
00832           printf ("\n");
00834           printf ("\n\nUnused area on page 0:");
00835 //          for ($i=0; $i<417; $i++) {
00836           for ($i=0; $i<445; $i++) {
00837             if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00838             $d=$g_raw_ul[$a++];
00839             printf (" %08x",$d);
00840           }
00841 
00842         } else {
00843           printf ("\nGamma table (direct):");
00844           for ($i=0; $i<129; $i++) {
00845             if (($i & 0x07)==0) printf ("\n0x%03x:",$i*2);
00846             $d=$g_raw_ul[$a++];
00847             printf (" %04x %04x",$d & 0xffff, ($d>>16) & 0xffff );
00848           }
00849           printf ("\n\nGamma table (reverse):");
00850           for ($i=0; $i<64; $i++) {
00851             if (($i & 0x03)==0) printf ("\n0x%03x:",$i*4);
00852             $d=$g_raw_ul[$a++];
00853             printf (" %02x %02x %02x %02x",$d & 0xff, ($d>>8) & 0xff, ($d>>16) & 0xff, ($d>>24) & 0xff);
00854           }
00855 
00856           printf ("\n\nFPGA gamma data:");
00857           for ($i=0; $i<256; $i++) {
00858             if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00859             $d=$g_raw_ul[$a++];
00860             printf (" %05x",$d);
00861           }
00862         }
00863         echo "</pre>\n";
00864 }
00865 /*
00866 struct histogram_stuct_t {
00867    unsigned long frame;                /// frame number correspoding to the current histogram
00868    unsigned long valid;                /// bit mask of valid arrays (0 - hist_r, ... ,4-cumul_hist_r, ...,  11 - percentile_b)
00870    union {
00871      unsigned long hist[1024] ;          /// All 4 histograms
00872      struct {
00873        unsigned long hist_r [256] ;        /// Histogram for the red component
00874        unsigned long hist_g [256] ;        /// Histogram for the first green component (in the "red" line)
00875        unsigned long hist_gb[256] ;        /// Histogram for the second green component (in the "blue" line)
00876        unsigned long hist_b [256] ;        /// Histogram for blue component
00877      };
00878    };
00880    union {
00881      unsigned long cumul_hist[1024] ;          /// All 4 cumulative histograms
00882      struct {
00883        unsigned long cumul_hist_r [256] ;    /// Cumulative histogram for the red component
00884        unsigned long cumul_hist_g [256] ;    /// Cumulative histogram for the first green component (in the "red" line)
00885        unsigned long cumul_hist_gb[256] ;    /// Cumulative histogram for the second green component (in the "blue" line)
00886        unsigned long cumul_hist_b [256] ;    /// Cumulative histogram for blue component
00887      };
00888    };
00896    union {
00897      unsigned char percentile[1024] ;     /// All 4 percentiles
00898      struct {
00899        unsigned char percentile_r [256] ; /// percentile for the red component
00900        unsigned char percentile_g [256] ; /// percentile for the first green component (in the "red" line)
00901        unsigned char percentile_gb[256] ; /// percentile for the second green component (in the "blue" line)
00902        unsigned char percentile_b [256] ; /// percentile for the blue component
00903      };
00904    };
00905 };
00906 
00907 */
00908 function printHistogram($frame) {
00909      $colors=array(0=>"R",1=>"G",2=>"GB",3=>"B");
00910      $h_arr=elphel_histogram_get(0xfff,$frame);
00911      $a=0;
00912      $offset2sum=1024+255; 
00913      echo "<pre>\n";
00914      for ($color=0;$color<4;$color++) {
00915        printf("\nhistogram for color #%d %s, Total number of pixels=%d (0x%x):",$color,$colors[$color],$h_arr[$a+$offset2sum],$h_arr[$a+$offset2sum]);
00916        for ($i=0; $i<256; $i++) {
00917          if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00918          printf (" %05x",$h_arr[$a++]);
00919        }
00920        printf ("\n");
00921      }
00922      for ($color=0;$color<4;$color++) {
00923        printf("\ncumulative histogram for color #%d %s:",$color,$colors[$color]);
00924        for ($i=0; $i<256; $i++) {
00925          if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00926          printf (" %08x",$h_arr[$a++]);
00927        }
00928        printf ("\n");
00929      }
00930      for ($color=0;$color<4;$color++) {
00931        printf("\npercentile for color #%d %s:",$color,$colors[$color]);
00932        for ($i=0; $i<256; $i++) {
00933          if (($i & 0x01f)==0) printf ("\n0x%03x:",$i);
00934          printf (" %02x",$h_arr[$a++]);
00935        }
00936        printf ("\n");
00937      }
00938      echo "</pre>\n";
00939 }
00940 
00941 function printRawHistogram($needed,$frame) {
00942         $percentile_start=8232;
00943         $colors=array(0=>"R",1=>"G",2=>"GB",3=>"B");
00944         $h_raw=elphel_histogram_get_raw($needed,$frame);
00945 //var_dump()
00946         $h_raw_ul=unpack('V*',substr($h_raw,0,$percentile_start));
00947         echo "<pre>\n";
00948         $a=1; 
00949         $hframe=   $h_raw_ul[$a++];
00950         $valid=    $h_raw_ul[$a++];
00951         $hash32_r= $h_raw_ul[$a++];
00952         $hash32_g= $h_raw_ul[$a++];
00953         $hash32_gb=$h_raw_ul[$a++];
00954         $hash32_b= $h_raw_ul[$a++];
00955 
00956         printf ("Histogram for frame= %d (0x%x), valid mask=0x%x, requested=0x%x, data length=%d (0x%x)\n",$hframe,$hframe, $valid,$needed,strlen($h_raw),strlen($h_raw));
00957         printf ("hash32: R:0x%x G:0x%x GB:0x%x B:0x%x)\n",$hash32_r,$hash32_g,$hash32_gb,$hash32_b);
00958         for ($color=0;$color<4;$color++) {
00959           $sum=0;
00960           for ($i=0; $i<256; $i++)   $sum+=$h_raw_ul[$a+$i];
00961           printf("\nhistogram for color #%d %s sum=%d (0x%x):",$color,$colors[$color],$sum,$sum);
00962           for ($i=0; $i<256; $i++) {
00963             if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00964             $d=$h_raw_ul[$a++];
00965             printf (" %05x",$d);
00966           }
00967           printf ("\n");
00968         }
00969         for ($color=0;$color<4;$color++) {
00970           printf("\ncumulative histogram for color #%d %s:",$color,$colors[$color]);
00971           for ($i=0; $i<256; $i++) {
00972             if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00973             $d=$h_raw_ul[$a++];
00974             printf (" %08x",$d);
00975           }
00976           printf ("\n");
00977         }
00978         for ($color=0;$color<4;$color++) {
00979           printf("\npercentile for color #%d %s:",$color,$colors[$color]);
00980           for ($i=0; $i<256; $i++) {
00981             if (($i & 0x01f)==0) printf ("\n0x%03x:",$i);
00982             printf (" %02x",ord($h_raw[$percentile_start+(256*$color)+$i]));
00983           }
00984           printf ("\n");
00985         }
00986         echo "</pre>\n";
00987 }
00988 
00989 
00990 function printRawFrame($frame) {
00991         $fp_raw=elphel_framepars_get_raw($frame);
00992         $fp_raw_ul=unpack('V*',$fp_raw);
00993         echo "<pre>\n";
00994         printf ("\nFrame= %d(%08x)\n",$frame,$frame);
00995         $a=1; 
00996         echo ".pars:";
00997         for ($i=0; $i<927; $i++) {
00998           if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
00999           printf (" %08x:",$fp_raw_ul[$a++]);
01000         }
01001         printf ("\n.functions= %08x:",$fp_raw_ul[$a++]);
01002         echo "\n.modsince:";
01003         for ($i=0; $i<31; $i++) {
01004           if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
01005           printf (" %08x:",$fp_raw_ul[$a++]);
01006         }
01007         printf ("\n.modsince32= %08x:",$fp_raw_ul[$a++]);
01008         echo "\n.mod:";
01009         for ($i=0; $i<31; $i++) {
01010           if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
01011           printf (" %08x:",$fp_raw_ul[$a++]);
01012         }
01013         printf ("\n.mod32= %08x:",$fp_raw_ul[$a++]);
01014         echo "\n.needproc:";
01015         for ($i=0; $i<31; $i++) {
01016           if (($i & 0x0f)==0) printf ("\n0x%03x:",$i);
01017           printf (" %08x:",$fp_raw_ul[$a++]);
01018         }
01019         printf ("\n.needproc32= %08x:",$fp_raw_ul[$a++]);
01020 //        var_dump($fp_raw_ul);
01021         echo "</pre>\n";
01022 }
01023 
01024 function image_table8 (){
01025   global $imgsrv;
01026 //  $back=6;
01027 //  $min_back=1;
01028   $back=8;
01029   $min_back=0;
01030   printf ("<table>\n");
01031   $scale="100%";
01032   $row_open=$false;
01033   for ($hist=$back;$hist>=$min_back;$hist--) {
01034     if (!(($back-$hist) % 3)) {
01035       if ($row_open) printf ("</tr>\n");
01036       printf                 ("<tr>");
01037       $row_open=true;
01038     }
01039     $url=$imgsrv;
01040     for ($i=0;$i<$hist;$i++) $url.='/prev';
01041 //    $url .= '/img';
01042     printf ('<td><a href="%s"><img src="%s" width="%s" height="%s"/><br \>%d</a>&nbsp;&nbsp;<a href="%s">meta</a></td>',$url.'/img',$url.'/img',$scale,$scale,$hist,$url.'/meta');
01043   }
01044   if ($row_open) printf ("</tr>\n");
01045   printf ("</table>\n");
01046 }
01047 ?>

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