dvb_signal.c

C/C++

No description

ManiacTwister

Download Edit

/*
* dvb_signal.c
*
* Copyright (C) 2014 ManiacTwister
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <linux/dvb/dmx.h>
#include <linux/dvb/frontend.h>
int main(int argc, char** argv) {
char adapter[1024];
int frontend_fd = -1;
struct dvb_frontend_info Info;
uint16_t Signal;
uint16_t Snr;
if(argc < 2) {
printf("Arguments: <int adapter nr>\n");
return -1;
}
sprintf(adapter, "/dev/dvb/adapter%s/frontend0", argv[1]);
if ((frontend_fd = open (adapter, O_RDWR | O_NONBLOCK)) < 0) {
printf("Failed to open %s\n", adapter);
}
if(ioctl(frontend_fd, FE_GET_INFO, &Info) < 0) {
printf("ioctl FE_GET_INFO failed\n");
return -1;
}
if (ioctl(frontend_fd, FE_READ_SIGNAL_STRENGTH, &Signal) != 0) {
printf("ioctl FE_READ_SIGNAL_STRENGTH failed\n");
}
if (ioctl(frontend_fd, FE_READ_SNR, &Snr) != 0) {
printf("ioctl FE_READ_SNR failed\n");
}
printf("%s:\nSignal: %d SNR: %d\n", Info.name, ((Signal * 100 + 0x8001) >> 16), ((Snr * 100 + 0x8001) >> 16));
close(frontend_fd);
}