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

Generated on Thu Aug 7 16:19:00 2008 for elphel by  doxygen 1.5.1