| 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 |
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 |
#define TOTAL_IDS_TO_SCAN 128 |
|---|
| 169 |
uint32_t old_vals[TOTAL_IDS_TO_SCAN+1]; |
|---|
| 170 |
|
|---|
| 171 |
while(1) { |
|---|
| 172 |
for (int id=0; id<TOTAL_IDS_TO_SCAN;id++) { |
|---|
| 173 |
if (id==64) continue; // metering |
|---|
| 174 |
if (id==65) continue; // metering |
|---|
| 175 |
if (id==66) continue; // metering |
|---|
| 176 |
if (id==67) continue; // metering |
|---|
| 177 |
cmd.setCommandType( AVC::AVCCommand::eCT_Status ); |
|---|
| 178 |
cmd.setNodeId( arguments.node ); |
|---|
| 179 |
cmd.setSubunitType( AVC::eST_Unit ); |
|---|
| 180 |
cmd.setSubunitId( 0xff ); |
|---|
| 181 |
cmd.m_id=id; |
|---|
| 182 |
cmd.m_value=0; |
|---|
| 183 |
|
|---|
| 184 |
if ( !cmd.fire() ) { |
|---|
| 185 |
debugError( "FocusriteVendorDependentCmd info command failed\n" ); |
|---|
| 186 |
// shouldn't this be an error situation? |
|---|
| 187 |
// return false; |
|---|
| 188 |
} |
|---|
| 189 |
if (old_vals[id] != cmd.m_value) { |
|---|
| 190 |
printf("%04d changed from %08X to %08X\n", cmd.m_id, old_vals[id], cmd.m_value); |
|---|
| 191 |
old_vals[id] = cmd.m_value; |
|---|
| 192 |
} |
|---|
| 193 |
} |
|---|
| 194 |
SleepRelativeUsec(1000000); |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
delete m_1394Service; |
|---|
| 199 |
|
|---|
| 200 |
return 0; |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|