Commit 49fd7bff authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Small tracing fixes

Add support for keeping last known values in trace_proxy
(Can be used for dt position while console/controller is offline)
Reduce sun and moon time offset to 2 seconds
Add UTC time of controller trace to gui
Fix some padding in dt_ui javascript
parent f4993f33
......@@ -648,7 +648,7 @@ char *enum_trace_state2str(enum trace_state state)
}
}
char *enum_trace_cap2str(unsigned cap)
char *flag_trace_cap2str(unsigned cap)
{
switch(cap) {
case TRACE_CAP_PROXY:
......
......@@ -85,7 +85,7 @@ struct trace_value {
#define TRACE_CAP_PROXY 0x01
#define TRACE_CAP_MULTIPLEX 0x02
char *enum_trace_cap2str(unsigned cap);
char *flag_trace_cap2str(unsigned cap);
struct trace {
int fd;
......
......@@ -78,9 +78,10 @@ int trace_connect(struct trace *trace)
void trace_close(struct trace *trace)
{
log_send(LOG_T_DEBUG, "Close trace on request");
if (trace->fd >= 0)
if (trace->fd >= 0) {
log_send(LOG_T_DEBUG, "Close trace on request");
close(trace->fd);
}
trace->fd = -1;
trace->recover = false;
}
......
......@@ -34,7 +34,8 @@ static bool trace_proxy = true;
static bool command_proxy = true;
static char *trace_proxy_src_host = NULL;
static unsigned short trace_proxy_src_port = 0;
static char **trace_proxy_keep = NULL;
static int trace_proxy_keep_nr = 0;
static bool init_done = false;
static int load_config(void)
......@@ -93,6 +94,13 @@ static int load_config(void)
trace_proxy_src_port =
g_key_file_get_integer(keyfile, groups[i], "src_port", NULL);
}
if (g_key_file_has_key(keyfile, groups[i], "keep", NULL)) {
gsize size;
trace_proxy_keep = g_key_file_get_string_list (
keyfile, groups[i], "keep",
&size, NULL);
trace_proxy_keep_nr = size;
}
}
if (!strcmp(groups[i], "log")) {
if (g_key_file_has_key(keyfile, groups[i], "path", NULL)) {
......@@ -211,3 +219,13 @@ unsigned short dt_host_trace_proxy_src_port(void)
return trace_proxy_src_port;
}
void dt_host_trace_proxy_keep(char ***keep, int *nr)
{
if (!init_done)
load_config();
*keep = trace_proxy_keep;
*nr = trace_proxy_keep_nr;
return;
}
......@@ -34,4 +34,6 @@ bool dt_host_command_proxy(void);
char *dt_host_trace_proxy_src_host(void);
unsigned short dt_host_trace_proxy_src_port(void);
void dt_host_trace_proxy_keep(char ***, int *);
#endif /* _INCLUDE_DT_HOST_H_ */
......@@ -73,7 +73,6 @@ static bool tracking_command_send_p180 = false;
static bool tracking_command_last_az_valid = false;
static float tracking_command_last_az = 0;
bool tracking_enabled = false;
bool refraction_enable = true;
bool dt_model_enable = false;
......@@ -236,6 +235,7 @@ void output(struct status_server *stat_srv)
{
static time_t last = 0;
time_t now;
time_t now_t = time(NULL);
struct ln_hrz_posn hrz;
struct ln_date date;
double JD;
......@@ -252,6 +252,10 @@ void output(struct status_server *stat_srv)
do_output = 0;
}
now = traceval_az->value.t.tv_sec;
if (now_t - now > 2) {
printf("No trace for more than 2 seconds, using last known position\n");
now = now_t;
}
if (now <= last) {
do_output = 0;
......
......@@ -49,6 +49,8 @@
#include <utils/status_server.h>
#include <log/log.h>
#define TIME_OFFSET 2
char *command_host = "localhost";
int command_port = CONSOLE_COMMAND_PORT;
......@@ -194,7 +196,7 @@ int main(int argc, char **argv)
t = time(NULL);
if (t != lastt) {
lastt = t;
t += 5;
t += TIME_OFFSET;
// jul 26 2008 5:39 utc
// t = 1217050740;
......
......@@ -50,6 +50,8 @@
#include <log/log.h>
#define TIME_OFFSET 2
char *command_host = "localhost";
int command_port = CONSOLE_COMMAND_PORT;
int stat_port = CONSOLE_SUN_STAT_PORT;
......@@ -191,7 +193,7 @@ int main(int argc, char **argv)
t = time(NULL);
if (t != lastt) {
lastt = t;
t += 5;
t += TIME_OFFSET;
aalib(0, t,
weather_get_temperature(weather),
......
......@@ -49,9 +49,14 @@ struct private {
time_t lastclient;
struct trace_value lastvalue;
bool firstvalue;
bool keep; /* keep this trace even without active clients */
};
static char **keep_traces;
static int nr_keep_traces = 0;
static int nr_client_traces = 0;
static struct trace **client_traces;
......@@ -103,7 +108,12 @@ static void server_interval_check(struct trace *server)
int i;
bool fullrate = false;
interval.tv_sec = 0;
if (priv->keep) {
interval.tv_sec = 1;
type = TRACE_INTERVAL_TYPE_INTERVAL;
} else {
interval.tv_sec = 0;
}
interval.tv_nsec = 0;
......@@ -341,7 +351,7 @@ static void server_timestamp(struct trace *trace,
trace_packet_put(pkt);
}
if (!priv->nr_clients && trace->fd >= 0 && priv->lastclient + TIMEOUT < time(NULL)) {
if (!priv->nr_clients && trace->fd >= 0 && priv->lastclient + TIMEOUT < time(NULL) && !priv->keep) {
printf("Timeout, closing trace\n");
trace_close(trace);
trace_autorecover(trace, false);
......@@ -488,6 +498,11 @@ static void client_add(struct trace *client)
if (trace->value_set) {
struct trace_pkt *pkt;
pkt = trace_packet_new();
trace_packet_timestamp_set(pkt, &trace->value.t);
trace_packet_write(client, pkt);
trace_packet_put(pkt);
pkt = trace_packet_new();
trace_packet_value_add(pkt, 0, &trace->value, trace->type);
trace_packet_write(client, pkt);
......@@ -562,6 +577,22 @@ int main (int argc, char **argv)
printf("Received list from server, now waiting for clients\n");
dt_host_trace_proxy_keep(&keep_traces, &nr_keep_traces);
for (i = 0; i < nr_keep_traces; i++) {
struct trace *trace;
trace = server_find(keep_traces[i]);
if (trace) {
struct private *priv = trace->private;
priv->keep = true;
server_interval_check(trace);
printf("Pre-opened trace: %s\n", keep_traces[i]);
} else {
printf("Failed to pre-open: %s\n", keep_traces[i]);
}
}
while (1) {
struct timeval timeout;
......
......@@ -39,10 +39,12 @@ function dt_status(element_name) {
this.lbl_az = new dt_ui_element(element_name + "_lbl_az");
this.lbl_el = new dt_ui_element(element_name + "_lbl_el");
this.lbl_fb = new dt_ui_element(element_name + "_lbl_fb");
this.lbl_t = new dt_ui_element(element_name + "_lbl_t");
this.val_az_pos = new dt_ui_value_trace(element_name + "_val_az_pos", "Azimuth_Position", 4);
this.val_el_pos = new dt_ui_value_trace(element_name + "_val_el_pos", "Elevation_Position", 4);
this.val_fb_pos = new dt_ui_value_trace(element_name + "_val_fb_pos", "Focusbox_Position", 4);
this.val_t = new dt_ui_value(element_name + "_val_t");
this.az_view = new dt_ui_canvas(element_name + "_az_view");
this.el_view = new dt_ui_canvas(element_name + "_el_view");
......@@ -63,8 +65,8 @@ function dt_status(element_name) {
this.val_az_north = new dt_ui_value(element_name + "_val_az_north");
this.window.add([
this.lbl_az, this.lbl_el, this.lbl_fb,
this.val_az_pos, this.val_el_pos, this.val_fb_pos,
this.lbl_az, this.lbl_el, this.lbl_fb, this.lbl_t,
this.val_az_pos, this.val_el_pos, this.val_fb_pos, this.val_t,
this.val_az_en, this.val_el_en,
this.val_az_safe, this.val_el_safe,
this.az_view, this.el_view,
......@@ -75,12 +77,14 @@ function dt_status(element_name) {
this.lbl_az.text_set("Azimuth");
this.lbl_el.text_set("Elevation");
this.lbl_fb.text_set("Focusbox");
this.lbl_t.text_set("Time");
this.val_az_pos.label_set("Position");
this.val_el_pos.label_set("Position");
this.val_fb_pos.label_set("Position");
this.val_az_pos.suffix_set("deg");
this.val_el_pos.suffix_set("deg");
this.val_fb_pos.suffix_set("cm ");
this.val_t.suffix_set("UTC");
this.val_az_north.label_set("True north");
this.val_az_north.suffix_set("deg");
......@@ -96,9 +100,9 @@ function dt_status(element_name) {
this.button_disable.color_set("red");
this.window.resize_equal([
this.lbl_az, this.lbl_el, this.lbl_fb]);
this.lbl_az, this.lbl_el, this.lbl_fb, this.lbl_t]);
this.window.resize_equal([
this.val_az_pos, this.val_el_pos, this.val_fb_pos]);
this.val_az_pos, this.val_el_pos, this.val_fb_pos, this.val_t]);
this.window.resize_equal([
this.val_az_en, this.val_az_safe,
this.val_el_en, this.val_el_safe]);
......@@ -109,7 +113,7 @@ function dt_status(element_name) {
this.button_az_enable, this.button_el_enable, this.button_disable]);
this.window.align_vertical([
this.lbl_az, this.lbl_el, this.lbl_fb], 5);
this.lbl_az, this.lbl_el, this.lbl_fb, this.lbl_t], 5);
this.window.align_horizontal([
this.lbl_az, this.val_az_pos, this.val_az_en, this.val_az_safe], 5);
......@@ -117,6 +121,8 @@ function dt_status(element_name) {
this.lbl_el, this.val_el_pos, this.val_el_en, this.val_el_safe], 5);
this.window.align_horizontal([
this.lbl_fb, this.val_fb_pos, this.button_fb_m, this.button_fb_p], 5);
this.window.align_horizontal([
this.lbl_t, this.val_t], 5);
this.az_view.width_set(100);
this.az_view.height_set(100);
......@@ -152,7 +158,7 @@ function dt_status(element_name) {
this.elevation_position = 1000;
this.val_az_pos.value_func = function(val) {
this.val_az_pos.value_func = function(val, timestamp) {
dt_status_this.azimuth_position = val * 1.0;
val = rad2deg(val);
......@@ -164,6 +170,29 @@ function dt_status(element_name) {
dt_status_this.val_az_north.value_set(val_nd);
timestamp *= 1000;
var diff = Date.now() - timestamp;
if (diff > 10000 || diff < -10000) {
dt_status_this.val_t.background_set("red");
console.log("diff: " + diff);
} else {
dt_status_this.val_t.background_set("white");
}
utcc = new Date(timestamp);
function padtime(val) {
if (("" + val).length < 2)
return "0" + val;
else
return val;
}
dt_status_this.val_t.value_set(
padtime(utcc.getUTCHours()) + ":" +
padtime(utcc.getUTCMinutes()) + ":" +
padtime(utcc.getUTCSeconds()));
return val;
}
this.val_az_pos.number_set(true, 4);
......@@ -196,7 +225,7 @@ function dt_status(element_name) {
else
dt_status_this.view_elevation.draw(el_pos);
}
this.el_setpoint_trace.open(trace_url, 'Elevation_Setpoint', 4);
this.el_setpoint_trace.open(null, 'Elevation_Setpoint', 4);
this.az_setpoint_trace = new trace();
this.az_setpoint_trace.timeout = 3000;
......@@ -214,7 +243,7 @@ function dt_status(element_name) {
else
dt_status_this.view_azimuth.draw(az_pos);
}
this.az_setpoint_trace.open(trace_url, 'Azimuth_Setpoint', 4);
this.az_setpoint_trace.open(null, 'Azimuth_Setpoint', 4);
this.elevation_position_get = function() {
......
......@@ -415,6 +415,7 @@ function dt_ui_value(elementid)
this.element.style.background = dt_ui_color_background_value;
this.element.style.alignContent = "center";
this.element.style.textAlign = this.align;
this.element.style.paddingRight = "5px";
this.element.style.display = "block";
this.style_display = "block";
this.element.innerHTML = "X";
......@@ -733,13 +734,12 @@ function dt_ui_value_trace(elementid, name, freq)
this.element.style.fontFamily = "monospace; fons-size: 120%";
this.element.style.whiteSpace = "pre";
this.element.style.textAlign = "right";
this.element.style.paddingRight = "5px";
this.element.style.overflow = "hidden";
this.trace = new trace();
this.trace.timeout = 3000;
this.value_func = function(val) { return val; }
this.value_func = function(val, timestamp) { return val; }
this.trace.timeout_callback = function trace_timeout_cb(obj)
{
......@@ -750,7 +750,7 @@ function dt_ui_value_trace(elementid, name, freq)
{
var changed = false;
new_value = dt_ui_value_trace_this.value_func(new_value);
new_value = dt_ui_value_trace_this.value_func(new_value, time);
if (dt_ui_value_trace_this.boolean) {
if (new_value != 0) {
......
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