root/trunk/libffado/tests/streaming/debugtools.c

Revision 742, 5.3 kB (checked in by ppalmers, 13 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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  * Copyright (C) 2005-2007 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 3 of the License, or
13  * (at your option) any later version.
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 <libraw1394/raw1394.h>
26 #include <libiec61883/iec61883.h>
27 #include "debugtools.h"
28 #include <stdio.h>
29 #include <netinet/in.h>
30
31 ////////////////////////////////////////////////////////////////
32 ////////////////////////////////////////////////////////////////
33
34 unsigned char
35 toAscii( unsigned char c )
36 {
37     if ( ( c > 31 ) && ( c < 126) ) {
38         return c;
39     } else {
40         return '.';
41     }
42 }
43
44 /* converts a quadlet to a uchar * buffer
45  * not implemented optimally, but clear
46  */
47 void
48 quadlet2char( quadlet_t quadlet, unsigned char* buff )
49 {
50     *(buff)   = (quadlet>>24)&0xFF;
51     *(buff+1) = (quadlet>>16)&0xFF;
52     *(buff+2) = (quadlet>> 8)&0xFF;
53     *(buff+3) = (quadlet)    &0xFF;
54 }
55
56 void
57 hexDump( unsigned char *data_start, unsigned int length )
58 {
59     unsigned int i=0;
60     unsigned int byte_pos;
61     unsigned int bytes_left;
62     //printf("hexdump: %p %d\n",data_start,length);
63
64     if ( length <= 0 ) {
65         return;
66     }
67     if ( length >= 7 ) {
68         for ( i = 0; i < (length-7); i += 8 ) {
69             printf( "%04X: %02X %02X %02X %02X %02X %02X %02X %02X "
70                                         "- [%c%c%c%c%c%c%c%c] - %2.5F %2.5F\n",
71
72                     i,
73
74                     *(data_start+i+0),
75                     *(data_start+i+1),
76                     *(data_start+i+2),
77                     *(data_start+i+3),
78                     *(data_start+i+4),
79                     *(data_start+i+5),
80                     *(data_start+i+6),
81                     *(data_start+i+7),
82
83                     toAscii( *(data_start+i+0) ),
84                     toAscii( *(data_start+i+1) ),
85                     toAscii( *(data_start+i+2) ),
86                     toAscii( *(data_start+i+3) ),
87                     toAscii( *(data_start+i+4) ),
88                     toAscii( *(data_start+i+5) ),
89                     toAscii( *(data_start+i+6) ),
90                     toAscii( *(data_start+i+7) ),
91                                        
92                                         (*((float *)(data_start+i+0))),
93                                         (*((float *)(data_start+i+4)))
94                                   );
95         }
96     }
97     byte_pos = i;
98     bytes_left = length - byte_pos;
99
100     printf( "%04X:" ,i );
101     for ( i = byte_pos; i < length; i += 1 ) {
102         printf( " %02X", *(data_start+i) );
103     }
104     for ( i=0; i < 8-bytes_left; i+=1 ) {
105         printf( "   " );
106     }
107
108     printf( " - [" );
109     for ( i = byte_pos; i < length; i += 1) {
110         printf( "%c", toAscii(*(data_start+i)));
111     }
112     for ( i = 0; i < 8-bytes_left; i += 1) {
113         printf( " " );
114     }
115
116     printf( "]" );
117     printf( "\n" );
118 }
119
120 void
121 hexDumpToFile( FILE* fid, unsigned char *data_start, unsigned int length )
122 {
123     unsigned int i=0;
124     unsigned int byte_pos;
125     unsigned int bytes_left;
126     //printf("hexdump: %p %d\n",data_start,length);
127
128     if ( length <= 0 ) {
129         return;
130     }
131     if ( length >= 7 ) {
132         for ( i = 0; i < (length-7); i += 8 ) {
133                         float *f1=(float *)(data_start+i+0);
134                        
135             fprintf(fid, "%04X: %02X %02X %02X %02X %02X %02X %02X %02X "
136                                         "- [%c%c%c%c%c%c%c%c] - %2.5e %2.5e\n",
137
138                     i,
139
140                     *(data_start+i+0),
141                     *(data_start+i+1),
142                     *(data_start+i+2),
143                     *(data_start+i+3),
144                     *(data_start+i+4),
145                     *(data_start+i+5),
146                     *(data_start+i+6),
147                     *(data_start+i+7),
148
149                     toAscii( *(data_start+i+0) ),
150                     toAscii( *(data_start+i+1) ),
151                     toAscii( *(data_start+i+2) ),
152                     toAscii( *(data_start+i+3) ),
153                     toAscii( *(data_start+i+4) ),
154                     toAscii( *(data_start+i+5) ),
155                     toAscii( *(data_start+i+6) ),
156                     toAscii( *(data_start+i+7) ),
157                                                        
158                                         (*(f1)),
159                                         (*(f1+1))
160                                    );
161         }
162     }
163     byte_pos = i;
164     bytes_left = length - byte_pos;
165
166     fprintf(fid, "%04X:" ,i );
167     for ( i = byte_pos; i < length; i += 1 ) {
168         fprintf(fid, " %02X", *(data_start+i) );
169     }
170     for ( i=0; i < 8-bytes_left; i+=1 ) {
171         fprintf(fid, "   " );
172     }
173
174     fprintf(fid, " - [" );
175     for ( i = byte_pos; i < length; i += 1) {
176         fprintf(fid, "%c", toAscii(*(data_start+i)));
177     }
178     for ( i = 0; i < 8-bytes_left; i += 1) {
179         fprintf(fid, " " );
180     }
181
182     fprintf(fid, "]" );
183     fprintf(fid, "\n" );
184 }
185
186
187 void
188 hexDumpQuadlets( quadlet_t *data, unsigned int length )
189 {
190     unsigned int i=0;
191
192     if ( length <= 0 ) {
193         return;
194     }
195     for (i=0;i<length;i+=1) {
196             printf( "%02d %04X: %08X (%08X)"
197                     "\n", i, i*4, data[i],ntohl(data[i]));
198     }
199 }
Note: See TracBrowser for help on using the browser.