Commit 0ea7e550 authored by Adam Wujek's avatar Adam Wujek 💬

tools: add printing version of programs

with -V switch
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent fc911276
...@@ -10,7 +10,9 @@ REPO_PARENT=../.. ...@@ -10,7 +10,9 @@ REPO_PARENT=../..
# user-space tools for spec-fine-delay # user-space tools for spec-fine-delay
DESTDIR ?= /usr/local DESTDIR ?= /usr/local
GIT_VERSION := $(shell git describe --dirty --long --tags)
CFLAGS += -I../kernel -Wno-trigraphs -Wall -ggdb -O2 $(EXTRACFLAGS) CFLAGS += -I../kernel -Wno-trigraphs -Wall -ggdb -O2 $(EXTRACFLAGS)
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
CC ?= $(CROSS_COMPILE)gcc CC ?= $(CROSS_COMPILE)gcc
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
static char git_version[] = "version: " GIT_VERSION;
#define buf_len 50 #define buf_len 50
/* user will edit by adding the device name */ /* user will edit by adding the device name */
char basepath[40] = "/sys/bus/zio/devices/"; char basepath[40] = "/sys/bus/zio/devices/";
...@@ -102,9 +104,15 @@ static void fau_help() ...@@ -102,9 +104,15 @@ static void fau_help()
{ {
printf("\nfau-acq-time [OPTIONS] <DEVICE>\n\n"); printf("\nfau-acq-time [OPTIONS] <DEVICE>\n\n");
printf(" <DEVICE>: ZIO name of the device to use\n"); printf(" <DEVICE>: ZIO name of the device to use\n");
printf(" --last|-l : time between the last trigger and the acquisition end\n\n"); printf(" --last|-l : time between the last trigger and the acquisition end\n");
printf(" --full|-f : time between the acquisition start and the acquisition end\n\n"); printf(" --full|-f : time between the acquisition start and the acquisition end\n");
printf(" --help|-h: show this help\n\n"); printf(" --version|-V : print version information\n");
printf(" --help|-h : show this help\n\n");
}
static void print_version(char *pname)
{
printf("%s %s\n", pname, git_version);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
...@@ -114,6 +122,7 @@ int main(int argc, char *argv[]) ...@@ -114,6 +122,7 @@ int main(int argc, char *argv[])
static struct option options[] = { static struct option options[] = {
{"last",no_argument, &last, 1}, {"last",no_argument, &last, 1},
{"full",no_argument, &full, 1}, {"full",no_argument, &full, 1},
{"version",no_argument, 0, 'V'},
{"help",no_argument, 0, 'h'}, {"help",no_argument, 0, 'h'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
...@@ -126,12 +135,16 @@ int main(int argc, char *argv[]) ...@@ -126,12 +135,16 @@ int main(int argc, char *argv[])
exit(1); exit(1);
} }
while( (c = getopt_long(argc, argv, "lfh", options, &opt_index)) >=0 ){ while( (c = getopt_long(argc, argv, "lfVh", options, &opt_index)) >=0 ){
if (c == 'h') { if (c == 'h') {
fau_help(); fau_help();
exit(1); exit(1);
break; break;
} }
if (c == 'V') {
print_version(argv[0]);
exit(1);
}
} }
if (optind != argc - 1 ) { if (optind != argc - 1 ) {
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
static char git_version[] = "version: " GIT_VERSION;
#define buf_len 50 #define buf_len 50
/* user will edit by adding the device name */ /* user will edit by adding the device name */
char basepath[40] = "/sys/bus/zio/devices/"; char basepath[40] = "/sys/bus/zio/devices/";
...@@ -89,11 +91,17 @@ static void fau_help() ...@@ -89,11 +91,17 @@ static void fau_help()
printf(" --disable-hw-trg: disable the hardware trigger. By default " printf(" --disable-hw-trg: disable the hardware trigger. By default "
"is enabled\n"); "is enabled\n");
printf(" --force: force all attribute to the program default\n"); printf(" --force: force all attribute to the program default\n");
printf(" --version|-V: print version information\n");
printf(" --help|-h: show this help\n\n"); printf(" --help|-h: show this help\n\n");
printf("NOTE: The software trigger works only if also hardware trigger " printf("NOTE: The software trigger works only if also hardware trigger "
"is enabled\n\n"); "is enabled\n\n");
} }
static void print_version(char *pname)
{
printf("%s %s\n", pname, git_version);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* default attribute */ /* default attribute */
...@@ -113,6 +121,7 @@ int main(int argc, char *argv[]) ...@@ -113,6 +121,7 @@ int main(int argc, char *argv[])
{"enable-sw-trg", no_argument, &attrval[FAU_SW_TRG_EN], 1}, {"enable-sw-trg", no_argument, &attrval[FAU_SW_TRG_EN], 1},
{"disable-hw-trg", no_argument, &attrval[FAU_TRG_EN], 0}, {"disable-hw-trg", no_argument, &attrval[FAU_TRG_EN], 0},
{"force", no_argument, &force, 1}, {"force", no_argument, &force, 1},
{"version",no_argument, 0, 'V'},
{"help",no_argument, 0, 'h'}, {"help",no_argument, 0, 'h'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
...@@ -124,7 +133,7 @@ int main(int argc, char *argv[]) ...@@ -124,7 +133,7 @@ int main(int argc, char *argv[])
exit(1); exit(1);
} }
while( (c = getopt_long(argc, argv, "p:P:n:d:t:c:h", while( (c = getopt_long(argc, argv, "p:P:n:d:t:c:Vh",
options, &opt_index)) >=0 ){ options, &opt_index)) >=0 ){
switch(c){ switch(c){
case 'p': case 'p':
...@@ -145,6 +154,9 @@ int main(int argc, char *argv[]) ...@@ -145,6 +154,9 @@ int main(int argc, char *argv[])
case 'c': case 'c':
attrval[FAU_TRG_CHN] = atoi(optarg); attrval[FAU_TRG_CHN] = atoi(optarg);
break; break;
case 'V':
print_version(argv[0]);
exit(1);
case 'h': case 'h':
fau_help(); fau_help();
exit(1); exit(1);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
static char git_version[] = "version: " GIT_VERSION;
/* Returns the numer of microsecond timer ticks (Tomasz Wlostowski) */ /* Returns the numer of microsecond timer ticks (Tomasz Wlostowski) */
static int64_t get_tics() static int64_t get_tics()
{ {
...@@ -36,11 +38,22 @@ static void delay_to(int64_t until) ...@@ -36,11 +38,22 @@ static void delay_to(int64_t until)
; ;
} }
static void print_version(char *pname)
{
printf("%s %s\n", pname, git_version);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd, addr, count, usec; int fd, addr, count, usec;
int64_t tics; int64_t tics;
if ((argc == 2) &&
(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
print_version(argv[0]);
exit(0);
}
if (argc != 4) { if (argc != 4) {
fprintf(stderr, fprintf(stderr,
"%s: Use \"%s <hexaddr> <count> <period-usec>\"\n", "%s: Use \"%s <hexaddr> <count> <period-usec>\"\n",
......
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