25 | | #include <argp.h> |
---|
26 | | |
---|
27 | | using namespace std; |
---|
28 | | |
---|
29 | | //////////////////////////////////////////////// |
---|
30 | | // arg parsing |
---|
31 | | //////////////////////////////////////////////// |
---|
32 | | const char *argp_program_version = "test-volume 0.1"; |
---|
33 | | const char *argp_program_bug_address = "<freebob-devel@lists.sf.net>"; |
---|
34 | | static char doc[] = "test-extplugcmd -- tests some extended plug info commands on a BeBoB device"; |
---|
35 | | static char args_doc[] = "NODE_ID FFB_ID VOL"; |
---|
36 | | static struct argp_option options[] = { |
---|
37 | | {"verbose", 'v', 0, 0, "Produce verbose output" }, |
---|
38 | | {"port", 'p', "PORT", 0, "Set port" }, |
---|
39 | | { 0 } |
---|
40 | | }; |
---|
41 | | |
---|
42 | | struct arguments |
---|
| 25 | short int getMaxVolume(Ieee1394Service& ieee1394service, int node_id, int ffb_id) |
---|
44 | | arguments() |
---|
45 | | : verbose( false ) |
---|
46 | | , test( false ) |
---|
47 | | , port( 0 ) |
---|
48 | | { |
---|
49 | | args[0] = 0; |
---|
50 | | } |
---|
51 | | |
---|
52 | | char* args[3]; |
---|
53 | | bool verbose; |
---|
54 | | bool test; |
---|
55 | | int port; |
---|
56 | | } arguments; |
---|
57 | | |
---|
58 | | // Parse a single option. |
---|
59 | | static error_t |
---|
60 | | parse_opt( int key, char* arg, struct argp_state* state ) |
---|
61 | | { |
---|
62 | | // Get the input argument from `argp_parse', which we |
---|
63 | | // know is a pointer to our arguments structure. |
---|
64 | | struct arguments* arguments = ( struct arguments* ) state->input; |
---|
65 | | |
---|
66 | | char* tail; |
---|
67 | | switch (key) { |
---|
68 | | case 'v': |
---|
69 | | arguments->verbose = true; |
---|
70 | | break; |
---|
71 | | case 't': |
---|
72 | | arguments->test = true; |
---|
73 | | break; |
---|
74 | | case 'p': |
---|
75 | | errno = 0; |
---|
76 | | arguments->port = strtol(arg, &tail, 0); |
---|
77 | | if (errno) { |
---|
78 | | perror("argument parsing failed:"); |
---|
79 | | return errno; |
---|
80 | | } |
---|
81 | | break; |
---|
82 | | case ARGP_KEY_ARG: |
---|
83 | | if (state->arg_num >= 3) { |
---|
84 | | // Too many arguments. |
---|
85 | | argp_usage (state); |
---|
86 | | } |
---|
87 | | arguments->args[state->arg_num] = arg; |
---|
88 | | break; |
---|
89 | | case ARGP_KEY_END: |
---|
90 | | if (state->arg_num < 3 ) { |
---|
91 | | // Not enough arguments. |
---|
92 | | argp_usage (state); |
---|
93 | | } |
---|
94 | | break; |
---|
95 | | default: |
---|
96 | | return ARGP_ERR_UNKNOWN; |
---|
| 27 | FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); |
---|
| 28 | ffbCmd.setNodeId( node_id ); |
---|
| 29 | ffbCmd.setSubunitId( 0x00 ); |
---|
| 30 | ffbCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
| 31 | ffbCmd.setFunctionBlockId( ffb_id ); |
---|
| 32 | ffbCmd.setControlAttribute(FeatureFunctionBlockCmd::eCA_Maximum); |
---|
| 33 | |
---|
| 34 | if ( !ffbCmd.fire() ) { |
---|
| 35 | printf( "cmd failed\n" ); |
---|
101 | | static struct argp argp = { options, parse_opt, args_doc, doc }; |
---|
| 40 | short int getMinVolume(Ieee1394Service& ieee1394service, int node_id, int ffb_id) |
---|
| 41 | { |
---|
| 42 | FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); |
---|
| 43 | ffbCmd.setNodeId( node_id ); |
---|
| 44 | ffbCmd.setSubunitId( 0x00 ); |
---|
| 45 | ffbCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
| 46 | ffbCmd.setFunctionBlockId( ffb_id ); |
---|
| 47 | ffbCmd.setControlAttribute(FeatureFunctionBlockCmd::eCA_Minimum); |
---|
103 | | //////////////////////////////////////// |
---|
104 | | // Application |
---|
105 | | //////////////////////////////////////// |
---|
| 49 | if ( !ffbCmd.fire() ) { |
---|
| 50 | printf( "cmd failed\n" ); |
---|
| 51 | } |
---|
| 52 | return ffbCmd.m_volumeControl.m_volume; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | short int getCurrentVolume(Ieee1394Service& ieee1394service, int node_id, int ffb_id) |
---|
| 56 | { |
---|
| 57 | FeatureFunctionBlockCmd ffbCmd( &ieee1394service ); |
---|
| 58 | ffbCmd.setNodeId( node_id ); |
---|
| 59 | ffbCmd.setSubunitId( 0x00 ); |
---|
| 60 | ffbCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
| 61 | ffbCmd.setFunctionBlockId( ffb_id ); |
---|
| 62 | |
---|
| 63 | if ( !ffbCmd.fire() ) { |
---|
| 64 | printf( "cmd failed\n" ); |
---|
| 65 | } |
---|
| 66 | return ffbCmd.m_volumeControl.m_volume; |
---|
| 67 | } |
---|
| 72 | short int maxVolume = getMaxVolume(ieee1394service, node_id, ffb_id); |
---|
| 73 | short int minVolume = getMinVolume(ieee1394service, node_id, ffb_id); |
---|
| 74 | |
---|
| 75 | printf("max volume value = %d\n", maxVolume); |
---|
| 76 | printf("min volume value = %d\n", minVolume); |
---|
| 77 | |
---|
| 78 | short int volume = getCurrentVolume(ieee1394service, node_id, ffb_id); |
---|
| 79 | printf("old volume value = %d\n", volume); |
---|
| 80 | |
---|
137 | | int node_id = strtol( arguments.args[0], &tail, 0 ); |
---|
138 | | int ffb_id = strtol( arguments.args[1], &tail, 0 ); |
---|
139 | | int vol = strtol( arguments.args[2], &tail, 0 ); |
---|
| 112 | int node_id = strtol( argv[1], &tail, 0 ); |
---|
| 113 | int ffb_id = strtol( argv[2], &tail, 0 ); |
---|
| 114 | int vol = strtol( argv[3], &tail, 0 ); |
---|