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

Revision 2802, 3.8 kB (checked in by jwoithe, 3 years ago)

Cosmetic: "Firewire" becomes "FireWire?".

Officially both the "F" and "W" were capitalised in the FireWire? name, so
reflect this throughout FFADO's source tree. This mostly affects comments.

This patch originated from pander on the ffado-devel mailing list. To
maintain consistency, the committed version has been expanded to include
files not originally included in the original patch.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Pieter Palmers
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 "downloader.h"
28
29 #include "libieee1394/configrom.h"
30 #include "libieee1394/ieee1394service.h"
31
32 #include "debugmodule/debugmodule.h"
33
34 #include <iostream>
35 #include <cstdlib>
36 #include <cstring>
37
38 using namespace std;
39
40 DECLARE_GLOBAL_DEBUG_MODULE;
41
42 static char args_doc[] = "OPERATION [ARGUMENTS]";
43 static struct argp _argp = { options, parse_opt, args_doc, doc };
44 struct argp* argp = &_argp;
45 static struct arguments _args = { {0}, };
46 struct arguments* args = &_args;
47
48 error_t
49 parse_opt( int key, char* arg, struct argp_state* state )
50 {
51     // Get the input argument from `argp_parse', which we
52     // know is a pointer to our arguments structure.
53     struct arguments* arguments = ( struct arguments* ) state->input;
54    
55     char* tail;
56     switch (key) {
57     case 'v':
58         if (arg) {
59             arguments->verbose = strtol( arg, &tail, 0 );
60             if ( errno ) {
61                 debugError( "Could not parse 'verbose' argument\n" );
62                 return ARGP_ERR_UNKNOWN;
63             }
64         }
65         break;
66     case 'p':
67         errno = 0;
68         arguments->port = strtol(arg, &tail, 0);
69         if (errno) {
70             debugError("argument parsing failed: %s\n",
71                        strerror(errno));
72             return errno;
73         }
74         break;
75     case 'g':
76         errno = 0;
77         arguments->guid = strtoll(arg, &tail, 0);
78         if (errno) {
79             debugError("argument parsing failed: %s\n",
80                        strerror(errno));
81             return errno;
82         }
83         break;
84     case 'm':
85         errno = 0;
86         arguments->magic = strtoll(arg, &tail, 0);
87         if (errno) {
88             debugError("argument parsing failed: %s\n",
89                        strerror(errno));
90             return errno;
91         }
92         break;
93     case 'f':
94         arguments->force = 1;
95         break;
96     case 'b':
97         arguments->no_bootloader_restart = 1;
98         break;
99     case ARGP_KEY_ARG:
100         if (state->arg_num >= MAX_NB_ARGS) {
101             // Too many arguments.
102             argp_usage (state);
103         }
104        
105         arguments->args[state->arg_num] = arg;
106         arguments->nargs = state->arg_num;
107         break;
108     case ARGP_KEY_END:
109         arguments->nargs = state->arg_num;
110         break;
111     default:
112         return ARGP_ERR_UNKNOWN;
113     }
114     return 0;
115 }
116
117 void
118 printDeviceList()
119 {
120     Ieee1394Service service;
121     // switch off all messages since they mess up the list
122     service.setVerboseLevel(0);
123     if ( !service.initialize( args->port ) ) {
124         cerr << "Could not initialize IEEE 1394 service" << endl;
125         exit(-1);
126     }
127
128     cout << "Node id        GUID                  Vendor - Model" << endl;
129     for (int i = 0; i < service.getNodeCount(); i++) {
130         ConfigRom crom(service, i);
131         if (!crom.initialize())
132             break;
133
134         cout << i << "             "
135              << " 0x" <<  crom.getGuidString()
136              << "    '" << crom.getVendorName()
137              << "' - '" << crom.getModelName() << "'" << endl;
138     }
139 }
Note: See TracBrowser for help on using the browser.