aboutsummaryrefslogtreecommitdiffstats
path: root/util/szap/czap.c
diff options
context:
space:
mode:
authoretobi <git@e-tobi.net>2013-09-03 09:48:41 +0200
committeretobi <git@e-tobi.net>2013-09-03 09:48:41 +0200
commitab959d7b4194715870128e616b8e29d4a101e488 (patch)
tree61a746231d30817be73416a7d67763fd677a1042 /util/szap/czap.c
parent6b350466c4902c5b137e0efaf1d189128a7f18f5 (diff)
downloadlinux-dvb-apps-ab959d7b4194715870128e616b8e29d4a101e488.tar.gz
Imported Upstream version 1.1.1+rev1207upstream/1.1.1+rev1207
Diffstat (limited to 'util/szap/czap.c')
-rw-r--r--util/szap/czap.c147
1 files changed, 85 insertions, 62 deletions
diff --git a/util/szap/czap.c b/util/szap/czap.c
index 9d183f9..469df56 100644
--- a/util/szap/czap.c
+++ b/util/szap/czap.c
@@ -16,8 +16,9 @@
static char FRONTEND_DEV [80];
static char DEMUX_DEV [80];
+static int exit_after_tuning;
-#define CHANNEL_FILE "/.czap/channels.conf"
+#define CHANNEL_FILE "channels.conf"
#define ERROR(x...) \
do { \
@@ -71,14 +72,17 @@ static const Param modulation_list[] = {
static
-int parse_param(const char *val, const Param * plist, int list_size)
+int parse_param(const char *val, const Param * plist, int list_size, int *ok)
{
int i;
for (i = 0; i < list_size; i++) {
- if (strcasecmp(plist[i].name, val) == 0)
+ if (strcasecmp(plist[i].name, val) == 0) {
+ *ok = 1;
return plist[i].value;
+ }
}
+ *ok = 0;
return -1;
}
@@ -119,6 +123,7 @@ int parse(const char *fname, int list_channels, int chan_no, const char *channel
FILE *f;
char *chan;
char *name, *inv, *fec, *mod;
+ int ok;
if ((f = fopen(fname, "r")) == NULL) {
PERROR("could not open file '%s'", fname);
@@ -144,19 +149,19 @@ int parse(const char *fname, int list_channels, int chan_no, const char *channel
ERROR("cannot parse service data");
return -3;
}
- frontend->inversion = parse_param(inv, inversion_list, LIST_SIZE(inversion_list));
- if (frontend->inversion < 0) {
+ frontend->inversion = parse_param(inv, inversion_list, LIST_SIZE(inversion_list), &ok);
+ if (!ok) {
ERROR("inversion field syntax '%s'", inv);
return -4;
}
- frontend->u.qam.fec_inner = parse_param(fec, fec_list, LIST_SIZE(fec_list));
- if (frontend->u.qam.fec_inner < 0) {
+ frontend->u.qam.fec_inner = parse_param(fec, fec_list, LIST_SIZE(fec_list), &ok);
+ if (!ok) {
ERROR("FEC field syntax '%s'", fec);
return -5;
}
frontend->u.qam.modulation = parse_param(mod, modulation_list,
- LIST_SIZE(modulation_list));
- if (frontend->u.qam.modulation < 0) {
+ LIST_SIZE(modulation_list), &ok);
+ if (!ok) {
ERROR("modulation field syntax '%s'", mod);
return -6;
}
@@ -223,7 +228,7 @@ int setup_frontend(int fe_fd, struct dvb_frontend_parameters *frontend)
static
-int check_frontend (int fe_fd)
+int check_frontend (int fe_fd, int human_readable)
{
fe_status_t status;
uint16_t snr, signal;
@@ -236,9 +241,13 @@ int check_frontend (int fe_fd)
ioctl(fe_fd, FE_READ_BER, &ber);
ioctl(fe_fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks);
- printf ("status %02x | signal %04x | snr %04x | "
- "ber %08x | unc %08x | ",
- status, signal, snr, ber, uncorrected_blocks);
+ if (human_readable) {
+ printf ("status %02x | signal %3u%% | snr %3u%% | ber %d | unc %d | ",
+ status, (signal * 100) / 0xffff, (snr * 100) / 0xffff, ber, uncorrected_blocks);
+ } else {
+ printf ("status %02x | signal %04x | snr %04x | ber %08x | unc %08x | ",
+ status, signal, snr, ber, uncorrected_blocks);
+ }
if (status & FE_HAS_LOCK)
printf("FE_HAS_LOCK");
@@ -246,13 +255,16 @@ int check_frontend (int fe_fd)
usleep(1000000);
printf("\n");
+
+ if (exit_after_tuning && (status & FE_HAS_LOCK))
+ break;
} while (1);
return 0;
}
-static const char *usage = "\nusage: %s [-a adapter_num] [-f frontend_id] [-d demux_id] [-c conf_file] {<channel name>| -n channel_num}\n"
+static const char *usage = "\nusage: %s [-a adapter_num] [-f frontend_id] [-d demux_id] [-c conf_file] [ -H ] {<channel name>| -n channel_num} [-x]\n"
" or: %s [-c conf_file] -l\n\n";
@@ -266,66 +278,78 @@ int main(int argc, char **argv)
int vpid, apid;
int frontend_fd, video_fd, audio_fd;
int opt, list_channels = 0, chan_no = 0;
+ int human_readable = 0;
+
+ while ((opt = getopt(argc, argv, "Hln:hrn:a:f:d:c:x")) != -1) {
+ switch (opt) {
+ case 'a':
+ adapter = strtoul(optarg, NULL, 0);
+ break;
+ case 'f':
+ frontend = strtoul(optarg, NULL, 0);
+ break;
+ case 'd':
+ demux = strtoul(optarg, NULL, 0);
+ break;
+ case 'r':
+ dvr = 1;
+ break;
+ case 'l':
+ list_channels = 1;
+ break;
+ case 'n':
+ chan_no = strtoul(optarg, NULL, 0);
+ break;
+ case 'x':
+ exit_after_tuning = 1;
+ break;
+ case 'H':
+ human_readable = 1;
+ break;
+ case 'c':
+ confname = optarg;
+ break;
+ case '?':
+ case 'h':
+ default:
+ fprintf (stderr, usage, argv[0], argv[0]);
+ return -1;
+ };
+ }
- while ((opt = getopt(argc, argv, "ln:hrn:a:f:d:c:")) != -1) {
- switch (opt) {
- case 'a':
- adapter = strtoul(optarg, NULL, 0);
- break;
- case 'f':
- frontend = strtoul(optarg, NULL, 0);
- break;
- case 'd':
- demux = strtoul(optarg, NULL, 0);
- break;
- case 'r':
- dvr = 1;
- break;
- case 'l':
- list_channels = 1;
- break;
- case 'n':
- chan_no = strtoul(optarg, NULL, 0);
- break;
- case 'c':
- confname = optarg;
- break;
- case '?':
- case 'h':
- default:
- fprintf (stderr, usage, argv[0], argv[0]);
- return -1;
- };
- }
-
- if (optind < argc)
- channel = argv[optind];
-
- if (!channel && chan_no <= 0 && !list_channels) {
- fprintf (stderr, usage, argv[0], argv[0]);
- return -1;
- }
+ if (optind < argc)
+ channel = argv[optind];
+
+ if (!channel && chan_no <= 0 && !list_channels) {
+ fprintf (stderr, usage, argv[0], argv[0]);
+ return -1;
+ }
if (!homedir)
ERROR("$HOME not set");
- snprintf (FRONTEND_DEV, sizeof(FRONTEND_DEV),
- "/dev/dvb/adapter%i/frontend%i", adapter, frontend);
+ snprintf (FRONTEND_DEV, sizeof(FRONTEND_DEV),
+ "/dev/dvb/adapter%i/frontend%i", adapter, frontend);
- snprintf (DEMUX_DEV, sizeof(DEMUX_DEV),
- "/dev/dvb/adapter%i/demux%i", adapter, demux);
+ snprintf (DEMUX_DEV, sizeof(DEMUX_DEV),
+ "/dev/dvb/adapter%i/demux%i", adapter, demux);
printf ("using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV);
if (!confname)
{
+ int len = strlen(homedir) + strlen(CHANNEL_FILE) + 18;
if (!homedir)
ERROR("$HOME not set");
- confname = malloc(strlen(homedir) + strlen(CHANNEL_FILE) + 1);
- memcpy(confname, homedir, strlen(homedir));
- memcpy(confname + strlen(homedir), CHANNEL_FILE,
- strlen(CHANNEL_FILE) + 1);
+ confname = malloc(len);
+ snprintf(confname, len, "%s/.czap/%i/%s",
+ homedir, adapter, CHANNEL_FILE);
+ if (access(confname, R_OK))
+ snprintf(confname, len, "%s/.czap/%s",
+ homedir, CHANNEL_FILE);
}
+ printf("reading channels from file '%s'\n", confname);
+
memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters));
if (parse(confname, list_channels, chan_no, channel, &frontend_param, &vpid, &apid))
@@ -357,7 +381,7 @@ int main(int argc, char **argv)
if (set_pesfilter (audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
return -1;
- check_frontend (frontend_fd);
+ check_frontend (frontend_fd, human_readable);
close (audio_fd);
close (video_fd);
@@ -365,4 +389,3 @@ int main(int argc, char **argv)
return 0;
}
-