packages/web/353/test/sensor_pattern_compress.php

Go to the documentation of this file.
00001 <?php
00002 
00003 //$__result = "UNKNOWN"; // OK, FAIL, UNKNOWN
00004 // OK - all is OK
00005 // FAIL - can read the image, but test not passed
00006 // UNKNOWN - the image is unacceptable
00007 //$__description = "";
00008 
00009 $_pass = FALSE;
00010 
00011 $MD_LENGTH = 32;
00012 $SPC_DAT_FILE = "/etc/test/spc.dat";
00013 if(file_exists($SPC_DAT_FILE)) {
00014         $inits = parse_ini_file($SPC_DAT_FILE);
00015 } else {
00016         $inits["test"] = "empty";
00017 }
00018 
00019 require 'i2c.inc';
00020 
00021 # initialize result
00022 /*
00023 $res_xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><test name=\"sensor_pattern_compression\"/>");
00024 */
00025 $res_xml = "<?xml version='1.0' standalone='yes'?><test name=\"sensor_pattern_compression\">";
00026 
00027 # "online result" - i.e. runtime
00028 function res_update($name, $result, $description) {
00029         global $res_xml;
00030 
00031         $res_xml .= "<${name} result=\"${result}\">";
00032         if($description != "")
00033                 $res_xml .= $description;
00034         $res_xml .= "</${name}>\n";
00035 }
00036 
00037 // return XML responce
00038 function _finish() {
00039 //      global $__result;
00040 //      global $__description;
00041 //      echo "test result: ".$RESULT."<br>";
00042 //      if($DESCRIPTION != "")
00043 //              echo "test description: ".$DESCRIPTION."<br>";
00044         global $res_xml;
00045         global $_pass;
00046         if($_pass == TRUE)
00047                 res_update("finish", "OK", "");
00048         else
00049                 res_update("finish", "FAIL", "");
00050 
00051 $res_xml .= "</test>";
00052 #echo $res_xml;
00053 
00054         $xml = new SimpleXMLElement($res_xml);
00055 /*
00056         $xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><test name=\"sensor_pattern_compression\"/>");
00057         $xml->addChild('result', $__result);
00058         if($__description != "")
00059                 $xml->addChild('description', $__description);
00060 */
00061         $rslt=$xml->asXML();
00062 
00063         header("Content-Type: text/xml");
00064         header("Content-Length: ".strlen($rslt)."\n");
00065         header("Pragma: no-cache\n");
00066         printf($rslt);
00067         exit(0);
00068 }
00069 
00070 $MODE = "check";
00071 
00072 if($_GET['mode'] == "add")
00073         $MODE = "add";
00074 
00075 //--------------------
00076 // FPGA revision...
00077 $data = elphel_fpga_read(0x13);
00078 $fpga_rev = sprintf("0x%x",$data);
00079 
00080 //--------------------
00081 // check SDRAM phases
00082 $SDRAM_PHASES_LOG = "/var/log/fpga_sdram_phase";
00083 if(is_file($SDRAM_PHASES_LOG)) {
00084         $ph_rez = exec("cat $SDRAM_PHASES_LOG | grep 'result='");
00085         if($ph_rez == "result=OK") {
00086                 res_update("SDRAM_phase", "OK", "");
00087         } else {
00088 //              $__description = "SDRAM phase incorrect";
00089 //              $__result = "FAIL";
00090                 res_update("SDRAM_phase", "FAIL", "SDRAM phase incorrect");
00091                 _finish();
00092         }
00093 }
00094 
00095 //--------------------
00096 // test SDRAM
00097 $sdram_rez = exec("fpcf -mem 2000000 FFFF 0000 AAAA 5555 | grep 'result='");
00098 if($sdram_rez == "result=OK") {
00099         res_update("SDRAM_memory", "OK", "");
00100 } else {
00101 //      $__description = "SDRAM pattern test fail";
00102 //      $__result = "FAIL";
00103         res_update("SDRAM_memory", "FAIL", "SDRAM pattern test fail");
00104         _finish();
00105 }
00106 
00107 //--------------------
00108 // initialize...
00109 file_get_contents("http://127.0.0.1/camera_demo.php");
00110 
00111 //--------------------
00112 // sensor number...
00113 $s_id=i2c_receive(16, 0, 0x4800, 0);
00114 $s_id = sprintf("0x%x",$s_id);
00115 if($s_id != "0x1801") {
00116 //      $__result = "UNKNOWN";
00117 //      $__description = "can't identify sensor with ID == ".$s_id."; probably it's just not connected";
00118         res_update("SENSOR_id", "FAIL", "Unknown sensor ID ${s_id}");
00119         _finish();
00120 } else
00121         res_update("SENSOR_id", "OK", "");
00122 
00123 //--------------------
00124 // check test pattern compressed image
00125 
00126 // check FPGA revision
00127 if(array_key_exists("rev_".$fpga_rev, $inits) !== TRUE && $MODE == "check") {
00128 //      $__result = "UNKNOWN";
00129 //      $__description = "Unknown FPGA revision";
00130         res_update("FPGA_compress", "UNKNOWN", "Unknown FPGA revision");
00131         _finish();
00132 }
00133 
00134 // image settings...
00135 file_get_contents("http://127.0.0.1/imconf_load.php?conf=/etc/test/sensor_pattern_compress.conf");
00136 
00137 // set diagonal gradient test pattern on camera
00138 $s_id = i2c_send(16, 0, 0x48A0, 0x19, 0);
00139 
00140 
00141 // load test image to /tmp/spc.jpeg
00142 # skip the first two images (really needed first skip, second probably not)
00143 # because the top part of the previous real image will be at test image
00144 exec("wget http://127.0.0.1:8081/noexif/next/wait/img -O /dev/null");
00145 exec("wget http://127.0.0.1:8081/noexif/next/wait/img -O /dev/null");
00146 # this one is really test image
00147 exec("wget http://127.0.0.1:8081/noexif/next/wait/img -O /tmp/spc.jpeg");
00148 
00149 $md = "";
00150 if(is_file("/tmp/spc.jpeg")) {
00151         $md = substr(exec("md5sum /tmp/spc.jpeg"), 0, $MD_LENGTH);
00152         unlink("/tmp/spc.jpeg");
00153 }
00154 
00155 if($MODE == "check") {
00156         $_md = $inits["rev_".$fpga_rev];
00157         if($md != $_md) {
00158 //              $__result = "FAIL";
00159 //              $__description = "MD5SUM is |$md| and must be |$_md|";
00160                 res_update("FPGA_compress", "FAIL", "MD5SUM is |$md| and must be |$_md|");
00161                 $s_id = i2c_send(16, 0, 0x48A0, 0x00, 0);
00162                 _finish();
00163         } else {
00164                 res_update("FPGA_compress", "OK", "");
00165                 $_pass = TRUE;
00166 //              $__result="OK";
00167         }
00168 } else if($MODE == "add") {
00169         $f = fopen($SPC_DAT_FILE, 'a');
00170         # pair of "FPGA revision"="MD5SUM"
00171         fwrite($f, "rev_$fpga_rev=$md\n");
00172         fclose($f);
00173 //      $__result = "OK";
00174         res_update("FPGA_compress", "OK", "MD5SUM record updated");
00175         $_pass = TRUE;
00176 } else {
00177         res_update("FPGA_compress", "UNKNOWN", "wrong command ${MODE}");
00178 //      $__result = "WRONG COMMAND";
00179 }
00180 
00181 // disable test pattern
00182 $s_id = i2c_send(16, 0, 0x48A0, 0x00, 0);
00183 _finish();
00184 
00185 ?>

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