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

Revision 2803, 5.6 kB (checked in by jwoithe, 3 years ago)

Cosmetic: capitalise "L" in "Linux".

"Linux" is a proper noun so it should start with a capital letter. These
changes are almost all within comments.

This patch was originally proposed by pander on the ffado-devel mailing
list. It has been expanded to cover all similar cases to maintain
consistency throughout the source tree.

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