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/avc_extended_plug_info.h" |
---|
25 |
#include "libavc/avc_plug_info.h" |
---|
26 |
#include "libavc/avc_serialize.h" |
---|
27 |
|
---|
28 |
#include "libieee1394/configrom.h" |
---|
29 |
#include "libieee1394/ieee1394service.h" |
---|
30 |
|
---|
31 |
#include <argp.h> |
---|
32 |
|
---|
33 |
using namespace std; |
---|
34 |
|
---|
35 |
//////////////////////////////////////////////// |
---|
36 |
// arg parsing |
---|
37 |
//////////////////////////////////////////////// |
---|
38 |
const char *argp_program_version = "test-extplugcmd 0.2"; |
---|
39 |
const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; |
---|
40 |
static char doc[] = "test-extplugcmd -- tests some extended plug info commands on a BeBoB device"; |
---|
41 |
static char args_doc[] = "NODE_ID"; |
---|
42 |
static struct argp_option options[] = { |
---|
43 |
{"verbose", 'v', 0, 0, "Produce verbose output" }, |
---|
44 |
{"port", 'p', "PORT", 0, "Set port" }, |
---|
45 |
{ 0 } |
---|
46 |
}; |
---|
47 |
|
---|
48 |
struct arguments |
---|
49 |
{ |
---|
50 |
arguments() |
---|
51 |
: verbose( false ) |
---|
52 |
, test( false ) |
---|
53 |
, port( 0 ) |
---|
54 |
{ |
---|
55 |
args[0] = 0; |
---|
56 |
} |
---|
57 |
|
---|
58 |
char* args[1]; |
---|
59 |
bool verbose; |
---|
60 |
bool test; |
---|
61 |
int port; |
---|
62 |
} arguments; |
---|
63 |
|
---|
64 |
// Parse a single option. |
---|
65 |
static error_t |
---|
66 |
parse_opt( int key, char* arg, struct argp_state* state ) |
---|
67 |
{ |
---|
68 |
// Get the input argument from `argp_parse', which we |
---|
69 |
// know is a pointer to our arguments structure. |
---|
70 |
struct arguments* arguments = ( struct arguments* ) state->input; |
---|
71 |
|
---|
72 |
char* tail; |
---|
73 |
errno = 0; |
---|
74 |
switch (key) { |
---|
75 |
case 'v': |
---|
76 |
arguments->verbose = true; |
---|
77 |
break; |
---|
78 |
case 't': |
---|
79 |
arguments->test = true; |
---|
80 |
break; |
---|
81 |
case 'p': |
---|
82 |
arguments->port = strtol(arg, &tail, 0); |
---|
83 |
if (errno) { |
---|
84 |
perror("argument parsing failed:"); |
---|
85 |
return errno; |
---|
86 |
} |
---|
87 |
break; |
---|
88 |
case ARGP_KEY_ARG: |
---|
89 |
if (state->arg_num >= 1) { |
---|
90 |
// Too many arguments. |
---|
91 |
argp_usage (state); |
---|
92 |
} |
---|
93 |
arguments->args[state->arg_num] = arg; |
---|
94 |
break; |
---|
95 |
case ARGP_KEY_END: |
---|
96 |
if (state->arg_num < 1) { |
---|
97 |
// Not enough arguments. |
---|
98 |
argp_usage (state); |
---|
99 |
} |
---|
100 |
break; |
---|
101 |
default: |
---|
102 |
return ARGP_ERR_UNKNOWN; |
---|
103 |
} |
---|
104 |
return 0; |
---|
105 |
} |
---|
106 |
|
---|
107 |
static struct argp argp = { options, parse_opt, args_doc, doc }; |
---|
108 |
|
---|
109 |
//////////////////////////////////////// |
---|
110 |
// Application |
---|
111 |
//////////////////////////////////////// |
---|
112 |
|
---|
113 |
bool |
---|
114 |
doPlugType( Ieee1394Service& ieee1394service, int node_id ) |
---|
115 |
{ |
---|
116 |
ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service ); |
---|
117 |
UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 ); |
---|
118 |
extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input, |
---|
119 |
PlugAddress::ePAM_Unit, |
---|
120 |
unitPlugAddress ) ); |
---|
121 |
extPlugInfoCmd.setNodeId( node_id ); |
---|
122 |
extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
123 |
extPlugInfoCmd.setVerbose( arguments.verbose ); |
---|
124 |
ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugType ); |
---|
125 |
extendedPlugInfoInfoType.initialize(); |
---|
126 |
extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); |
---|
127 |
|
---|
128 |
if ( extPlugInfoCmd.fire() ) { |
---|
129 |
CoutSerializer se; |
---|
130 |
extPlugInfoCmd.serialize( se ); |
---|
131 |
} |
---|
132 |
|
---|
133 |
ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); |
---|
134 |
if ( infoType |
---|
135 |
&& infoType->m_plugType ) |
---|
136 |
{ |
---|
137 |
plug_type_t plugType = infoType->m_plugType->m_plugType; |
---|
138 |
|
---|
139 |
printf( "iso input plug %d is of type %d (%s)\n", |
---|
140 |
0, |
---|
141 |
plugType, |
---|
142 |
extendedPlugInfoPlugTypeToString( plugType ) ); |
---|
143 |
} else { |
---|
144 |
fprintf( stderr, "Not plug name specific data found\n" ); |
---|
145 |
return false; |
---|
146 |
} |
---|
147 |
|
---|
148 |
return true; |
---|
149 |
} |
---|
150 |
|
---|
151 |
|
---|
152 |
bool |
---|
153 |
doPlugName( Ieee1394Service& ieee1394service, int node_id ) |
---|
154 |
{ |
---|
155 |
ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service ); |
---|
156 |
UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 ); |
---|
157 |
extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input, |
---|
158 |
PlugAddress::ePAM_Unit, |
---|
159 |
unitPlugAddress ) ); |
---|
160 |
extPlugInfoCmd.setNodeId( node_id ); |
---|
161 |
extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
162 |
extPlugInfoCmd.setVerbose( arguments.verbose ); |
---|
163 |
ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugName ); |
---|
164 |
extendedPlugInfoInfoType.initialize(); |
---|
165 |
extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); |
---|
166 |
|
---|
167 |
if ( extPlugInfoCmd.fire() ) { |
---|
168 |
CoutSerializer se; |
---|
169 |
extPlugInfoCmd.serialize( se ); |
---|
170 |
} |
---|
171 |
|
---|
172 |
ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); |
---|
173 |
if ( infoType |
---|
174 |
&& infoType->m_plugName ) |
---|
175 |
{ |
---|
176 |
printf( "iso input plug %d has name '%s'\n", |
---|
177 |
0, |
---|
178 |
infoType->m_plugName->m_name.c_str() ); |
---|
179 |
} else { |
---|
180 |
fprintf( stderr, "Not plug name specific data found\n" ); |
---|
181 |
return false; |
---|
182 |
} |
---|
183 |
|
---|
184 |
return true; |
---|
185 |
} |
---|
186 |
|
---|
187 |
bool |
---|
188 |
doApp(Ieee1394Service& ieee1394service, int node_id ) |
---|
189 |
{ |
---|
190 |
bool success; |
---|
191 |
|
---|
192 |
success = doPlugType( ieee1394service, node_id ); |
---|
193 |
success &= doPlugName( ieee1394service, node_id ); |
---|
194 |
|
---|
195 |
return success; |
---|
196 |
} |
---|
197 |
|
---|
198 |
/////////////////////////// |
---|
199 |
// main |
---|
200 |
////////////////////////// |
---|
201 |
int |
---|
202 |
main(int argc, char **argv) |
---|
203 |
{ |
---|
204 |
// arg parsing |
---|
205 |
argp_parse (&argp, argc, argv, 0, 0, &arguments); |
---|
206 |
|
---|
207 |
errno = 0; |
---|
208 |
char* tail; |
---|
209 |
int node_id = strtol(arguments.args[0], &tail, 0); |
---|
210 |
if (errno) { |
---|
211 |
perror("argument parsing failed:"); |
---|
212 |
return -1; |
---|
213 |
} |
---|
214 |
Ieee1394Service ieee1394service; |
---|
215 |
if ( !ieee1394service.initialize( arguments.port ) ) { |
---|
216 |
fprintf( stderr, "could not set port on ieee1394service\n" ); |
---|
217 |
return -1; |
---|
218 |
} |
---|
219 |
|
---|
220 |
doApp( ieee1394service, node_id ); |
---|
221 |
|
---|
222 |
return 0; |
---|
223 |
} |
---|