root/trunk/libffado/tests/systemtests/test-isorecv-1.cpp

Revision 1234, 7.2 kB (checked in by holin, 16 years ago)

fix gcc 4.3 compile errors and some warnings (largely from Adrian Knoth)

Line 
1 /*
2  * Parts Copyright (C) 2005-2008 by Pieter Palmers
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 /*
25  * based on howdyget.c (unknown source, maybe Maas Digital LLC)
26  */
27
28 #include <libraw1394/raw1394.h>
29 #include <stdio.h>
30 #include <errno.h>
31 #include <unistd.h>
32
33 #include <argp.h>
34
35 #include "debugmodule/debugmodule.h"
36 #include "realtimetools.h"
37 #include <cstdlib>
38
39 uint32_t count = 0;
40
41 DECLARE_GLOBAL_DEBUG_MODULE;
42
43 #define MAX_EXTRA_ARGS 2
44 // Program documentation.
45 // Program documentation.
46 static char doc[] = "FFADO -- ISO receive test\n\n";
47
48 // A description of the arguments we accept.
49 static char args_doc[] = "";
50
51 struct arguments
52 {
53     long int verbose;
54     long int port;
55     long int channel;
56     long int packetsize;
57     long int buffersize;
58     long int interval;
59     long int countdown;
60     long int startoncycle;
61     long int printinterval;
62     long int rtprio;
63     char* args[MAX_EXTRA_ARGS];
64 };
65
66 // The options we understand.
67 static struct argp_option options[] = {
68     {"verbose",  'v', "level",    0,  "Verbose level" },
69     {"port",  'p', "port",  0,  "firewire port to use" },
70     {"channel",  'c', "channel",  0,  "iso channel to use" },
71     {"packetsize",  's', "packetsize",  0,  "packet size to use" },
72     {"buffersize",  'b', "buffersize",  0,  "number of packets to buffer" },
73     {"interval",  'i', "interval",  0,  "interrupt interval in packets" },
74     {"startoncycle",  't', "cycle",  0,  "start on a specific cycle" },
75      {"countdown",  'u', "count",  0,  "number of iterations to run" },
76     {"printinterval",  'r', "packets",  0,  "number of packets between successive status prints" },
77     {"rtprio",  'P', "prio",  0,  "real time priority of the iterator process/thread (0 = no RT)" },
78     { 0 }
79 };
80
81 // Parse a single option.
82 #define PARSE_ARG_LONG(XXletterXX, XXvarXX, XXdescXX) \
83     case XXletterXX: \
84         if (arg) { \
85             XXvarXX = strtol( arg, &tail, 0 ); \
86             if ( errno ) { \
87                 fprintf( stderr,  "Could not parse '%s' argument\n", XXdescXX ); \
88                 return ARGP_ERR_UNKNOWN; \
89             } \
90         } \
91         break;
92
93 static error_t
94 parse_opt( int key, char* arg, struct argp_state* state )
95 {
96     // Get the input argument from `argp_parse', which we
97     // know is a pointer to our arguments structure.
98     struct arguments* arguments = ( struct arguments* ) state->input;
99     char* tail;
100
101     errno = 0;
102     switch (key) {
103     PARSE_ARG_LONG('v', arguments->verbose, "verbose");
104     PARSE_ARG_LONG('p', arguments->port, "port");
105     PARSE_ARG_LONG('c', arguments->channel, "channel");
106     PARSE_ARG_LONG('s', arguments->packetsize, "packetsize");
107     PARSE_ARG_LONG('b', arguments->buffersize, "buffersize");
108     PARSE_ARG_LONG('i', arguments->interval, "interval");
109     PARSE_ARG_LONG('u', arguments->countdown, "countdown");
110     PARSE_ARG_LONG('r', arguments->printinterval, "printinterval");
111     PARSE_ARG_LONG('t', arguments->startoncycle, "startoncycle");
112     PARSE_ARG_LONG('P', arguments->rtprio, "rtprio");
113
114     case ARGP_KEY_ARG:
115         break;
116     case ARGP_KEY_END:
117         break;
118     default:
119         return ARGP_ERR_UNKNOWN;
120     }
121     return 0;
122 }
123
124 // Our argp parser.
125 static struct argp argp = { options, parse_opt, args_doc, doc };
126
127 // the global arguments struct
128 struct arguments arguments;
129
130 int last_cycle = -1;
131
132 static enum raw1394_iso_disposition myISOGetter(raw1394handle_t handle,
133         unsigned char *data,
134         unsigned int len,
135         unsigned char channel,
136         unsigned char tag,
137         unsigned char sy,
138         unsigned int cycle,
139         unsigned int dropped1)
140 {
141     unsigned int skipped = (dropped1 & 0xFFFF0000) >> 16;
142     unsigned int dropped = dropped1 & 0xFFFF;
143
144     //debugOutput(DEBUG_LEVEL_INFO, "In handler\n");
145     //sprintf((char *)data, "Hello World %8u\n", count);
146     if (last_cycle >= 0) {
147         if (cycle != ((unsigned int)last_cycle + 1) % 8000) {
148             debugOutput(DEBUG_LEVEL_INFO, "nonmonotonic cycles: this: %04d, last: %04d, dropped: 0x%08X\n", cycle, last_cycle, dropped1);
149         }
150     }
151     last_cycle = cycle;
152     count++;
153     if(dropped) debugOutput(DEBUG_LEVEL_INFO, "Dropped packets! (%d)\n", dropped);
154     if(skipped) debugOutput(DEBUG_LEVEL_INFO, "Skipped packets! (%d)\n", skipped);
155     if (count % arguments.printinterval == 0) debugOutput(DEBUG_LEVEL_INFO, "cycle=%d count=%d\n", cycle, count);
156     return RAW1394_ISO_OK;
157 }
158
159 int main(int argc, char **argv)
160 {
161     raw1394handle_t handle;
162
163     // Default values.
164     arguments.verbose = DEBUG_LEVEL_VERBOSE;
165     arguments.port = 0;
166     arguments.channel = 0;
167     arguments.packetsize = 1024;
168     arguments.buffersize = 100;
169     arguments.interval = -1;
170     arguments.startoncycle = -1;
171     arguments.countdown = 10000;
172     arguments.printinterval = 100;
173     arguments.rtprio = 0;
174
175     // Parse our arguments; every option seen by `parse_opt' will
176     // be reflected in `arguments'.
177     if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) {
178         debugError("Could not parse command line\n" );
179         return -1;
180     }
181
182     debugOutput(DEBUG_LEVEL_INFO, "Get 1394 handle...\n");
183     handle = raw1394_new_handle();
184     if(!handle)
185     {
186         perror("raw1394_new_handle");
187         return -1;
188     }
189
190     debugOutput(DEBUG_LEVEL_INFO, "Select 1394 port %d...\n", arguments.port);
191     do
192     {
193         if (raw1394_get_port_info(handle, NULL, 0) < 0)
194         {
195             perror("raw1394_get_port_info");
196             return 1;
197         }
198         raw1394_set_port(handle, arguments.port);
199     } while (errno == ESTALE);
200
201     if(errno)
202     {
203         perror("raw1394_set_port");
204         return 1;
205     }
206
207     debugOutput(DEBUG_LEVEL_INFO, "Init ISO receive...\n");
208     if(raw1394_iso_recv_init(handle,
209                 myISOGetter,
210                 arguments.buffersize,
211                 arguments.packetsize,
212                 arguments.channel,
213                 RAW1394_DMA_DEFAULT,
214                 arguments.interval))
215     {
216         perror("raw1394_iso_recv_init");
217         return 1;
218     }
219
220     debugOutput(DEBUG_LEVEL_INFO, "Start ISO receive...\n");
221     if(raw1394_iso_recv_start(handle, arguments.startoncycle, 0xF, 0))
222     {
223         perror("raw1394_iso_recv_start");
224         return 1;
225     }
226
227     debugOutput(DEBUG_LEVEL_INFO, "Setting RT priority (%d)...\n", arguments.rtprio);
228     set_realtime_priority(arguments.rtprio);
229
230     debugOutput(DEBUG_LEVEL_INFO, "Starting iterate loop...\n");
231     int countdown = arguments.countdown;
232     while(countdown--)
233     {
234         if(raw1394_loop_iterate(handle))
235         {
236             perror("raw1394_loop_iterate");
237             return 1;
238         }
239     }
240     return 0;
241 }
Note: See TracBrowser for help on using the browser.