version 1.11, 2005/07/28 17:15:11 |
version 1.12, 2005/12/05 16:30:24 |
|
|
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
#include <sys/radioio.h> |
#include <sys/radioio.h> |
|
|
|
#include <dev/ic/bt8xx.h> |
|
|
#include <err.h> |
#include <err.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
#define OPTION_MONO 0x05 |
#define OPTION_MONO 0x05 |
"stereo", |
"stereo", |
#define OPTION_STEREO 0x06 |
#define OPTION_STEREO 0x06 |
"sensitivity" |
"sensitivity", |
#define OPTION_SENSITIVITY 0x07 |
#define OPTION_SENSITIVITY 0x07 |
|
"channel", |
|
#define OPTION_CHANNEL 0x08 |
|
"chnlset" |
|
#define OPTION_CHNLSET 0x09 |
}; |
}; |
|
|
#define OPTION_NONE ~0u |
#define OPTION_NONE ~0u |
|
|
u_int32_t value; |
u_int32_t value; |
}; |
}; |
|
|
|
struct chansets { |
|
int value; |
|
char *name; |
|
} chansets[] = { |
|
{ CHNLSET_NABCST, "nabcst", }, |
|
{ CHNLSET_CABLEIRC, "cableirc", }, |
|
{ CHNLSET_CABLEHRC, "cablehrc", }, |
|
{ CHNLSET_WEUROPE, "weurope", }, |
|
{ CHNLSET_JPNBCST, "jpnbcst", }, |
|
{ CHNLSET_JPNCABLE, "jpncable", }, |
|
{ CHNLSET_XUSSR, "xussr", }, |
|
{ CHNLSET_AUSTRALIA, "australia", }, |
|
{ CHNLSET_FRANCE, "france", }, |
|
{ 0, NULL } |
|
}; |
|
|
extern char *__progname; |
extern char *__progname; |
const char *onchar = "on"; |
const char *onchar = "on"; |
#define ONCHAR_LEN 2 |
#define ONCHAR_LEN 2 |
|
|
#define OFFCHAR_LEN 3 |
#define OFFCHAR_LEN 3 |
|
|
struct radio_info ri; |
struct radio_info ri; |
|
unsigned int i = 0; |
|
|
int parse_opt(char *, struct opt_t *); |
int parse_opt(char *, struct opt_t *); |
|
|
void print_vars(int); |
void print_vars(int, int); |
void do_ioctls(int, struct opt_t *, int); |
void do_ioctls(int, struct opt_t *, int); |
|
|
void print_value(int); |
void print_value(int, int); |
void change_value(const struct opt_t); |
void change_value(const struct opt_t); |
void update_value(int, int *, int); |
void update_value(int, int *, int); |
|
|
|
|
int rd = -1; |
int rd = -1; |
int optchar; |
int optchar; |
int show_vars = 0; |
int show_vars = 0; |
|
int show_choices = 0; |
int silent = 0; |
int silent = 0; |
int mode = O_RDONLY; |
int mode = O_RDONLY; |
|
|
|
|
if (radiodev == NULL) |
if (radiodev == NULL) |
radiodev = RADIODEVICE; |
radiodev = RADIODEVICE; |
|
|
while ((optchar = getopt(argc, argv, "af:nw")) != -1) { |
while ((optchar = getopt(argc, argv, "af:nvw")) != -1) { |
switch (optchar) { |
switch (optchar) { |
case 'a': |
case 'a': |
show_vars = 1; |
show_vars = 1; |
|
|
case 'n': |
case 'n': |
silent = 1; |
silent = 1; |
break; |
break; |
|
case 'v': |
|
show_choices = 1; |
|
break; |
case 'w': |
case 'w': |
/* backwards compatibility */ |
/* backwards compatibility */ |
break; |
break; |
|
|
err(1, "RIOCGINFO"); |
err(1, "RIOCGINFO"); |
|
|
if (!argc && show_vars) |
if (!argc && show_vars) |
print_vars(silent); |
print_vars(silent, show_choices); |
else if (argc > 0 && !show_vars) { |
else if (argc > 0 && !show_vars) { |
if (mode == O_RDWR) { |
if (mode == O_RDWR) { |
for(; argc--; argv++) |
for(; argc--; argv++) |
|
|
if (parse_opt(*argv, &opt)) { |
if (parse_opt(*argv, &opt)) { |
show_verbose(varname[opt.option], |
show_verbose(varname[opt.option], |
silent); |
silent); |
print_value(opt.option); |
print_value(opt.option, show_choices); |
free(opt.string); |
free(opt.string); |
putchar('\n'); |
putchar('\n'); |
} |
} |
|
|
usage(void) |
usage(void) |
{ |
{ |
fprintf(stderr, |
fprintf(stderr, |
"usage: %s [-f file] [-n] variable ...\n" |
"usage: %s [-f file] [-nv] variable ...\n" |
" %s [-f file] [-n] variable=value ...\n" |
" %s [-f file] [-n] variable=value ...\n" |
" %s [-f file] [-n] -a\n", |
" %s [-f file] [-nv] -a\n", |
__progname, __progname, __progname); |
__progname, __progname, __progname); |
exit(1); |
exit(1); |
} |
} |
|
|
if (!silent) |
if (!silent) |
printf("%s: ", varname[oval]); |
printf("%s: ", varname[oval]); |
|
|
print_value(o->option); |
print_value(o->option, 0); |
printf(" -> "); |
printf(" -> "); |
|
|
if (o->option == OPTION_SEARCH) { |
if (o->option == OPTION_SEARCH) { |
|
|
return; |
return; |
} |
} |
|
|
print_value(o->option); |
print_value(o->option, 0); |
putchar('\n'); |
putchar('\n'); |
} |
} |
|
|
|
|
case OPTION_MUTE: |
case OPTION_MUTE: |
ri.mute = o.value; |
ri.mute = o.value; |
break; |
break; |
|
case OPTION_CHANNEL: |
|
update_value(o.sign, &ri.chan, o.value); |
|
break; |
|
case OPTION_CHNLSET: |
|
ri.chnlset = o.value; |
|
break; |
} |
} |
|
|
if (unsupported) |
if (unsupported) |
|
|
const char *badvalue = "bad value `%s'"; |
const char *badvalue = "bad value `%s'"; |
char *topt = NULL; |
char *topt = NULL; |
int slen, optlen; |
int slen, optlen; |
|
|
if (s == NULL || *s == '\0' || o == NULL) |
if (s == NULL || *s == '\0' || o == NULL) |
return 0; |
return 0; |
|
|
|
|
o->string = topt; |
o->string = topt; |
|
|
topt = &s[optlen]; |
topt = &s[optlen]; |
|
|
|
if (strcmp(o->string, "chnlset") == 0) { |
|
for (i = 0; chansets[i].name; i++) |
|
if (strncmp(chansets[i].name, topt, |
|
strlen(chansets[i].name)) == 0) |
|
break; |
|
if (chansets[i].name != NULL) { |
|
o->value = chansets[i].value; |
|
return 1; |
|
} else { |
|
warnx(badvalue, topt); |
|
return 0; |
|
} |
|
} |
|
|
switch (*topt) { |
switch (*topt) { |
case '+': |
case '+': |
case '-': |
case '-': |
|
|
* Print current value of the parameter. |
* Print current value of the parameter. |
*/ |
*/ |
void |
void |
print_value(int optval) |
print_value(int optval, int show_choices) |
{ |
{ |
if (optval == OPTION_NONE) |
if (optval == OPTION_NONE) |
return; |
return; |
|
|
case OPTION_STEREO: |
case OPTION_STEREO: |
printf(ri.stereo ? onchar : offchar); |
printf(ri.stereo ? onchar : offchar); |
break; |
break; |
|
case OPTION_CHANNEL: |
|
printf("%u", ri.chan); |
|
break; |
|
case OPTION_CHNLSET: |
|
for (i = 0; chansets[i].name; i++) { |
|
if (chansets[i].value == ri.chnlset) |
|
printf("%s", chansets[i].name); |
|
} |
|
if (show_choices) { |
|
printf("\n\t["); |
|
for (i = 0; chansets[i].name; i++) |
|
printf("%s ", chansets[i].name); |
|
printf("]"); |
|
} |
|
break; |
case OPTION_VOLUME: |
case OPTION_VOLUME: |
default: |
default: |
printf("%u", ri.volume); |
printf("%u", ri.volume); |
|
|
* Print all available parameters |
* Print all available parameters |
*/ |
*/ |
void |
void |
print_vars(int silent) |
print_vars(int silent, int show_choices) |
{ |
{ |
show_int_val(ri.volume, varname[OPTION_VOLUME], "", silent); |
show_int_val(ri.volume, varname[OPTION_VOLUME], "", silent); |
|
show_int_val(ri.chan, varname[OPTION_CHANNEL], "", silent); |
|
for (i = 0; chansets[i].name; i++) { |
|
if (chansets[i].value == ri.chnlset) |
|
show_char_val(chansets[i].name, varname[OPTION_CHNLSET], silent); |
|
} |
|
if (show_choices) { |
|
printf("\t[ "); |
|
for (i = 0; chansets[i].name; i++) |
|
printf("%s ", chansets[i].name); |
|
printf("]\n"); |
|
} |
show_float_val((float)ri.freq / 1000., varname[OPTION_FREQUENCY], |
show_float_val((float)ri.freq / 1000., varname[OPTION_FREQUENCY], |
"MHz", silent); |
"MHz", silent); |
show_char_val(ri.mute ? onchar : offchar, varname[OPTION_MUTE], silent); |
show_char_val(ri.mute ? onchar : offchar, varname[OPTION_MUTE], silent); |