GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> CLI / V0-1-2 > TV / sun-gcc
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CLI/CLI_msgs.h>
#include <CLI/CLI_pubdefs.h>
#include <CLI_tv.h>
Classes | |
struct | _TV |
A virtual television. More... | |
Defines | |
#define | TV_M_BRIGHT 0x01 |
#define | TV_M_CHANNEL 0x02 |
#define | TV_M_CONTRAST 0x04 |
#define | TV_M_VOLUME 0x08 |
Typedefs | |
typedef struct _TV | TV |
Typedef for struct _TV. | |
Functions | |
static unsigned int | TV_decrease (CLI_Control *, void *) |
Handle the verb decrease. | |
static unsigned int | TV_exit (CLI_Control *, void *) |
Handle the verb exit. | |
static unsigned int | TV_help (CLI_Control *, void *) |
Handle the verb help. | |
static unsigned int | TV_increase (CLI_Control *, void *) |
Handle the verb increase. | |
static unsigned int | TV_power (CLI_Control *, void *) |
Turn the TV on and off. | |
static unsigned int | TV_set (CLI_Control *, void *) |
Callback for the set command. | |
static unsigned int | TV_setBright (CLI_Control *, void *) |
Set the brightness. | |
static unsigned int | TV_setChannel (CLI_Control *, void *) |
Set the channel. | |
static unsigned int | TV_setContrast (CLI_Control *, void *) |
Set the contrast. | |
static unsigned int | TV_setVolume (CLI_Control *, void *) |
Set the volume/mute. | |
static unsigned int | TV_show (CLI_Control *, void *) |
Show current settings. | |
static CLI_Syntax * | TV_syntax () |
Define the TV syntax. | |
static void | TV_printPower (int) |
Useful utility to print the power state. | |
static void | TV_printSetting (TV *, int) |
Useful utility to print control settings. | |
static unsigned int | TV_delta (CLI_Control *, void *, int) |
Utility to handle the "increase" and "decrease" commands. | |
int | main (int argc, char *argv[]) |
Main routine. | |
Variables | |
static const char * | s_abit = "abit" |
The string "abit". | |
static const char * | s_bright = "brightness" |
The string "brightness". | |
static const char * | s_channel = "channel" |
The string "channel". | |
static const char * | s_contrast = "contrast" |
The string "contrast". | |
static const char * | s_decrease = "decrease" |
The string "decrease". | |
static const char * | s_delta = "delta" |
The string "delta". | |
static const char * | s_exit = "exit" |
The string "exit". | |
static const char * | s_help = "help" |
The string "help". | |
static const char * | s_increase = "increase" |
The string "increase". | |
static const char * | s_lots = "lots" |
The string "lots". | |
static const char * | s_mute = "mute" |
The string "mute". | |
static const char * | s_off = "off" |
The string "off". | |
static const char * | s_on = "on" |
The string "on". | |
static const char * | s_power = "power" |
The string "power". | |
static const char * | s_set = "set" |
The string "set". | |
static const char * | s_show = "show" |
The string "show". | |
static const char * | s_some = "some" |
The string "some". | |
static const char * | s_volume = "volume" |
The string "volume". | |
static const char * | d_0 = "$0" |
The string "$0". | |
static const char * | f_decrease = "TV_decrease" |
The function name "TV_decrease". | |
static const char * | f_exit = "TV_exit" |
The function name "TV_exit". | |
static const char * | f_help = "TV_help" |
The function name "TV_help". | |
static const char * | f_increase = "TV_increase" |
The function name "TV_increase". | |
static const char * | f_power = "TV_power" |
The function name "TV_power". | |
static const char * | f_set = "TV_set" |
The function name "TV_set". | |
static const char * | f_setBright = "TV_setBright" |
The function name "TV_setBright". | |
static const char * | f_setChannel = "TV_setChannel" |
The function name "TV_setChannel". | |
static const char * | f_setContrast = "TV_setContrast" |
The function name "TV_setContrast". | |
static const char * | f_setVolume = "TV_setVolume" |
The function name "TV_setVolume". | |
static const char * | f_show = "TV_show" |
The function name "TV_show". |
CVS $Id: CLI_tv.c,v 1.6 2011/03/25 00:51:25 apw Exp $
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Main routine.
How to drive a TV set in forty-two easy lessons.
References _TV::bright, _TV::channel, _TV::contrast, _TV::mute, _TV::power, TV_syntax(), and _TV::volume.
static unsigned int TV_decrease | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Handle the verb decrease.
ctl | Anonymous control pointer | |
user | User parameter |
References TV_delta().
Referenced by TV_syntax().
static unsigned int TV_delta | ( | CLI_Control * | ctl, | |
void * | user, | |||
int | sign | |||
) | [static] |
Utility to handle the "increase" and "decrease" commands.
ctl | Anonymous control pointer | |
user | User parameter | |
sign | Increase or decrease |
increase constrast
decrease volume --delta=alot
increase
(no control specified) decrease volume --delta
(if specified, delta
must take a value) References _TV::bright, _TV::channel, _TV::contrast, _TV::power, TV_printPower(), TV_printSetting(), and _TV::volume.
Referenced by TV_decrease(), and TV_increase().
static unsigned int TV_exit | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Handle the verb exit.
ctl | Anonymous control pointer | |
user | User parameter |
exit
References _TV::power.
Referenced by TV_syntax().
static unsigned int TV_help | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Handle the verb help.
ctl | Anonymous control pointer | |
user | User parameter |
help
Referenced by TV_syntax().
static unsigned int TV_increase | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Handle the verb increase.
ctl | Anonymous control pointer | |
user | User parameter |
References TV_delta().
Referenced by TV_syntax().
static unsigned int TV_power | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Turn the TV on and off.
ctl | Anonymous control pointer | |
user | User parameter |
power on
power off
References _TV::mute, _TV::power, and TV_printPower().
Referenced by TV_syntax().
static void TV_printPower | ( | int | toggle | ) | [static] |
Useful utility to print the power state.
toggle | The power state to print |
Referenced by TV_delta(), TV_power(), TV_setBright(), TV_setChannel(), TV_setContrast(), TV_setVolume(), and TV_show().
static void TV_printSetting | ( | TV * | tv, | |
int | mask | |||
) | [static] |
Useful utility to print control settings.
tv | TV structure | |
mask | Mask of settings to print |
References _TV::bright, _TV::channel, _TV::contrast, _TV::mute, and _TV::volume.
Referenced by TV_delta(), TV_setBright(), TV_setChannel(), TV_setContrast(), TV_setVolume(), and TV_show().
static unsigned int TV_set | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Callback for the set command.
ctl | Anonymous control pointer | |
user | User parameter |
Referenced by TV_syntax().
static unsigned int TV_setBright | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Set the brightness.
ctl | Anonymous control pointer | |
user | User parameter |
set brightness 3
set brightness 8
set brightness
(parameter missing) set brightness six
(parameter is not an integer) set brightness 6 typo
(too many parameters) References _TV::bright, _TV::power, TV_printPower(), and TV_printSetting().
Referenced by TV_syntax().
static unsigned int TV_setChannel | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Set the channel.
ctl | Anonymous control pointer | |
user | User parameter |
set channel 3
(perhaps you want to use your DVD/VCR) set channel 432
set channel
(parameter missing) set channel PBS
(parameter is not an integer) set channel 6 typo
(too many parameters) References _TV::channel, _TV::power, TV_printPower(), and TV_printSetting().
Referenced by TV_syntax().
static unsigned int TV_setContrast | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Set the contrast.
ctl | Anonymous control pointer | |
user | User parameter |
set contrast 3
set contrast 8
set contrast
(parameter missing) set contrast alot
(parameter is not an integer) set contrast 6 typo
(too many parameters) References _TV::contrast, _TV::power, TV_printPower(), and TV_printSetting().
Referenced by TV_syntax().
static unsigned int TV_setVolume | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Set the volume/mute.
ctl | Anonymous control pointer | |
user | User parameter |
In fact this is a very bad way to implement the mute function. It would make far more sense to add a primary command verb "mute" which takes a single keyword parameter "on" or "off" (much like the power command). Alternatively it could be implemented as a toggle ... just a simple one word command "mute" which mutes the first time it's issued and unmutes the second time. The value of implementing a poor syntax is that it demonstrates two features:
set volume 3
set volume --mute
set volume 8 --nomute
set volume
(nothing to do ... but this routine must catch that) set volume mute
(mute is a qualifier, not a parameter) set volume 6 typo --mute
(too many parameters) References _TV::mute, _TV::power, TV_printPower(), TV_printSetting(), and _TV::volume.
Referenced by TV_syntax().
static unsigned int TV_show | ( | CLI_Control * | ctl, | |
void * | user | |||
) | [static] |
Show current settings.
ctl | Anonymous control pointer | |
user | User parameter |
show
(shows all controls) show volume
(shows just the volume control) show volume,contrast,channel
(shows volume, contrast and channel)
show volume contrast
(not a comma separated list) show mute
(mute is not a control) References _TV::power, TV_printPower(), and TV_printSetting().
Referenced by TV_syntax().
static CLI_Syntax * TV_syntax | ( | ) | [static] |
Define the TV syntax.
This is where all the real work of setting up the syntax is done. TV defines two syntaxes: a primary syntax (the verbs decrease, increase, exit, help, power, set and show) and a secondary syntax (to handle the variants of the set command ... set brightness, set channel, set contrast and set volume).
To look at "internals", uncomment the "CLI_dmpdefs.h" include at the top of the file CLI_tv.c and then call any of the dump routines:
void CLI_dumpSyntax( CLI_Syntax *sntx ) | Dump a specific syntax |
void CLI_dumpSyntaxList( void ) | Dump all known syntaxes |
void CLI_dumpKeyList( CLI_KeyList *keys ) | Dump a specific keyword list |
void CLI_dumpKeyListList( void ) | Dump all known keyword lists |
void CLI_dumpParse( CLI_Control *ctl ) | Dump the results of a parse (use in a callback routine) |
References TV_decrease(), TV_exit(), TV_help(), TV_increase(), TV_power(), TV_set(), TV_setBright(), TV_setChannel(), TV_setContrast(), TV_setVolume(), and TV_show().
Referenced by main().