From 0d9752284ebfb72b4766a51a1806c294df7120dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20B=C3=A9richon?= Date: Thu, 24 May 2018 15:39:55 +0200 Subject: [PATCH] Make setmod tool configurable --- apps/setmod.c | 88 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/apps/setmod.c b/apps/setmod.c index 41e11d5..0adbe20 100644 --- a/apps/setmod.c +++ b/apps/setmod.c @@ -9,25 +9,85 @@ #include #include #include +#include #include -int main() +int main(int argc, char* argv[]) { - int fd; - struct dvb_mod_params mp; - struct dvb_mod_channel_params mc; + int fd; + struct dvb_mod_params mp; + struct dvb_mod_channel_params mc; - fd = open("/dev/dvb/adapter1/mod0", O_RDONLY); + if (argc != 7) + { + printf("Usage: device base_frequency[Hz] attenuation[dB]" + " modulation[qam_16, qam32, qam_64, qam_128, qam256] pcr_correction[1/0]" + " bitrate[bps]\n"); + exit(EXIT_FAILURE); + } - mp.base_frequency = 722000000; - mp.attenuator = 0; - ioctl(fd, DVB_MOD_SET, &mp); + char *device = argv[1]; + uint32_t base_freq = strtoul(argv[2], NULL, 10); + if (base_freq < 114000000 || base_freq > 794000000) + { + printf("Invalid frequency \'%i\'\n", base_freq); + exit(EXIT_FAILURE); + } + uint32_t attenuation = strtoul(argv[3], NULL, 10); - mc.modulation = QAM_256; - mc.input_bitrate = 40000000ULL << 32; - mc.pcr_correction = 0; - ioctl(fd, DVB_MOD_CHANNEL_SET, &mc); - close(fd); + enum fe_modulation modulation; + char *modulation_str = argv[4]; + if (strcmp(modulation_str, "qam_16") == 0) + { + modulation = QAM_16; + } + else if (strcmp(modulation_str, "qam_32") == 0) + { + modulation = QAM_32; + } + else if (strcmp(modulation_str, "qam_64") == 0) + { + modulation = QAM_64; + } + else if (strcmp(modulation_str, "qam_128") == 0) + { + modulation = QAM_128; + } + else if (strcmp(modulation_str, "qam_256") == 0) + { + modulation = QAM_256; + } + else + { + printf("Invalid modulation \'%s\'\n", modulation_str); + exit(EXIT_FAILURE); + } + int pcr_correction = strtoul(argv[5], NULL, 10); + uint64_t bitrate = strtoul(argv[6], NULL, 10); + + fd = open(device, O_RDONLY); + if (fd == -1) + { + printf("Invalid device \'%s\': %s\n", device, strerror(errno)); + exit(EXIT_FAILURE); + } + + printf("Setting base_freq=%u attenuation=%u modulation=%s, pcr_correction=%d" + "input_bitrate=%u on %s\n", + base_freq, attenuation, modulation_str, pcr_correction, bitrate, device); + + mp.base_frequency = base_freq; + mp.attenuator = attenuation; + ioctl(fd, DVB_MOD_SET, &mp); + + mc.modulation = modulation; + mc.input_bitrate = bitrate << 32; + mc.pcr_correction = pcr_correction; + if (ioctl(fd, DVB_MOD_CHANNEL_SET, &mc) != 0) + { + printf("Invalid options: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + close(fd); } -