Commit a31de72f authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Federico Vaga

wrtd/tools: show timestamps wrs to the current time in human readable form


NOTE
This commit has been created by `git subtree` on the Mock Turtle repository
on tag mock-turtle-2.0

This commit will not compile
parent 2120f191
......@@ -95,9 +95,9 @@ static void help()
exit(1);
}
void dump_input_state(struct wrtd_input_state *state)
void dump_input_state(struct wrtd_input_state *state, struct wr_timestamp current)
{
char tmp[1024], tmp2[1024];
char tmp[1024], tmp2[1024], tmp3[1024];
if(!(state->flags & WRTD_ENABLED))
printf("Channel %d: disabled\n", state->input );
......@@ -120,14 +120,16 @@ void dump_input_state(struct wrtd_input_state *state)
if( state-> flags & WRTD_LAST_VALID ) {
format_ts( tmp, state->last_tagged_pulse, 1 );
printf(" - Last input pulse: %s\n", tmp );
format_ago( tmp2, state->last_tagged_pulse, current );
printf(" - Last input pulse: %s (%s)\n", tmp, tmp2 );
}
if(state->sent_triggers > 0) {
format_ts( tmp, state->last_sent.ts, 1 );
format_id( tmp2, state->last_sent.id );
printf(" - Last sent trigger: %s, ID: %s, SeqNo %d\n",
tmp, tmp2, state->last_sent.seq);
format_ago( tmp3, state->last_sent.ts, current );
printf(" - Last sent trigger: %s (%s), ID: %s, SeqNo %d\n",
tmp, tmp3, tmp2, state->last_sent.seq);
}
printf(" - Dead time: %" PRIu64 " ns\n",
......@@ -145,11 +147,18 @@ static int wrtd_cmd_state(struct wrtd_node *wrtd, int input,
{
struct wrtd_input_state state;
int err;
struct wr_timestamp current;
err = wrtd_in_state_get(wrtd, input, &state);
if (err)
return err;
dump_input_state(&state);
err = wrtd_in_base_time(wrtd, &current);
if(err)
return err;
dump_input_state(&state, current);
return 0;
}
static int wrtd_cmd_enable(struct wrtd_node *wrtd, int input,
......
......@@ -115,6 +115,29 @@ void format_ts(char *buf, struct wr_timestamp ts, int with_seconds)
}
}
void format_ago(char *buf, struct wr_timestamp ts, struct wr_timestamp current)
{
uint64_t delta = current.seconds - ts.seconds;
char when[16];
if (delta < 0)
{
sprintf(when, "future");
delta = -delta;
} else {
sprintf(when, "past");
}
if(delta < 60)
sprintf(buf, "%lu seconds in the %s", delta, when);
else if (delta < 3600)
sprintf(buf, "%lu minutes in the %s", delta/60, when);
else if (delta < 3600*24)
sprintf(buf, "%lu hours in the %s", delta/3600, when);
else
sprintf(buf, "%lu days in the %s", delta/(24*3600), when);
}
void format_id(char *buf, struct wrtd_trig_id id)
{
sprintf( buf, "%04x:%04x:%08x", id.system, id.source_port,id.trigger);
......
......@@ -32,6 +32,7 @@ extern void decode_flags(char *buf, uint32_t flags);
extern void decode_mode(char *buf, int mode);
extern void decode_log_level(char *buf, uint32_t flags);
extern void format_ts(char *buf, struct wr_timestamp ts, int with_seconds);
extern void format_ago(char *buf, struct wr_timestamp ts, struct wr_timestamp current);
extern void format_id(char *buf, struct wrtd_trig_id id);
extern uint64_t ts_to_picos(struct wr_timestamp ts);
extern int parse_delay(char *dly, uint64_t *delay_ps);
......
......@@ -105,9 +105,9 @@ static struct wrtd_commands cmds[] = {
{ NULL }
};
static void dump_output_state(struct wrtd_output_state *state)
static void dump_output_state(struct wrtd_output_state *state, struct wr_timestamp current)
{
char tmp[1024], tmp2[1024];
char tmp[1024], tmp2[1024], tmp3[1024];
if(! (state->flags & WRTD_ENABLED))
printf("Channel %d: disabled\n", state->output);
......@@ -135,23 +135,27 @@ static void dump_output_state(struct wrtd_output_state *state)
format_ts(tmp, state->last_executed.ts, 1);
format_id(tmp2, state->last_executed.id);
printf(" - Last executed trigger: %s, ID: %s, SeqNo %d\n",
tmp, tmp2, state->last_executed.seq);
format_ago(tmp3, state->last_executed.ts, current);
printf(" - Last executed trigger: %s (%s), ID: %s, SeqNo %d\n",
tmp, tmp3, tmp2, state->last_executed.seq);
format_ts(tmp, state->last_enqueued.ts, 1);
format_id(tmp2, state->last_enqueued.id);
printf(" - Last enqueued trigger: %s, ID: %s, SeqNo %d\n",
tmp, tmp2, state->last_enqueued.seq);
format_ago(tmp3, state->last_enqueued.ts, current);
printf(" - Last enqueued trigger: %s (%s), ID: %s, SeqNo %d\n",
tmp, tmp3, tmp2, state->last_enqueued.seq);
format_ts(tmp, state->last_received.ts, 1);
format_id(tmp2, state->last_received.id);
printf(" - Last received trigger: %s, ID: %s, SeqNo %d\n",
tmp, tmp2, state->last_received.seq);
format_ago(tmp3, state->last_received.ts, current);
printf(" - Last received trigger: %s (%s), ID: %s, SeqNo %d\n",
tmp, tmp3, tmp2, state->last_received.seq);
format_ts(tmp, state->last_lost.ts, 1);
format_id(tmp2, state->last_lost.id);
printf(" - Last missed/lost trigger: %s, ID: %s, SeqNo %d\n",
tmp, tmp2, state->last_lost.seq);
format_ago(tmp3, state->last_lost.ts, current);
printf(" - Last missed/lost trigger: %s (%s), ID: %s, SeqNo %d\n",
tmp, tmp3, tmp2, state->last_lost.seq);
wrtd_strlogging_full(tmp, state->log_level);
printf(" - Log level: %s\n", tmp);
......@@ -255,13 +259,19 @@ static int wrtd_cmd_state(struct wrtd_node *wrtd, int output,
{
struct wrtd_output_state state;
int err;
struct wr_timestamp current;
err = wrtd_out_state_get(wrtd, output, &state);
if(err)
return err;
dump_output_state(&state);
err = wrtd_out_base_time(wrtd, &current);
if(err)
return err;
dump_output_state(&state, current);
return 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