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