1 /* scan.c - v4l radio band scanner using signal strength
3 Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <asm/types.h>
27 #include <sys/ioctl.h>
28 #include <linux/videodev.h>
30 void help (char *prog
)
32 printf ("usage: %s [-h] [-s <freq>] [-e <freq>] [-i <freq>]\n\n", prog
);
34 printf ("-h - display this help\n");
35 printf ("-s <freq> - set start of scanning range to <freq>\n");
36 printf ("-e <freq> - set end of scanning range to <freq>\n");
37 printf ("-i <freq> - set increment value between channels to <freq>\n");
38 printf ("<freq> - a value in the format nnn.nn (MHz)\n");
43 int main(int argc
, char **argv
)
45 int fd
, ret
, i
, tries
= 25;
46 struct video_tuner vt
;
47 float perc
, begval
, incval
, endval
;
48 long lowf
, highf
, freq
, totsig
, incr
, fact
;
51 progname
= argv
[0]; /* getopt munges argv[] later */
53 fd
= open ("/dev/radio0", O_RDONLY
);
55 perror ("Unable to open /dev/radio0");
60 begval
= 87.9; /* start at 87.9 MHz */
61 incval
= 0.20; /* increment 0.2 MHz */
62 endval
= 107.9; /* stop at 107.9 MHz */
64 while ((i
= getopt(argc
, argv
, "+e:hi:s:")) != EOF
) {
67 endval
= atof (optarg
);
70 incval
= atof (optarg
);
73 begval
= atof (optarg
);
83 ret
= ioctl(fd
, VIDIOCGTUNER
, &vt
); /* get initial info */
85 if ((vt
.flags
& VIDEO_TUNER_LOW
) == 0)
90 /* cope with bizarre things from atof() like 95.099998 */
91 lowf
= fact
* (ceil(rint(begval
* 10)) / 10);
92 highf
= fact
* (ceil(rint(endval
* 10)) / 10);
96 printf ("Scanning range: %2.1f - %2.1f MHz (%2.1f MHz increments)...\n",
97 begval
, endval
, incval
);
99 for (freq
= lowf
; freq
<= highf
; freq
+= incr
) {
100 ioctl (fd
, VIDIOCSFREQ
, &freq
); /* tune */
102 printf ("%2.1f: checking\r", (freq
/ (double) fact
));
105 usleep (400000); /* let it lock on */
108 for (i
= 0; i
< tries
; i
++) {
110 ret
= ioctl(fd
, VIDIOCGTUNER
, &vt
); /* get info */
116 /* clean up the display */
119 perc
= (totsig
/ (65535.0 * tries
));
122 printf ("%2.1f: %3.1f%% \n",
123 (freq
/ (double) fact
), perc
* 100.0);