root/trunk/libffado/support/firmware/fireworks-downloader.cpp

Revision 739, 5.5 kB (checked in by ppalmers, 15 years ago)

- Adapt the ffado external API (upgrade to v3)

NEEDS NEW JACK BACKEND

- simplify FFADODevice constructor even more
- implement first framework support for supporting multiple adapters.

currently all firewire adapters are scanned for supported devices unless specified otherwise
however attaching devices to separate adapters is not supported. using multiple adapters at
that are connected together might work.

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 is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * FFADO is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with FFADO; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA.
23  */
24
25 #include "src/fireworks/fireworks_device.h"
26 #include "src/fireworks/fireworks_firmware.h"
27
28 #include "libieee1394/configrom.h"
29 #include "libieee1394/ieee1394service.h"
30
31 #include "debugmodule/debugmodule.h"
32
33 #include <argp.h>
34 #include <iostream>
35
36 #include <string.h>
37 #include <string>
38
39 DECLARE_GLOBAL_DEBUG_MODULE;
40
41 using namespace FireWorks;
42 ////////////////////////////////////////////////
43 // arg parsing
44 ////////////////////////////////////////////////
45 const char *argp_program_version = "fireworks-downloader 0.1";
46 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
47 static char doc[] = "fireworks-downloader -- firmware downloader application for ECHO Fireworks devices\n\n"
48                     "OPERATION: display\n"
49                     "           firmware FILE\n";
50 static char args_doc[] = "NODE_ID OPERATION";
51 static struct argp_option options[] = {
52     {"verbose",   'v', "level",     0,  "Produce verbose output" },
53     {"port",      'p', "PORT",      0,  "Set port" },
54     { 0 }
55 };
56
57 struct arguments
58 {
59     arguments()
60         : verbose( 0 )
61         , port( 0 )
62         {
63             args[0] = 0;
64             args[1] = 0;
65             args[2] = 0;
66         }
67
68     char* args[3];
69     short verbose;
70     int   port;
71 } arguments;
72
73 // Parse a single option.
74 static error_t
75 parse_opt( int key, char* arg, struct argp_state* state )
76 {
77     // Get the input argument from `argp_parse', which we
78     // know is a pointer to our arguments structure.
79     struct arguments* arguments = ( struct arguments* ) state->input;
80
81     char* tail;
82     switch (key) {
83     case 'v':
84         if (arg) {
85             arguments->verbose = strtol( arg, &tail, 0 );
86             if ( errno ) {
87                 debugError( "Could not parse 'verbose' argument\n" );
88                 return ARGP_ERR_UNKNOWN;
89             }
90         }
91         break;
92     case 'p':
93         errno = 0;
94         arguments->port = strtol(arg, &tail, 0);
95         if (errno) {
96             debugError("argument parsing failed: %s\n",
97                        strerror(errno));
98             return errno;
99         }
100         break;
101     case ARGP_KEY_ARG:
102         if (state->arg_num >= 3) {
103             // Too many arguments.
104             argp_usage (state);
105         }
106         arguments->args[state->arg_num] = arg;
107         break;
108     case ARGP_KEY_END:
109         if (state->arg_num < 2) {
110             // Not enough arguments.
111             argp_usage (state);
112         }
113         break;
114     default:
115         return ARGP_ERR_UNKNOWN;
116     }
117     return 0;
118 }
119
120 static struct argp argp = { options, parse_opt, args_doc, doc };
121
122
123 int
124 main( int argc, char** argv )
125 {
126     using namespace std;
127
128     // arg parsing
129     argp_parse (&argp, argc, argv, 0, 0, &arguments);
130
131     errno = 0;
132     char* tail;
133     int node_id = strtol(arguments.args[0], &tail, 0);
134     if (errno) {
135         debugError("argument parsing failed: %s\n",
136                     strerror(errno));
137         return -1;
138     }
139
140     Ieee1394Service service;
141     if ( !service.initialize( arguments.port ) ) {
142         debugError("Could not initialize IEEE 1394 service\n");
143         return -1;
144     }
145     service.setVerboseLevel( arguments.verbose );
146
147     ConfigRom *configRom = new ConfigRom(service, node_id );
148     if (configRom == NULL) {
149         debugError("Could not create ConfigRom\n");
150         return -1;
151     }
152     configRom->setVerboseLevel( arguments.verbose );
153
154     if ( !configRom->initialize() ) {
155         debugError( "Could not read config rom from device (node id %d).\n",
156                     node_id );
157         delete configRom;
158         return -1;
159     }
160
161     if ( !Device::probe(*configRom) ) {
162         debugError( "Device with node id %d is not an ECHO FireWorks device.\n",
163                     node_id );
164         delete configRom;
165         return -1;
166     }
167
168     Device *dev = new Device( std::auto_ptr<ConfigRom>(configRom) );
169     if (dev == NULL) {
170         debugError("Could not create FireWorks::Device\n");
171         delete configRom;
172         return -1;
173     }
174
175     // create the firmware util class
176     FirmwareUtil util = FirmwareUtil(*dev);
177     util.setVerboseLevel( arguments.verbose );
178    
179     if ( strcmp( arguments.args[1], "firmware" ) == 0 ) {
180         if (!arguments.args[2] ) {
181             cerr << "FILE argument is missing" << endl;
182             delete dev;
183             return -1;
184         }
185         std::string str( arguments.args[2] );
186
187         // load the file
188         Firmware f = Firmware();
189         f.setVerboseLevel( arguments.verbose );
190        
191         f.loadFile(str);
192         f.show();
193
194     } else if ( strcmp( arguments.args[1], "display" ) == 0 ) {
195         // nothing to do
196         dev->showDevice();
197     } else {
198         cout << "Unknown operation" << endl;
199     }
200
201     delete dev;
202     return 0;
203 }
Note: See TracBrowser for help on using the browser.