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

Revision 2802, 6.4 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  *
4  * This file is part of FFADO
5  * FFADO = Free FireWire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include <libraw1394/raw1394.h>
25 #include <libiec61883/iec61883.h>
26
27 #include <argp.h>
28 #include <stdlib.h>
29 #include <iostream>
30 #include <unistd.h>
31
32 using namespace std;
33
34 ////////////////////////////////////////////////
35 // arg parsing
36 ////////////////////////////////////////////////
37 const char *argp_program_version = "test-fw410 0.1";
38 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
39 static char doc[] = "test-fw410 -- test program to get the fw410 streaming";
40 static char args_doc[] = "NODE_ID";
41 static struct argp_option options[] = {
42     {"verbose",   'v', 0,           0,  "Produce verbose output" },
43     {"port",      'p', "PORT",      0,  "Set port" },
44    { 0 }
45 };
46
47 struct arguments
48 {
49     arguments()
50         : verbose( false )
51         , test( false )
52         , port( 0 )
53         {
54             args[0] = 0;
55         }
56
57     char* args[1];
58     bool  verbose;
59     bool  test;
60     int   port;
61 } arguments;
62
63 // Parse a single option.
64 static error_t
65 parse_opt( int key, char* arg, struct argp_state* state )
66 {
67     // Get the input argument from `argp_parse', which we
68     // know is a pointer to our arguments structure.
69     struct arguments* arguments = ( struct arguments* ) state->input;
70
71     char* tail;
72     switch (key) {
73     case 'v':
74         arguments->verbose = true;
75         break;
76     case 't':
77         arguments->test = true;
78         break;
79     case 'p':
80         errno = 0;
81         arguments->port = strtol(arg, &tail, 0);
82         if (errno) {
83             perror("argument parsing failed:");
84             return errno;
85         }
86         break;
87     case ARGP_KEY_ARG:
88         if (state->arg_num >= 1) {
89             // Too many arguments.
90             argp_usage (state);
91         }
92         arguments->args[state->arg_num] = arg;
93         break;
94     case ARGP_KEY_END:
95         if (state->arg_num < 1) {
96             // Not enough arguments.
97             argp_usage (state);
98         }
99         break;
100     default:
101         return ARGP_ERR_UNKNOWN;
102     }
103     return 0;
104 }
105
106 static struct argp argp = { options, parse_opt, args_doc, doc };
107
108 ///////////////////////////
109 // main
110 //////////////////////////
111 int
112 main(int argc, char **argv)
113 {
114     // arg parsing
115     argp_parse (&argp, argc, argv, 0, 0, &arguments);
116
117     errno = 0;
118     char* tail;
119     int iNodeId = strtol(arguments.args[0], &tail, 0);
120     if (errno) {
121     perror("argument parsing failed:");
122     return -1;
123     }
124
125     raw1394handle_t pHandle = raw1394_new_handle_on_port( arguments.port );
126     if ( !pHandle ) {
127         if ( !errno ) {
128             cerr << "libraw1394 not compatible" << endl;
129         } else {
130             perror( "Could not get 1394 handle" );
131             cerr << "Is ieee1394 and raw1394 driver loaded?" << endl;
132         }
133         return -1;
134     }
135
136     struct Connection {
137         int m_output;
138         int m_oplug;
139         int m_input;
140         int m_iplug;
141         int m_iBandwith;
142         int m_iIsoChannel;
143     };
144
145
146     int iLocalId  = raw1394_get_local_id( pHandle );
147     int iRemoteId = iNodeId | 0xffc0;
148     Connection cons[] = {
149         //   output,  oplug,     input, iplug, bandwith, iso channel
150         { iRemoteId,      0,  iLocalId,    -1,    0x148,          -1 },     // oPCR[0]
151         { iRemoteId,      1,  iLocalId,    -1,    0x148,          -1 },     // oPCR[1]
152         //        { iRemoteId,      2,  iLocalId,    -1,        0,          -1 },     // oPCR[2]: cmp not supported
153         {  iLocalId,     -1, iRemoteId,     0,    0x148,          -1 },     // iPCR[0]
154         {  iLocalId,     -1, iRemoteId,     1,    0x148,          -1 },     // iPCR[1]
155         //        {  iLocalId,     -1, iRemoteId,     2,        0,          -1 },     // iPCR[2]: cmp not supported
156     };
157
158     printf( "local node id %d\n", iLocalId  & ~0xffc0);
159     printf( "remote node id %d\n", iRemoteId & ~0xffc0);
160
161     for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
162         Connection* pCons = &cons[i];
163
164         // the bandwith calculation fails, so its better to use
165         // some default values.
166         pCons->m_iBandwith = iec61883_cmp_calc_bandwidth ( pHandle,
167                                                            pCons->m_output,
168                                                            pCons->m_oplug,
169                                                            IEC61883_DATARATE_400 );
170         sleep(1);
171         pCons->m_iIsoChannel = iec61883_cmp_connect( pHandle,
172                                                      pCons->m_output,
173                                                      &pCons->m_oplug,
174                                                      pCons->m_input,
175                                                      &pCons->m_iplug,
176                                                      &pCons->m_iBandwith );
177         printf( "%2d -> %2d %cPCR[%2d]: bw = %4d, ch = %2d\n",
178                 pCons->m_output & ~0xffc0,
179                 pCons->m_input & ~0xffc0,
180                 pCons->m_oplug == -1? 'i' : 'o',
181                 pCons->m_oplug == -1? pCons->m_iplug: pCons->m_oplug,
182                 pCons->m_iBandwith,
183                 pCons->m_iIsoChannel );
184         sleep(1);
185     }
186
187     sleep( 3 );
188
189     for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
190         Connection* pCons = &cons[i];
191
192         if ( pCons->m_iIsoChannel != -1 ) {
193             iec61883_cmp_disconnect( pHandle,
194                                      pCons->m_output,
195                                      pCons->m_oplug,
196                                      pCons->m_input,
197                                      pCons->m_iplug,
198                                      pCons->m_iIsoChannel,
199                                      pCons->m_iBandwith );
200
201
202         }
203     }
204
205
206     raw1394_destroy_handle( pHandle );
207     return 0;
208 }
Note: See TracBrowser for help on using the browser.