From 1b55871e6572d8836de21ae4526e8752cebe14b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Vasseur?= Date: Wed, 9 Oct 2024 13:27:53 +0200 Subject: [PATCH] Get signal stats in decibel using newer DVB API --- dvb.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/dvb.c b/dvb.c index 106a942..6186315 100644 --- a/dvb.c +++ b/dvb.c @@ -290,16 +290,37 @@ static void PrintCb( struct ev_loop *loop, struct ev_timer *w, int revents ) ioctl(i_frontend, FE_READ_SNR, &i_snr); ioctl(i_frontend, FE_READ_UNCORRECTED_BLOCKS, &i_uncorrected); + int64_t i_strength_dbm = i_strength; + int64_t i_snr_db = i_snr; + +#ifdef DTV_STAT_SIGNAL_STRENGTH + struct dtv_property prop[] = { + { .cmd = DTV_STAT_SIGNAL_STRENGTH }, + { .cmd = DTV_STAT_CNR }, + }; + + struct dtv_properties props = { .num = 2, .props = prop }; + if (ioctl(i_frontend, FE_GET_PROPERTY, &props) != -1) + { + if (prop[0].u.st.len > 0 && + prop[0].u.st.stat[0].scale == FE_SCALE_DECIBEL) + i_strength_dbm = prop[0].u.st.stat[0].svalue; + if (prop[1].u.st.len > 0 && + prop[1].u.st.stat[0].scale == FE_SCALE_DECIBEL) + i_snr_db = prop[1].u.st.stat[0].svalue; + } +#endif + switch (i_print_type) { case PRINT_XML: fprintf(print_fh, - "\n", - i_ber, i_strength, i_snr, i_uncorrected); + "\n", + i_ber, i_strength_dbm, i_snr_db, i_uncorrected); break; case PRINT_TEXT: - fprintf(print_fh, "frontend ber: %"PRIu32" strength: %"PRIu16" snr: %"PRIu16" uncorrected: %"PRIu32"\n", - i_ber, i_strength, i_snr, i_uncorrected); + fprintf(print_fh, "frontend ber: %"PRIu32" strength: %"PRId64" snr: %"PRId64" uncorrected: %"PRIu32"\n", + i_ber, i_strength_dbm, i_snr_db, i_uncorrected); break; default: break; -- 2.11.4.GIT