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

Revision 742, 6.4 kB (checked in by ppalmers, 16 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

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