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

Cleanup htdocs dir

Don't double load js files.
Hopefully fix 100% cpu load bug in httpd.
Make sure changed type traces get a default value.
parent eefd8984
......@@ -640,7 +640,7 @@ int main(void) {
struct status *status;
time_t now;
n = poll(pollfds, count_pollfds, 25);
n = poll(pollfds, count_pollfds, 1000);
if (n < 0)
break;
......@@ -655,7 +655,7 @@ int main(void) {
if (fd == pollfds[n].fd) {
trace_handle(trace, NULL);
if (trace_fd_get(trace) < 0) {
if (trace_fd_get(trace) != fd) {
poll_remove(fd);
}
break;
......
......@@ -86,7 +86,7 @@ void nextpass(struct predict *predict)
double JD;
struct ln_date date;
int i;
double prev_az, az, el;
double prev_az = 0.0, az, el;
bool aos = false, los = false;
bool cross_west = false, cross_east = false;
int t_west_1 = 0, t_east_1 = 0, t_west_2 = 0, t_east_2 = 0;
......
......@@ -191,6 +191,7 @@ static void client_interval(struct trace *trace,
{
struct trace_pkt *pkt;
struct trace *server;
struct private *priv;
printf("Client %s requests %ld.%09ld type %d\n",
trace->name,
......@@ -207,6 +208,15 @@ static void client_interval(struct trace *trace,
return;
server_interval_check(server);
priv = server->private;
if (type == TRACE_INTERVAL_TYPE_CHANGED && !priv->firstvalue) {
pkt = trace_packet_new();
trace_packet_value_add(pkt, &priv->lastvalue, server->type);
trace_packet_write(trace, pkt);
trace_packet_put(pkt);
}
}
static struct trace_pkt *list_pkt;
......
/*
Javascript sending commands over XMLHttp
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2011, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2011, 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/>.
*/
function command (url, ident)
{
this.send = function send (switches)
{
dt_websocket_send("command " + ident + " " + switches);
}
}
/*
Javascript sending controller commands
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 controller_command_loaded;
if (!controller_command_loaded) {
controller_command_loaded = true;
function controller_command (name, vtype)
{
this.send = function send (value)
{
dt_websocket_send("controller_command " + name + " " + vtype + " " + value);
}
}
}
......@@ -114,4 +114,22 @@ function dt_websocket_onmessage_add(name, func, obj)
}
}
function command (url, ident)
{
this.send = function send (switches)
{
dt_websocket_send("command " + ident + " " + switches);
}
}
function controller_command (name, vtype)
{
this.send = function send (value)
{
dt_websocket_send("controller_command " + name + " " + vtype + " " + value);
}
}
} /* dt_websocket loaded */
......@@ -269,8 +269,6 @@ eval(load("trace.js"));
eval(load("azel.js"));
eval(load("j2000.js"));
eval(load("status.js"));
eval(load("command.js"));
eval(load("controller_command.js"));
eval(load("manual.js"));
eval(load("sun.js"));
eval(load("moon.js"));
......
......@@ -18,8 +18,22 @@
*/
function load (url)
var load_list = [ "load" ];
function load (url, reload = false)
{
var i;
if (!reload) {
/* prevent double loading of scripts */
for (i = 0; i < load_list.length; i++) {
if (load_list[i] == url) {
return "";
}
}
load_list.push(url);
}
var request = new XMLHttpRequest();
request.open('GET', url, false);
......
......@@ -233,15 +233,14 @@
<script src="load.js"></script>
<script src="trace.js"></script>
<script src="utils.js"></script>
<script src="weather.js"></script>
<script type="text/javascript">
eval(load("dt_ui.js"));
eval(load("dt_websocket.js"));
eval(load("controller_command.js"));
eval(load("trace.js"));
eval(load("utils.js"));
eval(load("weather.js"));
new dt_websocket("ws://"+ window.location.host +"/dt");
......
......@@ -219,7 +219,7 @@ function sat(element_name) {
this.button_update_tle.onclick = function()
{
var update_ret = load("tle_update.cgi");
var update_ret = load("tle_update.cgi", true);
alert("Response from console: \n" + update_ret);
......@@ -262,9 +262,9 @@ function sat(element_name) {
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');
gps_ops = load("tle/gps-ops.txt" + extra).split('\n');
amateur = load("tle/amateur.txt" + extra, true).split('\n');
tle_new = load("tle/tle-new.txt" + extra, true).split('\n');
gps_ops = load("tle/gps-ops.txt" + extra, true).split('\n');
amateur.length -= amateur.length % 3;
tle_new.length -= tle_new.length % 3;
......
/*
Javascript for parsing traces 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 trace_list_entry (tracename, unit)
{
this.tracename = tracename;
this.unit = unit;
}
function trace_list ()
{
var trace_this = this;
/* Callbacks */
this.callback = trace_cb_default;
this.list = new Array();
this.handle_xml = function (event)
{
var lines = event.target.responseText.split("\n");
for (i = 0; i < lines.length - 1; i++) {
trace_this.list[i] = new trace_list_entry(
lines[i].split("\t")[0],
lines[i].split("\t")[1]
);
}
}
this.open = function (url)
{
var xrequest = new XMLHttpRequest();
xrequest.multipart = false;
xrequest.open("GET", url, false);
xrequest.onload = this.handle_xml;
xrequest.send(null);
}
}
......@@ -365,6 +365,7 @@ static void *sample_thread(void *arg)
}
wait_init(&t);
controller_time_nseconds = timestamp_from_timespec(&t);
while (1) {
/* Pre sample stuff: */
......
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