root/branches/streaming-rework/tests/test-fw410.cpp

Revision 336, 6.4 kB (checked in by pieterpalmers, 16 years ago)

- Merged the developments on trunk since branch-off:

branch occurred at rev 194
svn merge -r 194:HEAD https://svn.sourceforge.net/svnroot/freebob/trunk/libfreebob

- Modified libfreebobavc to use the messagebuffer for debug info.
- This should compile and run

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