Commit 47226c29 authored by Andrey Filippov's avatar Andrey Filippov

trying modem signal strength

parent 472d7772
......@@ -3,3 +3,4 @@
/.buildpath
/.project
*.kate-swp
attic
<?php
$motosat_ip= "192.168.1.250";
$motosat_url= "http://".$motosat_ip."/motor.xml";
$modem_ip = "192.168.0.1";
$modem_ip = "http://localhost/motosat/attic";
$modem_strengt_url = $modem_ip."/sqf/sqfdisp/index.html";
$AZ_CPD = 12.74445;
$EL_CPD = 75.78567;
$SK_CPD = 8.34;
$AZ_0 = 0.0; // degrees
$EL_0 = 0.0; // degrees
$SK_0 = 55.7554; // degrees
$AZ_CMAX = 4790;
$EL_CMAX = 10979;
$SK_CMAX = 931;
/*
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=1&Units=0 1 step up
http://192.168.1.250/motor.xml?Action=ElDn&Distance=1&Units=0 1 step down
http://192.168.1.250/motor.xml?Action=AzUp&Distance=1&Units=0 1 sep az +
http://192.168.1.250/motor.xml?Action=AzDn&Distance=1&Units=0 1 sep az -
SK0 = 465 steps
http://192.168.1.250/motor.xml?Action=SkUp&Distance=1&Units=0 1 step sk +
http://192.168.1.250/motor.xml?Action=SkDn&Distance=1&Units=0 1 step sk -
http://192.168.1.250/motor.xml?Action=Stop&Distance=100&Units=1 - stop
$xml_state = simplexml_load_file("http://192.168.1.250/motor.xml");
LEDState -> 1344
SignalQuality -> 15.00, 0.00, 99.00
SignalStrength -> 31.18
SysStatus -> System initialized
SkMotor -> 1
SatSys -> 1
MotorState -> 0
DishAngle -> 9.97, 0.00, 0.00
DishCount -> 127, 0, 465
php > var_dump ($xml_state);
object(SimpleXMLElement)#1 (10) {
["State"]=> string(1) "1"
["LEDState"]=> string(4) "1344"
["SignalQuality"]=> string(18) "15.00, 0.00, 99.00"
["SignalStrength"]=> string(5) "31.18"
["SysStatus"]=> string(18) "System initialized"
["SkMotor"]=> string(1) "1"
["SatSys"]=> string(1) "1"
["MotorState"]=> string(1) "0"
["DishAngle"]=> string(16) "9.97, 0.00, 0.00"
["DishCount"]=> string(11) "127, 0, 465"
}
["DishAngle"]=> string(22) "196.48, 114.98, -12.95"
["DishCount"]=> string(15) "2504, 8714, 357" round to the
*/
// Read Motosat state:
/*
$xml_state = simplexml_load_file($motosat_url);
$SignalQuality = (explode(",",$xml_state->SignalQuality)[0]+0.0);
$State = $xml_state->State+0; // 1 - Ready, 2 - Busy
$DishAngle = explode(",",$xml_state->DishAngle);
foreach ($DishAngle as $key => $value){
$DishAngle[$key] = $value + 0.0;
}
$DishCount = explode(",",$xml_state->DishCount);
foreach ($DishCount as $key => $value){
$DishCount[$key] = $value + 0;
}
localhost/motosat/test_01.php?el=114.98&az=196.48&nodbg
8714: 114.98
<!--array(3) {
[0]=>
float(196.48)
[1]=>
float(114)
[2]=>
float(-12.95)
}
array(3) {
[0]=>
float(2504.029536)
[1]=>
float(8639.56638)
[2]=>
float(356.997036)
}
array(3) {
[0]=>
int(2504)
[1]=>
int(8640)
[2]=>
int(357)
}
--><!--array(3) {
[0]=>
int(2504)
[1]=>
int(8640)
[2]=>
int(357)
}
array(3) {
[0]=>
int(2504)
[1]=>
int(8714)
[2]=>
int(357)
}
string(62) "http://192.168.1.250/motor.xml?Action=ElDn&Distance=74&Units=0"
--><?xml version="1.0"?>
<motosat><cycles>1</cycles></motosat>
8639: 113.99
view-source:http://localhost/motosat/test_01.php?el=114.98
<!--array(3) {
[0]=>
float(196.48)
[1]=>
float(114.98)
[2]=>
float(-12.95)
}
array(3) {
[0]=>
float(2504.029536)
[1]=>
float(8713.8363366)
[2]=>
float(356.997036)
}
array(3) {
[0]=>
int(2504)
[1]=>
int(8714)
[2]=>
int(357)
}
--><!--array(3) {
[0]=>
int(2504)
[1]=>
int(8714)
[2]=>
int(357)
}
array(3) {
[0]=>
int(2504)
[1]=>
int(8639)
[2]=>
int(357)
}
string(62) "http://192.168.1.250/motor.xml?Action=ElUp&Distance=75&Units=0"
--><?xml version="1.0"?>
<motosat><cycles>1</cycles></motosat>
string(61) "http://192.168.1.250/motor.xml?Action=ElDn&Distance=1&Units=0"
--><?xml version="1.0"?>
<motosat><cycles>1</cycles></motosat>
*/
//php > var_dump($DishAngle);
//array(3) {[0]=> float(9.97), [1]=> float(0), [2]=> float(0)}
$dbg_file = fopen("/home/eyesis/git/motosat/attic/logs/modem.log","w");
fprintf($dbg_file,"test log\n");
$modem_strength= getModemStrength();
print($modem_strength);
exit (0);
$xml_state = simplexml_load_file($motosat_url);
$DishCount = explode(",",$xml_state->DishCount);
foreach ($DishCount as $key => $value){
$DishCount[$key] = $value + 0;
}
$DishAngle = explode(",",$xml_state->DishAngle);
foreach ($DishAngle as $key => $value){
$DishAngle[$key] = floatval($value);
}
$dbg = true;
$multi= false;
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"]);}
$total_cycles = 0;
if ($multi) {
while (true) {
$cycles = moveElAzSk_degrees($DishAngle);
if (!isset ($cycles)) {
break;
}
$total_cycles += $cycles;
}
} else {
$total_cycles = moveElAzSk_degrees($DishAngle);
}
$xml = new SimpleXMLElement("<?xml version='1.0'?><motosat/>");
$xml->addChild ('cycles',(string) $total_cycles );
$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);
/*
Start rotation
$AZ_CMAX = 4790;
$EL_CMAX = 10979;
$SK_CMAX = 931;
*/
function getModemStrength(){
global $modem_strengt_url,$dbg_file;
$modem_page=file_get_contents("$modem_strengt_url");
$matches=null; // just define
preg_match('@<b>([^<]*)</b>@i',$modem_page, $matches);
return myfval($matches[1]);
}
function moveElAzSk_start_counts($new_azelsk_count) {
global $motosat_url, $AZ_CMAX, $EL_CMAX, $SK_CMAX,$dbg,$dbg_file;
$xml_state = simplexml_load_file($motosat_url);
$DishCount = explode(",",$xml_state->DishCount);
foreach ($DishCount as $key => $value){
$DishCount[$key] = intval($value);
}
if ($DishCount[0] < 0) $DishCount[0] = 0;
if ($DishCount[1] < 0) $DishCount[1] = 0;
if ($DishCount[2] < 0) $DishCount[2] = 0;
if ($DishCount[0] > $AZ_CMAX) $DishCount[0] = $AZ_CMAX;
if ($DishCount[1] > $EL_CMAX) $DishCount[1] = $EL_CMAX;
if ($DishCount[2] > $SK_CMAX) $DishCount[2] = $SK_CMAX;
$dist_el = $new_azelsk_count[1] - $DishCount[1];
$dist_sk = $new_azelsk_count[2] - $DishCount[2];
$dist_az = $new_azelsk_count[0] - $DishCount[0];
$dir = "Up";
$dist = 0;
/*
* $dist_el > 0 do it first, $dist_el < 0 - do it last
*/
// if ($dist_el != 0){
if ($dist_el > 0){
// moving elevation up first
$mode = "El";
$dist = $dist_el;
} else if ($dist_sk != 0){
// moving skew second
$mode = "Sk";
$dist = $dist_sk;
} else if ($dist_az != 0){
// moving azimuth third
$mode = "Az";
$dist = $dist_az;
} else if ($dist_el < 0){
// moving elevation down last
$mode = "El";
$dist = $dist_el;
}
if ($dist != 0){
if ($dist > 0){
$dir = "Up";
} else {
$dir = "Dn";
}
$dist = abs($dist);
$url = $motosat_url."?Action=".$mode.$dir.'&Distance='.$dist."&Units=0";
if ($dbg_file) {
fprintf($dbg_file, "url = %s:\n",$url);
fprintf($dbg_file, "new_azelsk_count:\n");
fprintf($dbg_file, print_r($new_azelsk_count,1));
fprintf($dbg_file, "DishCount:\n");
fprintf($dbg_file, print_r($DishCount,1));
}
if ($dbg) {
echo "<!--";
var_dump($new_azelsk_count);
var_dump($DishCount);
var_dump($url);
$url = $motosat_url;
echo "-->";
}
$xml_state = simplexml_load_file($url);
return $xml_state;
}
return; // return null - no rotation is needed
}
function moveElAzSk_start_degrees($new_azelsk_degree) {
global $AZ_0, $EL_0, $SK_0, $AZ_CPD, $EL_CPD, $SK_CPD,$dbg,$dbg_file;
$new_azelsk_count = Array (
(int) round(($new_azelsk_degree[0] + $AZ_0)*$AZ_CPD),
(int) round(($new_azelsk_degree[1] + $EL_0)*$EL_CPD),
(int) round(($new_azelsk_degree[2] + $SK_0)*$SK_CPD));
if ($dbg_file) {
$new_azelsk_count_dbg = Array (
($new_azelsk_degree[0] + $AZ_0)*$AZ_CPD,
($new_azelsk_degree[1] + $EL_0)*$EL_CPD,
($new_azelsk_degree[2] + $SK_0)*$SK_CPD);
fprintf($dbg_file, "new_azelsk_degree:\n");
fprintf($dbg_file, print_r($new_azelsk_degree,1));
fprintf($dbg_file, "new_azelsk_count_dbg:\n");
fprintf($dbg_file, print_r($new_azelsk_count_dbg,1));
fprintf($dbg_file, "new_azelsk_count:\n");
fprintf($dbg_file, print_r($new_azelsk_count,1));
}
if ($dbg) {
$new_azelsk_count_dbg = Array (
($new_azelsk_degree[0] + $AZ_0)*$AZ_CPD,
($new_azelsk_degree[1] + $EL_0)*$EL_CPD,
($new_azelsk_degree[2] + $SK_0)*$SK_CPD);
echo "<!--";
var_dump($new_azelsk_degree);
var_dump($new_azelsk_count_dbg);
var_dump($new_azelsk_count);
echo "-->";
}
return moveElAzSk_start_counts($new_azelsk_count);
}
function waitMotorsReady(){
global $motosat_url;
$busy = true;
$try = 0;
while ($busy) {
$xml_state = simplexml_load_file($motosat_url);
$State = $xml_state->State+0; // 1 - Ready, 2 - Busy
$busy = ($State & 2) != 0;
$try++;
}
return $try;
}
function moveElAzSk_counts($new_azelsk_count) {
$xml_state = moveElAzSk_start_counts($new_azelsk_count);
if (isset ($xml_state)){
$cycles = waitMotorsReady();
return $cycles; // $xml_state;
}
return;
}
function moveElAzSk_degrees($new_azelsk_degree) {
$xml_state = moveElAzSk_start_degrees($new_azelsk_degree);
if (isset ($xml_state)){
$cycles = waitMotorsReady();
return $cycles; // $xml_state;
}
return;
}
function myval ($s) {
$s=trim($s,"\" ");
if (strtoupper(substr($s,0,2))=="0X") return intval(hexdec($s));
else return intval($s);
}
function myfval ($s) {
$s=trim($s,"\" ");
return floatval($s);
}
/*
$AZ_CPD = 12.74445;
$EL_CPD = 75.778567;
$SK_CPD = 8.34;
$AZ_0 = 0.0; // degrees
$EL_0 = 0.0; // degrees
$SK_0 = 55.7554; // degrees
$AZ_CMAX = 4790;
$EL_CMAX = 10979;
$SK_CMAX = 931;
*/
?>
\ No newline at end of file
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