1 /* fmscan.c - v4l radio band scanner using signal strength
3 Copyright (C) 2004, 2006, 2009 Ben Pfaff <blp@cs.stanford.edu>
4 Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/ioctl.h>
31 #define TRIES 25 /* get 25 samples */
32 #define LOCKTIME 400000 /* wait 400ms for card to lock on */
33 #define SAMPLEDELAY 15000 /* wait 15ms between samples */
38 printf("fmtools fmscan version %s\n\n", VERSION
);
39 printf("usage: %s [-h] [-d <dev>] [-T <tuner>] [-s <freq>] [-e <freq>] [-i <freq>] [-t <%%>]\n\n", program_name
);
41 printf("Auxiliary program to scan a frequency band for radio stations.\n\n");
43 printf(" -h - display this help\n");
44 printf(" -d <dev> - select device (default: /dev/radio0)\n");
45 printf(" -T <tuner> - select tuner (default: 0)\n");
46 printf(" -s <freq> - set start of scanning range to <freq>\n");
47 printf(" -e <freq> - set end of scanning range to <freq>\n");
48 printf(" -i <freq> - set increment value between channels to <freq>\n");
49 printf(" -t <%%> - set signal strength percentage to lock onto <%%>\n");
50 printf(" <freq> - a value in the format nnn.nn (MHz)\n");
55 int main(int argc
, char **argv
)
59 double perc
, begval
, incval
, endval
, threshold
, mhz
;
60 const char *device
= NULL
;
61 bool override
= false;
66 program_name
= argv
[0];
69 begval
= 87.9; /* start at 87.9 MHz */
70 incval
= 0.20; /* increment 0.2 MHz */
71 endval
= 107.9; /* stop at 107.9 MHz */
72 threshold
= 0.5; /* 50% signal strength */
75 int option
= getopt(argc
, argv
, "+e:hi:s:od:T:t:q");
87 endval
= atof(optarg
);
90 incval
= atof(optarg
);
93 begval
= atof(optarg
);
99 threshold
= atof(optarg
)/100.;
111 tuner_open(&tuner
, device
, index
);
114 double min
= tuner_get_min_freq(&tuner
) / 16000.0;
115 double max
= tuner_get_max_freq(&tuner
) / 16000.0;
118 printf("Setting start to tuner minimum %.1f MHz\n",
123 printf("Setting end to tuner maximum %.1f MHz\n",
128 printf("Scanning range: %2.1f - %2.1f MHz (%2.1f MHz increments)...\n",
129 begval
, endval
, incval
);
131 for (i
= 0; (mhz
= begval
+ i
* incval
) <= endval
; i
++) {
136 freq
= mhz
* 16000 + 0.5;
138 if (freq
< tuner_get_min_freq(&tuner
))
139 freq
= tuner_get_min_freq(&tuner
);
140 else if (freq
> tuner_get_max_freq(&tuner
))
141 freq
= tuner_get_max_freq(&tuner
);
143 tuner_set_freq(&tuner
, freq
, override
);
146 printf("%2.1f:\r", mhz
);
149 tuner_usleep(&tuner
, LOCKTIME
);
152 for (i
= 0; i
< tries
; i
++) {
153 totsig
+= tuner_get_signal(&tuner
);
154 perc
= totsig
/ (65535.0 * i
);
156 printf("%2.1f: checking: %3.1f%% (%d/%d)"
158 mhz
, perc
* 100.0, i
+ 1, tries
);
161 tuner_usleep(&tuner
, SAMPLEDELAY
);
164 /* clean up the display */
168 perc
= totsig
/ (65535.0 * tries
);
170 if (perc
> threshold
)
171 printf("%2.1f: %3.1f%%\n",