setup.php 3.51 KB
Newer Older
1 2
<?php

3 4
$port = 8888;

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
if (isset($_GET['cmd']))
	$cmd = $_GET['cmd'];
else
	$cmd = "do_nothing";

$sensor_type = get_sensor_type();
	
if ($cmd=="get_sensor_type"){
	echo json_encode(array('sensortype'=>$sensor_type));
}

if ($cmd=="set_test_pattern"){
	$chn = $_GET['chn'];
	$val = $_GET['val'];
	
	if ($sensor_type==5){
		if ($val=="true"){
			$regval = "0x90a00041";
		}else{
			$regval = "0x90a00000";
		}
	}
	if ($sensor_type==14){
		if ($val=="true"){
			$regval = "0x30700002";
		}else{
			$regval = "0x30700000";
		}
	}
	
35
	$str = "write_sensor_i2c $chn 1 0 $regval"."\r\n";
36
	
37 38
	echo send_cmd($port,$str);
	//$str = "cd /usr/local/verilog/;/usr/local/bin/test_mcntrl.py @includes -c ";
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
}

if ($cmd=="set_sensor_phase"){
	$chn = $_GET['chn'];
	$val = intval($_GET['val']);
	
	if ($val<0) $val=0;
	if ($val>7) $val=7;
	
		
	if ($sensor_type==14){
		$val += 8;
		$regval = "0x31c0".dechex($val)."000";
	}
	
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	$str = "write_sensor_i2c $chn 1 0 $regval"."\r\n";
	send_cmd($port,$str);
	
        $str = "compressor_control $chn 1"."\r\n";
	send_cmd($port,$str);
	usleep(100000);
        $str = "compressor_control $chn 0"."\r\n";
	send_cmd($port,$str);
	usleep(100000);
	
	$str = "control_sensor_memory $chn stop"."\r\n";
	send_cmd($port,$str);
	usleep(100000);
	$str = "control_sensor_memory $chn reset"."\r\n";
	send_cmd($port,$str);
	usleep(100000);
        $str = "control_sensor_memory $chn stop"."\r\n";
	send_cmd($port,$str);
	usleep(100000);
	$str = "control_sensor_memory $chn reset"."\r\n";
	send_cmd($port,$str);
	usleep(100000);
	$str = "control_sensor_memory $chn repetitive"."\r\n";
	send_cmd($port,$str);
	//$str = "sleep_ms 500"."\r\n";
	//send_cmd($port,$str);
	usleep(500000);
	$str = "compressor_control $chn 0"."\r\n";
	send_cmd($port,$str);
	//$str = "sleep_ms 500"."\r\n";
	//send_cmd($port,$str);
	usleep(500000);
	$str = "compressor_control $chn 3"."\r\n";
87 88 89 90
	
	echo send_cmd($port,$str);
	
	/*
91 92 93 94 95 96 97 98 99 100 101 102 103 104
	$str = "cd /usr/local/verilog/;/usr/local/bin/test_mcntrl.py @includes \
	-c write_sensor_i2c $chn 1 0 $regval\
	-c compressor_control $chn 1\
	-c control_sensor_memory $chn stop\
	-c control_sensor_memory $chn reset\
	-c control_sensor_memory $chn repetitive\
	-c sleep_ms 500\
	-c compressor_control $chn 0\
	-c sleep_ms 500\
	-c compressor_control $chn 3\
	";
	
	echo $str;
	exec($str);
105
	*/
106 107 108
}

if ($cmd=="find_sdram_phase"){
109
        $chn = $_GET['chn'];
110 111 112 113 114 115 116 117 118 119 120 121
	$str  = "compressor_control $chn 1"."\r\n";
	$str .= "compressor_control $chn 0"."\r\n";
	$str .= "control_sensor_memory $chn stop"."\r\n";
	$str .= "control_sensor_memory $chn reset"."\r\n";
	$str .= "measure_all \"*DI\""."\r\n";
	$str .= "measure_all"."\r\n";
	$str .= "control_sensor_memory $chn repetitive"."\r\n";
	$str .= "compressor_control $chn 3"."\r\n";
	
	echo send_cmd($port,$str);

	/*
122 123 124 125 126 127 128 129 130 131 132 133 134
	$str = "cd /usr/local/verilog/;/usr/local/bin/test_mcntrl.py @includes \
	-c compressor_control $chn 1\
	-c compressor_control $chn 0\
	-c control_sensor_memory $chn stop\
	-c control_sensor_memory $chn reset\
	-c measure_all \"*DI\"
	-c measure_all
	-c control_sensor_memory $chn repetitive\
	-c compressor_control $chn 3\
	";
	
	echo $str;
	exec($str);
135
	*/
136 137 138
}

function get_sensor_type(){
139
	$lastline = exec("cat /etc/init_elphel393.sh | grep \"SENSOR_TYPE=\"");
140 141 142 143 144 145
	$res = explode("=",$lastline);
	$res[1] = intval($res[1]);
	if (($res[1]!=5)&&($res[1]!=14)) $res[1]=0;
	return $res[1];
}

146 147 148 149 150 151 152 153 154
function send_cmd($port,$msg){
	$fp = fsockopen("localhost", $port, $errno, $errstr, 30);

	if (!$fp) {
		return "$errstr ($errno)<br />\n";
	}else{
		fwrite($fp,"$msg\r\n");
		fclose($fp);
		echo "sent: $msg";
155
		usleep(100);
156 157 158
	}
}

159
?>