Commit 25f5c310 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Alessandro Rubini

tools: report output config/status in both human and raw mode, depending on command line switch

parent a42d06be
...@@ -13,7 +13,7 @@ void help(char *name) ...@@ -13,7 +13,7 @@ void help(char *name)
fprintf(stderr, "fmc-fdelay-status: reports channel programming\n"); fprintf(stderr, "fmc-fdelay-status: reports channel programming\n");
fprintf(stderr, "Use: \"%s [-i <index>] [-d <dev>] [-r]\"\n", name); fprintf(stderr, "Use: \"%s [-i <index>] [-d <dev>] [-r]\"\n", name);
fprintf(stderr, "-r: display raw device configuration"); fprintf(stderr, " -r: display raw hardware configuration");
exit(1); exit(1);
} }
...@@ -21,8 +21,7 @@ int main(int argc, char **argv) ...@@ -21,8 +21,7 @@ int main(int argc, char **argv)
{ {
struct fdelay_board *b; struct fdelay_board *b;
struct fdelay_pulse p; struct fdelay_pulse p;
int nboards, ch, index = -1, dev = -1; int nboards, ch, index = -1, dev = -1, raw = 0, opt;
/* Standard part of the file (repeated code) */ /* Standard part of the file (repeated code) */
if (tools_need_help(argc, argv)) if (tools_need_help(argc, argv))
...@@ -42,7 +41,34 @@ int main(int argc, char **argv) ...@@ -42,7 +41,34 @@ int main(int argc, char **argv)
if (nboards == 1) if (nboards == 1)
index = 0; /* so it works with no arguments */ index = 0; /* so it works with no arguments */
tools_getopt_d_i(argc, argv, &dev, &index);
while ((opt = getopt(argc, argv, "i:d:rh")) != -1) {
char *rest;
switch (opt) {
case 'i':
index = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
break;
case 'd':
dev = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
break;
case 'r':
raw = 1;
break;
case 'h':
help(argv[0]);
exit(0);
}
}
if (index < 0 && dev < 0) { if (index < 0 && dev < 0) {
fprintf(stderr, "%s: several boards, please pass -i or -d\n", fprintf(stderr, "%s: several boards, please pass -i or -d\n",
...@@ -50,11 +76,6 @@ int main(int argc, char **argv) ...@@ -50,11 +76,6 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
/* Error if too many arguments */
if (optind != argc)
help(argv[0]);
b = fdelay_open(index, dev); b = fdelay_open(index, dev);
if (!b) { if (!b) {
fprintf(stderr, "%s: fdelay_open(): %s\n", argv[0], fprintf(stderr, "%s: fdelay_open(): %s\n", argv[0],
...@@ -70,9 +91,7 @@ int main(int argc, char **argv) ...@@ -70,9 +91,7 @@ int main(int argc, char **argv)
} }
/* pass hw number again, as the function is low-level */ /* pass hw number again, as the function is low-level */
report_output_config(FDELAY_OUTPUT_USER_TO_HW(ch), report_output_config(FDELAY_OUTPUT_USER_TO_HW(ch),
&p, TOOLS_UMODE_USER); &p, raw ? TOOLS_UMODE_RAW : TOOLS_UMODE_USER);
// tools_report_action(FDELAY_OUTPUT_USER_TO_HW(ch),
// &p, TOOLS_UMODE_RAW);
} }
fdelay_close(b); fdelay_close(b);
fdelay_exit(); fdelay_exit();
......
...@@ -99,6 +99,8 @@ static struct fdelay_time fd_ts_sub(struct fdelay_time a, struct fdelay_time b) ...@@ -99,6 +99,8 @@ static struct fdelay_time fd_ts_sub(struct fdelay_time a, struct fdelay_time b)
rv.utc = u; rv.utc = u;
rv.coarse = c; rv.coarse = c;
rv.frac = f; rv.frac = f;
rv.seq_id = 0;
rv.channel = 0;
return rv; return rv;
} }
...@@ -128,7 +130,7 @@ static void report_output_config_human(int channel, struct fdelay_pulse *p) ...@@ -128,7 +130,7 @@ static void report_output_config_human(int channel, struct fdelay_pulse *p)
} }
if(p->mode & 0x80) if(p->mode & 0x80)
printf("(triggered) "); printf(" (triggered) ");
tools_report_time(m == FD_OUT_MODE_DELAY ? "\n delay: " : "\n start at: ", tools_report_time(m == FD_OUT_MODE_DELAY ? "\n delay: " : "\n start at: ",
&p->start, TOOLS_UMODE_USER); &p->start, TOOLS_UMODE_USER);
...@@ -138,21 +140,45 @@ static void report_output_config_human(int channel, struct fdelay_pulse *p) ...@@ -138,21 +140,45 @@ static void report_output_config_human(int channel, struct fdelay_pulse *p)
if(p->rep != 1) if(p->rep != 1)
{ {
printf(" repeat: "); printf(" repeat: ");
if(p->rep == -1) if(p->rep == -1)
printf("infinite\n"); printf("infinite\n");
else else
printf("%d times\n", p->rep); printf("%d times\n", p->rep);
tools_report_time(" period: ", &p->loop, TOOLS_UMODE_USER); tools_report_time(" period: ", &p->loop, TOOLS_UMODE_USER);
} }
} }
void report_output_config_raw(int channel, struct fdelay_pulse *p, int umode)
{
char mode[80];
int m = p->mode & 0x7f;
if (m == FD_OUT_MODE_DISABLED) strcpy(mode, "disabled");
else if (m == FD_OUT_MODE_PULSE) strcpy(mode, "pulse");
else if (m == FD_OUT_MODE_DELAY) strcpy(mode, "delay");
else sprintf(mode, "%i (0x%04x)", p->mode, p->mode);
if (p->mode & 0x80)
strcat(mode, " (triggered)");
printf("Channel %i, mode %s, repeat %i %s\n",
FDELAY_OUTPUT_HW_TO_USER(channel), mode,
p->rep, p->rep == -1 ? "(infinite)" : "");
tools_report_time("start", &p->start, umode);
tools_report_time("end ", &p->end, umode);
tools_report_time("loop ", &p->loop, umode);
}
void report_output_config(int channel, struct fdelay_pulse *p, int umode) void report_output_config(int channel, struct fdelay_pulse *p, int umode)
{ {
switch(umode) switch(umode)
{ {
case TOOLS_UMODE_USER: case TOOLS_UMODE_USER:
report_output_config_human(channel, p); report_output_config_human(channel, p);
break;
case TOOLS_UMODE_RAW:
case TOOLS_UMODE_FLOAT:
report_output_config_raw(channel, p, umode);
default: default:
break; break;
} }
......
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