Deleted Added
full compact
setchannel.c (165025) setchannel.c (165026)
1/*
2 * Copyright (c) 2003, 2004, 2005
3 * John Wehle <john@feith.com>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*
2 * Copyright (c) 2003, 2004, 2005
3 * John Wehle <john@feith.com>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.bin/setchannel/setchannel.c 165025 2006-12-09 02:33:26Z grog $
26 * $FreeBSD: head/usr.bin/setchannel/setchannel.c 165026 2006-12-09 02:44:09Z grog $
27 */
28
27 */
28
29/*
30 * Set the channel of the tuner card.
31 */
29/* Set the channel of the tuner card. */
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <ctype.h>
36#include <fcntl.h>
37#include <string.h>
38#include <sys/types.h>
39#include <sys/param.h>

--- 7 unchanged lines hidden (view full) ---

47# include <dev/bktr/ioctl_meteor.h>
48# include <dev/bktr/ioctl_bt848.h>
49#endif
50
51
52static void
53usage()
54{
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <ctype.h>
34#include <fcntl.h>
35#include <string.h>
36#include <sys/types.h>
37#include <sys/param.h>

--- 7 unchanged lines hidden (view full) ---

45# include <dev/bktr/ioctl_meteor.h>
46# include <dev/bktr/ioctl_bt848.h>
47#endif
48
49
50static void
51usage()
52{
55 printf("Usage: setchannel [-a {on|off}] [-c | -r | -s | -t] [-g geom] [-m chnl_set] [chnl | freq]\n"
56 " -a Enable / disable AFC.\n"
57 " -c Select composite input.\n"
58 " -r Select radio input.\n"
59 " -s Select svideo input.\n"
60 " -t Select tuner.\n"
61 " -g Select geometry.\n"
62 " 352x240 or 352x288 = VCD\n"
63 " 480x480 or 480x576 = SVCD\n"
64 " 352x480 or 352x576 = DVD (half D1)\n"
65 " 720x480 or 720x576 = DVD (full D1)\n"
66 " -m Select channel set / system.\n"
67 " 0 = Tuner Default\n"
68 " %u = US Broadcast / NTSC\n"
69 " %u = US Cable / NTSC\n"
70 " %u = Western Europe / PAL\n"
71 " %u = Japan Broadcast / NTSC\n"
72 " %u = Japan Cable / NTSC\n"
73 " %u = Australia / PAL\n"
74 " %u = France / SECAM\n"
75 " chnl Channel\n"
76 " freq Frequency in MHz (must include decimal point).\n",
77 CHNLSET_NABCST, CHNLSET_CABLEIRC,
78 CHNLSET_WEUROPE, CHNLSET_JPNBCST, CHNLSET_JPNCABLE,
79 CHNLSET_AUSTRALIA, CHNLSET_FRANCE);
53 printf
54 ("Usage: setchannel [-a {on|off}] [-c | -r | -s | -t] "
55 "[-g geom] [-m chnl_set] [chnl | freq]\n"
56 " -a Enable / disable AFC.\n"
57 " -c Select composite input.\n" " -r Select radio input.\n"
58 " -s Select svideo input.\n" " -t Select tuner.\n"
59 " -g Select geometry.\n" " 352x240 or 352x288 = VCD\n"
60 " 480x480 or 480x576 = SVCD\n"
61 " 352x480 or 352x576 = DVD (half D1)\n"
62 " 720x480 or 720x576 = DVD (full D1)\n"
63 " -m Select channel set / system.\n"
64 " 0 = Tuner Default\n"
65 " %u = US Broadcast / NTSC\n"
66 " %u = US Cable / NTSC\n"
67 " %u = Western Europe / PAL\n"
68 " %u = Japan Broadcast / NTSC\n"
69 " %u = Japan Cable / NTSC\n"
70 " %u = Australia / PAL\n"
71 " %u = France / SECAM\n" " chnl Channel\n"
72 " freq Frequency in MHz (must include decimal point).\n",
73 CHNLSET_NABCST, CHNLSET_CABLEIRC, CHNLSET_WEUROPE, CHNLSET_JPNBCST,
74 CHNLSET_JPNCABLE, CHNLSET_AUSTRALIA, CHNLSET_FRANCE);
80}
81
75}
76
82int main( int argc, char *argv[] )
77int
78main(int argc, char *argv[])
83{
79{
84 char *ptr;
85 char *endptr;
86 int afc;
87 int audio;
88 int c;
89 int channel_set;
90 int i;
91 int status;
92 int tfd;
93 unsigned int channel;
94 unsigned int fraction;
95 unsigned int freq;
96 unsigned int x_size;
97 unsigned int y_size;
98 unsigned long device;
99 struct bktr_capture_area cap;
80 char *ptr;
81 char *endptr;
82 int afc;
83 int audio;
84 int c;
85 int channel_set;
86 int i;
87 int status;
88 int tfd;
89 unsigned int channel;
90 unsigned int fraction;
91 unsigned int freq;
92 unsigned int x_size;
93 unsigned int y_size;
94 unsigned long device;
95 struct bktr_capture_area cap;
100
96
101 afc = -1;
102 audio = -1;
103 channel = 0;
104 channel_set = -1;
105 device = 0;
106 freq = 0;
107 status = 0;
108 x_size = 0;
109 y_size = 0;
97 afc = -1;
98 audio = -1;
99 channel = 0;
100 channel_set = -1;
101 device = 0;
102 freq = 0;
103 status = 0;
104 x_size = 0;
105 y_size = 0;
110
106
111 while ((c = getopt (argc, argv, "a:crstg:m:")) != -1)
112 switch (c) {
113 case 'a':
114 if (strcasecmp (optarg, "on") == 0)
115 afc = 1;
116 else if (strcasecmp (optarg, "off") == 0)
117 afc = 0;
118 else {
119 usage ();
120 exit (1);
121 }
122 break;
107 while ((c = getopt(argc, argv, "a:crstg:m:")) != -1)
108 switch (c) {
109 case 'a':
110 if (strcasecmp(optarg, "on") == 0)
111 afc = 1;
112 else if (strcasecmp(optarg, "off") == 0)
113 afc = 0;
114 else {
115 usage();
116 exit(1);
117 }
118 break;
123
119
124 case 'c':
125 device = METEOR_INPUT_DEV2;
126 audio = -1;
127 break;
120 case 'c':
121 device = METEOR_INPUT_DEV2;
122 audio = -1;
123 break;
128
124
129 case 'r':
130 device = 0;
131 audio = AUDIO_INTERN;
132 break;
125 case 'r':
126 device = 0;
127 audio = AUDIO_INTERN;
128 break;
133
129
134 case 's':
135 device = METEOR_INPUT_DEV_SVIDEO;
136 audio = -1;
137 break;
130 case 's':
131 device = METEOR_INPUT_DEV_SVIDEO;
132 audio = -1;
133 break;
138
134
139 case 't':
140 device = METEOR_INPUT_DEV1;
141 audio = -1;
142 break;
135 case 't':
136 device = METEOR_INPUT_DEV1;
137 audio = -1;
138 break;
143
139
144 case 'g':
145 if (sscanf (optarg, "%ux%u", &x_size, &y_size) != 2
146 || x_size == 0 || y_size == 0) {
147 usage ();
148 exit (1);
149 }
150 break;
140 case 'g':
141 if (sscanf(optarg, "%ux%u", &x_size, &y_size) != 2
142 || x_size == 0 || y_size == 0) {
143 usage();
144 exit(1);
145 }
146 break;
151
147
152 case 'm':
153 channel_set = atoi (optarg);
154 if (channel_set < 0 || channel_set > CHNLSET_MAX) {
155 usage ();
156 exit (1);
157 }
158 break;
148 case 'm':
149 channel_set = atoi(optarg);
150 if (channel_set < 0 || channel_set > CHNLSET_MAX) {
151 usage();
152 exit(1);
153 }
154 break;
159
155
160 default:
161 usage ();
162 exit (1);
163 }
156 default:
157 usage();
158 exit(1);
159 }
164
160
165 if ( optind < argc) {
161 if (optind < argc) {
166
162
167 /*
168 * A number containing a decimal point is the frequency in MHz.
169 */
163 /*
164 * A number containing a decimal point is the frequency in MHz.
165 */
170
166
171 if ((ptr = strchr( argv[optind], '.' )) != NULL) {
172 freq = strtol( argv[optind], &endptr, 10) * 1000;
173 if (ptr != endptr) {
174 usage ();
175 exit (1);
176 }
167 if ((ptr = strchr(argv[optind], '.')) != NULL) {
168 freq = strtol(argv[optind], &endptr, 10) * 1000;
169 if (ptr != endptr) {
170 usage();
171 exit(1);
172 }
177
173
178 ptr++;
174 ptr++;
179
175
180 fraction = strtol( ptr, &endptr, 10);
181 if (! isdigit( *ptr ) || *endptr != '\0') {
182 usage ();
183 exit (1);
184 }
176 fraction = strtol(ptr, &endptr, 10);
177 if (!isdigit(*ptr) || *endptr != '\0') {
178 usage();
179 exit(1);
180 }
185
181
186 for (i = endptr - ptr; i > 3; i--)
187 fraction /= 10;
188 for ( ; i < 3; i++)
189 fraction *= 10;
182 for (i = endptr - ptr; i > 3; i--)
183 fraction /= 10;
184 for (; i < 3; i++)
185 fraction *= 10;
190
186
191 freq += fraction;
192 }
187 freq += fraction;
188 }
193
189
194 /*
195 * An integer is the channel.
196 */
190 /* An integer is the channel. */
191 else
192 channel = atoi(argv[optind]);
193 }
197
194
198 else
199 channel = atoi( argv[optind] );
200 }
195 if (afc == -1 && audio == -1 && !device && x_size == 0 && y_size == 0
196 && channel_set == -1 && !channel && !freq) {
197 usage();
198 exit(1);
199 }
201
200
202 if (afc == -1 && audio == -1 && ! device && x_size == 0 && y_size == 0
203 && channel_set == -1 && ! channel && ! freq) {
204 usage ();
205 exit (1);
206 }
201 tfd = open("/dev/cxm0", O_RDONLY);
202 if (tfd < 0) {
203 perror("open() of /dev/cxm0 failed.");
204 exit(1);
205 }
207
206
208 tfd = open( "/dev/cxm0", O_RDONLY );
209 if ( tfd < 0 ) {
210 perror( "open() of /dev/cxm0 failed." );
211 exit(1);
212 }
207 if (afc != -1)
208 if (ioctl(tfd, TVTUNER_SETAFC, &afc) < 0) {
209 perror("ioctl(tfd, TVTUNER_SETAFC) failed.");
210 status = 1;
211 }
213
212
214 if (afc != -1)
215 if ( ioctl( tfd, TVTUNER_SETAFC, &afc ) < 0 ) {
216 perror( "ioctl( tfd, TVTUNER_SETAFC ) failed." );
217 status = 1;
218 }
213 if (device)
214 if (ioctl(tfd, METEORSINPUT, &device) < 0) {
215 perror("ioctl(tfd, METEORSINPUT) failed.");
216 status = 1;
217 }
219
218
220 if (device)
221 if ( ioctl( tfd, METEORSINPUT, &device ) < 0 ) {
222 perror( "ioctl( tfd, METEORSINPUT ) failed." );
223 status = 1;
224 }
219 if (audio != -1)
220 if (ioctl(tfd, BT848_SAUDIO, &audio) < 0) {
221 perror("ioctl(tfd, BT848_SAUDIO) failed.");
222 status = 1;
223 }
225
224
226 if (audio != -1)
227 if ( ioctl( tfd, BT848_SAUDIO, &audio ) < 0 ) {
228 perror( "ioctl( tfd, BT848_SAUDIO ) failed." );
229 status = 1;
230 }
225 if (ioctl(tfd, BT848_GAUDIO, &audio) < 0) {
226 perror("ioctl(tfd, BT848_GAUDIO) failed.");
227 status = 1;
228 }
231
229
232 if ( ioctl( tfd, BT848_GAUDIO, &audio ) < 0 ) {
233 perror( "ioctl( tfd, BT848_GAUDIO ) failed." );
234 status = 1;
235 }
230 if (x_size && y_size) {
231 memset(&cap, 0, sizeof(cap));
232 cap.x_size = x_size;
233 cap.y_size = y_size;
234 if (ioctl(tfd, BT848_SCAPAREA, &cap) < 0) {
235 perror("ioctl(tfd, BT848_SCAPAREA) failed.");
236 status = 1;
237 }
238 }
236
239
237 if (x_size && y_size ) {
238 memset (&cap, 0, sizeof (cap));
239 cap.x_size = x_size;
240 cap.y_size = y_size;
241 if ( ioctl( tfd, BT848_SCAPAREA, &cap ) < 0 ) {
242 perror( "ioctl( tfd, BT848_SCAPAREA ) failed." );
243 status = 1;
244 }
245 }
240 if (channel_set != -1)
241 if (ioctl(tfd, TVTUNER_SETTYPE, &channel_set) < 0) {
242 perror("ioctl(tfd, TVTUNER_SETTYPE) failed.");
243 status = 1;
244 }
246
245
247 if (channel_set != -1)
248 if ( ioctl( tfd, TVTUNER_SETTYPE, &channel_set ) < 0 ) {
249 perror( "ioctl( tfd, TVTUNER_SETTYPE ) failed." );
250 status = 1;
251 }
246 if (channel) {
247 if (ioctl(tfd, TVTUNER_SETCHNL, &channel) < 0) {
248 perror("ioctl(tfd, TVTUNER_SETCHNL) failed.");
249 status = 1;
250 }
251 } else if (freq) {
252 if (audio == AUDIO_INTERN) {
253 /* Convert from kHz to MHz * 100 */
254 freq = freq / 10;
252
255
253 if (channel) {
254 if ( ioctl( tfd, TVTUNER_SETCHNL, &channel ) < 0 ) {
255 perror( "ioctl( tfd, TVTUNER_SETCHNL ) failed." );
256 status = 1;
257 }
258 }
259 else if (freq) {
260 if (audio == AUDIO_INTERN) {
261 /* Convert from kHz to MHz * 100 */
262 freq = freq / 10;
256 if (ioctl(tfd, RADIO_SETFREQ, &freq) < 0) {
257 perror("ioctl(tfd, RADIO_SETFREQ) failed.");
258 status = 1;
259 }
260 } else {
261 /* Convert from kHz to MHz * 16 */
262 freq = (freq * 16) / 1000;
263
263
264 if ( ioctl( tfd, RADIO_SETFREQ, &freq ) < 0 ) {
265 perror( "ioctl( tfd, RADIO_SETFREQ ) failed." );
266 status = 1;
267 }
268 }
269 else {
270 /* Convert from kHz to MHz * 16 */
271 freq = (freq * 16) / 1000;
264 if (ioctl(tfd, TVTUNER_SETFREQ, &freq) < 0) {
265 perror("ioctl(tfd, TVTUNER_SETFREQ) failed.");
266 status = 1;
267 }
268 }
269 }
272
270
273 if ( ioctl( tfd, TVTUNER_SETFREQ, &freq ) < 0 ) {
274 perror( "ioctl( tfd, TVTUNER_SETFREQ ) failed." );
275 status = 1;
276 }
277 }
278 }
279
280 close ( tfd );
281 exit ( status );
271 close(tfd);
272 exit(status);
282}
273}