From d293b9a7021dc6e9a600ca492d62935354cb1374 Mon Sep 17 00:00:00 2001 From: Ralph Metzler Date: Mon, 5 Aug 2019 16:02:34 +0200 Subject: [PATCH] add options to setmod app for type 3 mods --- apps/setmod3.c | 94 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/apps/setmod3.c b/apps/setmod3.c index 302cb09..83c10f8 100644 --- a/apps/setmod3.c +++ b/apps/setmod3.c @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -51,33 +52,96 @@ static int get_property(int fd, uint32_t cmd, uint32_t *data) -int main() +int main(int argc, char*argv[]) { int fd; struct dvb_mod_params mp; struct dvb_mod_channel_params mc; uint32_t data; + int adapter = 0, channel = 0, gain = -1; + int32_t base = -1, freq = -1, rate = -1; + char mod_name[128]; - fd = open("/dev/dvb/adapter0/mod0", O_RDONLY); + while (1) { + int cur_optind = optind ? optind : 1; + int option_index = 0; + int c; + static struct option long_options[] = { + {"adapter", required_argument, 0, 'a'}, + {"channel", required_argument, 0, 'c'}, + {"gain", required_argument, 0, 'g'}, + {"base", required_argument, 0, 'b'}, + {"frequency", required_argument, 0, 'f'}, + {"rate", required_argument, 0, 'r'}, + {0, 0, 0, 0} + }; + c = getopt_long(argc, argv, + "a:c:g:b:f:r:", + long_options, &option_index); + if (c==-1) + break; + switch (c) { + case 'a': + adapter = strtoul(optarg, NULL, 0); + break; + case 'c': + channel = strtoul(optarg, NULL, 0); + break; + case 'g': + gain = strtoul(optarg, NULL, 0); + break; + case 'b': + base = strtoul(optarg, NULL, 0); + break; + case 'f': + freq = strtoul(optarg, NULL, 0); + break; + case 'r': + if (!strcmp(optarg, "DVBT_8")) + rate = SYS_DVBT_8; + else if (!strcmp(optarg, "DVBT_7")) + rate = SYS_DVBT_7; + else if (!strcmp(optarg, "DVBT_6")) + rate = SYS_DVBT_6; + else if (!strcmp(optarg, "ISDBT_6")) + rate = SYS_ISDBT_6; + else rate = strtoul(optarg, NULL, 0); + break; + default: + break; + } + } + if (optind < argc) { + printf("too man arguments\n"); + exit(1); + } + + snprintf(mod_name, 127, "/dev/dvb/adapter%d/mod%d", adapter, channel); + fd = open(mod_name, O_RDONLY); + + if (fd < 0) { + printf("Could not open modulator device.\n"); + exit(1); + } + + /* gain 0-255 */ - get_property(fd, MODULATOR_GAIN, &data); - printf("Modulator gain = %u\n", data); - set_property(fd, MODULATOR_GAIN, 100); + //get_property(fd, MODULATOR_GAIN, &data); + //printf("Modulator gain = %u\n", data); + //set_property(fd, MODULATOR_GAIN, 100); - get_property(fd, MODULATOR_GAIN, &data); - printf("Modulator gain = %u\n", data); + //get_property(fd, MODULATOR_ATTENUATOR, &data); + //printf("Modulator attenuator = %u\n", data); - get_property(fd, MODULATOR_ATTENUATOR, &data); - printf("Modulator attenuator = %u\n", data); - - - get_property(fd, MODULATOR_STATUS, &data); - printf("Modulator status = %u\n", data); - set_property(fd, MODULATOR_STATUS, 2); + if (base > 0) + set_property(fd, MODULATOR_BASE_FREQUENCY, base); + if (freq > 0) + set_property(fd, MODULATOR_FREQUENCY, base); + if (rate > 0) + set_property(fd, MODULATOR_OUTPUT_RATE, rate); - //set_property(fd, MODULATOR_RESET, 0); close(fd); }