Added web hooks for rotator control to advanced control modal

pull/920/head
Andrew Koenig 2024-10-12 16:38:26 -05:00
rodzic 41b54bb1aa
commit 87740d4a75
3 zmienionych plików z 156 dodań i 1 usunięć

Wyświetl plik

@ -289,7 +289,7 @@ function start_decoder(){
// Grab the selected type
_type = $('#sonde-type-select').val();
// Parse to a floar.
// Parse to a float.
_freq_float = parseFloat(_freq);
if(_freq_float > autorx_config["max_freq"]){
alert("Supplied frequency above maximum (" + autorx_config["max_freq"] + " MHz)");
@ -319,3 +319,84 @@ function start_decoder(){
}
});
}
function move_rotator(){
// Move rotator to requested position
// Re-verify the password. This will occur async, so wont stop the main request from going ahead,
// but will at least present an error for the user.
verify_password();
// Grab the password
_api_password = getCookie("password");
// Grab the az/el input
_az = $('#azimuth-input').val();
_el = $('#azimuth-input').val();
// Parse to a float.
_az_float = parseFloat(_az);
if(_az_float > 360){
alert("Supplied azimuth above 360 degrees");
return;
}
if(_az_float < 0){
alert("Supplied azimuth below 0 degrees");
return;
}
_el_float = parseFloat(_el);
if(_el_float > 90){
alert("Supplied elevation above 360 degrees");
return;
}
if(_el_float < 0){
alert("Supplied elevation below 0 degrees");
return;
}
// Do the request
$.post(
"move_rotator",
{password: _api_password, az: _az_float.toFixed(1), el: _el_float.toFixed(1)},
function(data){
alert("Moving rotator to " + _az + ", " + _el + ".");
pause_web_controls();
setTimeout(resume_web_controls,10000);
}
).fail(function(xhr, status, error){
console.log(error);
// Otherwise, we probably got a 403 error (forbidden) which indicates the password was bad.
if(error == "FORBIDDEN"){
$("#password-header").html("<h2>Incorrect Password</h2>");
}
});
}
function home_rotator(){
// Home rotator
// Re-verify the password. This will occur async, so wont stop the main request from going ahead,
// but will at least present an error for the user.
verify_password();
// Grab the password
_api_password = getCookie("password");
// Do the request
$.post(
"home_rotator",
{password: _api_password},
function(data){
alert("Homing rotator.");
pause_web_controls();
setTimeout(resume_web_controls,10000);
}
).fail(function(xhr, status, error){
console.log(error);
// Otherwise, we probably got a 403 error (forbidden) which indicates the password was bad.
if(error == "FORBIDDEN"){
$("#password-header").html("<h2>Incorrect Password</h2>");
}
});
}

Wyświetl plik

@ -1689,6 +1689,19 @@
<div style="display:inline;vertical-align:middle;">
<button id="disable-scanner" onclick="disable_scanner();">Disable</button>
</div>
<br>
<h2>Rotator Control</h2>
<p>Go To Position</p>
<input style="display:inline;vertical-align:middle;" type="text" id="azimuth-input" placeholder="Azimuth (degrees)">
<input style="display:inline;vertical-align:middle;" type="text" id="elevation-input" placeholder="Elevation (degrees)">
<div style="display:inline;vertical-align:middle;">
<button id="move-rotator" onclick="move_rotator();">Move</button>
</div>
<br>
<div style="display:inline;vertical-align:middle;">
<button id="home-rotator" onclick="home_rotator();">Home Rotator</button>
</div>
<br>
</div>
</div>
</div>

Wyświetl plik

@ -21,6 +21,7 @@ import sys
import xml.etree.ElementTree as ET
import autorx
import autorx.config
import autorx.rotator
import autorx.scan
from autorx.geometry import GenericTrack
from autorx.utils import check_autorx_versions
@ -598,6 +599,66 @@ def flask_enable_scanner():
abort(403)
@app.route("/move_rotator", methods=["POST"])
def flask_move_rotator():
""" Move rotator to target az/el position by injecting telem packet in rotator queue
Example:
curl -d "az=180&el=15&password=foobar" -X POST http://localhost:5000/move_rotator
"""
if request.method == "POST" and autorx.config.global_config["web_control"]:
if "password" not in request.form:
abort(403)
if (request.form["password"] == autorx.config.web_password) and (
autorx.config.web_password != "none"
):
try:
_az = float(request.form["az"])
_el = float(request.form["el"])
except Exception as e:
logging.error("Web - Error in rotator move request: %s", str(e))
abort(500)
logging.info("Web - Got rotator move request: %f, %f" % (_az, _el))
# autorx.scan_results.put([[_freq, _type]])
# autorx.rotator.
return "OK"
else:
abort(403)
else:
abort(403)
@app.route("/home_rotator", methods=["POST"])
def flask_home_rotator():
""" Move rotator to target az/el position by injecting telem packet in rotator queue
Example:
curl -d "password=foobar" -X POST http://localhost:5000/home_rotator
"""
if request.method == "POST" and autorx.config.global_config["web_control"]:
if "password" not in request.form:
abort(403)
if (request.form["password"] == autorx.config.web_password) and (
autorx.config.web_password != "none"
):
logging.info("Web - Got rotator move request: %f, %f" % (_az, _el))
# autorx.scan_results.put([[_freq, _type]])
return "OK"
else:
abort(403)
else:
abort(403)
#
# SocketIO Events
#