packages/web/353/php_top/ccam.php

Go to the documentation of this file.
00001 <?php
00002 /*!*******************************************************************************
00003 *! FILE NAME  : ccam.php
00004 *! DESCRIPTION: Programs major sensor parameters similar (not exactly) to ccam.cgi,
00005 *!              returns xml OK
00006 *! Copyright (C) 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: ccam.php,v $
00023 *!  Revision 1.1.1.1  2008/11/27 20:04:03  elphel
00024 *!
00025 *!
00026 *!  Revision 1.4  2008/11/04 00:16:50  elphel
00027 *!  started porting
00028 *!
00029 *!  Revision 1.3  2008/11/02 07:26:41  elphel
00030 *!  started porting ccam.php/camvc2
00031 *!
00032 *!  Revision 1.2  2008/09/28 00:31:42  elphel
00033 *!  Some histogram related constants renamed from *AUTOEXP*, *AEXPWND*  to *HISTWND*
00034 *!
00035 *!  Revision 1.8  2008/04/24 18:20:40  elphel
00036 *!  added retrieval of circbuf structure
00037 *!
00038 *!  Revision 1.4  2008/04/16 20:39:32  elphel
00039 *!  removed actions that are unneeded with the current drivers, limited number of retries to stop compressor in "mode=set", added "mode=force" that unconditionally reprograms camera without an attempt to nicely stop the compressor
00040 *!
00041 *!  Revision 1.3  2008/03/25 07:38:43  elphel
00042 *!  just troubleshooting
00043 *!
00044 *!  Revision 1.2  2008/03/22 04:43:03  elphel
00045 *!  few minor changes
00046 *!
00047 *!  Revision 1.1  2008/03/20 22:32:12  elphel
00048 *!  sensor/compressor control, similar commands as ccam.cgi, but no images returned (use imgsrv - port 8081)
00049 *!
00050 *!
00051 */
00052 function out1x1gif() {
00053          header("Content-Type: image/gif");
00054          header("Content-Length: 35\n");
00055          echo "GIF87a\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00".
00056               "\xff\xff\xff\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x4c".
00057               "\x01\x00\x3b";
00058  }
00059 /*
00060 $debugGetPars= var_export($_GET, true);
00061 $debugFile=fopen('/var/html/ccam.php.log','a+');
00062 fwrite($debugFile,"\n================================\n".$debugGetPars);
00063 fclose($debugFile);
00064 */
00065 //Default parameters to be written after sensor reset
00066          $init_pars=array(
00067            "FLIP"=>3,  
00068            "COLOR"=>1, 
00069            "DCM_HOR"  => 1,  
00070            "DCM_VERT" => 1,  
00071            "BIN_HOR"  => 1,  
00072            "BIN_VERT" => 1,  
00073            "QUALITY"  => 90, 
00074            "COLOR_SATURATION_BLUE" => 200 , 
00075            "COLOR_SATURATION_RED" => 200 ,  
00076            "BITS" => 8,                     
00077            "GAMMA" => 57,                   
00078            "PIXEL_LOW" => 10,               
00079            "PIXEL_HIGH" => 254,             
00080            "EXPOS" =>    100,               
00081            "WOI_LEFT" =>  0,                 
00082            "WOI_TOP" =>   0,                 
00083            "WOI_WIDTH" =>  10000,            
00084            "WOI_HEIGHT" => 10000,            
00085            "RSCALE" =>       256,            
00086            "BSCALE" =>       256,            
00087            "GAINR" =>        512,            
00088            "GAING" =>        512,            
00089            "GAINB" =>        512,            
00090            "GAINGB" =>       512,            
00091            "BAYER" =>          4             
00092          );
00093           $aexp_arr=array(
00094             "AUTOEXP_ON"=>0,
00095             "HISTWND_RWIDTH"=>0,
00096             "HISTWND_RHEIGHT"=>0,
00097             "HISTWND_RLEFT"=>0,
00098             "HISTWND_RTOP"=>0,
00099             "AUTOEXP_EXP_MAX"=>0,
00100             "AUTOEXP_OVEREXP_MAX"=>0,
00101             "AUTOEXP_S_PERCENT"=>0,
00102             "AUTOEXP_S_INDEX"=>0,
00103             "AUTOEXP_EXP"=>0,
00104             "AUTOEXP_SKIP_PMIN"=>0,
00105             "AUTOEXP_SKIP_PMAX"=>0,
00106             "AUTOEXP_SKIP_T"=>0,
00107             "HISTWND_WIDTH"=>0,
00108             "HISTWND_HEIGHT"=>0,
00109             "HISTWND_TOP"=>0,
00110             "HISTWND_LEFT"=>0
00111           );
00112 
00113          $keep_pars=array(
00114            "COLOR"=>0,
00115            "TRIG"=>0
00116          );
00117 
00118          $wb_thrsh=0.98;
00119          $wb_minfrac=0.01;
00120          $wb_rscale=1.0;
00121          $wb_bscale=1.0;
00122          $white_balance=false;
00123          $wbrslt=-1;
00124          $autoexp_set=false; // change autoexposure settings
00125          $sleep=  ($_GET["sleep"]);  if ($sleep>0) sleep($sleep);   //missing sleep() in javaScript - sleeps before other actions
00126          $usleep= ($_GET["usleep"]); if ($usleep>0) usleep($usleep);
00127          $autoexp=elphel_get_P_value (ELPHEL_AUTOEXP_ON);
00128          $pars=array();
00129          $mode=$_GET["mode"];
00130          $keep_pars=elphel_get_P_arr($keep_pars); // parameters, some bits of which should be preserved
00131          $timeout=500; //miliseconds - how long to wait for compressor stop
00132          $hist_in_thresh=0.0;
00133          $hist_out_thresh=0.0;
00134          $autoexp_get=false; // output autoexposure data
00135          $streamer_get=false; // output streamer data
00136          $show_written=false; // show parameters written
00137          $exif_get=false;
00138          $circbuf_get=false;
00139          $debug_arr=array();
00140          if ($mode=="reset") { // reset sensor
00141            $pars=$init_pars;
00142            $mode="set";
00143            if (elphel_get_state()>7) {  
00144              if ($keep_pars["TRIG"]& 4) { // no sense to check also elphel_get_P_value (ELPHEL_TRIG+ELPHEL_NUMBER) - written value
00145                elphel_set_P_value(ELPHEL_TRIG,$keep_pars["TRIG"] & ~4);
00146                elphel_program_sensor (0); 
00147              }
00148            }
00149            elphel_reset_sensor();
00150          } // reset sensor
00151          $toRead=array(); // raw parameters to read by name
00152 // now parse/add parameters to be programmed
00153          foreach($_GET as $key=>$value) {
00154            switch($key) {
00156             case "_time":
00157               if (elphel_get_fpga_time() > 100000000) break; // time already set
00158             case "_stime":
00159               $a=((float) $value)/1000;
00160               elphel_set_fpga_time ($a); // set FPGA time
00161               exec("date -s ".date("mdHiY.s",(int)$a),$out,$ret); // set system time
00162               break;
00163             case "timeout":
00164               $timeout=(int) ($value+0);
00165             case "mode":
00166             case "acquire":
00167             case "out":
00168             case "compressor":
00169             case "imgsrv":
00170 
00171                break; // not processed here
00172             case "color": 
00173               switch ($value) {
00174                 case "jp4":  $value=2; break;
00175                 case "color":$value=1; break;
00176                 case "mono": $value=0; break;
00177               }
00178               $keep_pars["COLOR"]=$pars["COLOR"]=((integer) $value) | ($keep_pars["COLOR"] & ~7); // 3 LSBs - for color mode
00179               break;
00180             case "test": 
00181               switch ($value) {
00182                 case "fpga":  $value=2; break;
00183                 case "sensor":$value=1; break;
00184               }
00185               $keep_pars["COLOR"]=$pars["COLOR"]=(((integer) $value) << 8) | ($keep_pars["COLOR"] & ~0x700); // 3 LSBs - for color mode
00186               break;
00187             case "flip":  $pars["FLIP"]= ((strpos($value,"x")===false)?0:1)+((strpos($value,"y")===false)?0:2); break;
00188             case "trig": 
00189               switch ($value) {
00190                 case "sync":  $value=0; break;
00191                 case "async": $value=4; break;
00192               }
00193               $keep_pars["TRIG"]=$pars["TRIG"]=($value? 4: 0) | ($keep_pars["TRIG"] & ~0x4); // only change bit 2
00194               break;
00195 // options "m,..." - not implemented
00196             case "gam":
00197             case "gamma":
00198               $pars["GAMMA"]=(integer) $value;
00199               break;
00200             case "pxl":
00201             case "pixel_low":
00202               $pars["PIXEL_LOW"]=(integer) $value;
00203               break;
00204             case "pxh":
00205             case "pixel_high":
00206               $pars["PIXEL_HIGH"]=(integer) $value;
00207               break;
00208             case "iq":
00209             case "quality":
00210               $pars["QUALITY"]=(integer) $value;
00211               break;
00212             case "iq":
00213             case "quality":
00214               $pars["QUALITY"]=(integer) $value;
00215               break;
00216             case "byr":
00217             case "bayer":
00218               if ($value="auto") $value=4;
00219               $pars["BAYER"]=(integer) $value;
00220               break;
00221             case "fpns":
00222             case "fpn_sub":
00223               $pars["FPNS"]=(integer) $value;
00224               break;
00225             case "fpnm":
00226             case "fpn_mpy":
00227               $pars["FPNM"]=(integer) $value;
00228               break;
00229             case "expos": // in seconds
00230             case "exposure":
00231               if (is_numeric($value)) $value=$value*10000; // now in 1/10000 sec)
00232             case "e": //1/10000 sec, currently in  ccam.cgi
00233               switch ($value) {
00234                 case "auto":
00235                   if ($autoexp==0) {
00236                     $pars["AUTOEXP_ON"]=1;
00237                     $autoexp_set=true;
00238                   }
00239                   break;
00240                 case "manual":
00241                   if ($autoexp!=0) {
00242                     $pars["AUTOEXP_ON"]=0;
00243                     $autoexp_set=true;
00244                   }
00245                   break;
00246                 default:
00247                   $value=(integer) $value;
00248                   if ($value>0) {
00249                      $pars["EXPOS"]=$value;
00250                     if ($autoexp!=0) {
00251                       $pars["AUTOEXP_ON"]=0;
00252                       $autoexp_set=true;
00253                     }
00254                   }
00255               }
00256               break;
00257             case "ve": // in scan lines - don't change autoexposure!
00258               $pars["VEXPOS"]=(integer) $value;
00259               break;
00260             case "vw":
00261               $pars["VIRT_WIDTH"]=(integer) $value;
00262               break;
00263             case "vh":
00264               $pars["VIRT_HEIGHT"]=(integer) $value;
00265               break;
00266             case "wl":
00267             case "left":
00268               $pars["WOI_LEFT"]=(integer) $value;
00269               break;
00270             case "wt":
00271             case "top":
00272               $pars["WOI_TOP"]=(integer) $value;
00273               break;
00274             case "ww":
00275             case "width":
00276               $pars["WOI_WIDTH"]=(integer) $value;
00277               break;
00278             case "wh":
00279             case "height":
00280               $pars["WOI_HEIGHT"]=(integer) $value;
00281               break;
00282             case "pfh": // lower 16 bits - "pfh", higher bits - "ts<<16"
00283               $pars["PF_HEIGHT"]=(integer) $value;
00284               break;
00285             case "fsd":
00286             case "fsync_dly": // mostly debug - delay frame sync by $value lines
00287               $pars["FRAMESYNC_DLY"]=(integer) $value;
00288               break;
00289             case "dh":
00290               $pars["DCM_HOR"]=(integer) $value;
00291               break;
00292             case "dv":
00293               $pars["DCM_VERT"]=(integer) $value;
00294               break;
00295             case "bh":
00296               $pars["BIN_HOR"]=(integer) $value;
00297               break;
00298             case "bv":
00299               $pars["BIN_VERT"]=(integer) $value;
00300               break;
00301             case "clk": // not used
00302             case "shl": // not used
00303               break;
00304             case "bit":
00305             case "bits":
00306               $pars["BITS"]=(integer) $value;
00307               break;
00308             case "gr":
00309             case "red":
00310               $pars["GAINR"]=(integer) ($value*256);
00311               break;
00312             case "gg":
00313             case "green":
00314               $pars["GAING"]=(integer) ($value*256);
00315               break;
00316             case "gb":
00317             case "blue":
00318               $pars["GAINB"]=(integer) ($value*256);
00319               break;
00320             case "ggb":
00321             case "gg2":
00322             case "green2":
00323               $pars["GAINGB"]=(integer) ($value*256);
00324               break;
00325             case "sens": // just set all gains together
00326             case "gain":
00327               $value= (integer) ($value*256); 
00328               $pars["GAINR"] = $value;
00329               $pars["GAING"] = $value;
00330               $pars["GAINB"] = $value;
00331               $pars["GAINGB"]= $value;
00332               break;
00333             case "rscale":
00334               $pars["RSCALE"]=(integer) ($value*256);
00335               break;
00336             case "bscale":
00337               $pars["BSCALE"]=(integer) ($value*256);
00338               break;
00339             case "csb":
00340               $pars["COLOR_SATURATION_BLUE"]=(integer) $value;
00341               break;
00342             case "saturation_blue":
00343               $pars["COLOR_SATURATION_BLUE"]=(integer)(100*$value);
00344               break;
00345             case "csr":
00346               $pars["COLOR_SATURATION_RED"]=(integer) $value;
00347               break;
00348             case "saturation_red":
00349               $pars["COLOR_SATURATION_RED"]=(integer)(100*$value);
00350               break;
00351             case "eol": // probably not used
00352               $pars["OVERLAP"]=(integer)(100*$value);
00353               break;
00354             case "vtrig": // probably not used
00355               $pars["VIRTTRIG"]=(integer)(100*$value);
00356               break;
00357             case "fclk": // FPGA clock, MHz (likely will not work)
00358               $pars["CLK_FPGA"]=(integer)(1000000*$value);
00359               break;
00360             case "sclk": // sensor clock, MHz (likely will not work )
00361               $pars["CLK_SENSOR"]=(integer)(1000000*$value);
00362               break;
00363             case "xtra": // number of additional (to number of macroblocks*768)  clock cycles needed to compress a frame
00364               $pars["FPGA_XTRA"]=(integer) $value; 
00365               break;
00366 //#define P_FP1000SLIM     9 // FPS limit, frames per 1000 sec
00367 //#define P_FPSFLAGS      10 // FPS limit mode - bit 0 - limit fps (not higher than), bit 1 - maintain fps (not lower than)
00368 
00369             case "fps":
00370               $value=(integer)  (1000 *$value); 
00371               $pars["FP1000SLIM"]=$value;
00372               if ($_GET["fpslm"]!==NULL) $pars["FPSFLAGS"]=(integer) $_GET["fpslm"];
00373               else $pars["FPSFLAGS"]= 1;// old behavior - just upper limit, if fps !=0
00374               break;
00375             case "fpslm":
00376               if ($_GET["fps"]===NULL) $pars["FPSFLAGS"]=(integer) $_GET["fpslm"];
00377               break;
00379             case "wb_thrsh":
00380               if (is_numeric ($value) && ($value > 0) && ($value <= 1)) $wb_thrsh=$value;
00381               $white_balance=true;
00382               break;
00383             case "wb_minfrac":
00384               if (is_numeric ($value) && ($value > 0) && ($value <  1)) $wb_minfrac=$value;
00385               $white_balance=true;
00386               break;
00387             case "wb_rscale":
00388               if (is_numeric ($value) && ($value >= 0.1) && ($value <=  10.1)) $wb_rscale=$value;
00389               $white_balance=true;
00390               break;
00391             case "wb_bscale":
00392               if (is_numeric ($value) && ($value >= 0.1) && ($value <=  10.1)) $wb_rscale=$value;
00393               $white_balance=true;
00394               break;
00395             case "wbalance":
00396             case "balance":
00397               $white_balance=true;
00398               break;
00399             case "aexp_get":
00400               $autoexp_get=true;
00401               break;
00403             case "aexp_on": 
00404               $pars["AUTOEXP_ON"]=($value)?1:0;
00405               $autoexp_set=true;
00406              break;
00407             case "aexp_width": //relative width of the autoexposure window (<1.0)
00408               if ($value < 1) $value=100*$value; // now %
00409               $pars["HISTWND_RWIDTH"]=(integer) $value; 
00410               $autoexp_set=true;
00411              break;
00412             case "aexp_height": //relative height of the autoexposure window (<1.0)
00413               if ($value < 1) $value=100*$value; // now %
00414               $pars["HISTWND_RHEIGHT"]=(integer) $value; 
00415               $autoexp_set=true;
00416              break;
00417             case "aexp_left": //relative left of the autoexposure window (<1.0)
00418               if ($value < 1) $value=100*$value; // now %
00419               $pars["HISTWND_RLEFT"]=(integer) $value; 
00420               $autoexp_set=true;
00421              break;
00422             case "aexp_top": //relative top of the autoexposure window (<1.0)
00423               if ($value < 1) $value=100*$value; // now %
00424               $pars["HISTWND_RTOP"]=(integer) $value; 
00425               $autoexp_set=true;
00426              break;
00427             case "aexp_exp_max": // maximal exposure in seconds (<20)
00428               if ($value < 20) $value=1000*$value; // now in milliseconds
00429               $pars["AUTOEXP_EXP_MAX"]=(integer) $value; 
00430               $autoexp_set=true;
00431              break;
00432             case "aexp_overexp": // maximal fraction of overexposed pixels (both fractions and integer 1/100%)
00433               if ($value < 1) $value=10000*$value; // now in 0.01%
00434               $pars["AUTOEXP_OVEREXP_MAX"]=(integer) $value; 
00435               $autoexp_set=true;
00436              break;
00437             case "aexp_below": // maximal fraction of pixels exposed less than the threshold (both fractions and integer 1/100%)
00438               if ($value < 1) $value=10000*$value; // now in 0.01%
00439               $pars["AUTOEXP_OVEREXP_MAX"]=(integer) $value; 
00440               $autoexp_set=true;
00441              break;
00442             case "aexp_threshold": // threshold, (0..0.999 or 1..255) used together with 
00443             case "aexp_thresh":
00444             case "aexp_index":
00445               if ($value < 1) $value=255.5*$value; // now in 0..255
00446               $pars["AUTOEXP_S_INDEX"]=(integer) $value; 
00447               $autoexp_set=true;
00448              break;
00449             case "aexp_frac": // fraction of pixels below given threshold
00450             case "aexp_fraction": // fraction of pixels below given threshold
00451               if ($value < 1) $value=10000*$value; // now in 0..255
00452               $pars["AUTOEXP_S_PERCENT"]=(integer) $value; 
00453               $autoexp_set=true;
00454              break;
00455 
00456             case "aexp_chng_min": // minimal realtive change in exposure to be applied (0..1.0 and in 0.001%)
00457               if ($value < 1) $value=10000*$value; // now in 0.01%
00458               $pars["AUTOEXP_SKIP_PMIN"]=(integer) $value; 
00459               $autoexp_set=true;
00460              break;
00461             case "aexp_chng_minabs": // minimal absoluteve change in exposure to be applied (in "ticks"=1/10000 s, default=2)
00462               $pars["AUTOEXP_SKIP_T"]=(integer) $value; 
00463               $autoexp_set=true;
00464              break;
00465             case "aexp_chng_max": // maximal realtive change in exposure to be applied (0..1.0 and in 0.001%)
00466               if ($value < 1) $value=10000*$value; // now in 0.01%
00467               $pars["AUTOEXP_SKIP_PMAX"]=(integer) $value; 
00468               $autoexp_set=true;
00469              break;
00470 /*
00471             case "hist_in_thresh": // calculate the input and output levels
00472              $hist_in_thresh=$value+0.0;
00473              break;
00474             case "hist_out_thresh": // calculate the input and output levels
00475              $hist_out_thresh=$value+0.0;
00476              break;
00477 */
00478             case "written":      // show parameters written (accepted)
00479             case "show_written":
00480              $show_written=true;
00481              break;
00482             case "streamer_get":
00483              $streamer_get=true;
00484              break;
00485             case "exif":
00486               $exif_get=$value+0; //page number
00487               break;
00488             case "description":
00489               if ( $value!==null)  elphel_set_exif_field(0x10e, $value.chr(0));
00490               break;
00491             case "circbuf":
00492               $circbuf_get=true;
00493               break;
00494             default: 
00495              $toRead[$key]="";
00496              if ($value!=="") $pars[$key]=(integer) $value+0;
00497            }
00498          }
00499          $npars=elphel_set_P_arr($pars);
00500          if ($white_balance) {
00501            $wbrslt=elphel_white_balance ($wb_thrsh, $wb_minfrac, $wb_rscale, $wb_bscale); // remember result - if OK - needs to be updated
00502          } 
00503          if ($autoexp_set) {
00504            elphel_autoexposure_set();
00505          }
00507 
00508          $was_running=(elphel_get_state()>7);
00509          if (($mode=="safe") && !$was_running) $mode=$set;
00510          if (($npars>0) || ($wbrslt>=0)  || ($mode=="skipbad") || ($mode=="set") || ($mode=="force")){
00511            if (($mode=="skipbad") || ($mode=="set") || ($mode=="force")) {
00512              if ($was_running && !($mode=="force")) elphel_compressor_stop(); 
00513              if (!($mode=="force")) { 
00514                  for ($i=0; $i<=($timeout/50);$i++) // wait for some time (but not too long) trying to be nice and stop compressor gracefully
00515                     if (!elphel_is_compressor_idle()) usleep (50000) ; //0.05sec
00516                     else break;
00517  $debug_arr["stopping_force"]=$i;
00518              }
00519              if ($mode=="skipbad") elphel_program_sensor (1); // will stop compressor if it was running
00520              else                  elphel_program_sensor (0); // will stop compressor if it was running
00521            } else {
00522  $debug_arr["program_sensor"]=1;
00523              elphel_program_sensor (1); // nonstop, just update on the fly
00524            }
00525          }
00526 // now control compressor
00527 // (Try to) Stop it if quality is specified and different from the current
00528          if (($pars["QUALITY"] !==null) &&
00529              ($pars["QUALITY"] != elphel_get_P_value (ELPHEL_QUALITY))) {
00530              if (elphel_get_state()>7) elphel_compressor_stop(); 
00531              for ($i=0; $i<=($timeout/50);$i++) // wait for some time trying to stop compressor gracefully
00532                     if (!elphel_is_compressor_idle()) usleep (50000) ; //0.05sec
00533                     else break;
00534  $debug_arr["stopping_quality"]=$i;
00535          }
00536 
00537          switch ($_GET["compressor"]) {
00538            case "stop":
00539              elphel_compressor_stop();
00540             break;
00541            case "wait":
00542              while (elphel_get_state()>7) usleep (100000) ; 
00543             break;
00544            case "restore": // run if was running before programming
00545 $debug_arr["was_running"]=$was_running;
00546 $debug_arr["before_restore_state"]=elphel_get_state();
00547              if ($was_running && (elphel_get_state() <=7)) elphel_compressor_run();
00548              else elphel_fpga_write (4,5); 
00549             break;
00550            case "run":
00551              elphel_compressor_run();
00552             break;
00553            case "single":
00554              elphel_compressor_frame();
00555             break;
00556            case "reset":
00557 // try this.
00558 // if running and async turn to sync, stop,reset,reset,turn back to sync
00559 // if running and sync - just stop,reset,reset
00560              if (elphel_get_state()>7) {  
00561                if (elphel_get_P_value (ELPHEL_TRIG) & 4) { // keep_pars may have new value, not yet set - we use here current one
00562                  elphel_set_P_value(ELPHEL_TRIG,$keep_pars["TRIG"] & ~4);
00563                  elphel_program_sensor (0); // set internal trigger mode, frames might be broken
00564                }
00565                elphel_compressor_stop(); 
00566                while (elphel_get_state()>7) usleep (100000) ; 
00567                elphel_compressor_reset(); 
00568                elphel_compressor_reset(); 
00569 
00570 
00571                if ($keep_pars["TRIG"]& 4) { // no sense to check also elphel_get_P_value (ELPHEL_TRIG+ELPHEL_NUMBER) - written value
00572                  elphel_set_P_value(ELPHEL_TRIG,$keep_pars["TRIG"]);
00573                  elphel_program_sensor (0);
00574                }
00575              }
00576             break;
00577          }
00578          if ($_GET["out"]=="gif") {
00579               out1x1gif();
00580               exit (0);
00581          }
00582          $xml = new SimpleXMLElement("<?xml version='1.0'?><pars/>");
00583          if (count($toRead)>0) $toRead=elphel_get_P_arr($toRead);
00584          if ($_GET["STATE"]!==NULL) $toRead["STATE"]=elphel_get_state();
00585          if ($_GET["imgsrv"]!==NULL) $toRead["imgsrv"]='http://'.$_SERVER['HTTP_HOST'].':8081/';
00586          foreach ($debug_arr as $key=>$value) {
00587             $xml->addChild ($key,$value);
00588          }
00589          foreach ($toRead as $key=>$value) {
00590             $xml->addChild ($key,$value);
00591          }
00592          if ($exif_get!==false) {
00593            $exif_got=elphel_get_exif_elphel($exif_get);
00594            if ($exif_got) {
00595              $xml->addChild ('Exif');
00596              $xml->Exif->addChild ("Exif_page",$exif_get);
00597              foreach ($exif_got as $key=>$value) {
00598                 $xml->Exif->addChild ($key,$value);
00599              }
00600            }
00601          }
00602 
00605          if ($hist_in_thresh) {
00606               $xml->addChild ('hist_in');
00607               $xml->hist_in->addChild ('hist_in_thresh',$hist_in_thresh);
00608               $xml->hist_in->addChild ('hist_in_r', elphel_histogram(0,elphel_gamma(0,$hist_in_thresh)));
00609               $xml->hist_in->addChild ('hist_in_g', elphel_histogram(1,elphel_gamma(1,$hist_in_thresh)));
00610               $xml->hist_in->addChild ('hist_in_g2',elphel_histogram(2,elphel_gamma(2,$hist_in_thresh)));
00611               $xml->hist_in->addChild ('hist_in_b', elphel_histogram(3,elphel_gamma(3,$hist_in_thresh)));
00612          }
00614          if ($hist_out_thresh) {
00615               $xml->addChild ('hist_out');
00616               $xml->hist_out->addChild ('hist_out_thresh',$hist_out_thresh);
00617               $xml->hist_out->addChild ('hist_out_r', elphel_histogram(0,$hist_out_thresh));
00618               $xml->hist_out->addChild ('hist_out_g', elphel_histogram(1,$hist_out_thresh));
00619               $xml->hist_out->addChild ('hist_out_g2',elphel_histogram(2,$hist_out_thresh));
00620               $xml->hist_out->addChild ('hist_out_b', elphel_histogram(3,$hist_out_thresh));
00621          }
00622 
00624          if ($autoexp_get) {
00625               $xml->addChild ('autoexposure');
00626               elphel_autoexposure_get();
00627               $aexp_arr=elphel_get_P_arr ($aexp_arr);
00628               foreach ($aexp_arr as $key=>$value) {
00629                  $xml->autoexposure->addChild ($key,$value);
00630               }
00631          }
00632 
00633          if ($white_balance) {
00634                 $xml->addChild ('white_balance');
00635                 $xml->white_balance->addChild ('wb_thrsh',  $wb_thrsh);
00636                 $xml->white_balance->addChild ('wb_minfrac',$wb_minfrac);
00637                 $xml->white_balance->addChild ('wb_rscale', $wb_rscale);
00638                 $xml->white_balance->addChild ('wb_bscale', $wb_bscale);
00639                 $xml->white_balance->addChild ('result',($rslt>=0)?"OK":"failure");
00640                 if ($wbrslt>=0) {
00641                    $xml->white_balance->addChild ('after');
00642                    $balance_pars=elphel_get_P_arr(array("RSCALE"=>0,"BSCALE"=>0,"GSCALE"=>0));
00643                    foreach ($balance_pars as $key=>$value) {
00644                      $xml->white_balance->after->addChild ($key,$value);
00645                    }
00646                 }
00647           }
00648 // Output streamer state
00649           if ($streamer_get) {
00650             $xml->addChild ('streamer');
00651             $streamer_run=false;
00654 
00655             $streamer_conf=file($streamer_run?'/var/state/streamer.conf':'/etc/streamer.conf');
00656             foreach ($streamer_conf as $line) {
00657               $conf_cmd=split('=',$line);
00658               if (trim($conf_cmd[0])=='pid') {
00659                 exec ('kill -0 '.$conf_cmd[1], $outv,$retv);
00660                 $streamer_run=($retv==0);
00661               } else {
00662                 $xml->streamer->addChild ('S_'.trim($conf_cmd[0]),trim($conf_cmd[1]));
00663               }
00664             }
00665             $xml->streamer->addChild ('S_STREAM',$streamer_run?1:0);
00666           }
00668           if ($circbuf_get) {
00669             $xml->addChild ('circbuf');
00670              $circbuf=elphel_get_circbuf_pointers();
00671             if (is_array  ($circbuf)) {
00672               $circbuf_count=count($circbuf);
00673               $xml->circbuf->addChild ('circbuf_count',$circbuf_count);
00674               for ($i=0;$i<$circbuf_count;$i++) {
00675                 $xml->circbuf->addChild ('frame'.$i);
00676                 $xml->circbuf->{'frame'.$i}->addChild ('circbuf_pointer',$circbuf[$i]['circbuf_pointer']);
00677                 $xml->circbuf->{'frame'.$i}->addChild ('exif_pointer'   ,$circbuf[$i]['exif_pointer']);
00678               }
00679             }
00680           }
00681           switch ($_GET["out"]) { // Remove completely?
00682             case "all":
00683               $xml->addChild ('state',elphel_get_state());
00684               $xml->addChild ('FRAME',elphel_get_P_value (ELPHEL_FRAME));
00685               $xml->addChild ('TRIG',elphel_get_P_value (ELPHEL_TRIG));
00686               break;
00687           }
00688           if (count($pars)) { // last item - what was written 
00689             $xml->addChild ('pars_written');
00690             $xml->pars_written->addChild ('number_written',$npars);
00691             if ($show_written) {
00692                foreach ($pars as $key=>$value) {
00693                  $xml->pars_written->addChild ($key,$value);
00694                }
00695             }
00696           }
00697 
00698           $rslt=$xml->asXML();
00699           header("Content-Type: text/xml");
00700           header("Content-Length: ".strlen($rslt)."\n");
00701           header("Pragma: no-cache\n");
00702           printf($rslt);
00703 
00704 ?>

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