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

Fix websocket buffering.

And some additional things for the UI.
parent c5154ccd
......@@ -189,6 +189,7 @@ struct status {
struct plugin_private *priv;
};
#define LINEBUF_SIZE 8192
void *status_thread(void *arg)
{
struct status *status = arg;
......@@ -198,7 +199,7 @@ void *status_thread(void *arg)
int port = -1;
int fd = -1;
int pos = 0;
unsigned char linebuf[1000];
unsigned char linebuf[LINEBUF_SIZE];
free(status);
......@@ -245,7 +246,7 @@ void *status_thread(void *arg)
select(fd + 1, &fd_rd, NULL, NULL, &timeout);
if (FD_ISSET(fd, &fd_rd)) {
r = read(fd, linebuf + pos, 999 - pos);
r = read(fd, linebuf + pos, LINEBUF_SIZE - 1 - pos);
if (r > 0) {
int i;
......
......@@ -287,6 +287,9 @@ dt_ui_title.prototype.title_set = function (titletext) {
function dt_ui_window(elementid)
{
if (elementid === undefined)
return;
dt_ui_element.call(this, elementid);
this.title = new dt_ui_title(elementid + "_windowtitle");
......@@ -322,6 +325,51 @@ dt_ui_window.prototype.align_horizontal = function(elements, spacing)
this.content.align_horizontal(elements, spacing);
}
function dt_ui_window_hide(elementid)
{
dt_ui_window.call(this, elementid);
this.hide_ui = new dt_ui_button(elementid + "_windowhide");
dt_ui_element.prototype.add.call(this, this.hide_ui);
this.hide_ui.top_set(0);
this.hide_ui.left_set(0);
this.hide_ui.text_set("hide");
var dt_ui_window_hide_this = this;
var dt_ui_window_hide_visible = true;
var dt_ui_window_hide_height;
this.hide_ui.onclick = function(elem) {
if (dt_ui_window_hide_visible) {
dt_ui_window_hide_height =
dt_ui_window_hide_this.height_get();
dt_ui_window_hide_this.height_set(
dt_ui_window_hide_this.title.height_get());
dt_ui_window_hide_this.hide_ui.text_set("show");
} else {
dt_ui_window_hide_this.height_set(
dt_ui_window_hide_height);
dt_ui_window_hide_this.hide_ui.text_set("hide");
}
dt_ui_window_hide_visible = !dt_ui_window_hide_visible;
dt_ui_window_hide_this.content.visible_set(
dt_ui_window_hide_visible);
}
}
dt_ui_window_hide.prototype = new dt_ui_window();
dt_ui_window_hide.prototype.title_set = function (titletext)
{
dt_ui_window.prototype.title_set.call(this, titletext);
this.hide_ui.left_set(this.title.width_get());
}
dt_ui_window_hide.prototype.hide = function()
{
this.hide_ui.onclick(null);
}
function dt_ui_value(elementid)
{
......
......@@ -279,30 +279,9 @@
-->
<td>
<div style="background: lightgrey; border:thin solid black" width="50%"
id="DT_model">
<i>
DT model
</i>
<div id="DT_model_show" align="right" style="float:right"></div>
<table border="0" id="DT_model_table">
<tr><th>Name</th><td><div id="DT_model_name"></div></td></tr>
<tr><th>a0</th><td><div id="DT_model_a0"></div></td></tr>
<tr><th>c1</th><td><div id="DT_model_c1"></div></td></tr>
<tr><th>c2</th><td><div id="DT_model_c2"></div></td></tr>
<tr><th>e0</th><td><div id="DT_model_e0"></div></td></tr>
<tr><th>b</th><td><div id="DT_model_b"></div></td></tr>
<tr><th>za</th><td><div id="DT_model_za"></div></td></tr>
<tr><th>aa</th><td><div id="DT_model_aa"></div></td></tr>
<tr><th colspan="2"><span id="DT_model_reload"></span></th></tr>
</table>
</p>
<div id="model"></div>
</div>
<!--
......@@ -408,6 +387,7 @@ eval(load("dt_view.js"));
eval(load("authorization.js"));
eval(load("utils.js"));
eval(load("offset.js"));
eval(load("model.js"));
eval(load("dt_websocket.js"));
new dt_websocket("ws://"+ window.location.hostname +"/dt");
......@@ -437,6 +417,8 @@ var j2000_spg = new j2000("spg_j2000");
var sat_spg = new sat("spg_sat");
var auth_win = new authorization("authorization");
var model_win = new model("model");
function offset_cb(azimuth_off, elevation_off)
{
Azimuth_Offset_value(azimuth_off);
......@@ -1001,110 +983,6 @@ log_draw();
/****************************
DT model
*/
var DT_model_status_url = "status.cgi";
var DT_model_command_url = "command.cgi_dt_model";
var DT_model_table = document.getElementById('DT_model_table');
var DT_model_show = document.getElementById('DT_model_show');
var DT_model_visible = false;
function DT_model_draw()
{
if (DT_model_visible) {
DT_model_show.innerHTML=
'<input type="button" value="hide" onclick="DT_model_show_set(0, true)">';
DT_model_table.style.display='block';
} else {
DT_model_show.innerHTML=
'<input type="button" value="show" onclick="DT_model_show_set(1, true)">';
DT_model_table.style.display='none';
}
}
function DT_model_show_set(show, interactive)
{
DT_model_visible = show;
DT_model_draw();
}
var DT_model_name_val = new dt_traceval("DT_model_name");
var DT_model_a0_val = new dt_traceval("DT_model_a0");
var DT_model_c1_val = new dt_traceval("DT_model_c1");
var DT_model_c2_val = new dt_traceval("DT_model_c2");
var DT_model_e0_val = new dt_traceval("DT_model_e0");
var DT_model_b_val = new dt_traceval("DT_model_b");
var DT_model_za_val = new dt_traceval("DT_model_za");
var DT_model_aa_val = new dt_traceval("DT_model_aa");
DT_model_draw();
var DT_model_vars = "0";
function DT_model_status_cb(vars)
{
if (vars != DT_model_vars) {
var vars_array = vars.split(',');
var i;
DT_model_vars = vars;
for (i = 0; i < vars_array.length; i++) {
var varname = vars_array[i].split('=')[0];
var varvalue = vars_array[i].split('=')[1];
if (varname == 'name') {
DT_model_name_val.value(varvalue);
DT_model_name_val.background("white");
}
if (varname == 'a0') {
DT_model_a0_val.value(varvalue);
DT_model_a0_val.background("white");
}
if (varname == 'c1') {
DT_model_c1_val.value(varvalue);
DT_model_c1_val.background("white");
}
if (varname == 'c2') {
DT_model_c2_val.value(varvalue);
DT_model_c2_val.background("white");
}
if (varname == 'e0') {
DT_model_e0_val.value(varvalue);
DT_model_e0_val.background("white");
}
if (varname == 'b') {
DT_model_b_val.value(varvalue);
DT_model_b_val.background("white");
}
if (varname == 'za') {
DT_model_za_val.value(varvalue);
DT_model_za_val.background("white");
}
if (varname == 'aa') {
DT_model_aa_val.value(varvalue);
DT_model_aa_val.background("white");
}
}
}
}
DT_model_status = new status(DT_model_status_url, "dt_model");
DT_model_status.callback = DT_model_status_cb;
DT_model_status.open();
DT_model_command = new command(DT_model_command_url, "dt_model");
var DT_model_reload_button = new dt_button("DT_model_reload");
DT_model_reload_button.value("Reload");
DT_model_reload_button.click(function(){DT_model_command.send("reload=1")});
</script>
</html>
/*
Javascript for DT model
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 model_loaded;
if (!model_loaded) {
model_loaded = true;
eval(load("dt_ui.js"));
eval(load("status.js"));
function model(element_name) {
var model_this = this;
/*
Create all the UI elements
*/
this.window = new dt_ui_window_hide(element_name);
this.window.title_set("DT model");
this.lbl_name = new dt_ui_element(element_name + "_lbl_name");
this.lbl_a0 = new dt_ui_element(element_name + "_lbl_a0");
this.lbl_c1 = new dt_ui_element(element_name + "_lbl_c1");
this.lbl_c2 = new dt_ui_element(element_name + "_lbl_c2");
this.lbl_e0 = new dt_ui_element(element_name + "_lbl_e0");
this.lbl_b = new dt_ui_element(element_name + "_lbl_b");
this.lbl_za = new dt_ui_element(element_name + "_lbl_za");
this.lbl_aa = new dt_ui_element(element_name + "_lbl_aa");
this.val_name = new dt_ui_value(element_name + "_val_name");
this.val_a0 = new dt_ui_value(element_name + "_val_a0");
this.val_c1 = new dt_ui_value(element_name + "_val_c1");
this.val_c2 = new dt_ui_value(element_name + "_val_c2");
this.val_e0 = new dt_ui_value(element_name + "_val_e0");
this.val_b = new dt_ui_value(element_name + "_val_b");
this.val_za = new dt_ui_value(element_name + "_val_za");
this.val_aa = new dt_ui_value(element_name + "_val_aa");
this.button_reload = new dt_ui_button(element_name + "_reload");
this.window.add([
this.lbl_name, this.lbl_a0, this.lbl_c1, this.lbl_c2,
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa,
this.val_name, this.val_a0, this.val_c1, this.val_c2,
this.val_e0, this.val_b, this.val_za, this.val_aa,
this.button_reload]);
this.lbl_name.text_set("Model name");
this.lbl_a0.text_set("parameter a0");
this.lbl_c1.text_set("parameter c1");
this.lbl_c2.text_set("parameter c2");
this.lbl_e0.text_set("parameter e0");
this.lbl_b.text_set("parameter b");
this.lbl_za.text_set("parameter za");
this.lbl_aa.text_set("parameter aa");
this.val_name.value_set("?Unknown name?");
this.val_a0.value_set("??.????????");
this.val_c1.value_set("??");
this.val_c2.value_set("??");
this.val_e0.value_set("??");
this.val_b.value_set("??");
this.val_za.value_set("??");
this.val_aa.value_set("??");
this.button_reload.text_set("Reload");
this.window.resize_equal([
this.lbl_name, this.lbl_a0, this.lbl_c1, this.lbl_c2,
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa,
this.val_name, this.val_a0, this.val_c1, this.val_c2,
this.val_e0, this.val_b, this.val_za, this.val_aa]);
this.window.align_horizontal([this.lbl_name, this.val_name], 5);
this.window.align_vertical([
this.lbl_name, this.lbl_a0, this.lbl_c1, this.lbl_c2,
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa], 5);
this.window.align_horizontal([this.lbl_a0, this.val_a0], 5);
this.window.align_horizontal([this.lbl_c1, this.val_c1], 5);
this.window.align_horizontal([this.lbl_c2, this.val_c2], 5);
this.window.align_horizontal([this.lbl_e0, this.val_e0], 5);
this.window.align_horizontal([this.lbl_b, this.val_b], 5);
this.window.align_horizontal([this.lbl_za, this.val_za], 5);
this.window.align_horizontal([this.lbl_aa, this.val_aa], 5);
this.window.align_vertical([this.lbl_aa, this.button_reload], 10);
this.status = new status("dummy mode", "dt_model");
this.vars = "?";
this.status.callback = function DT_model_status_cb(vars)
{
if (vars == model_this.vars)
return;
var vars_array = vars.split(',');
var i;
model_this.vars = vars;
for (i = 0; i < vars_array.length; i++) {
var varname = vars_array[i].split('=')[0];
var varvalue = vars_array[i].split('=')[1];
if (varname == 'name') {
model_this.val_name.value_set(varvalue);
}
if (varname == 'a0') {
model_this.val_a0.value_set(varvalue);
}
if (varname == 'c1') {
model_this.val_c1.value_set(varvalue);
}
if (varname == 'c2') {
model_this.val_c2.value_set(varvalue);
}
if (varname == 'e0') {
model_this.val_e0.value_set(varvalue);
}
if (varname == 'b') {
model_this.val_b.value_set(varvalue);
}
if (varname == 'za') {
model_this.val_za.value_set(varvalue);
}
if (varname == 'aa') {
model_this.val_aa.value_set(varvalue);
}
}
}
this.status.open();
this.command = new command("dummy_dt_command", "dt_model");
this.button_reload.onclick = function(elem )
{
model_this.command.send("reload=1")
}
this.window.hide();
}
} /* model_loaded */
......@@ -223,7 +223,7 @@ function sat(element_name) {
alert("Response from console: \n" + update_ret);
this.sat_reload();
sat_this.sat_reload();
}
this.button_enabled.onclick = function(elem) {
......@@ -259,8 +259,8 @@ function sat(element_name) {
var d = new Date();
var extra = "?" + d.getTime();
this.select_sat.option_clear();
this.sat_tle.length = 0;
sat_this.select_sat.option_clear();
sat_this.sat_tle.length = 0;
amateur = load("tle/amateur.txt" + extra).split('\n');
tle_new = load("tle/tle-new.txt" + extra).split('\n');
......@@ -273,20 +273,20 @@ function sat(element_name) {
element_lines = amateur.concat(tle_new).concat(gps_ops);
for (i = 0; i < element_lines.length - 2; i += 3) {
var ti = this.sat_tle.length;
var ti = sat_this.sat_tle.length;
this.sat_tle[ti] = new function() {
sat_this.sat_tle[ti] = new function() {
this.name = element_lines[i+0];
this.tle1 = element_lines[i+1];
this.tle2 = element_lines[i+2];
}
}
this.sat_tle.sort(function(a, b) { return a.name > b.name });
sat_this.sat_tle.sort(function(a, b) { return a.name > b.name });
for (i = 0; i < this.sat_tle.length; i++) {
this.select_sat.option_add(this.sat_tle[i].name,
this.sat_elem_onclick, this.sat_tle[i]);
for (i = 0; i < sat_this.sat_tle.length; i++) {
sat_this.select_sat.option_add(sat_this.sat_tle[i].name,
sat_this.sat_elem_onclick, sat_this.sat_tle[i]);
}
}
......
Supports Markdown
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