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