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

Revision 1781, 8.2 kB (checked in by arnonym, 14 years ago)

Adopt the test:-)

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 #include "dice/dice_eap.h"
41
42 using namespace Dice;
43
44 #include <argp.h>
45 #include <iostream>
46 #include <cstdlib>
47 #include <cstring>
48
49 #include <signal.h>
50 int run;
51
52 static void sighandler(int sig)
53 {
54     run = 0;
55 }
56
57 using namespace std;
58 using namespace Util;
59
60 DECLARE_GLOBAL_DEBUG_MODULE;
61
62 #define MAX_ARGS 1000
63
64 ////////////////////////////////////////////////
65 // arg parsing
66 ////////////////////////////////////////////////
67 const char *argp_program_version = "test-dice-eap 0.1";
68 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
69 static char doc[] = "test-dice-eap -- test program to examine the DICE EAP code.";
70 static char args_doc[] = "NODE_ID";
71 static struct argp_option options[] = {
72     {"verbose",   'v', "LEVEL",     0,  "Produce verbose output" },
73     {"port",      'p', "PORT",      0,  "Set port" },
74     {"node",      'n', "NODE",      0,  "Set node" },
75     {"application",'a',  NULL,      0,  "Show the application space"},
76     {"counts",    'c', "COUNTS",    0,  "Number of runs to do. -1 means to run forever."},
77    { 0 }
78 };
79
80 struct arguments
81 {
82     arguments()
83         : nargs ( 0 )
84         , verbose( DEBUG_LEVEL_NORMAL )
85         , test( false )
86         , port( -1 )
87         , node( -1 )
88         , application( false )
89         , counts( -1 )
90         {
91             args[0] = 0;
92         }
93
94     char* args[MAX_ARGS];
95     int   nargs;
96     int   verbose;
97     bool  test;
98     int   port;
99     int   node;
100     bool  application;
101     int   counts;
102 } arguments;
103
104 // Parse a single option.
105 static error_t
106 parse_opt( int key, char* arg, struct argp_state* state )
107 {
108     // Get the input argument from `argp_parse', which we
109     // know is a pointer to our arguments structure.
110     struct arguments* arguments = ( struct arguments* ) state->input;
111
112     char* tail;
113     errno = 0;
114     switch (key) {
115     case 'v':
116         arguments->verbose = strtol(arg, &tail, 0);
117         break;
118     case 't':
119         arguments->test = true;
120         break;
121     case 'a':
122         arguments->application = true;
123         break;
124     case 'p':
125         arguments->port = strtol(arg, &tail, 0);
126         if (errno) {
127             perror("argument parsing failed:");
128             return errno;
129         }
130         break;
131     case 'n':
132         arguments->node = strtol(arg, &tail, 0);
133         if (errno) {
134             perror("argument parsing failed:");
135             return errno;
136         }
137         break;
138     case 'c':
139         arguments->counts = strtol(arg, &tail, 0);
140         if (errno) {
141             perror("argument parsing failed:");
142             return errno;
143         }
144         break;
145     case ARGP_KEY_ARG:
146         if (state->arg_num >= MAX_ARGS) {
147             // Too many arguments.
148             argp_usage (state);
149         }
150         arguments->args[state->arg_num] = arg;
151         arguments->nargs++;
152         break;
153     case ARGP_KEY_END:
154         if(arguments->nargs<0) {
155             printf("not enough arguments\n");
156             return -1;
157         }
158        
159         break;
160     default:
161         return ARGP_ERR_UNKNOWN;
162     }
163     return 0;
164 }
165
166 static struct argp argp = { options, parse_opt, args_doc, doc };
167
168 ///////////////////////////
169 // main
170 //////////////////////////
171 int
172 main(int argc, char **argv)
173 {
174     run=1;
175
176     signal (SIGINT, sighandler);
177     signal (SIGPIPE, sighandler);
178
179     // arg parsing
180     if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) {
181         printMessage("Could not parse command line\n" );
182         exit(-1);
183     }
184     errno = 0;
185
186     DeviceManager *m_deviceManager = new DeviceManager();
187     if ( !m_deviceManager ) {
188         printMessage("Could not allocate device manager\n" );
189         return -1;
190     }
191
192     if ( arguments.verbose ) {
193         m_deviceManager->setVerboseLevel(arguments.verbose);
194     }
195
196     if ( !m_deviceManager->initialize() ) {
197         printMessage("Could not initialize device manager\n" );
198         delete m_deviceManager;
199         return -1;
200     }
201
202     char s[1024];
203     if(arguments.node > -1) {
204         snprintf(s, 1024, "hw:%d,%d", arguments.port, arguments.node);
205         if ( !m_deviceManager->addSpecString(s) ) {
206             printMessage("Could not add spec string %s to device manager\n", s );
207             delete m_deviceManager;
208             return -1;
209         }
210     } else {
211         snprintf(s, 1024, "hw:%d", arguments.port);
212         if ( !m_deviceManager->addSpecString(s) ) {
213             printMessage("Could not add spec string %s to device manager\n", s );
214             delete m_deviceManager;
215             return -1;
216         }
217     }
218
219     if ( !m_deviceManager->discover(false) ) {
220         printMessage("Could not discover devices\n" );
221         delete m_deviceManager;
222         return -1;
223     }
224
225     if(m_deviceManager->getAvDeviceCount() == 0) {
226         printMessage("No devices found\n");
227         delete m_deviceManager;
228         return -1;
229     }
230
231     Dice::Device* avDevice = dynamic_cast<Dice::Device*>(m_deviceManager->getAvDeviceByIndex(0));
232
233     if(avDevice == NULL) {
234         printMessage("Device is not a DICE device\n" );
235         delete m_deviceManager;
236         return -1;
237     }
238
239     // now play
240     //avDevice->setVerboseLevel(DEBUG_LEVEL_VERY_VERBOSE);
241
242     bool supports_eap = EAP::supportsEAP(*avDevice);
243     if (!supports_eap) {
244         printMessage("EAP not supported on this device\n");
245         delete m_deviceManager;
246         return -1;
247     }
248     printMessage("device supports EAP\n");
249
250     EAP &eap = *(avDevice->getEAP());
251
252     if (arguments.application)
253         eap.showApplication();
254     else
255         eap.show();
256     eap.lockControl();
257     Control::Element *e = eap.getElementByName("MatrixMixer");
258     if(e == NULL) {
259         printMessage("Could not get MatrixMixer control element\n");
260     } else {
261         Control::MatrixMixer *m = dynamic_cast<Control::MatrixMixer *>(e);
262         if(m == NULL) {
263             printMessage("Element is not a MatrixMixer control element\n");
264         }/* else {
265             for(int row=0; row < 16; row++) {
266                 for(int col=0; col < 18; col++) {
267                      m->setValue(row, col, 0);
268                 }
269             }
270         }*/
271     }
272     // after unlocking, these should not be used anymore
273     e = NULL;
274     eap.unlockControl();
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                 std::map<std::string, double> peaks = c->getPeakValues();
287                 for (std::map<std::string, double>::iterator it=peaks.begin(); it!=peaks.end();
288                         ++it) {
289                     printMessage("%s: %g\n", it->first.c_str(), it->second);
290                 }
291             }
292         }
293         // after unlocking, these should not be used anymore
294         e = NULL;
295         eap.unlockControl();
296         sleep(1);
297         arguments.counts--;
298     }
299
300     // cleanup
301     delete m_deviceManager;
302     return 0;
303 }
304
Note: See TracBrowser for help on using the browser.