Commit 41401431 authored by Andrey Filippov's avatar Andrey Filippov

Added python test code

parent 3c863b6f
# Runs 'make', 'make install', and 'make clean' in specified subdirectories
SUBDIRS := src/php_top # src1
SUBDIRS := src/php_top src/python_tests # src1
INSTALLDIRS = $(SUBDIRS:%=install-%)
CLEANDIRS = $(SUBDIRS:%=clean-%)
......
......@@ -106,14 +106,16 @@
*!
*/
function myval ($s) {
$s=trim($s,"\" ");
if (strtoupper(substr($s,0,2))=="0X") return intval(hexdec($s));
else return intval($s);
function myval($s) {
$s = trim ( $s, "\" " );
if (strtoupper ( substr ( $s, 0, 2 ) ) == "0X")
return intval ( hexdec ( $s ) );
else
return intval ( $s );
}
$imgsrv="http://".$_SERVER['SERVER_ADDR'].":8081";
if (count($_GET)==0) {
echo <<<USAGE
$imgsrv = "http://" . $_SERVER ['SERVER_ADDR'] . ":8081";
if (count ( $_GET ) == 0) {
echo <<<USAGE
<p>This is a collection of tools for the 8.0 software development/testing, you can provide parameters in HTTP GET request.</p>
<p>At this alpha stage very few programs/pages are working, among them:</p>
<ul>
......@@ -145,55 +147,80 @@ function myval ($s) {
<li><b>"gamma=G</b> - show raw data of the gamma page <b>G</b> (page 0 is a root)</li>
</ul>
USAGE;
exit (0);
exit ( 0 );
}
//$_SERVER["SERVER_ADDR"] . ":8081
$sensor_port=0; /// TODO: NC393 - add sensor port control, initially will use $sensor_port=0 for all php functions that require it
$address="";
$data="";
$frame="";
$gamma_page="";
$flags=0;
$elp_const=get_defined_constants(true);
$elp_const=$elp_const["elphel"];
$test=0;
$hist_needed=0;
foreach($_GET as $key=>$value) {
switch($key) {
case "profile":
$num_entries=myval($value);
//echo "<pre>";
$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]="";
}
// $_SERVER["SERVER_ADDR"] . ":8081
$sensor_port = 0; // / TODO: NC393 - add sensor port control, initially will use $sensor_port=0 for all php functions that require it
$sensor_subchn = 0; // / TODO: NC393 - add sensor port control, initially will use $sensor_port=0 for all php functions that require it
$address = "";
$data = "";
$frame = "";
$gamma_page = "";
$flags = 0;
$elp_const = get_defined_constants ( true );
$elp_const = $elp_const ["elphel"];
$test = 0;
$hist_needed = 0;
$framepars_paths = array ("/dev/frameparsall0",
"/dev/frameparsall1",
"/dev/frameparsall2",
"/dev/frameparsall3");
echo <<<CAPTION
if (array_key_exists ( 'sensor_port', $_GET )) {
$sensor_port = (myval($_GET ['sensor_port'])) & 3;
}
if (array_key_exists ( 'sensor_subchn', $_GET )) {
$sensor_port = (myval($_GET ['sensor_subchn'])) & 3;
}
$framepars_path = $framepars_paths[$sensor_port];
foreach ( $_GET as $key => $value ) {
switch ($key) {
case "profile" :
$num_entries = myval ( $value );
// echo "<pre>";
$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 ($GLOBALS['sensor_port']) - 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 ($GLOBALS['sensor_port'], $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] = "";
}
echo <<<CAPTION
<p>reading profile time start=$time_start </p>
<p>reading profile time end=$time_end </p>
<ol>Profiling interrupt/tasklet execution time in microseconds, starting from the start of the frame
......@@ -207,337 +234,351 @@ $time_end=elphel_get_fpga_time();
</oul>
<br/><br/>
CAPTION;
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");
for ($i=$now-$num_entries;$i<=$now;$i++) {
printf("<tr style='align:right'><td>%d</td><td>%08x</td><td>%d</td>",$i,$i,$prof[$i]["dt0"]);
for ($j=1;$j<8;$j++) {
if ($prof[$i]["dt".$j]) printf("<td>%d</td>",$prof[$i]["dt".$j]);
else printf("<td>&nbsp;</td>");
}
printf("</tr>\n");
}
printf("</table>");
//echo "<pre>";print_r($prof_raw);echo"</pre>\n";
exit (0);
case "histogram_direct":
case "histogram_reverse":
case "gamma_direct":
case "gamma_reverse":
$xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
$value=floatval($value);
switch($key) {
case "histogram_direct":
$xml->addChild ('histogram_direct_r', elphel_histogram(0,$value));
$xml->addChild ('histogram_direct_g', elphel_histogram(1,$value));
$xml->addChild ('histogram_direct_gb',elphel_histogram(2,$value));
$xml->addChild ('histogram_direct_b', elphel_histogram(3,$value));
break;
case "histogram_reverse":
$xml->addChild ('histogram_reverse_r', elphel_reverse_histogram(0,$value));
$xml->addChild ('histogram_reverse_g', elphel_reverse_histogram(1,$value));
$xml->addChild ('histogram_reverse_gb',elphel_reverse_histogram(2,$value));
$xml->addChild ('histogram_reverse_b', elphel_reverse_histogram(3,$value));
break;
case "gamma_direct":
$xml->addChild ('gamma_direct_r', elphel_gamma(0,$value));
$xml->addChild ('gamma_direct_g', elphel_gamma(1,$value));
$xml->addChild ('gamma_direct_gb',elphel_gamma(2,$value));
$xml->addChild ('gamma_direct_b', elphel_gamma(3,$value));
break;
case "gamma_reverse":
$xml->addChild ('gamma_reverse_r', elphel_reverse_gamma(0,$value));
$xml->addChild ('gamma_reverse_g', elphel_reverse_gamma(1,$value));
$xml->addChild ('gamma_reverse_gb',elphel_reverse_gamma(2,$value));
$xml->addChild ('gamma_reverse_b', elphel_reverse_gamma(3,$value));
break;
}
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
printf($rslt);
exit (0);
case "cmd":
case "seek":
case "fseek":
case "lseek":
$xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
if (!$value) {
$xml->addChild ('frame',elphel_get_frame());
$xml->addChild ('frame8',elphel_fpga_read(0x16) & 7);
} else if ($value=="time"){
$xml->addChild ('fpga_time',elphel_get_fpga_time());
} else if ($value=="irqoff"){
$framepars_file=fopen("/dev/frameparsall","r");
$xml->addChild ('irqoff_result',fseek($framepars_file,ELPHEL_LSEEK_INTERRUPT_OFF,SEEK_END)); //#define LSEEK_INTERRUPT_OFF 0x23 /// disable camera interrupts
fclose($framepars_file);
} else if ($value=="irqon"){
/// wait for frame8=0
while (elphel_fpga_read(0x16) & 7) usleep (1000); /// Maybe needed to wait for 7, then 0?
$framepars_file=fopen("/dev/frameparsall","r");
$xml->addChild ('irqon_result',fseek($framepars_file,ELPHEL_LSEEK_INTERRUPT_ON,SEEK_END)); //#define LSEEK_INTERRUPT_ON 0x24 /// enable camera interrupts
fclose($framepars_file);
} else if ($value=="init"){
$framepars_file=fopen("/dev/frameparsall","r");
$xml->addChild ('LSEEK_FRAMEPARS_INIT',fseek($framepars_file,ELPHEL_LSEEK_FRAMEPARS_INIT,SEEK_END));
$xml->addChild ('elphel_set_P_value', elphel_set_P_value(ELPHEL_SENSOR, 0x00, 0, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC));/// will start detection
$xml->addChild ('LSEEK_SENSORPROC', fseek($framepars_file,ELPHEL_LSEEK_SENSORPROC, SEEK_END));
$frame=0;
// gets half-frame
elphel_set_P_value(ELPHEL_MAXAHEAD, 2, 0, 8); /// When servicing interrupts, try programming up to 2 frames ahead of due time)
elphel_set_P_value(ELPHEL_FPGA_XTRA, 1000, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC); ///compressor needs extra 1000 cycles to compress a frame (estimate)
elphel_set_P_value(ELPHEL_EXTERN_TIMESTAMP, 1, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC); /// only used with async trigger
/// good (latency should be changed, but for now that will make a correct initialization - maybe obsolete)
elphel_set_P_value(ELPHEL_BITS, 8, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_QUALITY, 80, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COLOR, 1, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_BAYER, 0, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_SENSOR_RUN, 2, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COMPRESSOR_RUN, 2, $frame+4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC); /// run compressor
/*
elphel_set_P_value(ELPHEL_BITS, 8, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_QUALITY, 80, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COLOR, 1, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COLOR_SATURATION_BLUE,200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_COLOR_SATURATION_RED, 200, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
elphel_set_P_value(ELPHEL_SENSOR_RUN, 2, $frame+3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC);
*/
fclose($framepars_file);
/*
} else if ($value=="gamma1"){
*/
$gamma=57;
$black=10;
$scale_r= (int) (1.0 * 1024);
$scale_g= (int) (0.9 * 1024);
$scale_b= (int) (1.1 * 1024);
$scale_gb=(int) (0.9 * 1024);
elphel_gamma_add (0.01*$gamma, $black);
#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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniqualy identify the table for applications
$gamma_pars=array("GTAB_R" => ($black<<24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black<<24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black<<24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
$frame=elphel_get_frame(); //0
elphel_set_P_arr ($gamma_pars, $frame+3,0);
} else if ($value=="gamma57"){
$gamma=57;
$black=10;
$scale_r= (int) (1.0 * 1024);
$scale_g= (int) (1.0 * 1024);
$scale_b= (int) (1.0 * 1024);
$scale_gb=(int) (1.0 * 1024);
elphel_gamma_add (0.01*$gamma, $black);
#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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
$gamma_pars=array("GTAB_R" => ($black<<24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black<<24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black<<24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
$frame=elphel_get_frame(); //0
elphel_set_P_arr ($gamma_pars, $frame+3,0);
} else if ($value=="gamma"){
$gamma=60;
$black=10;
$scale_r= (int) (1.0 * 1024);
$scale_g= (int) (0.9 * 1024);
$scale_b= (int) (1.1 * 1024);
$scale_gb=(int) (0.9 * 1024);
elphel_gamma_add (0.01*$gamma, $black);
#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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
$gamma_pars=array("GTAB_R" => ($black<<24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black<<24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black<<24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
$frame=elphel_get_frame(); //0
elphel_set_P_arr ($gamma_pars, $frame+3,0);
} else if ($value=="linear"){
$gamma=100;
$black=0;
$scale_r= (int) (1.0 * 1024);
$scale_g= (int) (1.0 * 1024);
$scale_b= (int) (1.0 * 1024);
$scale_gb=(int) (1.0 * 1024);
elphel_gamma_add (0.01*$gamma, $black);
#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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
$gamma_pars=array("GTAB_R" => ($black<<24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black<<24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black<<24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black<<24) | ($gamma << 16) | ($scale_gb & 0xffff));
$frame=elphel_get_frame(); //0
elphel_set_P_arr ($gamma_pars, $frame+3,0);
} else if ($value=="initgamma"){
$gammas_file=fopen("/dev/gamma_cache","r");
$xml->addChild ('LSEEK_GAMMA_INIT',fseek($gammas_file,ELPHEL_LSEEK_GAMMA_INIT,SEEK_END));
fclose($gammas_file);
} else if ($value=="jpegheader"){
$circbuf_file=fopen("/dev/circbuf","r");
fseek($circbuf_file,ELPHEL_LSEEK_CIRC_LAST,SEEK_END);
$jpeg_start=ftell($circbuf_file);
$xml->addChild ('circbuf_pointer',sprintf("0x%x (0x%x)",$jpeg_start,$jpeg_start>>2));
fclose($circbuf_file);
$header_file=fopen("/dev/jpeghead","r");
/// Now select right frame (different frames may have different header sizes)
fseek($header_file,$jpeg_start+1,SEEK_END); /// selects frame, creates header
fseek($header_file,0,SEEK_END); /// positions to the end
$header_size=ftell($header_file); ///
$xml->addChild ('header_size',$header_size);
fseek($header_file,0,SEEK_SET); /// positions to the beginning
$header=fread ($header_file,8192);
$xml->addChild ('header_read_length',strlen($header));
fclose($header_file);
$aheader=unpack('C*',$header);
for ($i=0; $i<count($aheader) ;$i+=16){
$d="";
for ($j=$i; ($j<$i+16) && ($j<count($aheader)); $j++) $d.=sprintf(" %02x",$aheader[$j+1]);
$xml->addChild (sprintf('header%03x',$i),$d);
}
} else if ($value=="reset"){
$framepars_file=fopen("/dev/frameparsall","r");
$xml->addChild ('LSEEK_DMA_STOP', fseek($framepars_file,ELPHEL_LSEEK_DMA_STOP,SEEK_END));
$xml->addChild ('LSEEK_DMA_INIT', fseek($framepars_file,ELPHEL_LSEEK_DMA_INIT,SEEK_END));
$xml->addChild ('LSEEK_COMPRESSOR_RESET', fseek($framepars_file,ELPHEL_LSEEK_COMPRESSOR_RESET,SEEK_END));
fclose($framepars_file);
} else if ($value=="constants"){
echo "<pre>\n";
print_r($elp_const);
echo "</pre>\n";
exit(0);
} else {
$framepars_file=fopen("/dev/frameparsall","r");
$xml->addChild ('lseek_'.$value,fseek($framepars_file,$value,SEEK_END));
fclose($framepars_file);
}
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
printf($rslt);
exit (0);
case "a": /// Make it recognize P_* constants?
case "adr":
case "na": /// add flag "new"
case "sa": /// add flag "static"
$address=myval ($value);
if (($address==0) && (strlen($value)>3)) { // suspect constant
$address=$elp_const["ELPHEL_".$value];
}
switch ($key){
case "na": /// flags defined in upper half of 32-bit word and can be OR-ed with address. When provided as "flags=" 0x3 is the same as 0x30000 ( internally flags = (flags | (flags <<16)) & 0xffff0000)
$address |= ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC;;
break;
case "sa":
$address |= ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO;
break;
}
if (($address & 0xffff) ==0) { /// wrong address - probably mistyped constant name
$xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
$xml->addChild ('ERROR','"Wrong address==0, probably misspelled constant: \''.$value.'\'"' );
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
printf($rslt);
exit (0);
}
break;
case "d":
case "data":
$data=myval ($value);
break;
case "hist_raw":
$hist_needed++;
case "hist":
case "histogram":
$hist_needed++; /// and fall to "frame"
case "f":
case "frame":
$current_frame=elphel_get_frame();
switch ($value) {
case "this": $frame=$current_frame;
break;
case "next": $frame=$current_frame+1;
break;
case "next2": $frame=$current_frame+2;
break;
case "next3": $frame=$current_frame+3;
break;
case "next4": $frame=$current_frame+4;
break;
case "next5": $frame=$current_frame+5;
break;
case "next6": $frame=$current_frame+6;
break;
break;
case "prev": $frame=$current_frame-1;
break;
case "prev2": $frame=$current_frame-2;
break;
case "prev3": $frame=$current_frame-3;
break;
case "prev4": $frame=$current_frame-4;
break;
case "prev5": $frame=$current_frame-5;
break;
case "prev6": $frame=$current_frame-6;
break;
default:
$frame=myval ($value);
}
break;
case "flags": /// simple flags - "z(ero)"/"(s(tatic), "n(new)",+ constants
case "flag":
switch ($value) {
case "z":
case "zero":
case "s":
case "static":
$flags=ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO;
break;
case "n":
case "new":
$flags=ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC;
break;
default:
$flags=myval ($value);
}
break;
case "t":
case "test":
$test=myval ($value);
break;
case "gamma":
case "gamma_page":
$gamma_page=myval ($value);
break;
case "gamma_structure":
/// later add value - list of pages to process
printGammaStructure();
/* echo "<pre>\n";
var_dump(getGammaStructure());
echo "</pre>\n";*/
exit (0);
}
}
if ($address==="") {
if ($frame==="") {
if ($gamma_page==="") {
echo <<<USAGE
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" );
for($i = $now - $num_entries; $i <= $now; $i ++) {
printf ( "<tr style='align:right'><td>%d</td><td>%08x</td><td>%d</td>", $i, $i, $prof [$i] ["dt0"] );
for($j = 1; $j < 8; $j ++) {
if ($prof [$i] ["dt" . $j])
printf ( "<td>%d</td>", $prof [$i] ["dt" . $j] );
else
printf ( "<td>&nbsp;</td>" );
}
printf ( "</tr>\n" );
}
printf ( "</table>" );
// echo "<pre>";print_r($prof_raw);echo"</pre>\n";
exit ( 0 );
case "histogram_direct" :
case "histogram_reverse" :
case "gamma_direct" :
case "gamma_reverse" :
$xml = new SimpleXMLElement ( "<?xml version='1.0'?><framepars/>" );
$value = floatval ( $value );
switch ($key) {
case "histogram_direct" :
$xml->addChild ( 'histogram_direct_r', elphel_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 0, $value ) );
$xml->addChild ( 'histogram_direct_g', elphel_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 1, $value ) );
$xml->addChild ( 'histogram_direct_gb', elphel_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 2, $value ) );
$xml->addChild ( 'histogram_direct_b', elphel_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 3, $value ) );
break;
case "histogram_reverse" :
$xml->addChild ( 'histogram_reverse_r', elphel_reverse_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 0, $value ) );
$xml->addChild ( 'histogram_reverse_g', elphel_reverse_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 1, $value ) );
$xml->addChild ( 'histogram_reverse_gb', elphel_reverse_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 2, $value ) );
$xml->addChild ( 'histogram_reverse_b', elphel_reverse_histogram ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 3, $value ) );
break;
case "gamma_direct" :
$xml->addChild ( 'gamma_direct_r', elphel_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 0, $value ) );
$xml->addChild ( 'gamma_direct_g', elphel_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 1, $value ) );
$xml->addChild ( 'gamma_direct_gb', elphel_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 2, $value ) );
$xml->addChild ( 'gamma_direct_b', elphel_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 3, $value ) );
break;
case "gamma_reverse" :
$xml->addChild ( 'gamma_reverse_r', elphel_reverse_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 0, $value ) );
$xml->addChild ( 'gamma_reverse_g', elphel_reverse_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 1, $value ) );
$xml->addChild ( 'gamma_reverse_gb', elphel_reverse_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 2, $value ) );
$xml->addChild ( 'gamma_reverse_b', elphel_reverse_gamma ($GLOBALS['sensor_port'],$GLOBALS['$sensor_subchn'], 3, $value ) );
break;
}
$rslt = $xml->asXML ();
header ( "Content-Type: text/xml" );
header ( "Content-Length: " . strlen ( $rslt ) . "\n" );
header ( "Pragma: no-cache\n" );
printf ( $rslt );
exit ( 0 );
case "cmd" :
case "seek" :
case "fseek" :
case "lseek" :
$xml = new SimpleXMLElement ( "<?xml version='1.0'?><framepars/>" );
if (! $value) {
$xml->addChild ( 'frame', elphel_get_frame ($GLOBALS['sensor_port']) );
// $xml->addChild ( 'frame8', elphel_fpga_read ( 0x16 ) & 7 );
} else if ($value == "time") {
$xml->addChild ( 'fpga_time', elphel_get_fpga_time ($GLOBALS['sensor_port']) );
} else if ($value == "irqoff") {
$framepars_file = fopen ( $framepars_path, "r" );
$xml->addChild ( 'irqoff_result', fseek ( $framepars_file, ELPHEL_LSEEK_INTERRUPT_OFF, SEEK_END ) ); // #define LSEEK_INTERRUPT_OFF 0x23 /// disable camera interrupts
fclose ( $framepars_file );
} else if ($value == "irqon") {
// / wait for frame8=0
// while ( elphel_fpga_read ( 0x16 ) & 7 )
// usleep ( 1000 ); // / Maybe needed to wait for 7, then 0?
$framepars_file = fopen ( $framepars_path, "r" );
$xml->addChild ( 'irqon_result', fseek ( $framepars_file, ELPHEL_LSEEK_INTERRUPT_ON, SEEK_END ) ); // #define LSEEK_INTERRUPT_ON 0x24 /// enable camera interrupts
fclose ( $framepars_file );
} else if ($value == "init") {
$framepars_file = fopen ( $framepars_path, "r" );
$xml->addChild ( 'LSEEK_FRAMEPARS_INIT', fseek ( $framepars_file, ELPHEL_LSEEK_FRAMEPARS_INIT, SEEK_END ) );
$xml->addChild ( 'elphel_set_P_value', elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_SENSOR, 0x00, 0, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC ) ); // / will start detection
$xml->addChild ( 'LSEEK_SENSORPROC', fseek ( $framepars_file, ELPHEL_LSEEK_SENSORPROC, SEEK_END ) );
$frame = 0;
// gets half-frame
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_MAXAHEAD, 2, 0, 8 ); // / When servicing interrupts, try programming up to 2 frames ahead of due time)
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_FPGA_XTRA, 1000, $frame + 3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC ); // /compressor needs extra 1000 cycles to compress a frame (estimate)
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_EXTERN_TIMESTAMP, 1, $frame + 3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC ); // / only used with async trigger
// / good (latency should be changed, but for now that will make a correct initialization - maybe obsolete)
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_BITS, 8, $frame + 3, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_QUALITY, 80, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_COLOR, 1, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_COLOR_SATURATION_BLUE, 200, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_COLOR_SATURATION_RED, 200, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_BAYER, 0, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_SENSOR_RUN, 2, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC );
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_COMPRESSOR_RUN, 2, $frame + 4, ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC ); // / run compressor
fclose ( $framepars_file );
$gamma = 57;
$black = 10;
$scale_r = ( int ) (1.0 * 1024);
$scale_g = ( int ) (0.9 * 1024);
$scale_b = ( int ) (1.1 * 1024);
$scale_gb = ( int ) (0.9 * 1024);
elphel_gamma_add ( 0.01 * $gamma, $black ); // does not depend on $GLOBALS['sensor_port']
// 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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniqualy identify the table for applications
$gamma_pars = array (
"GTAB_R" => ($black << 24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black << 24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black << 24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black << 24) | ($gamma << 16) | ($scale_gb & 0xffff)
);
$frame = elphel_get_frame ($GLOBALS['sensor_port']); // 0
elphel_set_P_arr ($GLOBALS['sensor_port'], $gamma_pars, $frame + 3, 0 );
} else if ($value == "gamma57") {
$gamma = 57;
$black = 10;
$scale_r = ( int ) (1.0 * 1024);
$scale_g = ( int ) (1.0 * 1024);
$scale_b = ( int ) (1.0 * 1024);
$scale_gb = ( int ) (1.0 * 1024);
elphel_gamma_add ( 0.01 * $gamma, $black ); // does not depend on $GLOBALS['sensor_port']
// 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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
$gamma_pars = array (
"GTAB_R" => ($black << 24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black << 24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black << 24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black << 24) | ($gamma << 16) | ($scale_gb & 0xffff)
);
$frame = elphel_get_frame ($GLOBALS['sensor_port']); // 0
elphel_set_P_arr ($GLOBALS['sensor_port'], $gamma_pars, $frame + 3, 0 );
} else if ($value == "gamma") {
$gamma = 60;
$black = 10;
$scale_r = ( int ) (1.0 * 1024);
$scale_g = ( int ) (0.9 * 1024);
$scale_b = ( int ) (1.1 * 1024);
$scale_gb = ( int ) (0.9 * 1024);
elphel_gamma_add ( 0.01 * $gamma, $black );
// 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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
$gamma_pars = array (
"GTAB_R" => ($black << 24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black << 24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black << 24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black << 24) | ($gamma << 16) | ($scale_gb & 0xffff)
);
$frame = elphel_get_frame ($GLOBALS['sensor_port']); // 0
elphel_set_P_arr ($GLOBALS['sensor_port'], $gamma_pars, $frame + 3, 0 );
} else if ($value == "linear") {
$gamma = 100;
$black = 0;
$scale_r = ( int ) (1.0 * 1024);
$scale_g = ( int ) (1.0 * 1024);
$scale_b = ( int ) (1.0 * 1024);
$scale_gb = ( int ) (1.0 * 1024);
elphel_gamma_add ( 0.01 * $gamma, $black ); // does not depend on $GLOBALS['sensor_port']
// 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.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
$gamma_pars = array (
"GTAB_R" => ($black << 24) | ($gamma << 16) | ($scale_r & 0xffff),
"GTAB_G" => ($black << 24) | ($gamma << 16) | ($scale_g & 0xffff),
"GTAB_B" => ($black << 24) | ($gamma << 16) | ($scale_b & 0xffff),
"GTAB_GB" => ($black << 24) | ($gamma << 16) | ($scale_gb & 0xffff)
);
$frame = elphel_get_frame ($GLOBALS['sensor_port']); // 0
elphel_set_P_arr ($GLOBALS['sensor_port'], $gamma_pars, $frame + 3, 0 );
} else if ($value == "initgamma") {
$gammas_file = fopen ( "/dev/gamma_cache", "r" );
$xml->addChild ( 'LSEEK_GAMMA_INIT', fseek ( $gammas_file, ELPHEL_LSEEK_GAMMA_INIT, SEEK_END ) );
fclose ( $gammas_file );
} else if ($value == "jpegheader") {
$circbuf_file = fopen ( "/dev/circbuf", "r" );
fseek ( $circbuf_file, ELPHEL_LSEEK_CIRC_LAST, SEEK_END );
$jpeg_start = ftell ( $circbuf_file );
$xml->addChild ( 'circbuf_pointer', sprintf ( "0x%x (0x%x)", $jpeg_start, $jpeg_start >> 2 ) );
fclose ( $circbuf_file );
$header_file = fopen ( "/dev/jpeghead", "r" );
// / Now select right frame (different frames may have different header sizes)
fseek ( $header_file, $jpeg_start + 1, SEEK_END ); // / selects frame, creates header
fseek ( $header_file, 0, SEEK_END ); // / positions to the end
$header_size = ftell ( $header_file ); // /
$xml->addChild ( 'header_size', $header_size );
fseek ( $header_file, 0, SEEK_SET ); // / positions to the beginning
$header = fread ( $header_file, 8192 );
$xml->addChild ( 'header_read_length', strlen ( $header ) );
fclose ( $header_file );
$aheader = unpack ( 'C*', $header );
for($i = 0; $i < count ( $aheader ); $i += 16) {
$d = "";
for($j = $i; ($j < $i + 16) && ($j < count ( $aheader )); $j ++)
$d .= sprintf ( " %02x", $aheader [$j + 1] );
$xml->addChild ( sprintf ( 'header%03x', $i ), $d );
}
} else if ($value == "reset") {
$framepars_file = fopen ( $framepars_path, "r" );
$xml->addChild ( 'LSEEK_DMA_STOP', fseek ( $framepars_file, ELPHEL_LSEEK_DMA_STOP, SEEK_END ) );
$xml->addChild ( 'LSEEK_DMA_INIT', fseek ( $framepars_file, ELPHEL_LSEEK_DMA_INIT, SEEK_END ) );
$xml->addChild ( 'LSEEK_COMPRESSOR_RESET', fseek ( $framepars_file, ELPHEL_LSEEK_COMPRESSOR_RESET, SEEK_END ) );
fclose ( $framepars_file );
} else if ($value == "constants") {
echo "<pre>\n";
print_r ( $elp_const );
echo "</pre>\n";
exit ( 0 );
} else {
$framepars_file = fopen ( $framepars_path, "r" );
$xml->addChild ( 'lseek_' . $value, fseek ( $framepars_file, $value, SEEK_END ) );
fclose ( $framepars_file );
}
$rslt = $xml->asXML ();
header ( "Content-Type: text/xml" );
header ( "Content-Length: " . strlen ( $rslt ) . "\n" );
header ( "Pragma: no-cache\n" );
printf ( $rslt );
exit ( 0 );
case "a" : // / Make it recognize P_* constants?
case "adr" :
case "na" : // / add flag "new"
case "sa" : // / add flag "static"
$address = myval ( $value );
if (($address == 0) && (strlen ( $value ) > 3)) { // suspect constant
$address = $elp_const ["ELPHEL_" . $value];
}
switch ($key) {
case "na" : // / flags defined in upper half of 32-bit word and can be OR-ed with address. When provided as "flags=" 0x3 is the same as 0x30000 ( internally flags = (flags | (flags <<16)) & 0xffff0000)
$address |= ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC;
;
break;
case "sa" :
$address |= ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO;
break;
}
if (($address & 0xffff) == 0) { // / wrong address - probably mistyped constant name
$xml = new SimpleXMLElement ( "<?xml version='1.0'?><framepars/>" );
$xml->addChild ( 'ERROR', '"Wrong address==0, probably misspelled constant: \'' . $value . '\'"' );
$rslt = $xml->asXML ();
header ( "Content-Type: text/xml" );
header ( "Content-Length: " . strlen ( $rslt ) . "\n" );
header ( "Pragma: no-cache\n" );
printf ( $rslt );
exit ( 0 );
}
break;
case "d" :
case "data" :
$data = myval ( $value );
break;
case "hist_raw" :
$hist_needed ++;
case "hist" :
case "histogram" :
$hist_needed ++; // / and fall to "frame"
case "f" :
case "frame" :
$current_frame = elphel_get_frame ($GLOBALS['sensor_port']);
switch ($value) {
case "this" :
$frame = $current_frame;
break;
case "next" :
$frame = $current_frame + 1;
break;
case "next2" :
$frame = $current_frame + 2;
break;
case "next3" :
$frame = $current_frame + 3;
break;
case "next4" :
$frame = $current_frame + 4;
break;
case "next5" :
$frame = $current_frame + 5;
break;
case "next6" :
$frame = $current_frame + 6;
break;
break;
case "prev" :
$frame = $current_frame - 1;
break;
case "prev2" :
$frame = $current_frame - 2;
break;
case "prev3" :
$frame = $current_frame - 3;
break;
case "prev4" :
$frame = $current_frame - 4;
break;
case "prev5" :
$frame = $current_frame - 5;
break;
case "prev6" :
$frame = $current_frame - 6;
break;
default :
$frame = myval ( $value );
}
break;
case "flags" : // / simple flags - "z(ero)"/"(s(tatic), "n(new)",+ constants
case "flag" :
switch ($value) {
case "z" :
case "zero" :
case "s" :
case "static" :
$flags = ELPHEL_CONST_FRAMEPAIR_FRAME_ZERO;
break;
case "n" :
case "new" :
$flags = ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC;
break;
default :
$flags = myval ( $value );
}
break;
case "t" :
case "test" :
$test = myval ( $value );
break;
case "gamma" :
case "gamma_page" :
$gamma_page = myval ( $value );
break;
case "gamma_structure" :
// / later add value - list of pages to process
printGammaStructure ();
/*
* echo "<pre>\n";
* var_dump(getGammaStructure());
* echo "</pre>\n";
*/
exit ( 0 );
}
}
if ($address === "") {
if ($frame === "") {
if ($gamma_page === "") {
echo <<<USAGE
<p>read/fwrite frame parameters, execute commands</p>
<ul>
<li><b>framepars.php?cmd=<i>command number</i></b> - execute <i>register_address</i></li>
......@@ -545,468 +586,543 @@ CAPTION;
<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>
</ul>
USAGE;
exit (0);
} else {
///read raw gamma page
printRawGamma($gamma_page);
exit (0);
}
} else { ///$frame !== ""
switch ($hist_needed) {
case 2:
printRawHistogram(0xfff,$frame);
exit (0);
case 1:
printHistogram($frame);
exit (0);
default:
/// read raw framepars
printRawFrame($frame);
exit (0);
}
}
}
$xml = new SimpleXMLElement("<?xml version='1.0'?><framepars/>");
$xml->addChild ('frame',$frame);
$xml->addChild ('hex_frame',sprintf("0x%x",$frame));
$xml->addChild ('address',$address);
$xml->addChild ('hex_address',sprintf("0x%x",$address));
if ($data==="") {
if ($frame==='') $data=elphel_get_P_value($address);
else $data=elphel_get_P_value($address, $frame);
$xml->addChild ('read',$data);
$xml->addChild ('hex_read',sprintf("0x%x",$data));
} else {
if (($frame==='') && flags) $frame =0;
$xml->addChild ('frame_was',$frame);
///***************************************************************************
if ($test>0) {
ob_flush(); flush();
elphel_set_P_value(ELPHEL_COMPRESSOR_RUN | ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC, ELPHEL_CONST_COMPRESSOR_RUN_CONT, $current_frame+2);
$frame+=2;
$current_frame+=2;
elphel_skip_frames(2);
}
if ($frame==='') elphel_set_P_value($address, $data);
else elphel_set_P_value($address, $data, $frame, $flags);
if ($test>0) {
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);
ob_flush(); flush(); ///OK here
$circbuf_file=fopen("/dev/circbuf","r");
$current_frame=$frame;
printf ("<p>frame=%d (0x%x), time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
elphel_skip_frames(2);
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();
// printf ("<p>start_frame2=0x%x</p>\n",$current_frame);
elphel_set_P_value(ELPHEL_COMPRESSOR_RUN | ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC, ELPHEL_CONST_COMPRESSOR_RUN_STOP, $current_frame+4);
printf ("<p>frame=%d (0x%x), time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
$current_frame+=6; /// to be sure - less is enough?
for ($i=0;$i<6;$i++) {
elphel_skip_frames(1);
printf ("<p>skipped 1 frame - frame=%d (0x%x), time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
}
// elphel_skip_frames(6);
// printf ("<p>after skip 6 frames - frame=0x%x, time=%d </p>\n",elphel_get_frame(),time()); ob_flush(); flush();
fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
///stuck before here?
printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
elphel_skip_frames(1);
fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
elphel_skip_frames(1);
fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
elphel_skip_frames(1);
fseek($circbuf_file,LSEEK_CIRC_TOWP,SEEK_END);
printf ("<p>frame=%d (0x%x) time=%d </p>\n",elphel_get_frame(),elphel_get_frame(),time()); ob_flush(); flush();
/// Strange - frame normal delay sometimes wrong images in the
// printf ("<p>end_frame2=0x%x</p>\n",elphel_get_frame());
fclose($circbuf_file);
image_table8 ();
exit (0);
$xml->addChild ('test',$test);
}
$xml->addChild ('frame',$frame);
$xml->addChild ('written',$data);
$xml->addChild ('hex_written',sprintf("0x%x",$data));
$xml->addChild ('flags',sprintf("0x%x",$flags));
}
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
printf($rslt);
exit (0);
exit ( 0 );
} else {
// /read raw gamma page
printRawGamma ( $gamma_page );
exit ( 0 );
}
} else { // /$frame !== ""
switch ($hist_needed) {
case 2 :
printRawHistogram ( 0xfff, $frame );
exit ( 0 );
case 1 :
printHistogram ( $frame );
exit ( 0 );
default :
// / read raw framepars
printRawFrame ( $frame );
exit ( 0 );
}
}
}
$xml = new SimpleXMLElement ( "<?xml version='1.0'?><framepars/>" );
$xml->addChild ( 'frame', $frame );
$xml->addChild ( 'hex_frame', sprintf ( "0x%x", $frame ) );
$xml->addChild ( 'address', $address );
$xml->addChild ( 'hex_address', sprintf ( "0x%x", $address ) );
if ($data === "") {
if ($frame === '')
$data = elphel_get_P_value ($GLOBALS['sensor_port'], $address );
else
$data = elphel_get_P_value ($GLOBALS['sensor_port'], $address, $frame );
$xml->addChild ( 'read', $data );
$xml->addChild ( 'hex_read', sprintf ( "0x%x", $data ) );
} else {
if (($frame === '') && flags)
$frame = 0;
$xml->addChild ( 'frame_was', $frame );
// /***************************************************************************
if ($test > 0) {
ob_flush ();
flush ();
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_COMPRESSOR_RUN | ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC, ELPHEL_CONST_COMPRESSOR_RUN_CONT, $current_frame + 2 );
$frame += 2;
$current_frame += 2;
elphel_skip_frames ($GLOBALS['sensor_port'], 2 );
}
if ($frame === '')
elphel_set_P_value ($GLOBALS['sensor_port'], $address, $data );
else
elphel_set_P_value ($GLOBALS['sensor_port'], $address, $data, $frame, $flags );
if ($test > 0) {
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 );
ob_flush ();
flush (); // /OK here
$circbuf_file = fopen ( "/dev/circbuf", "r" );
$current_frame = $frame;
printf ( "<p>frame=%d (0x%x), time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
elphel_skip_frames ($GLOBALS['sensor_port'], 2 );
printf ( "<p>target frame=%d (0x%x) frame=%d(0x%x), time=%d </p>\n", $frame, $frame, elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
// printf ("<p>start_frame2=0x%x</p>\n",$current_frame);
elphel_set_P_value ($GLOBALS['sensor_port'], ELPHEL_COMPRESSOR_RUN | ELPHEL_CONST_FRAMEPAIR_FORCE_NEWPROC, ELPHEL_CONST_COMPRESSOR_RUN_STOP, $current_frame + 4 );
printf ( "<p>frame=%d (0x%x), time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
$current_frame += 6; // / to be sure - less is enough?
for($i = 0; $i < 6; $i ++) {
elphel_skip_frames ($GLOBALS['sensor_port'], 1 );
printf ( "<p>skipped 1 frame - frame=%d (0x%x), time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
}
// elphel_skip_frames($GLOBALS['sensor_port'],6);
// printf ("<p>after skip 6 frames - frame=0x%x, time=%d </p>\n",elphel_get_frame($GLOBALS['sensor_port']),time()); ob_flush(); flush();
fseek ( $circbuf_file, LSEEK_CIRC_TOWP, SEEK_END );
// /stuck before here?
printf ( "<p>frame=%d (0x%x) time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
elphel_skip_frames ($GLOBALS['sensor_port'], 1 );
fseek ( $circbuf_file, LSEEK_CIRC_TOWP, SEEK_END );
printf ( "<p>frame=%d (0x%x) time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
elphel_skip_frames ($GLOBALS['sensor_port'], 1 );
fseek ( $circbuf_file, LSEEK_CIRC_TOWP, SEEK_END );
printf ( "<p>frame=%d (0x%x) time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
elphel_skip_frames ($GLOBALS['sensor_port'], 1 );
fseek ( $circbuf_file, LSEEK_CIRC_TOWP, SEEK_END );
printf ( "<p>frame=%d (0x%x) time=%d </p>\n", elphel_get_frame ($GLOBALS['sensor_port']), elphel_get_frame ($GLOBALS['sensor_port']), time () );
ob_flush ();
flush ();
// / Strange - frame normal delay sometimes wrong images in the
// printf ("<p>end_frame2=0x%x</p>\n",elphel_get_frame($GLOBALS['sensor_port']));
fclose ( $circbuf_file );
image_table8 ();
exit ( 0 );
$xml->addChild ( 'test', $test );
}
$xml->addChild ( 'frame', $frame );
$xml->addChild ( 'written', $data );
$xml->addChild ( 'hex_written', sprintf ( "0x%x", $data ) );
$xml->addChild ( 'flags', sprintf ( "0x%x", $flags ) );
}
$rslt = $xml->asXML ();
header ( "Content-Type: text/xml" );
header ( "Content-Length: " . strlen ( $rslt ) . "\n" );
header ( "Pragma: no-cache\n" );
printf ( $rslt );
exit ( 0 );
function printGammaStructure() {
$gammaStructure=getGammaStructure();
printf("<table \"border=1\">\n");
printf( "<tr><td>oldest_non_scaled</td><td><b>%d</b></td></tr>\n"
."<tr><td>newest_non_scaled</td><td><b>%d</b></td></tr>\n"
."<tr><td>oldest_all</td><td><b>%d</b></td></tr>\n"
."<tr><td>newest_all</td><td><b>%d</b></td></tr>\n"
."<tr><td>non_scaled_length</td><td><b>%d</b></td></tr>\n"
."<tr><td>num_locked</td><td><b>%d</b></td></tr>\n"
."<tr><td>locked_col 0</td><td><b>%d</b></td>\n"
."<tr><td>locked_col 1</td><td><b>%d</b></td>\n"
."<tr><td>locked_col 2</td><td><b>%d</b></td>\n"
."<tr><td>locked_col 3</td><td><b>%d</b></td>\n"
."</table>\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("<br/><br/>\n");
printf("<table \"border=1\">\n");
// printf("<tr><td>index </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["index"]);printf("</tr>\n");
printf("<tr><td>index </td>\n"); foreach ($gammaStructure["entries"] as $entry)
printf ("<td><a href='?gamma_page=%d'><b>%d</b></a></td>",$entry["index"],$entry["index"]);printf("</tr>\n");
printf("<tr><td>hash32 </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%08x</b></td>",$entry["hash32"]);printf("</tr>\n");
printf("<tr><td>scale </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%01.3f</b></td>",$entry["scale"]);printf("</tr>\n");
printf("<tr><td>gamma </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%01.3f</b></td>",$entry["gamma"]);printf("</tr>\n");
printf("<tr><td>black </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["black"]);printf("</tr>\n");
printf("<tr><td>valid </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>0x%x</b></td>",$entry["valid"]);printf("</tr>\n");
printf("<tr><td>locked </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>0x%8x</b></td>",$entry["locked"]);printf("</tr>\n");
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");
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");
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");
printf("<tr><td>newer_all </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newer_all"]);printf("</tr>\n");
printf("<tr><td>older_all </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["older_all"]);printf("</tr>\n");
printf("<tr><td>oldest_scaled </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["oldest_scaled"]);printf("</tr>\n");
printf("<tr><td>newest_scaled </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newest_scaled"]);printf("</tr>\n");
printf("<tr><td>newer_scaled </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["newer_scaled"]);printf("</tr>\n");
printf("<tr><td>older_scaled </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["older_scaled"]);printf("</tr>\n");
printf("</table>\n");
}
$gammaStructure = getGammaStructure ();
printf ( "<table \"border=1\">\n" );
printf ( "<tr><td>oldest_non_scaled</td><td><b>%d</b></td></tr>\n" . "<tr><td>newest_non_scaled</td><td><b>%d</b></td></tr>\n" . "<tr><td>oldest_all</td><td><b>%d</b></td></tr>\n" . "<tr><td>newest_all</td><td><b>%d</b></td></tr>\n" . "<tr><td>non_scaled_length</td><td><b>%d</b></td></tr>\n" . "<tr><td>num_locked</td><td><b>%d</b></td></tr>\n" . "<tr><td>locked_col 0</td><td><b>%d</b></td>\n" . "<tr><td>locked_col 1</td><td><b>%d</b></td>\n" . "<tr><td>locked_col 2</td><td><b>%d</b></td>\n" . "<tr><td>locked_col 3</td><td><b>%d</b></td>\n" . "</table>\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 ( "<br/><br/>\n" );
printf ( "<table \"border=1\">\n" );
// printf("<tr><td>index </td>\n"); foreach ($gammaStructure["entries"] as $entry) printf ("<td><b>%d</b></td>",$entry["index"]);printf("</tr>\n");
printf ( "<tr><td>index </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><a href='?gamma_page=%d'><b>%d</b></a></td>", $entry ["index"], $entry ["index"] );
printf ( "</tr>\n" );
printf ( "<tr><td>hash32 </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%08x</b></td>", $entry ["hash32"] );
printf ( "</tr>\n" );
printf ( "<tr><td>scale </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%01.3f</b></td>", $entry ["scale"] );
printf ( "</tr>\n" );
printf ( "<tr><td>gamma </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%01.3f</b></td>", $entry ["gamma"] );
printf ( "</tr>\n" );
printf ( "<tr><td>black </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["black"] );
printf ( "</tr>\n" );
printf ( "<tr><td>valid </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>0x%x</b></td>", $entry ["valid"] );
printf ( "</tr>\n" );
printf ( "<tr><td>locked </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>0x%8x</b></td>", $entry ["locked"] );
printf ( "</tr>\n" );
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" );
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" );
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" );
printf ( "<tr><td>newer_all </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["newer_all"] );
printf ( "</tr>\n" );
printf ( "<tr><td>older_all </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["older_all"] );
printf ( "</tr>\n" );
printf ( "<tr><td>oldest_scaled </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["oldest_scaled"] );
printf ( "</tr>\n" );
printf ( "<tr><td>newest_scaled </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["newest_scaled"] );
printf ( "</tr>\n" );
printf ( "<tr><td>newer_scaled </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["newer_scaled"] );
printf ( "</tr>\n" );
printf ( "<tr><td>older_scaled </td>\n" );
foreach ( $gammaStructure ["entries"] as $entry )
printf ( "<td><b>%d</b></td>", $entry ["older_scaled"] );
printf ( "</tr>\n" );
printf ( "</table>\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 "<pre>\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 "</pre>\n";
$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 );// Does not depend on $GLOBALS['sensor_port']
$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 ); // Does not depend on $GLOBALS['sensor_port']
$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 ); // Does not depend on $GLOBALS['sensor_port']
// var_dump()
$g_raw_ul = unpack ( 'V*', $g_raw );
echo "<pre>\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 "</pre>\n";
}
/*
struct histogram_stuct_t {
unsigned long frame; /// frame number correspoding to the current histogram
unsigned long valid; /// bit mask of valid arrays (0 - hist_r, ... ,4-cumul_hist_r, ..., 11 - percentile_b)
/// Direct histograms, loaded from the FPGA
union {
unsigned long hist[1024] ; /// All 4 histograms
struct {
unsigned long hist_r [256] ; /// Histogram for the red component
unsigned long hist_g [256] ; /// Histogram for the first green component (in the "red" line)
unsigned long hist_gb[256] ; /// Histogram for the second green component (in the "blue" line)
unsigned long hist_b [256] ; /// Histogram for blue component
};
};
/// Direct cumulative histograms, calculated from the loaded from the FPGA
union {
unsigned long cumul_hist[1024] ; /// All 4 cumulative histograms
struct {
unsigned long cumul_hist_r [256] ; /// Cumulative histogram for the red component
unsigned long cumul_hist_g [256] ; /// Cumulative histogram for the first green component (in the "red" line)
unsigned long cumul_hist_gb[256] ; /// Cumulative histogram for the second green component (in the "blue" line)
unsigned long cumul_hist_b [256] ; /// Cumulative histogram for blue component
};
};
/// Calculated reverse cumulative histograms (~percentiles) - for the given 1 byte input X (0 - 1/256 of all pixels, ..., 255 - all pixels)
/// returns threshold value P (0..255), so that number of pixels with value less than x is less or equal to (P/256)*total_number_of_pixels,
/// and number of pixels with value less than (x+1) is greater than (P/256)*total_number_of_pixels,
/// P(0)=0, P(256)=256 /not included in the table/
/// percentiles arrays are calculated without division for each element, interpolation (with division) will be done only for the value of interest
/// on demand, in the user space.
/// NOTE: - argument is _output_ value (after gamma-correction), reverse gamma table is needed to relate percentiles to amount of light (proportional to exposure)
union {
unsigned char percentile[1024] ; /// All 4 percentiles
struct {
unsigned char percentile_r [256] ; /// percentile for the red component
unsigned char percentile_g [256] ; /// percentile for the first green component (in the "red" line)
unsigned char percentile_gb[256] ; /// percentile for the second green component (in the "blue" line)
unsigned char percentile_b [256] ; /// percentile for the blue component
};
};
};
*/
* struct histogram_stuct_t {
* unsigned long frame; /// frame number correspoding to the current histogram
* unsigned long valid; /// bit mask of valid arrays (0 - hist_r, ... ,4-cumul_hist_r, ..., 11 - percentile_b)
* /// Direct histograms, loaded from the FPGA
* union {
* unsigned long hist[1024] ; /// All 4 histograms
* struct {
* unsigned long hist_r [256] ; /// Histogram for the red component
* unsigned long hist_g [256] ; /// Histogram for the first green component (in the "red" line)
* unsigned long hist_gb[256] ; /// Histogram for the second green component (in the "blue" line)
* unsigned long hist_b [256] ; /// Histogram for blue component
* };
* };
* /// Direct cumulative histograms, calculated from the loaded from the FPGA
* union {
* unsigned long cumul_hist[1024] ; /// All 4 cumulative histograms
* struct {
* unsigned long cumul_hist_r [256] ; /// Cumulative histogram for the red component
* unsigned long cumul_hist_g [256] ; /// Cumulative histogram for the first green component (in the "red" line)
* unsigned long cumul_hist_gb[256] ; /// Cumulative histogram for the second green component (in the "blue" line)
* unsigned long cumul_hist_b [256] ; /// Cumulative histogram for blue component
* };
* };
* /// Calculated reverse cumulative histograms (~percentiles) - for the given 1 byte input X (0 - 1/256 of all pixels, ..., 255 - all pixels)
* /// returns threshold value P (0..255), so that number of pixels with value less than x is less or equal to (P/256)*total_number_of_pixels,
* /// and number of pixels with value less than (x+1) is greater than (P/256)*total_number_of_pixels,
* /// P(0)=0, P(256)=256 /not included in the table/
* /// percentiles arrays are calculated without division for each element, interpolation (with division) will be done only for the value of interest
* /// on demand, in the user space.
* /// NOTE: - argument is _output_ value (after gamma-correction), reverse gamma table is needed to relate percentiles to amount of light (proportional to exposure)
* union {
* unsigned char percentile[1024] ; /// All 4 percentiles
* struct {
* unsigned char percentile_r [256] ; /// percentile for the red component
* unsigned char percentile_g [256] ; /// percentile for the first green component (in the "red" line)
* unsigned char percentile_gb[256] ; /// percentile for the second green component (in the "blue" line)
* unsigned char percentile_b [256] ; /// percentile for the blue component
* };
* };
* };
*
*/
function printHistogram($frame) {
$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 "<pre>\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 "</pre>\n";
$colors = array (
0 => "R",
1 => "G",
2 => "GB",
3 => "B"
);
$h_arr = elphel_histogram_get ($GLOBALS['sensor_port'], $GLOBALS['$sensor_subchn'], 0xfff, $frame );
$a = 0;
$offset2sum = 1024 + 255; // / last in cumulative histogram for the same color
echo "<pre>\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 "</pre>\n";
}
function printRawHistogram($needed,$frame) {
$percentile_start=8232;
$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 "<pre>\n";
$a=1; /// unpack started with index 1
$hframe= $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++];
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 ("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 "</pre>\n";
function printRawHistogram($needed, $frame) {
$percentile_start = 8232;
$colors = array (
0 => "R",
1 => "G",
2 => "GB",
3 => "B"
);
$h_raw = elphel_histogram_get_raw ($GLOBALS['sensor_port'], $GLOBALS['$sensor_subchn'], $needed, $frame );
// var_dump()
$h_raw_ul = unpack ( 'V*', substr ( $h_raw, 0, $percentile_start ) );
echo "<pre>\n";
$a = 1; // / unpack started with index 1
$hframe = $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 ++];
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 ( "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 "</pre>\n";
}
function printRawFrame($frame) {
$fp_raw=elphel_framepars_get_raw($frame);
$fp_raw_ul=unpack('V*',$fp_raw);
echo "<pre>\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 "</pre>\n";
$fp_raw = elphel_framepars_get_raw ($GLOBALS['sensor_port'], $frame );
$fp_raw_ul = unpack ( 'V*', $fp_raw );
echo "<pre>\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 "</pre>\n";
}
function image_table8 (){
global $imgsrv;
// $back=6;
// $min_back=1;
$back=8;
$min_back=0;
printf ("<table>\n");
$scale="100%";
$row_open=$false;
for ($hist=$back;$hist>=$min_back;$hist--) {
if (!(($back-$hist) % 3)) {
if ($row_open) printf ("</tr>\n");
printf ("<tr>");
$row_open=true;
}
$url=$imgsrv;
for ($i=0;$i<$hist;$i++) $url.='/prev';
// $url .= '/img';
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');
}
if ($row_open) printf ("</tr>\n");
printf ("</table>\n");
function image_table8() {
global $imgsrv;
// $back=6;
// $min_back=1;
$back = 8;
$min_back = 0;
printf ( "<table>\n" );
$scale = "100%";
$row_open = $false;
for($hist = $back; $hist >= $min_back; $hist --) {
if (! (($back - $hist) % 3)) {
if ($row_open)
printf ( "</tr>\n" );
printf ( "<tr>" );
$row_open = true;
}
$url = $imgsrv;
for($i = 0; $i < $hist; $i ++)
$url .= '/prev';
// $url .= '/img';
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' );
}
if ($row_open)
printf ( "</tr>\n" );
printf ( "</table>\n" );
}
?>
PYTHONROOT=$(DESTDIR)/usr/local/bin
OWN = -o root -g root
INSTPYTHON = 0755
INSTALL = install
PYTHON_SCRIPTS = tests.py
all:
@echo "make all in python_tests"
install:
@echo "make install in python_tests"
$(INSTALL) $(OWN) -d $(PYTHONROOT)
$(INSTALL) $(OWN) -m $(INSTPYTHON) $(PYTHON_SCRIPTS) $(PYTHONROOT)
clean:
@echo "make clean in src"
#!/usr/bin/env python
from __future__ import division
from __future__ import print_function
import mmap
import struct
import os
import sys
#fp = open("/dev/frameparsall0","w+")
frameparsPaths = ("/dev/frameparsall0","/dev/frameparsall1","/dev/frameparsall2","/dev/frameparsall3")
mmap_size= 85*1024*4 # bytes
ENDIAN="<" # little, ">" for big
FRMT_BYTES={1:'B',2:'H',4:'L',8:'Q'}
def test_mmap (sensor_port = 0, out_path_base="mmap_dump_port"):
with open(out_path_base+str(sensor_port), "w+b") as bf:
with open(frameparsPaths[sensor_port],"w+") as fp:
mm = mmap.mmap(fp.fileno(), mmap_size, offset = 0) # mmap all data
bf.write(mm)
# byte_mode = 4
# data=struct.unpack_from(ENDIAN+FRMT_BYTES[byte_mode],mm, page_offs)
"""
elphel_globals->frameParsAll[port] = (struct framepars_all_t *) mmap(0, sizeof (struct framepars_all_t) , PROT_READ | PROT_WRITE, MAP_SHARED, elphel_globals->fd_fparmsall[port], 0);
/// All parameter data for a sensor port, including future ones and past. Size should be PAGE_SIZE aligned
struct framepars_all_t {
struct framepars_t framePars[PARS_FRAMES=16]; ///< Future frame parameters
struct framepars_t func2call; ///< func2call.pars[] - each parameter has a 32-bit mask of what pgm_function to call - other fields not used
unsigned long globalPars[NUM_GPAR=2048]; ///< parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both R/W
struct framepars_past_t pastPars [PASTPARS_SAVE_ENTRIES= (16 << 7)=2048]; ///< parameters of previously acquired frames
unsigned long multiSensIndex[P_MAX_PAR_ROUNDUP = 1024]; ///< indexes of individual sensor register shadows (first of 3) - now for all parameters, not just sensor ones
unsigned long multiSensRvrsIndex[P_MAX_PAR_ROUNDUP = 1024]; ///< reverse index (to parent) for the multiSensIndex in lower 16 bits, high 16 bits - sensor number
};
struct framepars_t { 1024
unsigned long pars[927]; ///< parameter values (indexed by P_* constants)
unsigned long functions; ///< each bit specifies function to be executed (triggered by some parameters change)
unsigned long modsince[31]; ///< parameters modified after this frame - each bit corresponds to one element in in par[960] (bit 31 is not used)
unsigned long modsince32; ///< parameters modified after this frame super index - non-zero elements in in mod[31] (bit 31 is not used)
unsigned long mod[31]; ///< modified parameters - each bit corresponds to one element in in par[960] (bit 31 is not used)
unsigned long mod32; ///< super index - non-zero elements in in mod[31] (bit 31 is not used)
unsigned long needproc[31]; ///< FIXME: REMOVE parameters "modified and not yet processed" (some do not need any processing)
unsigned long needproc32; ///< FIXME: REMOVE parameters "modified and not yet processed" frame super index - non-zero elements in in mod[31] (bit 31 is not used)
};
0x00000 1024*16 struct framepars_t framePars[PARS_FRAMES=16]; ///< Future frame parameters
0x04000 1024 struct framepars_t func2call; ///< func2call.pars[] - each parameter has a 32-bit mask of what pgm_function to call - other fields not used
0x04400 2048 unsigned long globalPars[NUM_GPAR=2048]; ///< parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both R/W
0x04c00 32*2048 struct framepars_past_t pastPars [PASTPARS_SAVE_ENTRIES= (16 << 7)=2048]; ///< parameters of previously acquired frames
0x14c00 1024 unsigned long multiSensIndex[P_MAX_PAR_ROUNDUP = 1024]; ///< indexes of individual sensor register shadows (first of 3) - now for all parameters, not just sensor ones
0x15000 1024 unsigned long multiSensRvrsIndex[P_MAX_PAR_ROUNDUP = 1024]; ///< reverse index (to parent) for the multiSensIndex in lower 16 bits, high 16 bits - sensor number
0x15400
85*1024*4 for mmap
return mmap.mmap(f.fileno(), self.PAGE_SIZE, offset = page_addr)
with open("/dev/mem", "r+b") as f:
for addr in range (start_addr,end_addr+byte_mode,byte_mode):
page_addr=addr & (~(self.PAGE_SIZE-1))
page_offs=addr-page_addr
mm = self.wrap_mm(f, page_addr)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
data=struct.unpack_from(self.ENDIAN+frmt_bytes[byte_mode],mm, page_offs)
rslt.append(data[0])
for addr in range (start_addr,end_addr+byte_mode,byte_mode):
if (addr == start_addr) or ((addr & print_mask) == 0):
if self.DRY_MODE:
print ("\nsimulated: 0x%08x:"%addr,end="")
else:
print ("\n0x%08x:"%addr,end="")
d=rslt[(addr-start_addr) // byte_mode]
print (data_frmt%(d),end=" ")
print("")
return rslt
mm = self.wrap_mm(f, page_addr)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
bf.write(mm[start_offset:end_offset])
"""
if __name__ == "__main__":
test_mmap(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment