1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 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 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
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/audiosubunit/avc_function_block.h" |
---|
25 |
#include "libutil/serialize.h" |
---|
26 |
#include "libutil/cmd_serialize.h" |
---|
27 |
|
---|
28 |
#include "libieee1394/ieee1394service.h" |
---|
29 |
|
---|
30 |
const bool bVerbose = false; |
---|
31 |
|
---|
32 |
using namespace AVC; |
---|
33 |
using namespace Util; |
---|
34 |
using namespace Util::Cmd; |
---|
35 |
|
---|
36 |
short int |
---|
37 |
getVolume( Ieee1394Service& ieee1394service, int node_id, int ffb_id, |
---|
38 |
FunctionBlockCmd::EControlAttribute control_attrib ) |
---|
39 |
{ |
---|
40 |
FunctionBlockCmd fbCmd( ieee1394service, |
---|
41 |
FunctionBlockCmd::eFBT_Feature, |
---|
42 |
ffb_id, |
---|
43 |
control_attrib ); |
---|
44 |
fbCmd.setNodeId( node_id ); |
---|
45 |
fbCmd.setSubunitId( 0x00 ); |
---|
46 |
fbCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
47 |
fbCmd.m_pFBFeature->m_audioChannelNumber = 0; |
---|
48 |
fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; |
---|
49 |
fbCmd.m_pFBFeature->m_pVolume->m_volume = 0; |
---|
50 |
|
---|
51 |
fbCmd.setVerbose( bVerbose ); |
---|
52 |
if (bVerbose) { |
---|
53 |
ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE ); |
---|
54 |
} |
---|
55 |
|
---|
56 |
if ( !fbCmd.fire() ) { |
---|
57 |
printf( "cmd failed\n" ); |
---|
58 |
} |
---|
59 |
|
---|
60 |
if ( bVerbose ) { |
---|
61 |
CoutSerializer se; |
---|
62 |
fbCmd.serialize( se ); |
---|
63 |
} |
---|
64 |
|
---|
65 |
return fbCmd.m_pFBFeature->m_pVolume->m_volume; |
---|
66 |
} |
---|
67 |
|
---|
68 |
bool |
---|
69 |
setVolume( Ieee1394Service& ieee1394service, int node_id, int ffb_id, int vol ) |
---|
70 |
{ |
---|
71 |
FunctionBlockCmd fbCmd( ieee1394service, |
---|
72 |
FunctionBlockCmd::eFBT_Feature, |
---|
73 |
ffb_id, |
---|
74 |
FunctionBlockCmd::eCA_Current ); |
---|
75 |
fbCmd.setNodeId( node_id ); |
---|
76 |
fbCmd.setSubunitId( 0x00 ); |
---|
77 |
fbCmd.setCommandType( AVCCommand::eCT_Control ); |
---|
78 |
fbCmd.m_pFBFeature->m_audioChannelNumber = 0; |
---|
79 |
fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; |
---|
80 |
fbCmd.m_pFBFeature->m_pVolume->m_volume = vol; |
---|
81 |
|
---|
82 |
fbCmd.setVerbose( bVerbose ); |
---|
83 |
if (bVerbose) { |
---|
84 |
ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE ); |
---|
85 |
} |
---|
86 |
|
---|
87 |
bool bStatus = fbCmd.fire(); |
---|
88 |
if ( !bStatus ) { |
---|
89 |
printf( "cmd failed\n" ); |
---|
90 |
} |
---|
91 |
|
---|
92 |
if ( bVerbose ) { |
---|
93 |
CoutSerializer se; |
---|
94 |
fbCmd.serialize( se ); |
---|
95 |
} |
---|
96 |
|
---|
97 |
return bStatus; |
---|
98 |
} |
---|
99 |
|
---|
100 |
bool |
---|
101 |
doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id, int vol ) |
---|
102 |
{ |
---|
103 |
short int maxVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Maximum ); |
---|
104 |
short int minVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Minimum ); |
---|
105 |
short int curVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current ); |
---|
106 |
printf( "max volume value = %d\n", maxVolume ); |
---|
107 |
printf( "min volume value = %d\n", minVolume ); |
---|
108 |
printf( "old volume value = %d\n", curVolume); |
---|
109 |
|
---|
110 |
setVolume( ieee1394service, node_id, fb_id, vol ); |
---|
111 |
|
---|
112 |
curVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current ); |
---|
113 |
printf( "new volume value = %d\n", curVolume ); |
---|
114 |
|
---|
115 |
return true; |
---|
116 |
} |
---|
117 |
|
---|
118 |
/////////////////////////// |
---|
119 |
// main |
---|
120 |
////////////////////////// |
---|
121 |
int |
---|
122 |
main(int argc, char **argv) |
---|
123 |
{ |
---|
124 |
|
---|
125 |
if (argc < 3) { |
---|
126 |
printf("usage: NODE_ID FB_ID VOL\n"); |
---|
127 |
exit(0); |
---|
128 |
} |
---|
129 |
|
---|
130 |
int errno = 0; |
---|
131 |
char* tail; |
---|
132 |
int node_id = strtol( argv[1], &tail, 0 ); |
---|
133 |
int fb_id = strtol( argv[2], &tail, 0 ); |
---|
134 |
int vol = strtol( argv[3], &tail, 0 ); |
---|
135 |
|
---|
136 |
if (errno) { |
---|
137 |
perror("argument parsing failed:"); |
---|
138 |
return -1; |
---|
139 |
} |
---|
140 |
Ieee1394Service ieee1394service; |
---|
141 |
if ( !ieee1394service.initialize( 0 ) ) { |
---|
142 |
fprintf( stderr, "could not set port on ieee1394service\n" ); |
---|
143 |
return -1; |
---|
144 |
} |
---|
145 |
|
---|
146 |
doApp( ieee1394service, node_id, fb_id, vol ); |
---|
147 |
|
---|
148 |
return 0; |
---|
149 |
} |
---|