Commit c5154ccd authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Move authorization to new dt_ui elements

parent bd8e93da
/*
Javascript for sending authorisation commands over XMLHttp
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008
Copyright Stichting C.A. Muller Radioastronomiestation, 2008
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function auth (url, ident)
{
this.ident = ident;
this.open = function open (command)
{
dt_websocket_send("command " + ident + " " + command);
}
}
/*
Javascript for parsing authorisation status over XMLHttp
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
eval(load("status.js"));
function auth_status_cb_default (line, azimuth_offset, elevation_offset)
{
/* default callback */
}
function auth_status(url, ident)
{
var auth_status_this = this;
this.url = url;
this.ident = ident;
this.status = new status(url, ident);
this.callback = auth_status_cb_default;
this.handle_xml = function auth_status_handle_xml(data)
{
var args = data.split(" ");
auth_status_this.callback(auth_status_this, args[0], args[1], args[2]);
}
this.open = function auth_status_open()
{
this.status.callback = this.handle_xml;
this.status.open();
}
}
function auth_status_old (url, ident)
{
var auth_status_this = this;
/* Callbacks */
this.callback = auth_status_cb_default;
this.xrequest = 0;
this.xrequest_prev = 0;
this.timeouto = 0;
this.timeout = 10 * 1000;
this.data_wd = 0;
this.handle_xml = function auth_status_handle_xml(event)
{
var args = auth_status_this.xrequest.responseText.split(" ");
auth_status_this.callback(auth_status_this, args[0], args[1], args[2]);
auth_status_this.data_wd = 1;
auth_status_this.xmit();
}
this.url = url;
this.ident = ident;
this.open = function auth_status_open()
{
return;
if (auth_status_this.xrequest_prev) {
auth_status_this.xrequest.abort();
}
this.xmit();
auth_status_this.timeouto =
setTimeout(auth_status_this.checktime,
auth_status_this.timeout, auth_status_this);
}
this.xmit = function auth_status_xmit()
{
if (auth_status_this.xrequest_prev) {
delete auth_status_this.xrequest;
}
auth_status_this.xrequest = new XMLHttpRequest();
auth_status_this.xrequest.multipart = false;
auth_status_this.xrequest.open("POST", auth_status_this.url, true);
auth_status_this.xrequest.onload = this.handle_xml;
auth_status_this.xrequest.send(this.ident);
auth_status_this.xrequest_prev = 1;
}
this.checktime = function auth_status_checktime(object)
{
if (!object.data_wd) {
/* no data for a while... reset trace */
object.open(object.url);
} else {
object.data_wd = 0;
setTimeout(object.checktime, object.timeout, object);
}
}
}
/*
Javascript for tracker authorization
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2014
Copyright Stichting C.A. Muller Radioastronomiestation, 2014
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var authorization_loaded;
if (!authorization_loaded) {
authorization_loaded = true;
eval(load("dt_ui.js"));
eval(load("status.js"));
eval(load("dt_websocket.js"));
function authorization_tracker(name, ui_element, ind_element)
{
this.name = name;
this.ui_element = ui_element;
this.ind_element = ind_element;
}
function authorization(element_name) {
var authorization_this = this;
this.window = new dt_ui_window(element_name);
this.window.title_set("Authorization");
this.lbl_auth = new dt_ui_element(element_name + "_lbl_auth");
this.val_auth = new dt_ui_value(element_name + "_val_auth");
this.button_idle = new dt_ui_button_indicator(element_name + "_idle");
this.button_azel = new dt_ui_button_indicator(element_name + "_azel");
this.button_j2000 = new dt_ui_button_indicator(element_name + "_j2000");
this.button_moon = new dt_ui_button_indicator(element_name + "_moon");
this.button_sun = new dt_ui_button_indicator(element_name + "_sun");
this.button_sat = new dt_ui_button_indicator(element_name + "_sat");
this.button_man = new dt_ui_button_indicator(element_name + "_man");
this.window.add(
[this.lbl_auth, this.val_auth,
this.button_idle, this.button_azel, this.button_j2000,
this.button_moon, this.button_sun, this.button_sat,
this.button_man]);
this.lbl_auth.text_set("Authorized:");
this.val_auth.value_set("??");
this.val_auth.width_set(300);
this.button_idle.text_set("Idle");
this.button_azel.text_set("Azimuth & Elevation");
this.button_j2000.text_set("J2000");
this.button_moon.text_set("Moon");
this.button_sun.text_set("Sun");
this.button_sat.text_set("Satellite");
this.button_man.text_set("Manual");
this.window.align_horizontal(
[this.lbl_auth, this.val_auth, this.button_idle ], 20);
this.window.align_horizontal(
[this.button_idle, this.button_azel, this.button_j2000,
this.button_moon, this.button_sun, this.button_sat,
this.button_man], 5);
this.trackers = new Array();
this.trackers[0] = new authorization_tracker(
"console/idle", null, this.button_idle);
this.trackers[1] = new authorization_tracker(
"console/azel", null, this.button_azel);
this.trackers[2] = new authorization_tracker(
"console/j2000tracker", null, this.button_j2000);
this.trackers[3] = new authorization_tracker(
"console/moontracker", null, this.button_moon);
this.trackers[4] = new authorization_tracker(
"console/suntracker", null, this.button_sun);
this.trackers[5] = new authorization_tracker(
"console/sattracker", null, this.button_sat);
this.trackers[6] = new authorization_tracker(
"console/manual", null, this.button_man);
this.tracker_window_set = function(name, ui_elem)
{
var i;
for (i = 0; i < authorization_this.trackers.length; i++) {
var tracker = authorization_this.trackers[i];
if (tracker.name == name) {
authorization_this.trackers[i].ui_element = ui_elem;
}
}
}
this.cur_auth = "??";
this.offset_cb = function(azoff, eloff) {}
this.status = new status("dummy_url_auth", "auth");
this.status.callback = function(stat)
{
var args = stat.split(" ");
var spg = args[0];
if (spg != authorization_this.cur_auth) {
authorization_this.cur_auth = spg;
authorization_this.val_auth.value_set(spg);
var i;
for (i = 0; i < authorization_this.trackers.length; i++) {
var tracker = authorization_this.trackers[i];
if (tracker.name == spg) {
tracker.ind_element.color_set(
dt_ui_color_indicator_green);
if (tracker.ui_element != null) {
tracker.ui_element.visible_set(true);
}
} else {
tracker.ind_element.color_set(
dt_ui_color_indicator_off);
if (tracker.ui_element != null) {
tracker.ui_element.visible_set(false);
}
}
}
}
authorization_this.offset_cb(args[1], args[2]);
}
this.idle = function() {
dt_websocket_send("command auth " + "console/idle");
}
this.button_idle.onclick = function() {
dt_websocket_send("command auth " + "console/idle");
}
this.button_azel.onclick = function() {
dt_websocket_send("command auth " + "console/azel");
}
this.button_j2000.onclick = function() {
dt_websocket_send("command auth " + "console/j2000tracker");
}
this.button_moon.onclick = function() {
dt_websocket_send("command auth " + "console/moontracker");
}
this.button_sun.onclick = function() {
dt_websocket_send("command auth " + "console/suntracker");
}
this.button_sat.onclick = function() {
dt_websocket_send("command auth " + "console/sattracker");
}
this.button_man.onclick = function() {
dt_websocket_send("command auth " + "console/manual");
}
this.status.open();
}
} /* authorization_loaded */
......@@ -300,8 +300,13 @@ function azel(element_name) {
*/
this.visible = true;
this.visible_set = function(visible)
{
if (azel_this.visible != visible && visible) {
azel_this.copy_position();
}
azel_this.visible = visible;
azel_this.window.visible_set(visible);
}
......
......@@ -137,29 +137,7 @@
-->
<div style="background: lightgrey; border:thin solid black">
<table border="0" width="100%">
<tr>
<th>
Authorized:
</th>
<td width="25%">
<div id="auth_status_line">No status received</div>
</td>
<td align="right">
<span id="auth_idle"></span>
<span id="auth_azel"></span>
<span id="auth_j2000"></span>
<span id="auth_moon"></span>
<span id="auth_sun"></span>
<span id="auth_sat"></span>
<span id="auth_manual"></span>
</td>
</tr>
</table>
</div>
<div id="authorization"></div>
</p>
......@@ -418,8 +396,6 @@
eval(load("dt_ui.js"));
eval(load("trace.js"));
eval(load("shell.js"));
eval(load("auth.js"));
eval(load("auth_status.js"));
eval(load("azel.js"));
eval(load("j2000.js"));
eval(load("status.js"));
......@@ -429,6 +405,7 @@ eval(load("sun.js"));
eval(load("moon.js"));
eval(load("sat.js"));
eval(load("dt_view.js"));
eval(load("authorization.js"));
eval(load("utils.js"));
eval(load("offset.js"));
eval(load("dt_websocket.js"));
......@@ -441,8 +418,6 @@ new dt_websocket("ws://"+ window.location.hostname +"/dt");
var trace_url = "trace.cgi";
var shell_url = "shell.cgi";
var auth_url = "command.cgi_auth";
var auth_status_url = "status.cgi";
var offset_url = "command.cgi_offset";
......@@ -460,6 +435,22 @@ var moon_spg = new moon("spg_moon");
var azel_spg = new azel("spg_azel");
var j2000_spg = new j2000("spg_j2000");
var sat_spg = new sat("spg_sat");
var auth_win = new authorization("authorization");
function offset_cb(azimuth_off, elevation_off)
{
Azimuth_Offset_value(azimuth_off);
Elevation_Offset_value(elevation_off);
}
auth_win.offset_cb = offset_cb;
auth_win.tracker_window_set("console/azel", azel_spg);
auth_win.tracker_window_set("console/j2000tracker", j2000_spg);
auth_win.tracker_window_set("console/moontracker", moon_spg);
auth_win.tracker_window_set("console/suntracker", sun_spg);
auth_win.tracker_window_set("console/sattracker", sat_spg);
auth_win.tracker_window_set("console/manual", manual_spg);
/*
......@@ -534,12 +525,12 @@ var azimuth_elevation_disable_param = 'controller \'params { { "azimuth_servo_st
var azimuth_disable = new dt_button("azimuth_elevation_disable");
azimuth_disable.background("red");
azimuth_disable.value("Disable");
azimuth_disable.click(function() { do_auth('console/idle'); do_shell(azimuth_elevation_disable_param); } );
azimuth_disable.click(function() { auth_win.idle(); do_shell(azimuth_elevation_disable_param); } );
var azimuth_enable = new dt_button("azimuth_enable");
azimuth_enable.background("springgreen");
azimuth_enable.value("Enable");
azimuth_enable.click(function() { do_auth('console/idle'); do_shell(azimuth_enable_param); } );
azimuth_enable.click(function() { auth_win.idle(); do_shell(azimuth_enable_param); } );
function bool_priv()
{
......@@ -706,7 +697,7 @@ var elevation_enable_param = 'controller \'params { { "elevation_servo_state", "
var elevation_enable = new dt_button("elevation_enable");
elevation_enable.background("springgreen");
elevation_enable.value("Enable");
elevation_enable.click(function() { do_auth('console/idle'); do_shell(elevation_enable_param); } );
elevation_enable.click(function() { auth_win.idle(); do_shell(elevation_enable_param); } );
var elevation_position = new dt_traceval("Elevation_Position");
elevation_position.number_set(true, 4);
......@@ -813,60 +804,8 @@ function do_shell(command)
*
******************************************************************/
var auth_color_inactive = "grey";
var auth_color_active = "lime";
var auth_idle = new dt_button_indicator("auth_idle");
auth_idle.indicator(auth_color_inactive);
auth_idle.value("Idle");
auth_idle.click(function() { do_auth('console/idle');} );
var auth_azel = new dt_button_indicator("auth_azel");
auth_azel.indicator(auth_color_inactive);
auth_azel.value("Azimuth & Elevation");
auth_azel.click(function() { do_auth('console/azel');} );
var auth_j2000 = new dt_button_indicator("auth_j2000");
auth_j2000.indicator(auth_color_inactive);
auth_j2000.value("J2000");
auth_j2000.click(function() { do_auth('console/j2000tracker');} );
var auth_moon = new dt_button_indicator("auth_moon");
auth_moon.indicator(auth_color_inactive);
auth_moon.value("Moon");
auth_moon.click(function() { do_auth('console/moontracker');} );
var auth_sun = new dt_button_indicator("auth_sun");
auth_sun.indicator(auth_color_inactive);
auth_sun.value("Sun");
auth_sun.click(function() { do_auth('console/suntracker');} );
var auth_sat = new dt_button_indicator("auth_sat");
auth_sat.indicator(auth_color_inactive);
auth_sat.value("Satellite");
auth_sat.click(function() { do_auth('console/sattracker');} );
var auth_manual = new dt_button_indicator("auth_manual");
auth_manual.indicator(auth_color_inactive);
auth_manual.value("Manual");
auth_manual.click(function() { do_auth('console/manual');} );
var do_auth_obj = new auth(auth_url, "auth");
var set_offset_obj = new offset(offset_url, "offset");
var auth_last_line = "no spg";
function do_auth(command)
{
if (command == "console/j2000tracker") {
j2000_spg.copy_position();
}
do_auth_obj.open(command);
}
var auth_last_line = "no spg";
var auth_last_scriptline = "-";
function my_event() {
this.keyCode = 0;
......@@ -982,81 +921,6 @@ function Elevation_Offset_value(value)
}
}
var auth_status_line = new dt_traceval("auth_status_line");
auth_status_line.background("white");
function dt_auth_status_line(obj, line, azimuth_off, elevation_off)
{
Azimuth_Offset_value(azimuth_off);
Elevation_Offset_value(elevation_off);
if (auth_last_line == line)
return;
var spg_sat = document.getElementById('spg_sat');
if (line == "\n") {
line = "No spg selected";
}
auth_last_line = line;
auth_status_line.value(line);
auth_idle.indicator(auth_color_inactive);
auth_azel.indicator(auth_color_inactive);
auth_j2000.indicator(auth_color_inactive);
auth_sat.indicator(auth_color_inactive);
auth_sun.indicator(auth_color_inactive);
auth_moon.indicator(auth_color_inactive);
auth_manual.indicator(auth_color_inactive);
if (line == "console/azel") {
azel_spg.copy_position();
auth_azel.indicator(auth_color_active);
azel_spg.visible_set(true);
} else {
azel_spg.visible_set(false);
}
if (line == "console/j2000tracker") {
auth_j2000.indicator(auth_color_active);
j2000_spg.visible_set(true);
} else {
j2000_spg.visible_set(false);
}
if (line == "console/sattracker") {
auth_sat.indicator(auth_color_active);
sat_spg.visible_set(true);
} else {
sat_spg.visible_set(false);
}
if (line == "console/idle") {
auth_idle.indicator(auth_color_active);
}
if (line == "console/moontracker") {
auth_moon.indicator(auth_color_active);
moon_spg.visible_set(true);
} else {
moon_spg.visible_set(false);
}
if (line == "console/suntracker") {
auth_sun.indicator(auth_color_active);
sun_spg.visible_set(true);
} else {
sun_spg.visible_set(false);
}
if (line == "console/manual") {
auth_manual.indicator(auth_color_active);
manual_spg.visible_set(true);
} else {
manual_spg.visible_set(false);
}
}
dt_auth_status = new auth_status(auth_status_url, "auth");
dt_auth_status.callback = dt_auth_status_line;
dt_auth_status.open();
/******************************************************************
*
......
......@@ -344,9 +344,13 @@ function j2000(element_name) {
*/
this.visible = true;
this.visible_set = function(visible)
{
if (j2000_this.visible != visible && visible) {
j2000_this.copy_position();
}
j2000_this.visible = visible;
j2000_this.window.visible_set(visible);
if (!visible) {
j2000_this.set_track("enabled=0");
......
......@@ -256,13 +256,15 @@ function sat(element_name) {
var tle_new;
var gps_ops;