root/trunk/libffado/tests/test-volume.cpp

Revision 742, 4.1 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "libavc/avc_function_block.h"
25 #include "libavc/avc_serialize.h"
26
27 #include "libieee1394/ieee1394service.h"
28
29 const bool bVerbose = false;
30
31 short int
32 getVolume( Ieee1394Service& ieee1394service, int node_id, int ffb_id,
33            FunctionBlockCmd::EControlAttribute control_attrib )
34 {
35     FunctionBlockCmd fbCmd( ieee1394service,
36                             FunctionBlockCmd::eFBT_Feature,
37                             ffb_id,
38                             control_attrib );
39     fbCmd.setNodeId( node_id );
40     fbCmd.setSubunitId( 0x00 );
41     fbCmd.setCommandType( AVCCommand::eCT_Status );
42     fbCmd.m_pFBFeature->m_pVolume = new FunctionBlockFeatureVolume;
43
44     fbCmd.setVerbose( bVerbose );
45     if (bVerbose) {
46         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE );
47     }
48
49     if ( !fbCmd.fire() ) {
50         printf( "cmd failed\n" );
51     }
52
53     if ( bVerbose ) {
54         CoutSerializer se;
55         fbCmd.serialize( se );
56     }
57
58     return fbCmd.m_pFBFeature->m_pVolume->m_volume;
59 }
60
61 bool
62 setVolume( Ieee1394Service& ieee1394service, int node_id, int ffb_id, int vol )
63 {
64     FunctionBlockCmd fbCmd( ieee1394service,
65                             FunctionBlockCmd::eFBT_Feature,
66                             ffb_id,
67                             FunctionBlockCmd::eCA_Current );
68     fbCmd.setNodeId( node_id );
69     fbCmd.setSubunitId( 0x00 );
70     fbCmd.setCommandType( AVCCommand::eCT_Control );
71     fbCmd.m_pFBFeature->m_pVolume = new FunctionBlockFeatureVolume;
72     fbCmd.m_pFBFeature->m_pVolume->m_volume = vol;
73
74     fbCmd.setVerbose( bVerbose );
75     if (bVerbose) {
76         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE );
77     }
78
79     bool bStatus = fbCmd.fire();
80     if ( !bStatus ) {
81         printf( "cmd failed\n" );
82     }
83
84     if ( bVerbose ) {
85         CoutSerializer se;
86         fbCmd.serialize( se );
87     }
88
89     return bStatus;
90 }
91
92 bool
93 doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id, int vol )
94 {
95     short int maxVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Maximum );
96     short int minVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Minimum );
97     short int curVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current );
98     printf( "max volume value = %d\n", maxVolume );
99     printf( "min volume value = %d\n", minVolume );
100     printf( "old volume value = %d\n", curVolume);
101
102     setVolume( ieee1394service, node_id, fb_id, vol );
103
104     curVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current );
105     printf( "new volume value = %d\n", curVolume );
106
107     return true;
108 }
109
110 ///////////////////////////
111 // main
112 //////////////////////////
113 int
114 main(int argc, char **argv)
115 {
116
117     if (argc < 3) {
118         printf("usage: NODE_ID FB_ID VOL\n");
119         exit(0);
120     }
121
122     int errno = 0;
123     char* tail;
124     int node_id = strtol( argv[1], &tail, 0 );
125     int fb_id   = strtol( argv[2], &tail, 0 );
126     int vol     = strtol( argv[3], &tail, 0 );
127
128     if (errno) {
129         perror("argument parsing failed:");
130         return -1;
131     }
132     Ieee1394Service ieee1394service;
133     if ( !ieee1394service.initialize( 0 ) ) {
134         fprintf( stderr, "could not set port on ieee1394service\n" );
135         return -1;
136     }
137
138     doApp( ieee1394service, node_id, fb_id, vol );
139
140     return 0;
141 }
Note: See TracBrowser for help on using the browser.