. *! -----------------------------------------------------------------------------** *! $Log: diag_utils.php,v $ *! Revision 1.5 2010/04/30 21:09:00 elphel *! added forced synchronization on/off links, parsedit.php link *! *! Revision 1.4 2008/11/30 21:56:39 elphel *! Added enforcing limit on the overall gains in the color channels, storage of exposure and gains in the histograms cache (to be used with autoexposure/white balance) *! *! Revision 1.3 2008/11/30 06:41:43 elphel *! changed default IP back to 192.168.0.9 (temporarily was 192.168.0.7) *! *! Revision 1.2 2008/11/30 05:02:27 elphel *! wrong links *! *! Revision 1.1.1.1 2008/11/27 20:04:03 elphel *! *! *! Revision 1.1 2008/11/27 09:29:22 elphel *! new file - diag_utils.php that includes somewhat cleaned-up version of utilities from framepars.php. That file installation is moved to attic *! *! */ $imgsrv="http://".$_SERVER['SERVER_ADDR'].":8081"; if (count($_GET)==0) { showUsage(); exit (0); } //$_SERVER["SERVER_ADDR"] . ":8081 $elp_const=get_defined_constants(true); $elp_const=$elp_const["elphel"]; foreach($_GET as $key=>$value) switch($key) { case "profile": profileShow(myval($value)); break; case "histogram_direct": case "histogram_reverse": case "gamma_direct": case "gamma_reverse": showHistGamma ($key,floatval($value)); break; case "jpegheader": showJpegHeader(); break; case "constants": echo "
\n";print_r($elp_const); echo "\n"; break; case "frame": printRawFrame(myval($value)); break; case "hist_raw": printRawHistogram(0xfff,myval($value)); break; case "hist": case "histogram": printHistogram(myval($value)); break; case "gamma": printGammaStructure(); break; case "gamma_page": printRawGamma(myval($value)); break; default: showUsage(); } exit (0); ///========================================================================================================== function showUsage() { global $imgsrv; echo <<
Here are some of the current options
There are additional development pages links available:
"; //http://192.168.0.9/parsedit.php?PROFILING_EN=1 $prof_template=array( "PROFILE00"=>0,"PROFILE01"=>0, "PROFILE02"=>0,"PROFILE03"=>0, "PROFILE04"=>0,"PROFILE05"=>0, "PROFILE06"=>0,"PROFILE07"=>0, "PROFILE08"=>0,"PROFILE09"=>0, "PROFILE10"=>0,"PROFILE11"=>0, "PROFILE12"=>0,"PROFILE13"=>0, "PROFILE14"=>0,"PROFILE15"=>0 ); $now=elphel_get_frame()-2; /// data is available 2 frames behind $time_start=elphel_get_fpga_time(); $prof_raw=array(); for ($i=$now-$num_entries-1;$i<=$now;$i++) { $prof_raw[$i]=elphel_get_P_arr($prof_template,$i); } $time_end=elphel_get_fpga_time(); $prof=array(); for ($i=$now-$num_entries;$i<=$now;$i++) { $prof[$i]=array ( "dt0"=>($prof_raw[$i]["PROFILE00"]-$prof_raw[$i-1]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE01"]-$prof_raw[$i-1]["PROFILE01"]), "dt1"=>($prof_raw[$i]["PROFILE02"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE03"]-$prof_raw[$i]["PROFILE01"]), "dt2"=>($prof_raw[$i]["PROFILE04"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE05"]-$prof_raw[$i]["PROFILE01"]), "dt3"=>($prof_raw[$i]["PROFILE06"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE07"]-$prof_raw[$i]["PROFILE01"]), "dt4"=>($prof_raw[$i]["PROFILE08"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE09"]-$prof_raw[$i]["PROFILE01"]), "dt5"=>($prof_raw[$i]["PROFILE10"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE11"]-$prof_raw[$i]["PROFILE01"]), "dt6"=>($prof_raw[$i]["PROFILE12"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE13"]-$prof_raw[$i]["PROFILE01"]), "dt7"=>($prof_raw[$i]["PROFILE14"]-$prof_raw[$i]["PROFILE00"])*1000000+($prof_raw[$i]["PROFILE15"]-$prof_raw[$i]["PROFILE01"])); foreach ($prof[$i] as $key=>$value) if ($prof[$i][$key]<0)$prof[$i][$key]=""; } if (!elphel_get_P_value(ELPHEL_PROFILING_EN)) { echo <<Interrupt service/tasklet profiling is currently disabled. You may enable it by following this link: /parsedit.php?PROFILING_EN=1 PROFILE_ENABLE; } echo << reading profile time start=$time_start reading profile time end=$time_end
Profiling interrupt/tasklet execution time in microseconds, starting from the start of the frame
- after updating frame pointers, Exif, parameters structures (IRQ service)
- start of the tasklet
- after Y histogram (G1) load from the FPGA (if enabled)
- after processing parameters (actions triggered by the parameter changes),
- after C histograms (R,G2,B) load from the FPGA (if enabled)
- When parameters are started to be written by appliaction(s) - overwritten if several calls take place during the same frame
- When parameters are finished to be written by appliaction(s) (may be overwritten)
CAPTION; printf (""); //echo "
\n"); for ($i=$now-$num_entries;$i<=$now;$i++) { printf(" Frame (hex) Period 1 2 3 4 5 6 7 \n"); } printf(" %d %08x %d ",$i,$i,$prof[$i]["dt0"]); for ($j=1;$j<8;$j++) { if ($prof[$i]["dt".$j]) printf("%d ",$prof[$i]["dt".$j]); else printf(""); } printf(" ";print_r($prof_raw);echo"\n"; } function printGammaStructure() { $gammaStructure=getGammaStructure(); printf("\n"); printf( "
\n", $gammaStructure["oldest_non_scaled"], $gammaStructure["newest_non_scaled"], $gammaStructure["oldest_all"], $gammaStructure["newest_all"], $gammaStructure["non_scaled_length"], $gammaStructure["num_locked"], $gammaStructure["locked_col"][0], $gammaStructure["locked_col"][1], $gammaStructure["locked_col"][2], $gammaStructure["locked_col"][3] ); printf("\n" ." oldest_non_scaled %d \n" ." newest_non_scaled %d \n" ." oldest_all %d \n" ." newest_all %d \n" ." non_scaled_length %d \n" ." num_locked %d locked_col 0 %d \n" ."locked_col 1 %d \n" ."locked_col 2 %d \n" ."locked_col 3 %d \n" ."
\n"); printf("\n"); // printf("
\n"); } function getGammaStructure() { $gammas_file=fopen("/dev/gamma_cache","r"); fseek($gammas_file,0,SEEK_END); $numberOfEntries=ftell($gammas_file); fclose($gammas_file); $gammaStructure=array(); $g_raw=elphel_gamma_get_raw(0); $g_raw_ul=unpack('V*',$g_raw); $gammaStructure["oldest_non_scaled"]=$g_raw_ul[5]; $gammaStructure["newest_non_scaled"]=$g_raw_ul[6]; $gammaStructure["oldest_all"]= $g_raw_ul[7]; $gammaStructure["newest_all"]= $g_raw_ul[8]; $gammaStructure["non_scaled_length"]=$g_raw_ul[9]; $gammaStructure["num_locked"]= $g_raw_ul[10]; $gammaStructure["locked_col"]= array ($g_raw_ul[11],$g_raw_ul[12],$g_raw_ul[13],$g_raw_ul[14]); $gammaStructure["entries"]= array (); for ($i=1; $i<$numberOfEntries; $i++) { $g_raw=elphel_gamma_get_raw($i); $g_raw_ul=unpack('V*',$g_raw); if ($g_raw_ul[ 4]>=0) { /// >=0 if ever used. This field seems to do nothing in the code. $hash32= $g_raw_ul[1]; $gammaStructure["entries"][$i]= array ( "index" => $i, "hash32"=> $hash32, "scale" => ($hash32 & 0xffff)/1024.0, "gamma" => (($hash32 >> 16) & 0xff)/100.0, "black" => (($hash32 >> 24) & 0xff), "valid" => $g_raw_ul[ 2], /// 0 - table invalid, 1 - table valid +2 for table locked (until sent to FPGA) "locked" => $g_raw_ul[ 3], /// bit frame+ (color<<3) locked for color/frame "this_non_scaled" => $g_raw_ul[ 4], /// 0 for non-scaled, others - (for scaled) - pointer to the corresponding non-scaled /// This is non-scaled (gamma data is full 16-bit) "newer_non_scaled" => $g_raw_ul[ 5], /// table type (non-scaled prototype) used later than this one "older_non_scaled" => $g_raw_ul[ 6], /// table type (non-scaled prototype) used before this one "newer_all" => $g_raw_ul[ 7], /// newer in a single chain of all scaled tables, regardless of the prototype "older_all" => $g_raw_ul[ 8], /// older in a single chain of all scaled tables, regardless of the prototype ///Next two pairs are the same (union) "oldest_scaled" => $g_raw_ul[ 9], /// oldest derivative of this prototype (scaled) "newest_scaled" => $g_raw_ul[10], /// newest derivative of this prototype (scaled) "newer_scaled" => $g_raw_ul[ 9], /// table type (non-scaled prototype) used later than this one "older_scaled" => $g_raw_ul[10] /// table type (non-scaled prototype) used before this one ); } } return $gammaStructure; } function printRawGamma($page=0) { $g_raw=elphel_gamma_get_raw($page); //var_dump() $g_raw_ul=unpack('V*',$g_raw); echo "\n"); printf(" index \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["index"]);printf("\n"); printf(" index \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["index"],$entry["index"]);printf("\n"); printf(" hash32 \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%08x ",$entry["hash32"]);printf("\n"); printf(" scale \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%01.3f ",$entry["scale"]);printf("\n"); printf(" gamma \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%01.3f ",$entry["gamma"]);printf("\n"); printf(" black \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["black"]);printf("\n"); printf(" valid \n"); foreach ($gammaStructure["entries"] as $entry) printf ("0x%x ",$entry["valid"]);printf("\n"); printf(" locked \n"); foreach ($gammaStructure["entries"] as $entry) printf ("0x%8x ",$entry["locked"]);printf("\n"); printf(" this_non_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["this_non_scaled"]);printf("\n"); printf(" newer_non_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["newer_non_scaled"]);printf("\n"); printf(" older_non_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["older_non_scaled"]);printf("\n"); printf(" newer_all \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["newer_all"]);printf("\n"); printf(" older_all \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["older_all"]);printf("\n"); printf(" oldest_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["oldest_scaled"]);printf("\n"); printf(" newest_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["newest_scaled"]);printf("\n"); printf(" newer_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["newer_scaled"]);printf("\n"); printf(" older_scaled \n"); foreach ($gammaStructure["entries"] as $entry) printf ("%d ",$entry["older_scaled"]);printf("\n"; printf ("Gamma cache page %d, length=%d\n",$page, strlen($g_raw)); $a=1; /// unpack started with index 1 $hash32= $g_raw_ul[$a++]; $scale= ($hash32 & 0xffff)/1024.0; $gamma= (($hash32 >> 16) & 0xff)/100.0; $black= (($hash32 >> 24) & 0xff); printf ("hash32= %08x (scale=%f gamma=%f black=%d)\n",$hash32,$scale,$gamma,$black); $valid= $g_raw_ul[$a++]; printf ("valid=%d, locked=%d\n",$valid & 1, $valid & 2); $locked= $g_raw_ul[$a++]; printf ("locked= 0x%x (for frame=%d/color=%d)\n",$locked, $locked & 7, ($locked>>3) & 3); $this_non_scaled=$g_raw_ul[$a++]; /// 0 for non-scaled printf ("this_non_scaled=%d\n",$this_non_scaled); if ($page==0) { printf ("oldest_non_scaled=%d\n",$g_raw_ul[$a++]); printf ("newest_non_scaled=%d\n",$g_raw_ul[$a++]); } else { printf ("newer_non_scaled=%d\n",$g_raw_ul[$a++]); printf ("older_non_scaled=%d\n",$g_raw_ul[$a++]); } if ($page==0) { printf ("oldest_all=%d\n",$g_raw_ul[$a++]); printf ("newest_all=%d\n",$g_raw_ul[$a++]); } else { printf ("newer_all=%d\n",$g_raw_ul[$a++]); printf ("older_all=%d\n",$g_raw_ul[$a++]); } if ($page==0) { printf ("non_scaled_length=%d\n",$g_raw_ul[$a++]); /// current number of different hash values printf ("num_locked=%d\n",$g_raw_ul[$a++]); /// number of nodes locked (until table sent to FPGA) } else if ($this_non_scaled==0){ printf ("oldest_scaled=%d\n",$g_raw_ul[$a++]); printf ("newest_scaled=%d\n",$g_raw_ul[$a++]); } else { printf ("newer_scaled=%d\n",$g_raw_ul[$a++]); printf ("older_scaled=%d\n",$g_raw_ul[$a++]); } ///data tables if ($page==0) { printf ("\nTable of locked indexes\n"); for ($color=0;$color<4; $color++) { // for ($frame=0;$frame<8; $frame++) { printf (" %4d",$g_raw_ul[$a++]); // } // printf ("\n"); } printf ("\n"); /// no need to dump the rest - it is unused in the page 0 printf ("\n\nUnused area on page 0:"); // for ($i=0; $i<417; $i++) { for ($i=0; $i<445; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); $d=$g_raw_ul[$a++]; printf (" %08x",$d); } } else { printf ("\nGamma table (direct):"); for ($i=0; $i<129; $i++) { if (($i & 0x07)==0) printf ("\n0x%03x:",$i*2); $d=$g_raw_ul[$a++]; printf (" %04x %04x",$d & 0xffff, ($d>>16) & 0xffff ); } printf ("\n\nGamma table (reverse):"); for ($i=0; $i<64; $i++) { if (($i & 0x03)==0) printf ("\n0x%03x:",$i*4); $d=$g_raw_ul[$a++]; printf (" %02x %02x %02x %02x",$d & 0xff, ($d>>8) & 0xff, ($d>>16) & 0xff, ($d>>24) & 0xff); } printf ("\n\nFPGA gamma data:"); for ($i=0; $i<256; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); $d=$g_raw_ul[$a++]; printf (" %05x",$d); } } echo "\n"; } function printHistogram($frame) { if (!$frame) $frame=elphel_get_frame()-1; $colors=array(0=>"R",1=>"G",2=>"GB",3=>"B"); $h_arr=elphel_histogram_get(0xfff,$frame); $a=0; $offset2sum=1024+255; /// last in cumulative histogram for the same color echo "\n"; for ($color=0;$color<4;$color++) { printf("\nhistogram for color #%d %s, Total number of pixels=%d (0x%x):",$color,$colors[$color],$h_arr[$a+$offset2sum],$h_arr[$a+$offset2sum]); for ($i=0; $i<256; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); printf (" %05x",$h_arr[$a++]); } printf ("\n"); } for ($color=0;$color<4;$color++) { printf("\ncumulative histogram for color #%d %s:",$color,$colors[$color]); for ($i=0; $i<256; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); printf (" %08x",$h_arr[$a++]); } printf ("\n"); } for ($color=0;$color<4;$color++) { printf("\npercentile for color #%d %s:",$color,$colors[$color]); for ($i=0; $i<256; $i++) { if (($i & 0x01f)==0) printf ("\n0x%03x:",$i); printf (" %02x",$h_arr[$a++]); } printf ("\n"); } echo "\n"; } function printRawHistogram($needed,$frame) { if (!$frame) $frame=elphel_get_frame()-1; ///FIXME: /// Use ELPHEL_CONST_HISTOGRAM_TABLE_OFFSET - byte offset of the first histogram table // $percentile_start=8232; // $percentile_start=8216; $percentile_start=8192+ ELPHEL_CONST_HISTOGRAM_TABLE_OFFSET; $colors=array(0=>"R",1=>"G",2=>"GB",3=>"B"); $h_raw=elphel_histogram_get_raw($needed,$frame); //var_dump() $h_raw_ul=unpack('V*',substr($h_raw,0,$percentile_start)); echo "\n"; $a=1; /// unpack started with index 1 $hframe= $h_raw_ul[$a++]; $gainr= $h_raw_ul[$a++]; $gaing= $h_raw_ul[$a++]; $gaingb= $h_raw_ul[$a++]; $gainb= $h_raw_ul[$a++]; $expos= $h_raw_ul[$a++]; $vexpos= $h_raw_ul[$a++]; $focus= $h_raw_ul[$a++]; $valid= $h_raw_ul[$a++]; $hash32_r= $h_raw_ul[$a++]; $hash32_g= $h_raw_ul[$a++]; $hash32_gb=$h_raw_ul[$a++]; $hash32_b= $h_raw_ul[$a++]; /// When not parsing all the data above - just skip ELPHEL_CONST_HISTOGRAM_TABLE_OFFSET bytes 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)); printf ("Exposure = %d (0x%x)usec, in scan lines (vexpos) =%d (0x%x)\n",$expos,$expos,$vexpos,$vexpos); printf ("Gains: R:0x%x G:0x%x GB:0x%x B:0x%x)\n",$gainr,$gaing,$gaingb,$gainb); printf ("Focus quality=%d (0x%x)\n",$focus,$focus); printf ("hash32: R:0x%x G:0x%x GB:0x%x B:0x%x)\n",$hash32_r,$hash32_g,$hash32_gb,$hash32_b); for ($color=0;$color<4;$color++) { $sum=0; for ($i=0; $i<256; $i++) $sum+=$h_raw_ul[$a+$i]; printf("\nhistogram for color #%d %s sum=%d (0x%x):",$color,$colors[$color],$sum,$sum); for ($i=0; $i<256; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); $d=$h_raw_ul[$a++]; printf (" %05x",$d); } printf ("\n"); } for ($color=0;$color<4;$color++) { printf("\ncumulative histogram for color #%d %s:",$color,$colors[$color]); for ($i=0; $i<256; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); $d=$h_raw_ul[$a++]; printf (" %08x",$d); } printf ("\n"); } for ($color=0;$color<4;$color++) { printf("\npercentile for color #%d %s:",$color,$colors[$color]); for ($i=0; $i<256; $i++) { if (($i & 0x01f)==0) printf ("\n0x%03x:",$i); printf (" %02x",ord($h_raw[$percentile_start+(256*$color)+$i])); } printf ("\n"); } echo "\n"; } function printRawFrame($frame) { $fp_raw=elphel_framepars_get_raw($frame); $fp_raw_ul=unpack('V*',$fp_raw); echo "\n"; printf ("\nFrame= %d(%08x)\n",$frame,$frame); $a=1; /// unpack started with index 1 echo ".pars:"; for ($i=0; $i<927; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); printf (" %08x:",$fp_raw_ul[$a++]); } printf ("\n.functions= %08x:",$fp_raw_ul[$a++]); echo "\n.modsince:"; for ($i=0; $i<31; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); printf (" %08x:",$fp_raw_ul[$a++]); } printf ("\n.modsince32= %08x:",$fp_raw_ul[$a++]); echo "\n.mod:"; for ($i=0; $i<31; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); printf (" %08x:",$fp_raw_ul[$a++]); } printf ("\n.mod32= %08x:",$fp_raw_ul[$a++]); echo "\n.needproc:"; for ($i=0; $i<31; $i++) { if (($i & 0x0f)==0) printf ("\n0x%03x:",$i); printf (" %08x:",$fp_raw_ul[$a++]); } printf ("\n.needproc32= %08x:",$fp_raw_ul[$a++]); // var_dump($fp_raw_ul); echo "\n"; } function myval ($s) { $current_frame=elphel_get_frame(); $s=trim($s,"\" "); if (strtoupper(substr($s,0,2))=="0X") return intval(hexdec($s)); else switch ($s) { case "this": return elphel_get_frame(); break; case "next": case "next1": return elphel_get_frame()+1; break; case "next2": return elphel_get_frame()+2; break; case "next3": return elphel_get_frame()+3; break; case "next4": return elphel_get_frame()+4; break; case "next5": return elphel_get_frame()+5; break; case "next6": return elphel_get_frame()+6; break; break; case "prev": case "prev1": return elphel_get_frame()-1; break; case "prev2": return elphel_get_frame()-2; break; case "prev3": return elphel_get_frame()-3; break; case "prev4": return elphel_get_frame()-4; break; case "prev5": return elphel_get_frame()-5; break; case "prev6": return elphel_get_frame()-6; break; default: return intval($s); } } ?>