Commit 726f0565 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

prohibiting saving parameters if camera is not initialized

parent 64661310
Loading
Loading
Loading
Loading
+38 −20
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ $initPage = $GLOBALS['useDefaultPageNumber'];
if ((array_key_exists ( 'new', $_GET )) || (in_array ( '--new', $_SERVER ['argv'] ))) {
	foreach ( $GLOBALS['ports'] as $port ) {
		log_msg ("Rotating configs for port $port");
		if (file_exists ($GLOBALS['configDir'].'/'.$GLOBALS['configDir'].'/'.$GLOBALS['configPaths'][$port])) {
		if (file_exists ($GLOBALS['configDir'].'/'.$GLOBALS['configPaths'][$port])) {
			rotateConfig ($port, $GLOBALS['numBackups'] );
		}
	}
@@ -389,6 +389,9 @@ if (($_SERVER ['REQUEST_METHOD'] == "GET") && ! ($GLOBALS['init'])) { // in init
	log_close();
	exit ( 0 );
} else if (($_SERVER ['REQUEST_METHOD'] == "POST") && !($GLOBALS['init'])) { // in init mode should go through init steps and return XML
	if ($GLOBALS['camera_state_arr']['state'] != 'INITIALIZED')	{
		respond_xml('','Camera is not initialized. Reboot or add "init" argument to HTTP GET request');
	}
	processPost ($GLOBALS['sensor_port']);
	processGet ($GLOBALS['sensor_port']);
	log_close();
@@ -1362,16 +1365,24 @@ function get_application_mode() {
		}
				
	}
	
	if (array_key_exists ( 'reboot', $_GET )){
		$GLOBALS['camera_state_arr']['state'] = 'REBOOT';
		$GLOBALS['init'] = true;
		$need_update = true;
	}

	if (array_key_exists ( 'init', $_GET )){ // try it
		$GLOBALS['init'] = true;
		$need_update = true;
	}
	
	if (array_key_exists ( 'init_stage', $_GET )){
		$GLOBALS['camera_state_arr']['state'] = $_GET['init_stage'];
		$GLOBALS['init'] = true;
		$need_update = true;
	}
	
	if (array_key_exists ( 'exit_stage', $_GET )){
		$GLOBALS['camera_state_arr']['exit_stage'] = $_GET['exit_stage'];
		$GLOBALS['init'] = true;
@@ -2167,7 +2178,7 @@ function createConfigLink($sensor_port){
}

function rotateConfig($sensor_port,$numBackups) {
	log_msg("rotateConfig($sensor_port,$numBackups)",0);
	log_msg("rotateConfig($sensor_port,$numBackups)",3);
	if (file_exists ( backupName ($sensor_port, $numBackups ) ))
		unlink ( backupName ($sensor_port, $numBackups ) );
	for($i = $numBackups - 1; $i > 0; $i --)
@@ -2238,14 +2249,20 @@ function parseConfig($filename) {
	return $config;
}

function encodeConfig($config) {
function encodeConfig($config) { // Can not use SimpleXMLElement as need comments and preserved sequence for human consumption
	log_msg("encodeConfig(): sensor_port=".$GLOBALS['sensor_port'],0); // , config=".print_r($config,1));
	log_msg(" \$config['defaultPage'] = ".$config['defaultPage'],0);
	
	$xml = "<?xml version=\"1.0\" standalone=\"yes\"?>\n<!-- This file is generated by " . $_SERVER ['argv'] [0] . " -->\n";
	$script_name=($_GET['SCRIPT_NAME'])?($_GET['SCRIPT_NAME'] . " in HTTP request mode"): ($_SERVER ['argv'] [0] ." in command line mode");
	$xml = "<?xml version=\"1.0\" standalone=\"yes\"?>\n<!-- This file is generated by " . $script_name . " -->\n";
	$xml .= "  <autocampars>\n";
	$xml .= "<!-- File version -->\n";
	$xml .= sprintf ( "    <version>%s</version>\n", $config ['version'] );
	$xml .= "<!-- Parameter groups that can be restored from the saved values  -->\n";
	$xml .= "    <groupNames>\n";
	foreach ( $config ['groupBits'] as $key => $bit )
		$xml .= sprintf ( "      <%s bit=\"%d\">\"%s\"</%s>\n", $key, $bit, $config ['groupDescriptions'] [$bit], $key );
	$xml .= "    </groupNames>\n";
	
	$xml .= "<!-- Number of parameter page that will be used as default (i.e. after camera boot) -->\n";
	$xml .= sprintf ( "    <defaultPage>%d</defaultPage>\n", $config ['defaultPage'] );
	$xml .= "<!-- Number of parameter page that will be next used to save parameters (if not specified) -->\n";
@@ -2253,28 +2270,26 @@ function encodeConfig($config) {
	$xml .= "<!-- Descriptions of the parameters -->\n";
	$xml .= "    <descriptions>\n";
	foreach ( $config ['descriptions'] as $name => $description )
		$xml .= sprintf ( "      <%s>%s</%s>\n", $name, htmlspecialchars ( $description, ENT_QUOTES ), $name );
		$xml .= sprintf ( "      <%s>\"%s\"</%s>\n", $name, htmlspecialchars ( $description, ENT_QUOTES ), $name );
	$xml .= "    </descriptions>\n";
	$xml .= "<!-- Parameter groups that can be restored from the saved values  -->\n";
	$xml .= "    <groupNames>\n";
	foreach ( $config ['groupBits'] as $key => $bit )
		$xml .= sprintf ( "      <%s bit=\"%d\">%s</%s>\n", $key, $bit, $config ['groupDescriptions'] [$bit], $key );
	$xml .= "    </groupNames>\n";
	
	$xml .= "<!-- Parameter groups -->\n";
	$xml .= "    <groups>\n";
//	log_msg("======= config ['groups'] = ".print_r($config ['groups'],1));
	foreach ($config['groups'] as $key => $value) {
		$groups = "";
		for($bit = 0; $bit < 24; $bit++)
			if ($value & (1 << $bit)) {
				if ($groups)
					$groups .= ",";
				if ($groups) $groups .= ",";
				$groups .= $config['groupNames'][$bit];
			}
		if ($config ['parTypes'] [$key])
		if ($config['parTypes'][$key]) {
			$xml .= sprintf ("      <%s type=\"%s\">\"%s\"</%s>\n", $key, $config['parTypes'][$key], $groups, $key);
		else
//			log_msg ("======= " . sprintf ("      <%s type=\"%s\">\"%s\"</%s>\n", $key, $config['parTypes'][$key], $groups, $key));
			} else {
			$xml .= sprintf ("      <%s>\"%s\"</%s>\n", $key, $groups, $key);
//			log_msg ("======= " . sprintf ("      <%s>\"%s\"</%s>\n", $key, $groups, $key));
		}
	}
	$xml .= "    </groups>\n";
	$xml .= "<!-- Saved parameter Sets -->\n";
@@ -2293,6 +2308,9 @@ function encodeConfig($config) {
	return $xml;
}




function myval($s) {
	$s = trim ( $s, "\" " );
	if (strtoupper ( substr ( $s, 0, 2 ) ) == "0X")