1
0
mirror of https://github.com/DigitalDevices/dddvb.git synced 2023-10-10 13:37:43 +02:00

add the -o option to write the dvr device to stdout

This commit is contained in:
Marcus Metzler 2019-10-24 16:05:19 +02:00
parent 11bd28ea82
commit 269e66ddca

View File

@ -5,6 +5,12 @@
#include <getopt.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
static uint32_t root2gold(uint32_t root)
{
@ -29,6 +35,9 @@ int main(int argc, char **argv)
enum fe_code_rate fec = FEC_AUTO;
enum fe_delivery_system delsys = ~0;
char *config = "config/";
int fd = 0;
int odvr = 0;
FILE *fout = stdout;
while (1) {
int cur_optind = optind ? optind : 1;
@ -46,18 +55,24 @@ int main(int argc, char **argv)
{"root", required_argument, 0, 'r'},
{"num", required_argument, 0, 'n'},
{"verbosity", required_argument, 0, 'v'},
{"open_dvr", no_argument, 0, 'o'},
{"help", no_argument , 0, 'h'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv,
"c:i:f:s:d:p:hg:r:n:b:l:v:",
"c:i:f:s:d:p:hg:r:n:b:l:v:o",
long_options, &option_index);
if (c==-1)
break;
switch (c) {
case 'o':
fout = stderr;
fprintf(fout,"Reading from dvr\n");
odvr = 1;
break;
case 'c':
config = strdup(optarg);
config = strdup(optarg);
break;
case 'f':
frequency = strtoul(optarg, NULL, 0);
@ -111,7 +126,7 @@ int main(int argc, char **argv)
pol = 0;
break;
case 'h':
printf("ddzap [-d delivery_system] [-p polarity] [-c config_dir] [-f frequency(Hz)]\n"
fprintf(fout,"ddzap [-d delivery_system] [-p polarity] [-c config_dir] [-f frequency(Hz)]\n"
" [-b bandwidth(Hz)] [-s symbol_rate(Hz)]\n"
" [-g gold_code] [-r root_code] [-i id] [-n device_num]\n"
"\n"
@ -126,11 +141,11 @@ int main(int argc, char **argv)
}
}
if (optind < argc) {
printf("Warning: unused arguments\n");
fprintf(fout,"Warning: unused arguments\n");
}
if (delsys == ~0) {
printf("You have to choose a delivery system: -d (C|S|S2|T|T2)\n");
fprintf(fout,"You have to choose a delivery system: -d (C|S|S2|T|T2)\n");
exit(-1);
}
switch (delsys) {
@ -142,17 +157,17 @@ int main(int argc, char **argv)
dd = dddvb_init(config, verbosity);
if (!dd) {
printf("dddvb_init failed\n");
fprintf(fout,"dddvb_init failed\n");
exit(-1);
}
printf("dvbnum = %u\n", dd->dvbfe_num);
fprintf(fout,"dvbnum = %u\n", dd->dvbfe_num);
if (num != DDDVB_UNDEF)
fe = dddvb_fe_alloc_num(dd, delsys, num);
else
fe = dddvb_fe_alloc(dd, delsys);
if (!fe) {
printf("dddvb_fe_alloc failed\n");
fprintf(fout,"dddvb_fe_alloc failed\n");
exit(-1);
}
dddvb_param_init(&p);
@ -171,7 +186,8 @@ int main(int argc, char **argv)
dddvb_ca_write(dd, 0, ts, 188);
}
while (1) {
if (!odvr){
while (1) {
fe_status_t stat;
int64_t str, cnr;
@ -182,5 +198,36 @@ int main(int argc, char **argv)
printf("stat=%02x, str=%lld.%03llddB, snr=%lld.%03llddB \n",
stat, str/1000, abs(str%1000), cnr/1000, abs(cnr%1000));
sleep(1);
}
} else {
#define BUFFSIZE (1024*188)
fe_status_t stat;
char filename[150];
uint8_t buf[BUFFSIZE];
stat = 0;
stat = dddvb_get_stat(fe);
while (!(stat == 0x1f)) {
int64_t str, cnr;
stat = dddvb_get_stat(fe);
str = dddvb_get_strength(fe);
cnr = dddvb_get_cnr(fe);
printf("stat=%02x, str=%lld.%03llddB, snr=%lld.%03llddB \n",
stat, str/1000, abs(str%1000), cnr/1000, abs(cnr%1000));
sleep(1);
}
fprintf(stderr,"got lock on %s\n", fe->name);
snprintf(filename,25,
"/dev/dvb/adapter%d/dvr%d",fe->anum, fe->fnum);
fprintf(stderr,"opening %s\n", filename);
if ((fd = open(filename ,O_RDONLY)) < 0){
fprintf(stderr,"Error opening input file:%s\n",filename);
}
while(1){
read(fd,buf,BUFFSIZE);
write(fileno(stdout),buf,BUFFSIZE);
}
}
}