root/trunk/libffado/tests/test-dice-eap.cpp

Revision 1717, 9.1 kB (checked in by arnonym, 13 years ago)

Make reading the whole application space its own special thing.

Line 
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-dice-eap -- 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     {"application",'a',  NULL,      0,  "Show the application space"},
74     {"counts",    'c', "COUNTS",    0,  "Number of runs to do. -1 means to run forever."},
75    { 0 }
76 };
77
78 struct arguments
79 {
80     arguments()
81         : nargs ( 0 )
82         , verbose( DEBUG_LEVEL_NORMAL )
83         , test( false )
84         , port( -1 )
85         , node( -1 )
86         , application( false )
87         , counts( -1 )
88         {
89             args[0] = 0;
90         }
91
92     char* args[MAX_ARGS];
93     int   nargs;
94     int   verbose;
95     bool  test;
96     int   port;
97     int   node;
98     bool  application;
99     int   counts;
100 } arguments;
101
102 // Parse a single option.
103 static error_t
104 parse_opt( int key, char* arg, struct argp_state* state )
105 {
106     // Get the input argument from `argp_parse', which we
107     // know is a pointer to our arguments structure.
108     struct arguments* arguments = ( struct arguments* ) state->input;
109
110     char* tail;
111     errno = 0;
112     switch (key) {
113     case 'v':
114         arguments->verbose = strtol(arg, &tail, 0);
115         break;
116     case 't':
117         arguments->test = true;
118         break;
119     case 'a':
120         arguments->application = true;
121         break;
122     case 'p':
123         arguments->port = strtol(arg, &tail, 0);
124         if (errno) {
125             perror("argument parsing failed:");
126             return errno;
127         }
128         break;
129     case 'n':
130         arguments->node = strtol(arg, &tail, 0);
131         if (errno) {
132             perror("argument parsing failed:");
133             return errno;
134         }
135         break;
136     case 'c':
137         arguments->counts = strtol(arg, &tail, 0);
138         if (errno) {
139             perror("argument parsing failed:");
140             return errno;
141         }
142         break;
143     case ARGP_KEY_ARG:
144         if (state->arg_num >= MAX_ARGS) {
145             // Too many arguments.
146             argp_usage (state);
147         }
148         arguments->args[state->arg_num] = arg;
149         arguments->nargs++;
150         break;
151     case ARGP_KEY_END:
152         if(arguments->nargs<0) {
153             printf("not enough arguments\n");
154             return -1;
155         }
156        
157         break;
158     default:
159         return ARGP_ERR_UNKNOWN;
160     }
161     return 0;
162 }
163
164 static struct argp argp = { options, parse_opt, args_doc, doc };
165
166 ///////////////////////////
167 // main
168 //////////////////////////
169 int
170 main(int argc, char **argv)
171 {
172     run=1;
173
174     signal (SIGINT, sighandler);
175     signal (SIGPIPE, sighandler);
176
177     // arg parsing
178     if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) {
179         printMessage("Could not parse command line\n" );
180         exit(-1);
181     }
182     errno = 0;
183
184     DeviceManager *m_deviceManager = new DeviceManager();
185     if ( !m_deviceManager ) {
186         printMessage("Could not allocate device manager\n" );
187         return -1;
188     }
189
190     if ( arguments.verbose ) {
191         m_deviceManager->setVerboseLevel(arguments.verbose);
192     }
193
194     if ( !m_deviceManager->initialize() ) {
195         printMessage("Could not initialize device manager\n" );
196         delete m_deviceManager;
197         return -1;
198     }
199
200     char s[1024];
201     if(arguments.node > -1) {
202         snprintf(s, 1024, "hw:%d,%d", arguments.port, arguments.node);
203         if ( !m_deviceManager->addSpecString(s) ) {
204             printMessage("Could not add spec string %s to device manager\n", s );
205             delete m_deviceManager;
206             return -1;
207         }
208     } else {
209         snprintf(s, 1024, "hw:%d", arguments.port);
210         if ( !m_deviceManager->addSpecString(s) ) {
211             printMessage("Could not add spec string %s to device manager\n", s );
212             delete m_deviceManager;
213             return -1;
214         }
215     }
216
217     if ( !m_deviceManager->discover(false) ) {
218         printMessage("Could not discover devices\n" );
219         delete m_deviceManager;
220         return -1;
221     }
222
223     if(m_deviceManager->getAvDeviceCount() == 0) {
224         printMessage("No devices found\n");
225         delete m_deviceManager;
226         return -1;
227     }
228
229     Dice::Device* avDevice = dynamic_cast<Dice::Device*>(m_deviceManager->getAvDeviceByIndex(0));
230
231     if(avDevice == NULL) {
232         printMessage("Device is not a DICE device\n" );
233         delete m_deviceManager;
234         return -1;
235     }
236
237     // now play
238     //avDevice->setVerboseLevel(DEBUG_LEVEL_VERY_VERBOSE);
239
240     bool supports_eap = Device::EAP::supportsEAP(*avDevice);
241     if (!supports_eap) {
242         printMessage("EAP not supported on this device\n");
243         delete m_deviceManager;
244         return -1;
245     }
246     printMessage("device supports EAP\n");
247
248     Device::EAP &eap = *(avDevice->getEAP());
249
250     if (arguments.application)
251         eap.showApplication();
252     else
253         eap.show();
254     eap.lockControl();
255     Control::Element *e = eap.getElementByName("MatrixMixer");
256     if(e == NULL) {
257         printMessage("Could not get MatrixMixer control element\n");
258     } else {
259         Control::MatrixMixer *m = dynamic_cast<Control::MatrixMixer *>(e);
260         if(m == NULL) {
261             printMessage("Element is not a MatrixMixer control element\n");
262         } else {
263             for(int row=0; row < 16; row++) {
264                 for(int col=0; col < 18; col++) {
265 //                     m->setValue(row, col, 0);
266                 }
267             }
268         }
269     }
270     // after unlocking, these should not be used anymore
271     e = NULL;
272     eap.unlockControl();
273
274     int cnt = 0;
275
276     while(run && arguments.counts != 0) {
277         eap.lockControl();
278         Control::Element *e = eap.getElementByName("Router");
279         if(e == NULL) {
280             printMessage("Could not get CrossbarRouter control element\n");
281         } else {
282             Control::CrossbarRouter *c = dynamic_cast<Control::CrossbarRouter *>(e);
283             if(c == NULL) {
284                 printMessage("Element is not a CrossbarRouter control element\n");
285             } else {
286 //                 if(cnt == 0) {
287 //                     Control::CrossbarRouter::NameVector n;
288 //                     n = c->getSourceNames();
289 //                     for(int i=0; i<n.size(); i++) {
290 //                         printMessage("Src  %02d: %s\n", i, n.at(i).c_str());
291 //                     }
292 //                     n = c->getDestinationNames();
293 //                     for(int i=0; i<n.size(); i++) {
294 //                         printMessage("Dest %02d: %s\n", i, n.at(i).c_str());
295 //                     }
296 //                 }
297                 #define NELEMS 10
298                 double peaks[NELEMS];
299                 int srcids[NELEMS];
300                 int dstidx = c->getDestinationIndex("MixerIn:00");
301                 for(int i=0; i<NELEMS; i++) {
302                     srcids[i] = c->getSourceForDestination(dstidx + i);
303                     peaks[i] = c->getPeakValue(srcids[i], dstidx + i);
304                 }
305                 for(int i=0; i<NELEMS; i++) {
306                     std::string srcname = c->getSourceName(srcids[i]);
307                     std::string dstname = c->getDestinationName(dstidx + i);
308                     printMessage("Peak %3d (%10s => %10s): %f\n", i, srcname.c_str(), dstname.c_str(), peaks[i]);
309                 }
310             }
311         }
312         // after unlocking, these should not be used anymore
313         e = NULL;
314         eap.unlockControl();
315         sleep(1);
316         arguments.counts--;
317     }
318
319     // cleanup
320     delete m_deviceManager;
321     return 0;
322 }
323
Note: See TracBrowser for help on using the browser.