#include <config.h>
#include <argp.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#ifdef ENABLE_NLS
# define _(string) gettext(string)
# include "gettext.h"
# include <locale.h>
# include <langinfo.h>
# include <iconv.h>
#else
# define _(string) string
#endif
# define N_(string) string
#define PROGRAM_NAME "dvb-fe-tool"
const char *argp_program_version = PROGRAM_NAME " version " V4L_UTILS_VERSION;
const char *argp_program_bug_address = "Mauro Carvalho Chehab <m.chehab@samsung.com>";
static const char doc[] = N_(
"\nA DVB frontend tool using API version 5\n"
"\nOn the options below, the arguments are:\n"
" ADAPTER - the dvb adapter to control\n"
" FRONTEND - the dvb frontend to control");
static const struct argp_option options[] = {
{"verbose", 'v', 0, 0, N_("enables debug messages"), 0},
{"adapter", 'a', N_("ADAPTER"), 0, N_("dvb adapter"), 0},
{"frontend", 'f', N_("FRONTEND"), 0, N_("dvb frontend"), 0},
{"set-delsys", 'd', N_("PARAMS"), 0, N_("set delivery system"), 0},
{"femon", 'm', 0, 0, N_("monitors frontend stats on an streaming frontend"), 0},
{"acoustical", 'A', 0, 0, N_("bips if signal quality is good. Also enables femon mode. Please notice that console bip should be enabled on your wm."), 0},
#if 0
{"set", 's', N_("PARAMS"), 0, N_("set frontend"), 0},
#endif
{"get", 'g', 0, 0, N_("get frontend"), 0},
{"help", '?', 0, 0, N_("Give this help list"), -1},
{"usage", -3, 0, 0, N_("Give a short usage message")},
{"version", 'V', 0, 0, N_("Print program version"), -1},
{ 0, 0, 0, 0, 0, 0 }
};
static int adapter = 0;
static int frontend = 0;
static unsigned get = 0;
static char *set_params = NULL;
static int verbose = 0;
static int delsys = 0;
static int femon = 0;
static int acoustical = 0;
static int timeout_flag = 0;
static void do_timeout(int x)
{
(void)x;
if (timeout_flag == 0) {
timeout_flag = 1;
alarm(2);
signal(SIGALRM, do_timeout);
} else {
exit(1);
}
}
#define PERROR(x...) \
do { \
fprintf(stderr, _("ERROR: ")); \
fprintf(stderr, x); \
fprintf(stderr, " (%s)\n", strerror(errno)); \
} while (0)
static error_t parse_opt(int k, char *arg, struct argp_state *state)
{
switch (k) {
case 'a':
adapter = atoi(arg);
break;
case 'f':
frontend = atoi(arg);
break;
case 'd':
if (delsys < 0)
return ARGP_ERR_UNKNOWN;
break;
case 'm':
femon++;
break;
case 'A':
femon++;
acoustical++;
break;
#if 0
case 's':
set_params = arg;
break;
#endif
case 'g':
get++;
break;
case 'v':
verbose ++;
break;
case '?':
argp_state_help(state, state->out_stream,
ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG
| ARGP_HELP_DOC);
fprintf(state->out_stream, _("\nReport bugs to %s.\n"), argp_program_bug_address);
exit(0);
case 'V':
fprintf (state->out_stream, "%s\n", argp_program_version);
exit(0);
case -3:
argp_state_help(state, state->out_stream, ARGP_HELP_USAGE);
exit(0);
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
.options = options,
.parser = parse_opt,
.doc = doc,
};
static int print_frontend_stats(FILE *fd,
{
char buf[512], *p;
int rc, i, len, show, n_status_lines = 0;
if (rc) {
PERROR(_("dvb_fe_get_stats failed"));
return -1;
}
p = buf;
len = sizeof(buf);
for (i = 0; i < MAX_DTV_STATS; i++) {
show = 1;
i, &p, &len, &show);
i, &p, &len, &show);
i, &p, &len, &show);
i, &p, &len, &show);
i, &p, &len, &show);
i, &p, &len, &show);
i, &p, &len, &show);
if (p != buf) {
if (isatty(fileno(fd))) {
int color;
switch (qual) {
color = 31;
break;
color = 36;
break;
color = 32;
break;
default:
color = 0;
break;
}
fprintf(fd, "\033[%dm", color);
if (acoustical) {
fprintf(fd, "\a");
}
}
if (n_status_lines)
fprintf(fd, "\t%s\n", buf);
else
fprintf(fd, "%s\n", buf);
n_status_lines++;
p = buf;
len = sizeof(buf);
}
}
fflush(fd);
return 0;
}
{
int rc;
signal(SIGTERM, do_timeout);
signal(SIGINT, do_timeout);
do {
if (!rc)
print_frontend_stats(stderr, parms);
if (!timeout_flag)
usleep(1000000);
} while (!timeout_flag);
}
int main(int argc, char *argv[])
{
int fe_flags = O_RDWR;
#ifdef ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
if (argp_parse(&argp, argc, argv, ARGP_NO_HELP | ARGP_NO_EXIT, 0, 0)) {
argp_help(&argp, stderr, ARGP_HELP_SHORT_USAGE, PROGRAM_NAME);
return -1;
}
if (!get && !delsys && !set_params && !femon)
if (!delsys && !set_params)
fe_flags = O_RDONLY;
if (!dvb)
return -1;
if (!dvb_dev)
return -1;
return -1;
if (delsys) {
printf(_("Changing delivery system to: %s\n"),
delivery_system_name[delsys]);
goto ret;
}
#if 0
if (set_params)
do_something();
#endif
if (get) {
}
if (femon)
get_show_stats(parms);
ret:
return 0;
}