1 |
/* |
---|
2 |
* Copyright (C) 2007 by Pieter Palmers |
---|
3 |
* Copyright (C) 2005-2007 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 |
* FFADO 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) any later version. |
---|
14 |
* FFADO 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 FFADO; if not, write to the Free Software |
---|
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
22 |
* MA 02111-1307 USA. |
---|
23 |
* |
---|
24 |
*/ |
---|
25 |
|
---|
26 |
#include <libraw1394/raw1394.h> |
---|
27 |
#include <libiec61883/iec61883.h> |
---|
28 |
|
---|
29 |
#include "debugmodule/debugmodule.h" |
---|
30 |
|
---|
31 |
#include "libieee1394/configrom.h" |
---|
32 |
#include "libieee1394/ieee1394service.h" |
---|
33 |
#include "libutil/cmd_serialize.h" |
---|
34 |
#include "libavc/general/avc_generic.h" |
---|
35 |
|
---|
36 |
#include "bebob/focusrite/focusrite_cmd.h" |
---|
37 |
using namespace BeBoB::Focusrite; |
---|
38 |
|
---|
39 |
#include <argp.h> |
---|
40 |
#include <stdlib.h> |
---|
41 |
#include <iostream> |
---|
42 |
|
---|
43 |
using namespace std; |
---|
44 |
using namespace AVC; |
---|
45 |
using namespace Util; |
---|
46 |
|
---|
47 |
DECLARE_GLOBAL_DEBUG_MODULE; |
---|
48 |
|
---|
49 |
#define MAX_ARGS 1000 |
---|
50 |
|
---|
51 |
//////////////////////////////////////////////// |
---|
52 |
// arg parsing |
---|
53 |
//////////////////////////////////////////////// |
---|
54 |
const char *argp_program_version = "test-focusrite 0.1"; |
---|
55 |
const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; |
---|
56 |
static char doc[] = "test-avccmd -- test program to examine the focusrite vendor dependent commands."; |
---|
57 |
static char args_doc[] = "NODE_ID"; |
---|
58 |
static struct argp_option options[] = { |
---|
59 |
{"verbose", 'v', 0, 0, "Produce verbose output" }, |
---|
60 |
{"port", 'p', "PORT", 0, "Set port" }, |
---|
61 |
{"node", 'n', "NODE", 0, "Set node" }, |
---|
62 |
{ 0 } |
---|
63 |
}; |
---|
64 |
|
---|
65 |
struct arguments |
---|
66 |
{ |
---|
67 |
arguments() |
---|
68 |
: nargs ( 0 ) |
---|
69 |
, verbose( false ) |
---|
70 |
, test( false ) |
---|
71 |
, port( 0 ) |
---|
72 |
{ |
---|
73 |
args[0] = 0; |
---|
74 |
} |
---|
75 |
|
---|
76 |
char* args[MAX_ARGS]; |
---|
77 |
int nargs; |
---|
78 |
bool verbose; |
---|
79 |
bool test; |
---|
80 |
int port; |
---|
81 |
int node; |
---|
82 |
} arguments; |
---|
83 |
|
---|
84 |
// Parse a single option. |
---|
85 |
static error_t |
---|
86 |
parse_opt( int key, char* arg, struct argp_state* state ) |
---|
87 |
{ |
---|
88 |
// Get the input argument from `argp_parse', which we |
---|
89 |
// know is a pointer to our arguments structure. |
---|
90 |
struct arguments* arguments = ( struct arguments* ) state->input; |
---|
91 |
|
---|
92 |
char* tail; |
---|
93 |
switch (key) { |
---|
94 |
case 'v': |
---|
95 |
arguments->verbose = true; |
---|
96 |
break; |
---|
97 |
case 't': |
---|
98 |
arguments->test = true; |
---|
99 |
break; |
---|
100 |
case 'p': |
---|
101 |
errno = 0; |
---|
102 |
arguments->port = strtol(arg, &tail, 0); |
---|
103 |
if (errno) { |
---|
104 |
perror("argument parsing failed:"); |
---|
105 |
return errno; |
---|
106 |
} |
---|
107 |
break; |
---|
108 |
case 'n': |
---|
109 |
errno = 0; |
---|
110 |
arguments->node = strtol(arg, &tail, 0); |
---|
111 |
if (errno) { |
---|
112 |
perror("argument parsing failed:"); |
---|
113 |
return errno; |
---|
114 |
} |
---|
115 |
break; |
---|
116 |
case ARGP_KEY_ARG: |
---|
117 |
if (state->arg_num >= MAX_ARGS) { |
---|
118 |
// Too many arguments. |
---|
119 |
argp_usage (state); |
---|
120 |
} |
---|
121 |
arguments->args[state->arg_num] = arg; |
---|
122 |
arguments->nargs++; |
---|
123 |
break; |
---|
124 |
case ARGP_KEY_END: |
---|
125 |
if(arguments->nargs<4) { |
---|
126 |
printf("not enough arguments\n"); |
---|
127 |
return -1; |
---|
128 |
} |
---|
129 |
|
---|
130 |
break; |
---|
131 |
default: |
---|
132 |
return ARGP_ERR_UNKNOWN; |
---|
133 |
} |
---|
134 |
return 0; |
---|
135 |
} |
---|
136 |
|
---|
137 |
static struct argp argp = { options, parse_opt, args_doc, doc }; |
---|
138 |
|
---|
139 |
/////////////////////////// |
---|
140 |
// main |
---|
141 |
////////////////////////// |
---|
142 |
int |
---|
143 |
main(int argc, char **argv) |
---|
144 |
{ |
---|
145 |
// arg parsing |
---|
146 |
if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { |
---|
147 |
fprintf( stderr, "Could not parse command line\n" ); |
---|
148 |
exit(-1); |
---|
149 |
} |
---|
150 |
errno = 0; |
---|
151 |
|
---|
152 |
Ieee1394Service *m_1394Service = new Ieee1394Service(); |
---|
153 |
if ( !m_1394Service ) { |
---|
154 |
debugFatal( "Could not create Ieee1349Service object\n" ); |
---|
155 |
return false; |
---|
156 |
} |
---|
157 |
|
---|
158 |
if ( !m_1394Service->initialize( arguments.port ) ) { |
---|
159 |
debugFatal( "Could not initialize Ieee1349Service object\n" ); |
---|
160 |
delete m_1394Service; |
---|
161 |
m_1394Service = 0; |
---|
162 |
return false; |
---|
163 |
} |
---|
164 |
|
---|
165 |
FocusriteVendorDependentCmd cmd( *m_1394Service ); |
---|
166 |
cmd.setVerbose( DEBUG_LEVEL_NORMAL ); |
---|
167 |
|
---|
168 |
for (int id=0; id<128;id++) { |
---|
169 |
cmd.setCommandType( AVC::AVCCommand::eCT_Status ); |
---|
170 |
cmd.setNodeId( arguments.node ); |
---|
171 |
cmd.setSubunitType( AVC::eST_Unit ); |
---|
172 |
cmd.setSubunitId( 0xff ); |
---|
173 |
cmd.m_id=id; |
---|
174 |
cmd.m_value=0; |
---|
175 |
|
---|
176 |
if ( !cmd.fire() ) { |
---|
177 |
debugError( "FocusriteVendorDependentCmd info command failed\n" ); |
---|
178 |
// shouldn't this be an error situation? |
---|
179 |
// return false; |
---|
180 |
} |
---|
181 |
printf("%04d: %08X\n", cmd.m_id, cmd.m_value); |
---|
182 |
} |
---|
183 |
|
---|
184 |
|
---|
185 |
delete m_1394Service; |
---|
186 |
|
---|
187 |
return 0; |
---|
188 |
} |
---|
189 |
|
---|