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

Revision 1184, 5.5 kB (checked in by ppalmers, 13 years ago)

add some extra saffire pro control elements

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
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     errno = 0;
94     switch (key) {
95     case 'v':
96         arguments->verbose = true;
97         break;
98     case 't':
99         arguments->test = true;
100         break;
101     case 'p':
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         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         SleepRelativeUsec(1000000);
194     }
195
196
197     delete m_1394Service;
198
199     return 0;
200 }
201
Note: See TracBrowser for help on using the browser.