From 5a4d24725a001d48877c986f5ebcd06133b9e0d2 Mon Sep 17 00:00:00 2001 From: Pierre Seznec Date: Tue, 19 Dec 2017 16:28:08 +0100 Subject: [PATCH] Use the absolute output power gain (refs #7651) --- apps/setmod.c | 97 ++++++++++++++++++++++++++++++++--- ddbridge/ddbridge-modulator.c | 1 - include/linux/dvb/mod.h | 10 ++-- 3 files changed, 96 insertions(+), 12 deletions(-) diff --git a/apps/setmod.c b/apps/setmod.c index 0adbe20..882a06e 100644 --- a/apps/setmod.c +++ b/apps/setmod.c @@ -13,17 +13,99 @@ #include +void usage(char* argv[]) +{ + printf("Usage: %s [-d device] [-f base_frequency[Hz]]" + " [-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 (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; +} + + int main(int argc, char* argv[]) { int fd; struct dvb_mod_params mp; struct dvb_mod_channel_params mc; + char *device = NULL; + uint32_t base_freq = 0; + uint8_t gain = POWER_REF; + char *modulation_str = NULL; + int pcr_correction = -1; + uint64_t bitrate = 0; + int opt; 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"); + } + + while ((opt = getopt(argc, argv, "d:f:m:p:b:g:")) != -1) + { + switch (opt) + { + case 'd': + device = optarg; + break; + case 'f': + base_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 'g': + gain = strtoul(optarg, NULL, 10); + break; + } + } + + if (device == NULL) + { + usage(argv); exit(EXIT_FAILURE); } @@ -73,14 +155,15 @@ int main(int argc, char* argv[]) 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); + 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); 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/ddbridge/ddbridge-modulator.c b/ddbridge/ddbridge-modulator.c index 5f74ecd..3b8ac99 100644 --- a/ddbridge/ddbridge-modulator.c +++ b/ddbridge/ddbridge-modulator.c @@ -1665,7 +1665,6 @@ 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 0c5633e..7193b2a 100644 --- a/include/linux/dvb/mod.h +++ b/include/linux/dvb/mod.h @@ -6,13 +6,12 @@ struct dvb_mod_params { __u32 base_frequency; - __u32 attenuator; }; struct dvb_mod_channel_params { enum fe_modulation modulation; __u64 input_bitrate; /* 2^-32 Hz */ - int pcr_correction; + int pcr_correction; }; @@ -23,10 +22,10 @@ struct dvb_mod_channel_params { #define MODULATOR_START 1 #define MODULATOR_STOP 2 #define MODULATOR_FREQUENCY 3 -#define MODULATOR_MODULATION 4 +#define MODULATOR_MODULATION 4 #define MODULATOR_SYMBOL_RATE 5 /* Hz */ #define MODULATOR_BASE_FREQUENCY 6 -#define MODULATOR_ATTENUATOR 32 +#define MODULATOR_ATTENUATOR 32 #define MODULATOR_INPUT_BITRATE 33 /* Hz */ #define MODULATOR_PCR_MODE 34 /* 1=pcr correction enabled */ #define MODULATOR_GAIN 35 @@ -34,4 +33,7 @@ struct dvb_mod_channel_params { #define MODULATOR_STATUS 37 #define MODULATOR_OUTPUT_ARI 64 +#define POWER_REF (79) +#define RF_VGA_GAIN_MAX (200) + #endif /*_UAPI_DVBMOD_H_*/