From de33eb47967fab56d2d3cf2f2729dff458b6971c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9lanie=20Benoit?= Date: Thu, 19 Apr 2018 11:04:14 +0200 Subject: [PATCH] Keep DVB_MOD_* API form Gen1 DVB-C modulators and use SET_PROPERTY for Gen3 DVB-C modulators --- apps/setmod.c | 76 +++------------- apps/setmod2.c | 159 +++++++++++++++++++++++++++++----- ddbridge/ddbridge-modulator.c | 1 + include/linux/dvb/mod.h | 1 + 4 files changed, 150 insertions(+), 87 deletions(-) diff --git a/apps/setmod.c b/apps/setmod.c index 318cd97..cb33f23 100644 --- a/apps/setmod.c +++ b/apps/setmod.c @@ -15,51 +15,9 @@ void usage(char* argv[]) { - printf("Usage: %s [-d device] [-f base_frequency[Hz]]" + printf("Usage: %s [-d device] [-f base_frequency[Hz]] [-a attenuation[dB]]" " [-m modulation[qam_16, qam32, qam_64, qam_128, qam256]] [-p pcr_correction[1/0]]" - " [-b bitrate[bps]] [-g gain[dB]]\n", argv[0]); -} - -static int set_mod_property (int fd, uint32_t cmd, uint32_t data) -{ - struct dtv_property p; - struct dtv_properties c; - int ret; - - if( fd < 0 ) return -1; - p.cmd = cmd; - c.num = 1; - c.props = &p; - p.u.data = data; - ret = ioctl(fd, FE_SET_PROPERTY, &c); - - if(cmd == MODULATOR_GAIN && ret == -EINVAL) //Expected for modc Gen 1 cards - return 0; - if (ret < 0) - { - fprintf(stderr, "FE_SET_PROPERTY %d returned %d\n", cmd, errno); - } -} - -int modulator_set_output_power (int fd, int power) -{ - unsigned int atten = 0; - unsigned int gain = 0; - if ( power > POWER_REF ) - gain = (power - POWER_REF) * 8; - else - atten = POWER_REF - power; - - if (gain > RF_VGA_GAIN_MAX) - gain = RF_VGA_GAIN_MAX; - if (atten > 31) - atten = 31; - - set_mod_property(fd, MODULATOR_ATTENUATOR,atten); - usleep(1000); // driver bug - - set_mod_property(fd, MODULATOR_GAIN,gain); - return 0; + " [-b bitrate[bps]]\n", argv[0]); } @@ -70,17 +28,13 @@ int main(int argc, char* argv[]) struct dvb_mod_channel_params mc; char *device = NULL; uint32_t base_freq = 0; - uint8_t gain = POWER_REF; + uint32_t attenuation = 0; char *modulation_str = NULL; int pcr_correction = -1; uint64_t bitrate = 0; int opt; - if (argc != 7) - { - } - - while ((opt = getopt(argc, argv, "d:f:m:p:b:g:")) != -1) + while ((opt = getopt(argc, argv, "d:f:m:p:b:a:")) != -1) { switch (opt) { @@ -99,8 +53,8 @@ int main(int argc, char* argv[]) case 'b': bitrate = strtoul(optarg, NULL, 10); break; - case 'g': - gain = strtoul(optarg, NULL, 10); + case 'a': + attenuation = strtoul(optarg, NULL, 10); break; } } @@ -111,17 +65,12 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } - char *device = argv[1]; - uint32_t base_freq = strtoul(argv[2], NULL, 10); - if (base_freq < 114000000 || base_freq > 794000000) + if (base_freq < 114000000 || base_freq > 786000000) { printf("Invalid frequency \'%i\'\n", base_freq); exit(EXIT_FAILURE); } - uint32_t attenuation = strtoul(argv[3], NULL, 10); - enum fe_modulation modulation; - char *modulation_str = argv[4]; if (strcmp(modulation_str, "qam_16") == 0) { modulation = QAM_16; @@ -147,8 +96,6 @@ int main(int argc, char* argv[]) 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) @@ -157,15 +104,14 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } - printf("Setting base_freq=%u modulation=%s, pcr_correction=%d" - "input_bitrate=%u gain=%udB on %s\n", - base_freq, modulation_str, pcr_correction, bitrate, gain, device); + 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); - modulator_set_output_power(fd, gain); - mc.modulation = modulation; mc.input_bitrate = bitrate << 32; mc.pcr_correction = pcr_correction; diff --git a/apps/setmod2.c b/apps/setmod2.c index 5d83ff7..21c93f0 100644 --- a/apps/setmod2.c +++ b/apps/setmod2.c @@ -15,33 +15,148 @@ static int set_property(int fd, uint32_t cmd, uint32_t data) { - struct dtv_property p; - struct dtv_properties c; - int ret; + struct dtv_property p; + struct dtv_properties c; + int ret; - p.cmd = cmd; - c.num = 1; - c.props = &p; - p.u.data = data; - ret = ioctl(fd, FE_SET_PROPERTY, &c); - if (ret < 0) { - fprintf(stderr, "FE_SET_PROPERTY returned %d\n", errno); - return -1; - } - return 0; + p.cmd = cmd; + c.num = 1; + c.props = &p; + p.u.data = data; + ret = ioctl(fd, FE_SET_PROPERTY, &c); + if (ret < 0) { + fprintf(stderr, "FE_SET_PROPERTY returned %d\n", errno); + return -1; + } + return 0; } -int main() +static void set_output_power (int fd, int power) { - int fd; - struct dvb_mod_params mp; - struct dvb_mod_channel_params mc; + unsigned int attenuation = 0; + unsigned int gain = 0; - fd = open("/dev/dvb/adapter0/mod0", O_RDONLY); + if (power > POWER_REF) { + gain = (power - POWER_REF) * 8; + } + else { + attenuation = POWER_REF - power; + } - set_property(fd, MODULATOR_MODULATION, QAM_256); - set_property(fd, MODULATOR_SYMBOL_RATE, 6900000); - set_property(fd, MODULATOR_FREQUENCY, 114000000); - close(fd); + if (gain > RF_VGA_GAIN_MAX) { + gain = RF_VGA_GAIN_MAX; + } + if (attenuation > 31) { + attenuation = 31; + } + + set_property(fd, MODULATOR_ATTENUATOR, attenuation); + usleep(1000); // driver bug + + set_property(fd, MODULATOR_GAIN, gain); } +static void usage(char* argv[]) +{ + printf("Usage: %s [-d device] [-f frequency[Hz]] [-P power[dB]]" + " [-m modulation[qam_16, qam32, qam_64, qam_128, qam256]] [-p pcr_correction[1/0]]" + " [-b bitrate[bps]]\n", argv[0]); +} + +int main(int argc, char* argv[]) +{ + int fd; + + char *device = NULL; + uint32_t freq = 0; + uint8_t power = POWER_REF; + char *modulation_str = NULL; + int pcr_correction = -1; + uint64_t bitrate = 0; + + int opt; + + while ((opt = getopt(argc, argv, "d:f:m:p:b:P:")) != -1) + { + switch (opt) + { + case 'd': + device = optarg; + break; + case 'f': + freq = strtoul(optarg, NULL, 10); + break; + case 'm': + modulation_str = optarg; + break; + case 'p': + pcr_correction = strtoul(optarg, NULL, 10); + break; + case 'b': + bitrate = strtoul(optarg, NULL, 10); + break; + case 'P': + power = strtoul(optarg, NULL, 10); + break; + } + } + + if (device == NULL) + { + usage(argv); + exit(EXIT_FAILURE); + } + + if (freq < 114000000 || freq > 858000000) + { + printf("Invalid frequency \'%i\'\n", freq); + exit(EXIT_FAILURE); + } + + fd = open(device, O_RDONLY); + if (fd == -1) + { + printf("Invalid device \'%s\': %s\n", device, strerror(errno)); + exit(EXIT_FAILURE); + } + + enum fe_modulation modulation; + 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); + } + + printf("Setting freq=%u power=%u modulation=%s, pcr_correction=%d " + "input_bitrate=%u on %s\n", + freq, power, modulation_str, pcr_correction, bitrate, device); + + set_property(fd, MODULATOR_FREQUENCY, freq); + set_property(fd, MODULATOR_MODULATION, modulation); + set_property(fd, MODULATOR_SYMBOL_RATE, 6900000); + set_property(fd, MODULATOR_PCR_MODE, pcr_correction); + set_output_power(fd, power); + set_property(fd, MODULATOR_INPUT_BITRATE, bitrate << 32); + + close(fd); +} diff --git a/ddbridge/ddbridge-modulator.c b/ddbridge/ddbridge-modulator.c index 3b8ac99..5f74ecd 100644 --- a/ddbridge/ddbridge-modulator.c +++ b/ddbridge/ddbridge-modulator.c @@ -1665,6 +1665,7 @@ int ddbridge_mod_do_ioctl(struct file *file, unsigned int cmd, void *parg) i * 8000000); } } + mod_set_attenuator(dev, mp->attenuator); break; } case DVB_MOD_CHANNEL_SET: diff --git a/include/linux/dvb/mod.h b/include/linux/dvb/mod.h index 7193b2a..db15325 100644 --- a/include/linux/dvb/mod.h +++ b/include/linux/dvb/mod.h @@ -6,6 +6,7 @@ struct dvb_mod_params { __u32 base_frequency; + __u32 attenuator; }; struct dvb_mod_channel_params {