root/trunk/libffado/tests/test-focusrite.cpp

Revision 1763, 5.6 kB (checked in by ppalmers, 14 years ago)

Merged revisions 1536,1541,1544-1546,1549,1554-1562,1571,1579-1581,1618,1632,1634-1635,1661,1677-1679,1703-1704,1715,1720-1723,1743-1745,1755 via svnmerge from
svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0

Also fix remaining format string warnings.

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 "libieee1394/configrom.h"
31 #include "libieee1394/ieee1394service.h"
32 #include "libutil/cmd_serialize.h"
33 #include "libavc/general/avc_generic.h"
34 #include "libutil/Time.h"
35 #include "libutil/ByteSwap.h"
36
37 #include "bebob/focusrite/focusrite_cmd.h"
38 #include "bebob/focusrite/focusrite_generic.h"
39 using namespace BeBoB::Focusrite;
40
41 #include <argp.h>
42 #include <stdlib.h>
43 #include <iostream>
44
45 using namespace std;
46 using namespace AVC;
47 using namespace Util;
48
49 DECLARE_GLOBAL_DEBUG_MODULE;
50
51 #define MAX_ARGS 1000
52
53 ////////////////////////////////////////////////
54 // arg parsing
55 ////////////////////////////////////////////////
56 const char *argp_program_version = "test-focusrite 0.1";
57 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
58 static char doc[] = "test-avccmd -- test program to examine the focusrite vendor dependent commands.";
59 static char args_doc[] = "NODE_ID";
60 static struct argp_option options[] = {
61     {"verbose",   'v', 0,           0,  "Produce verbose output" },
62     {"port",      'p', "PORT",      0,  "Set port" },
63     {"node",      'n', "NODE",      0,  "Set node" },
64    { 0 }
65 };
66
67 struct arguments
68 {
69     arguments()
70         : nargs ( 0 )
71         , verbose( false )
72         , test( false )
73         , port( 0 )
74         {
75             args[0] = 0;
76         }
77
78     char* args[MAX_ARGS];
79     int   nargs;
80     bool  verbose;
81     bool  test;
82     int   port;
83     int   node;
84 } arguments;
85
86 // Parse a single option.
87 static error_t
88 parse_opt( int key, char* arg, struct argp_state* state )
89 {
90     // Get the input argument from `argp_parse', which we
91     // know is a pointer to our arguments structure.
92     struct arguments* arguments = ( struct arguments* ) state->input;
93
94     char* tail;
95     errno = 0;
96     switch (key) {
97     case 'v':
98         arguments->verbose = true;
99         break;
100     case 't':
101         arguments->test = true;
102         break;
103     case 'p':
104         arguments->port = strtol(arg, &tail, 0);
105         if (errno) {
106             perror("argument parsing failed:");
107             return errno;
108         }
109         break;
110     case 'n':
111         arguments->node = strtol(arg, &tail, 0);
112         if (errno) {
113             perror("argument parsing failed:");
114             return errno;
115         }
116         break;
117     case ARGP_KEY_ARG:
118         if (state->arg_num >= MAX_ARGS) {
119             // Too many arguments.
120             argp_usage (state);
121         }
122         arguments->args[state->arg_num] = arg;
123         arguments->nargs++;
124         break;
125     case ARGP_KEY_END:
126
127        
128         break;
129     default:
130         return ARGP_ERR_UNKNOWN;
131     }
132     return 0;
133 }
134
135 static struct argp argp = { options, parse_opt, args_doc, doc };
136
137 ///////////////////////////
138 // main
139 //////////////////////////
140 int
141 main(int argc, char **argv)
142 {
143     // arg parsing
144     if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) {
145         fprintf( stderr, "Could not parse command line\n" );
146         exit(-1);
147     }
148     errno = 0;
149
150     Ieee1394Service *m_1394Service = new Ieee1394Service();
151     if ( !m_1394Service ) {
152         debugFatal( "Could not create Ieee1349Service object\n" );
153         return false;
154     }
155
156     if ( !m_1394Service->initialize( arguments.port ) ) {
157         debugFatal( "Could not initialize Ieee1349Service object\n" );
158         delete m_1394Service;
159         m_1394Service = 0;
160         return false;
161     }
162    
163     FocusriteVendorDependentCmd cmd( *m_1394Service );
164         cmd.setVerbose( DEBUG_LEVEL_NORMAL );
165    
166     #define TOTAL_IDS_TO_SCAN 110
167     uint32_t old_vals[TOTAL_IDS_TO_SCAN+1];
168     m_1394Service->setVerboseLevel(DEBUG_LEVEL_INFO);
169    
170     while(1) {
171         for (int id=88; id<TOTAL_IDS_TO_SCAN;id++) {
172             quadlet_t value;
173             int ntries=5;
174             bool retval = false;
175             fb_nodeaddr_t addr = FR_PARAM_SPACE_START + (id * 4);
176             fb_nodeid_t nodeId = arguments.node | 0xFFC0;
177 //             if (id==64) continue; // metering
178 //             if (id==65) continue; // metering
179 //             if (id==66) continue; // metering
180 //             if (id==67) continue; // metering
181             while(ntries-- && !(retval = m_1394Service->read_quadlet(nodeId, addr, &value))) {
182                 SleepRelativeUsec(10000);
183             }
184             if (!retval) {
185                 debugError( " read from %16"PRIX64" failed (id: %d)\n", addr, id);
186             } else {
187                 value = CondSwapFromBus32(value);
188            
189                 if (old_vals[id] != value) {
190                     printf("%04d changed from %08X to %08X\n", id,  old_vals[id], value);
191                     old_vals[id] = value;
192                 }
193             }
194         }
195         SleepRelativeUsec(1000000);
196     }
197
198
199     delete m_1394Service;
200
201     return 0;
202 }
203
Note: See TracBrowser for help on using the browser.