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

264 lines
6.4 KiB
C
Raw Normal View History

#include "../include/linux/dvb/frontend.h"
2018-09-17 13:45:26 +02:00
#include "src/libdddvb.h"
#include <stdio.h>
#include <string.h>
#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>
2018-09-17 13:45:26 +02:00
2018-09-17 13:45:26 +02:00
static uint32_t root2gold(uint32_t root)
{
uint32_t x, g;
for (g = 0, x = 1; g < 0x3ffff; g++) {
if (root == x)
return g;
x = (((x ^ (x >> 7)) & 1) << 17) | (x >> 1);
}
return 0xffffffff;
}
int main(int argc, char **argv)
{
struct dddvb *dd;
struct dddvb_fe *fe;
struct dddvb_params p;
uint32_t bandwidth = DDDVB_UNDEF, frequency = 0, symbol_rate = 0, pol = DDDVB_UNDEF;
uint32_t id = DDDVB_UNDEF, ssi = DDDVB_UNDEF, num = DDDVB_UNDEF, source = 0;
uint32_t mtype= DDDVB_UNDEF;
2019-07-24 12:56:23 +02:00
uint32_t verbosity = 0;
2018-09-17 13:45:26 +02:00
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;
2018-09-17 13:45:26 +02:00
while (1) {
int cur_optind = optind ? optind : 1;
int option_index = 0;
int c;
static struct option long_options[] = {
{"config", required_argument, 0, 'c'},
{"frequency", required_argument, 0, 'f'},
2019-01-17 19:11:45 +01:00
{"bandwidth", required_argument, 0, 'b'},
2018-09-17 13:45:26 +02:00
{"symbolrate", required_argument, 0, 's'},
2019-07-24 12:56:23 +02:00
{"source", required_argument, 0, 'l'},
2018-09-17 13:45:26 +02:00
{"delsys", required_argument, 0, 'd'},
{"id", required_argument, 0, 'i'},
{"ssi", required_argument, 0, 'g'},
{"gold", required_argument, 0, 'g'},
2018-09-17 13:45:26 +02:00
{"root", required_argument, 0, 'r'},
{"num", required_argument, 0, 'n'},
{"mtype", required_argument, 0, 'm'},
2019-07-24 12:56:23 +02:00
{"verbosity", required_argument, 0, 'v'},
{"open_dvr", no_argument, 0, 'o'},
2018-09-17 13:45:26 +02:00
{"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:m:o",
2018-09-17 13:45:26 +02:00
long_options, &option_index);
if (c==-1)
break;
switch (c) {
case 'o':
fout = stderr;
fprintf(fout,"Reading from dvr\n");
odvr = 1;
break;
2018-09-17 13:45:26 +02:00
case 'c':
config = strdup(optarg);
2018-09-17 13:45:26 +02:00
break;
case 'f':
frequency = strtoul(optarg, NULL, 0);
break;
2019-01-17 19:11:45 +01:00
case 'b':
bandwidth = strtoul(optarg, NULL, 0);
break;
2018-09-17 13:45:26 +02:00
case 's':
symbol_rate = strtoul(optarg, NULL, 0);
break;
2019-07-24 12:56:23 +02:00
case 'l':
source = strtoul(optarg, NULL, 0);
break;
case 'v':
verbosity = strtoul(optarg, NULL, 0);
break;
2018-09-17 13:45:26 +02:00
case 'g':
ssi = strtoul(optarg, NULL, 0);
2018-09-17 13:45:26 +02:00
break;
case 'r':
ssi = root2gold(strtoul(optarg, NULL, 0));
2018-09-17 13:45:26 +02:00
break;
case 'i':
id = strtoul(optarg, NULL, 0);
break;
case 'n':
num = strtoul(optarg, NULL, 0);
break;
case 'm':
if (!strcmp(optarg, "16APSK"))
mtype = APSK_16;
if (!strcmp(optarg, "32APSK"))
mtype = APSK_32;
if (!strcmp(optarg, "64APSK"))
mtype = APSK_64;
if (!strcmp(optarg, "128APSK"))
mtype = APSK_128;
if (!strcmp(optarg, "256APSK"))
mtype = APSK_256;
if (mtype == DDDVB_UNDEF)
printf("unknown mtype %s\n", optarg);
break;
2018-09-17 13:45:26 +02:00
case 'd':
if (!strcmp(optarg, "C"))
delsys = SYS_DVBC_ANNEX_A;
if (!strcmp(optarg, "DVBC"))
delsys = SYS_DVBC_ANNEX_A;
2018-09-17 13:45:26 +02:00
if (!strcmp(optarg, "S"))
delsys = SYS_DVBS;
if (!strcmp(optarg, "DVBS"))
delsys = SYS_DVBS;
2018-09-17 13:45:26 +02:00
if (!strcmp(optarg, "S2"))
delsys = SYS_DVBS2;
if (!strcmp(optarg, "DVBS2"))
delsys = SYS_DVBS2;
2018-09-17 13:45:26 +02:00
if (!strcmp(optarg, "T"))
delsys = SYS_DVBT;
if (!strcmp(optarg, "DVBT"))
delsys = SYS_DVBT;
2018-09-17 13:45:26 +02:00
if (!strcmp(optarg, "T2"))
delsys = SYS_DVBT2;
if (!strcmp(optarg, "DVBT2"))
delsys = SYS_DVBT2;
2019-01-17 19:11:45 +01:00
if (!strcmp(optarg, "J83B"))
delsys = SYS_DVBC_ANNEX_B;
if (!strcmp(optarg, "ISDBC"))
delsys = SYS_ISDBC;
if (!strcmp(optarg, "ISDBT"))
delsys = SYS_ISDBT;
2018-09-17 13:45:26 +02:00
break;
case 'p':
if (!strcmp(optarg, "h") || !strcmp(optarg, "H"))
2018-09-17 13:45:26 +02:00
pol = 1;
if (!strcmp(optarg, "v") || !strcmp(optarg, "V"))
2018-09-17 13:45:26 +02:00
pol = 0;
break;
case 'h':
fprintf(fout,"ddzap [-d delivery_system] [-p polarity] [-c config_dir] [-f frequency(Hz)]\n"
2019-02-13 11:59:37 +01:00
" [-b bandwidth(Hz)] [-s symbol_rate(Hz)]\n"
" [-g gold_code] [-r root_code] [-i id] [-n device_num]\n"
2019-10-24 16:07:32 +02:00
" [-o (write dvr to stdout)]\n"
2019-02-13 11:59:37 +01:00
"\n"
" delivery_system = C,S,S2,T,T2,J83B,ISDBC,ISDBT\n"
" polarity = h/H,v/V\n"
2019-02-13 11:59:37 +01:00
"\n");
2018-09-17 13:45:26 +02:00
exit(-1);
default:
break;
}
}
if (optind < argc) {
fprintf(fout,"Warning: unused arguments\n");
2018-09-17 13:45:26 +02:00
}
if (delsys == ~0) {
fprintf(fout,"You have to choose a delivery system: -d (C|S|S2|T|T2)\n");
2018-09-17 13:45:26 +02:00
exit(-1);
}
switch (delsys) {
case SYS_DVBC_ANNEX_A:
if (!symbol_rate)
symbol_rate = 6900000;
break;
}
2019-07-24 12:56:23 +02:00
dd = dddvb_init(config, verbosity);
2018-09-17 13:45:26 +02:00
if (!dd) {
fprintf(fout,"dddvb_init failed\n");
2018-09-17 13:45:26 +02:00
exit(-1);
}
fprintf(fout,"dvbnum = %u\n", dd->dvbfe_num);
2018-09-17 13:45:26 +02:00
if (num != DDDVB_UNDEF)
fe = dddvb_fe_alloc_num(dd, delsys, num);
else
fe = dddvb_fe_alloc(dd, delsys);
if (!fe) {
fprintf(fout,"dddvb_fe_alloc failed\n");
2018-09-17 13:45:26 +02:00
exit(-1);
}
dddvb_param_init(&p);
dddvb_set_mtype(&p, mtype);
2018-09-17 13:45:26 +02:00
dddvb_set_frequency(&p, frequency);
2019-07-24 12:56:23 +02:00
dddvb_set_src(&p, source);
2019-01-17 19:11:45 +01:00
dddvb_set_bandwidth(&p, bandwidth);
2018-09-17 13:45:26 +02:00
dddvb_set_symbol_rate(&p, symbol_rate);
dddvb_set_polarization(&p, pol);
dddvb_set_delsys(&p, delsys);
dddvb_set_id(&p, id);
dddvb_set_ssi(&p, ssi);
2018-09-17 13:45:26 +02:00
dddvb_dvb_tune(fe, &p);
#if 0
2019-07-24 12:56:23 +02:00
{
uint8_t ts[188];
dddvb_ca_write(dd, 0, ts, 188);
}
#endif
if (!odvr){
while (1) {
fe_status_t stat;
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));
2018-09-17 13:45:26 +02:00
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);
fprintf(stderr,"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);
}
2018-09-17 13:45:26 +02:00
}
}