root/branches/streaming-rework/tests/test-volume.cpp

Revision 375, 3.9 kB (checked in by wagi, 17 years ago)

AVCCommand: All AVC commants take a reference instead a pointer to 1394 service
BeBoB::AvDevice?: PreSonus? FIREBOX id added

De/Serialize all AvPlugs? through AvPlugManager?
AvPlugManager? can't be a member because of serialization

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