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

Revision 742, 5.4 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

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