Commit 5bccccf6 authored by Andrey Filippov's avatar Andrey Filippov

Adding scan mode

parent 7c14c1c8
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
$motosat_ip= "192.168.1.250"; $motosat_ip= "192.168.1.250";
$motosat_url= "http://".$motosat_ip."/motor.xml"; $motosat_url= "http://".$motosat_ip."/motor.xml";
$modem_ip = "192.168.0.1"; $modem_ip = "192.168.0.1";
$modem_ip = "http://localhost/motosat/attic"; //$modem_ip = "http://localhost/motosat/attic";
$modem_strengt_url = $modem_ip."/sqf/sqfdisp/index.html"; //$modem_strengt_url = $modem_ip."/sqf/sqfdisp/index.html";
$modem_strengt_url = "http://".$modem_ip."/sqf/sqfdisp/index.html";
$AZ_CPD = 12.74445; $AZ_CPD = 12.74445;
$EL_CPD = 75.78567; $EL_CPD = 75.78567;
$SK_CPD = 8.34; $SK_CPD = 8.34;
...@@ -13,6 +14,7 @@ $SK_0 = 55.7554; // degrees ...@@ -13,6 +14,7 @@ $SK_0 = 55.7554; // degrees
$AZ_CMAX = 4790; $AZ_CMAX = 4790;
$EL_CMAX = 10979; $EL_CMAX = 10979;
$SK_CMAX = 931; $SK_CMAX = 931;
$MODEM_THRESHOLD = 17.0; // consider something if modem strength is above
/* /*
http://192.168.1.250/motor.xml?Action=ElUp&Distance=0.5&Units=1 0.5 degree up http://192.168.1.250/motor.xml?Action=ElUp&Distance=0.5&Units=1 0.5 degree up
...@@ -175,9 +177,15 @@ string(61) "http://192.168.1.250/motor.xml?Action=ElDn&Distance=1&Units=0" ...@@ -175,9 +177,15 @@ string(61) "http://192.168.1.250/motor.xml?Action=ElDn&Distance=1&Units=0"
$dbg_file = fopen("/home/eyesis/git/motosat/attic/logs/modem.log","w"); $dbg_file = fopen("/home/eyesis/git/motosat/attic/logs/modem.log","w");
fprintf($dbg_file,"test log\n"); fprintf($dbg_file,"test log\n");
$modem_strength= getModemStrength();
print($modem_strength); print("<p>".date('l jS \of F Y h:i:s A')."</p>");
$modem_strength= getModemStrength();
for ($i=0;$i<10;$i++){
//$modem_strength= getModemStrength();
$xml_state = simplexml_load_file($motosat_url); // 0.29 sec
}
print("<p>modem_strength=".$modem_strength." file=".$modem_strengt_url."</p>");
print("<p>".date('l jS \of F Y h:i:s A')."</p>");
exit (0); exit (0);
...@@ -192,15 +200,51 @@ foreach ($DishAngle as $key => $value){ ...@@ -192,15 +200,51 @@ foreach ($DishAngle as $key => $value){
$DishAngle[$key] = floatval($value); $DishAngle[$key] = floatval($value);
} }
$dbg = true; $dbg = false; // true;
$multi= false; $multi= true; // false;
if (isset($_GET["dbg"])) { $dbg=myval($_GET["dbg"]);} $wnd_az = 0;
if (isset($_GET["multi"])) { $multi=myval($_GET["multi"]);} $wnd_el = 0;
if (isset($_GET["az"])) { $DishAngle[0] = myfval($_GET["az"]);} $scan_step = 1.0;
if (isset($_GET["el"])) { $DishAngle[1] = myfval($_GET["el"]);} $min_strength = $MODEM_THRESHOLD;
if (isset($_GET["sk"])) { $DishAngle[2] = myfval($_GET["sk"]);}
if (isset($_GET["dbg"])) { $dbg=myval($_GET["dbg"]);}
if (isset($_GET["multi"])) { $multi=myval($_GET["multi"]);}
if (isset($_GET["az"])) { $DishAngle[0] = myfval($_GET["az"]);}
if (isset($_GET["el"])) { $DishAngle[1] = myfval($_GET["el"]);}
if (isset($_GET["sk"])) { $DishAngle[2] = myfval($_GET["sk"]);}
if (isset($_GET["wnd_az"])) { $wnd_az = myfval($_GET["wnd_az"]);}
if (isset($_GET["wnd_el"])) { $wnd_el = myfval($_GET["wnd_el"]);}
if (isset($_GET["scan_step"])) { $scan_step = myfval($_GET["scan_step"]);}
if (isset($_GET["min_strength"])) { $min_strength = myfval($_GET["min_strength"]);}
$scan_mode = ($wnd_az > 0) || ($wnd_el > 0);
if ($scan_mode){
$xml_state = scan_window($min_strength, $DishAngle, $wnd_az, $wnd_el, $scan_step);
$xml = new SimpleXMLElement("<?xml version='1.0'?><motosat/>");
$State = $xml_state->State+0; // 1 - Ready, 2 - Busy
$busy = ($State & 2) != 0;
$SignalQuality = (explode(",",myfval($xml_state->SignalQuality)[0]));
$DishCount = $xml_state->DishCount;
$DishAngle = $xml_state->DishAngle;
$Success = $xml_state->Success;
$xml->addChild ('Success',(string) $Success );
$xml->addChild ('SignalQuality',(string) $SignalQuality );
$xml->addChild ('DishAngle',(string) $DishAngle );
$xml->addChild ('DishCount',(string) $DishCount );
$xml->addChild ('busy',(string) $busy );
$xml->addChild ('State',(string) $State );
$rslt=$xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($rslt)."\n");
header("Pragma: no-cache\n");
// allow CORS: needed for multicam controls
header('Access-Control-Allow-Origin: *');
printf($rslt);
exit (0);
}
$total_cycles = 0; $total_cycles = 0;
if ($multi) { if ($multi) {
...@@ -236,7 +280,38 @@ $SK_CMAX = 931; ...@@ -236,7 +280,38 @@ $SK_CMAX = 931;
*/ */
function getModemStrength(){ function scan_window($threshold, $DishAngleCenter, $wnd_az, $wnd_el, $scan_step){
global $motosat_url;
$DishAngle = Array($DishAngleCenter[0],$DishAngleCenter[1],$DishAngleCenter[2]);
$pass = 0;
for ($DishAngle[1] = $DishAngleCenter[1] - $wnd_el/2;
$DishAngle[1] <= ($DishAngleCenter[1] + $wnd_el/2);
$DishAngle[1]+= $scan_step) {
if ($pass & 1) {
$az_start = $DishAngleCenter[1] + $wnd_el/2;
$az_end = $DishAngleCenter[1] - $wnd_el/2;
} else {
$az_start = $DishAngleCenter[1] - $wnd_el/2;
$az_end = $DishAngleCenter[1] + $wnd_el/2;
}
$DishAngle[0] = $az_start;
moveElAzSk_degrees($DishAngle);
$DishAngle[0] = $az_end;
moveElAzSk_start_degrees($DishAngle);
$scan_rslt = waitMotorsReady($threshold);
if ($scan_rslt < 0) {
$xml_state = simplexml_load_file($motosat_url);
$xml_state->addChild ('Success',(string) true );
return $xml_state;
}
}
moveElAzSk_degrees($DishAngleCenter);
$xml_state = simplexml_load_file($motosat_url);
$xml_state->addChild ('Success',(string) false );
return $xml_state;
}
function getModemStrength(){ //0.2sec
global $modem_strengt_url,$dbg_file; global $modem_strengt_url,$dbg_file;
$modem_page=file_get_contents("$modem_strengt_url"); $modem_page=file_get_contents("$modem_strengt_url");
$matches=null; // just define $matches=null; // just define
...@@ -351,7 +426,13 @@ function moveElAzSk_start_degrees($new_azelsk_degree) { ...@@ -351,7 +426,13 @@ function moveElAzSk_start_degrees($new_azelsk_degree) {
return moveElAzSk_start_counts($new_azelsk_count); return moveElAzSk_start_counts($new_azelsk_count);
} }
function waitMotorsReady(){ /**
* Wait motors stopped and optionally modem strength > threshold
* Can be improved slightly by curl-multi: reading modem - 0.2s, controller - 0.29s
* @param $modem_threshold - if >0, stop on modem strength above threshold
* @return: 0: no ovement needed, >0 - number of status requests, <0 - -SignalQuality
*/
function waitMotorsReady($modem_threshold = 0.0){ //
global $motosat_url; global $motosat_url;
$busy = true; $busy = true;
$try = 0; $try = 0;
...@@ -359,7 +440,14 @@ function waitMotorsReady(){ ...@@ -359,7 +440,14 @@ function waitMotorsReady(){
$xml_state = simplexml_load_file($motosat_url); $xml_state = simplexml_load_file($motosat_url);
$State = $xml_state->State+0; // 1 - Ready, 2 - Busy $State = $xml_state->State+0; // 1 - Ready, 2 - Busy
$busy = ($State & 2) != 0; $busy = ($State & 2) != 0;
if ($modem_threshold > 0){
$SignalQuality = (explode(",",myfval($xml_state->SignalQuality)[0]));
$url = $motosat_url."?Action=Stop&Distance=0&Units=0";
$xml_state = simplexml_load_file($url);
return -$SignalQuality;
}
$try++; $try++;
//?Action=Stop&Distance=0&Units=0
} }
return $try; return $try;
} }
......
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