1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* Copyright (C) 2005-2008 by Daniel Wagner |
---|
4 |
* |
---|
5 |
* This file is part of FFADO |
---|
6 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
7 |
* |
---|
8 |
* FFADO is based upon FreeBoB |
---|
9 |
* |
---|
10 |
* This program is free software: you can redistribute it and/or modify |
---|
11 |
* it under the terms of the GNU General Public License as published by |
---|
12 |
* the Free Software Foundation, either version 2 of the License, or |
---|
13 |
* (at your option) version 3 of the License. |
---|
14 |
* |
---|
15 |
* This program is distributed in the hope that it will be useful, |
---|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 |
* GNU General Public License for more details. |
---|
19 |
* |
---|
20 |
* You should have received a copy of the GNU General Public License |
---|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
22 |
* |
---|
23 |
*/ |
---|
24 |
|
---|
25 |
#include <libraw1394/raw1394.h> |
---|
26 |
#include <libiec61883/iec61883.h> |
---|
27 |
|
---|
28 |
#include "debugmodule/debugmodule.h" |
---|
29 |
|
---|
30 |
#include "devicemanager.h" |
---|
31 |
|
---|
32 |
#include "libieee1394/configrom.h" |
---|
33 |
#include "libieee1394/ieee1394service.h" |
---|
34 |
#include "libutil/Configuration.h" |
---|
35 |
|
---|
36 |
#include "libcontrol/MatrixMixer.h" |
---|
37 |
#include "libcontrol/CrossbarRouter.h" |
---|
38 |
|
---|
39 |
#include "dice/dice_avdevice.h" |
---|
40 |
using namespace Dice; |
---|
41 |
|
---|
42 |
#include <argp.h> |
---|
43 |
#include <iostream> |
---|
44 |
#include <cstdlib> |
---|
45 |
#include <cstring> |
---|
46 |
|
---|
47 |
#include <signal.h> |
---|
48 |
int run; |
---|
49 |
|
---|
50 |
static void sighandler(int sig) |
---|
51 |
{ |
---|
52 |
run = 0; |
---|
53 |
} |
---|
54 |
|
---|
55 |
using namespace std; |
---|
56 |
using namespace Util; |
---|
57 |
|
---|
58 |
DECLARE_GLOBAL_DEBUG_MODULE; |
---|
59 |
|
---|
60 |
#define MAX_ARGS 1000 |
---|
61 |
|
---|
62 |
//////////////////////////////////////////////// |
---|
63 |
// arg parsing |
---|
64 |
//////////////////////////////////////////////// |
---|
65 |
const char *argp_program_version = "test-dice-eap 0.1"; |
---|
66 |
const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; |
---|
67 |
static char doc[] = "test-avccmd -- test program to examine the DICE EAP code."; |
---|
68 |
static char args_doc[] = "NODE_ID"; |
---|
69 |
static struct argp_option options[] = { |
---|
70 |
{"verbose", 'v', "LEVEL", 0, "Produce verbose output" }, |
---|
71 |
{"port", 'p', "PORT", 0, "Set port" }, |
---|
72 |
{"node", 'n', "NODE", 0, "Set node" }, |
---|
73 |
{ 0 } |
---|
74 |
}; |
---|
75 |
|
---|
76 |
struct arguments |
---|
77 |
{ |
---|
78 |
arguments() |
---|
79 |
: nargs ( 0 ) |
---|
80 |
, verbose( DEBUG_LEVEL_NORMAL ) |
---|
81 |
, test( false ) |
---|
82 |
, port( -1 ) |
---|
83 |
, node( -1 ) |
---|
84 |
{ |
---|
85 |
args[0] = 0; |
---|
86 |
} |
---|
87 |
|
---|
88 |
char* args[MAX_ARGS]; |
---|
89 |
int nargs; |
---|
90 |
int verbose; |
---|
91 |
bool test; |
---|
92 |
int port; |
---|
93 |
int node; |
---|
94 |
} arguments; |
---|
95 |
|
---|
96 |
// Parse a single option. |
---|
97 |
static error_t |
---|
98 |
parse_opt( int key, char* arg, struct argp_state* state ) |
---|
99 |
{ |
---|
100 |
// Get the input argument from `argp_parse', which we |
---|
101 |
// know is a pointer to our arguments structure. |
---|
102 |
struct arguments* arguments = ( struct arguments* ) state->input; |
---|
103 |
|
---|
104 |
char* tail; |
---|
105 |
errno = 0; |
---|
106 |
switch (key) { |
---|
107 |
case 'v': |
---|
108 |
arguments->verbose = strtol(arg, &tail, 0); |
---|
109 |
break; |
---|
110 |
case 't': |
---|
111 |
arguments->test = true; |
---|
112 |
break; |
---|
113 |
case 'p': |
---|
114 |
arguments->port = strtol(arg, &tail, 0); |
---|
115 |
if (errno) { |
---|
116 |
perror("argument parsing failed:"); |
---|
117 |
return errno; |
---|
118 |
} |
---|
119 |
break; |
---|
120 |
case 'n': |
---|
121 |
arguments->node = strtol(arg, &tail, 0); |
---|
122 |
if (errno) { |
---|
123 |
perror("argument parsing failed:"); |
---|
124 |
return errno; |
---|
125 |
} |
---|
126 |
break; |
---|
127 |
case ARGP_KEY_ARG: |
---|
128 |
if (state->arg_num >= MAX_ARGS) { |
---|
129 |
// Too many arguments. |
---|
130 |
argp_usage (state); |
---|
131 |
} |
---|
132 |
arguments->args[state->arg_num] = arg; |
---|
133 |
arguments->nargs++; |
---|
134 |
break; |
---|
135 |
case ARGP_KEY_END: |
---|
136 |
if(arguments->nargs<0) { |
---|
137 |
printf("not enough arguments\n"); |
---|
138 |
return -1; |
---|
139 |
} |
---|
140 |
|
---|
141 |
break; |
---|
142 |
default: |
---|
143 |
return ARGP_ERR_UNKNOWN; |
---|
144 |
} |
---|
145 |
return 0; |
---|
146 |
} |
---|
147 |
|
---|
148 |
static struct argp argp = { options, parse_opt, args_doc, doc }; |
---|
149 |
|
---|
150 |
/////////////////////////// |
---|
151 |
// main |
---|
152 |
////////////////////////// |
---|
153 |
int |
---|
154 |
main(int argc, char **argv) |
---|
155 |
{ |
---|
156 |
run=1; |
---|
157 |
|
---|
158 |
signal (SIGINT, sighandler); |
---|
159 |
signal (SIGPIPE, sighandler); |
---|
160 |
|
---|
161 |
// arg parsing |
---|
162 |
if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { |
---|
163 |
printMessage("Could not parse command line\n" ); |
---|
164 |
exit(-1); |
---|
165 |
} |
---|
166 |
errno = 0; |
---|
167 |
|
---|
168 |
DeviceManager *m_deviceManager = new DeviceManager(); |
---|
169 |
if ( !m_deviceManager ) { |
---|
170 |
printMessage("Could not allocate device manager\n" ); |
---|
171 |
return -1; |
---|
172 |
} |
---|
173 |
|
---|
174 |
if ( arguments.verbose ) { |
---|
175 |
m_deviceManager->setVerboseLevel(arguments.verbose); |
---|
176 |
} |
---|
177 |
|
---|
178 |
if ( !m_deviceManager->initialize() ) { |
---|
179 |
printMessage("Could not initialize device manager\n" ); |
---|
180 |
delete m_deviceManager; |
---|
181 |
return -1; |
---|
182 |
} |
---|
183 |
|
---|
184 |
char s[1024]; |
---|
185 |
if(arguments.node > -1) { |
---|
186 |
snprintf(s, 1024, "hw:%d,%d", arguments.port, arguments.node); |
---|
187 |
if ( !m_deviceManager->addSpecString(s) ) { |
---|
188 |
printMessage("Could not add spec string %s to device manager\n", s ); |
---|
189 |
delete m_deviceManager; |
---|
190 |
return -1; |
---|
191 |
} |
---|
192 |
} else { |
---|
193 |
snprintf(s, 1024, "hw:%d", arguments.port); |
---|
194 |
if ( !m_deviceManager->addSpecString(s) ) { |
---|
195 |
printMessage("Could not add spec string %s to device manager\n", s ); |
---|
196 |
delete m_deviceManager; |
---|
197 |
return -1; |
---|
198 |
} |
---|
199 |
} |
---|
200 |
|
---|
201 |
if ( !m_deviceManager->discover(false) ) { |
---|
202 |
printMessage("Could not discover devices\n" ); |
---|
203 |
delete m_deviceManager; |
---|
204 |
return -1; |
---|
205 |
} |
---|
206 |
|
---|
207 |
if(m_deviceManager->getAvDeviceCount() == 0) { |
---|
208 |
printMessage("No devices found\n"); |
---|
209 |
delete m_deviceManager; |
---|
210 |
return -1; |
---|
211 |
} |
---|
212 |
|
---|
213 |
Dice::Device* avDevice = dynamic_cast<Dice::Device*>(m_deviceManager->getAvDeviceByIndex(0)); |
---|
214 |
|
---|
215 |
if(avDevice == NULL) { |
---|
216 |
printMessage("Device is not a DICE device\n" ); |
---|
217 |
delete m_deviceManager; |
---|
218 |
return -1; |
---|
219 |
} |
---|
220 |
|
---|
221 |
// now play |
---|
222 |
avDevice->setVerboseLevel(DEBUG_LEVEL_VERY_VERBOSE); |
---|
223 |
|
---|
224 |
bool supports_eap = Device::EAP::supportsEAP(*avDevice); |
---|
225 |
if (!supports_eap) { |
---|
226 |
printMessage("EAP not supported on this device\n"); |
---|
227 |
delete m_deviceManager; |
---|
228 |
return -1; |
---|
229 |
} |
---|
230 |
printMessage("device supports EAP\n"); |
---|
231 |
|
---|
232 |
Device::EAP &eap = *(avDevice->getEAP()); |
---|
233 |
|
---|
234 |
eap.show(); |
---|
235 |
eap.lockControl(); |
---|
236 |
Control::Element *e = eap.getElementByName("MatrixMixer"); |
---|
237 |
if(e == NULL) { |
---|
238 |
printMessage("Could not get MatrixMixer control element\n"); |
---|
239 |
} else { |
---|
240 |
Control::MatrixMixer *m = dynamic_cast<Control::MatrixMixer *>(e); |
---|
241 |
if(m == NULL) { |
---|
242 |
printMessage("Element is not a MatrixMixer control element\n"); |
---|
243 |
} else { |
---|
244 |
for(int row=0; row < 16; row++) { |
---|
245 |
for(int col=0; col < 18; col++) { |
---|
246 |
// m->setValue(row, col, 0); |
---|
247 |
} |
---|
248 |
} |
---|
249 |
} |
---|
250 |
} |
---|
251 |
// after unlocking, these should not be used anymore |
---|
252 |
e = NULL; |
---|
253 |
eap.unlockControl(); |
---|
254 |
|
---|
255 |
int cnt = 0; |
---|
256 |
|
---|
257 |
while(run) { |
---|
258 |
eap.lockControl(); |
---|
259 |
Control::Element *e = eap.getElementByName("Router"); |
---|
260 |
if(e == NULL) { |
---|
261 |
printMessage("Could not get CrossbarRouter control element\n"); |
---|
262 |
} else { |
---|
263 |
Control::CrossbarRouter *c = dynamic_cast<Control::CrossbarRouter *>(e); |
---|
264 |
if(c == NULL) { |
---|
265 |
printMessage("Element is not a CrossbarRouter control element\n"); |
---|
266 |
} else { |
---|
267 |
// if(cnt == 0) { |
---|
268 |
// Control::CrossbarRouter::NameVector n; |
---|
269 |
// n = c->getSourceNames(); |
---|
270 |
// for(int i=0; i<n.size(); i++) { |
---|
271 |
// printMessage("Src %02d: %s\n", i, n.at(i).c_str()); |
---|
272 |
// } |
---|
273 |
// n = c->getDestinationNames(); |
---|
274 |
// for(int i=0; i<n.size(); i++) { |
---|
275 |
// printMessage("Dest %02d: %s\n", i, n.at(i).c_str()); |
---|
276 |
// } |
---|
277 |
// } |
---|
278 |
#define NELEMS 10 |
---|
279 |
double peaks[NELEMS]; |
---|
280 |
int srcids[NELEMS]; |
---|
281 |
int dstidx = c->getDestinationIndex("MixerIn:00"); |
---|
282 |
for(int i=0; i<NELEMS; i++) { |
---|
283 |
srcids[i] = c->getSourceForDestination(dstidx + i); |
---|
284 |
peaks[i] = c->getPeakValue(srcids[i], dstidx + i); |
---|
285 |
} |
---|
286 |
for(int i=0; i<NELEMS; i++) { |
---|
287 |
std::string srcname = c->getSourceName(srcids[i]); |
---|
288 |
std::string dstname = c->getDestinationName(dstidx + i); |
---|
289 |
printMessage("Peak %3d (%10s => %10s): %f\n", i, srcname.c_str(), dstname.c_str(), peaks[i]); |
---|
290 |
} |
---|
291 |
} |
---|
292 |
} |
---|
293 |
// after unlocking, these should not be used anymore |
---|
294 |
e = NULL; |
---|
295 |
eap.unlockControl(); |
---|
296 |
sleep(1); |
---|
297 |
} |
---|
298 |
|
---|
299 |
// cleanup |
---|
300 |
delete m_deviceManager; |
---|
301 |
return 0; |
---|
302 |
} |
---|
303 |
|
---|