1 |
kusanagi |
5.1 |
/************************************************************ |
2 |
|
|
* 20/9/2005 modified by david fedele to read buffer-data |
3 |
|
|
* instead raw-data-file |
4 |
|
|
************************************************************** |
5 |
kusanagi |
1.1 |
* include needed system headers |
6 |
|
|
*/ |
7 |
|
|
#include <stdio.h> /* include standard i/o library */ |
8 |
|
|
#include <stdlib.h> /* include standard library */ |
9 |
|
|
#include <string.h> /* include string library */ |
10 |
|
|
#include <unistd.h> /* include unix standard library */ |
11 |
|
|
#include <sys/types.h> /* */ |
12 |
|
|
#include <sys/stat.h> /* */ |
13 |
|
|
#include <fcntl.h> /* */ |
14 |
|
|
#include <errno.h> /* error simbol definitions */ |
15 |
|
|
#include <time.h> /* system time definitions */ |
16 |
|
|
#include <math.h> /* math library */ |
17 |
kusanagi |
5.1 |
/************************************************************ |
18 |
|
|
* 20/9/2005 modified by david fedele */ |
19 |
|
|
/* void readbad_(unsigned short *bad_buf, int *error, int *fd) */ |
20 |
|
|
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); |
21 |
kusanagi |
1.1 |
|
22 |
kusanagi |
5.1 |
void readbad_(unsigned short *bad_buf, int *error,char *buffer, int *len,int *curpos) |
23 |
|
|
/**************************************************************/ |
24 |
kusanagi |
1.1 |
{ |
25 |
|
|
int i,j,ii,jj; |
26 |
kusanagi |
5.1 |
unsigned int word; |
27 |
|
|
unsigned int skip; |
28 |
|
|
unsigned int bad_buf_temp[64]; |
29 |
kusanagi |
1.1 |
|
30 |
|
|
*error=0; |
31 |
kusanagi |
5.1 |
/************************************************************ |
32 |
|
|
* 20/9/2005 modified by david fedele */ |
33 |
|
|
/* int nread; */ |
34 |
|
|
|
35 |
|
|
/* /\*** read the buffer ***\/ */ |
36 |
|
|
/* nread=read(*fd, bad_buf_temp, 2*64); */ |
37 |
|
|
/* if( nread==0 ) { */ |
38 |
|
|
/* printf("readbad: Unexpected end of file %d at %d \n",*fd,nread); */ |
39 |
|
|
/* *error=1; */ |
40 |
|
|
/* return ; */ |
41 |
|
|
/* } */ |
42 |
|
|
/* if ( nread != 2*64) { */ |
43 |
|
|
/* printf("readbad: Error on reading: nread = %d \n",nread); */ |
44 |
|
|
/* *error=-1; */ |
45 |
|
|
/* return ; */ |
46 |
|
|
/* } */ |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/* /\*** correct byte ***\/ //endianess... */ |
50 |
|
|
/* for(i=0; i<64; i++) { */ |
51 |
|
|
/* word = bad_buf_temp[i]; */ |
52 |
|
|
/* bad_buf_temp[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */ |
53 |
|
|
/* } */ |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
int nbytes2=2; |
57 |
|
|
char *buff=buffer; |
58 |
kusanagi |
6.1 |
|
59 |
|
|
if( *curpos+64+2>*len ) { |
60 |
kusanagi |
5.1 |
printf("readbad: Unexpected end of file \n"); |
61 |
kusanagi |
1.1 |
*error=1; |
62 |
|
|
return ; |
63 |
|
|
} |
64 |
kusanagi |
6.1 |
|
65 |
|
|
for(i=0; i<64; i++) |
66 |
|
|
getbytes_(&nbytes2,buff,curpos,&bad_buf_temp[i]); |
67 |
|
|
|
68 |
kusanagi |
5.1 |
/*****************************************************************/ |
69 |
kusanagi |
1.1 |
|
70 |
|
|
|
71 |
|
|
for(i=0; i<64; i++) { |
72 |
|
|
|
73 |
|
|
word = bad_buf_temp[i]; |
74 |
|
|
|
75 |
|
|
for(j=0; j<16; j++) { |
76 |
|
|
|
77 |
|
|
jj=15-j; |
78 |
|
|
ii=j+i*16; |
79 |
|
|
|
80 |
|
|
bad_buf[ii] = ( (word >> jj) & 0x0001 ); |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
|
89 |
|
|
// for( i=0; i<64; i++) printf("%i %x \n",i,bad_buf_temp[i]);//??? */ |
90 |
|
|
|
91 |
|
|
// printf("\n");//??? */ |
92 |
|
|
|
93 |
|
|
// for( i=0; i<1024; i++) printf("%i %i \n",i,bad_buf[i]);//??? */ |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
//legge la parola di fine ladder... per saltarla... |
107 |
kusanagi |
5.1 |
/************************************************************ |
108 |
|
|
* 20/9/2005 modified by david fedele */ |
109 |
kusanagi |
1.1 |
/* /\*** read the buffer ***\/ */ |
110 |
kusanagi |
5.1 |
/* nread=read(*fd, &skip, 2); */ |
111 |
kusanagi |
1.1 |
/* if( nread==0 ) { */ |
112 |
|
|
/* printf("readbad: Unexpected end of file %d at %d \n",*fd,nread); */ |
113 |
|
|
/* *error=1; */ |
114 |
|
|
/* return ; */ |
115 |
|
|
/* } */ |
116 |
kusanagi |
5.1 |
/* if ( nread != 2) { */ |
117 |
kusanagi |
1.1 |
/* printf("readbad: Error on reading: nread = %d \n",nread); */ |
118 |
|
|
/* *error=-1; */ |
119 |
|
|
/* return ; */ |
120 |
|
|
/* } */ |
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
kusanagi |
5.1 |
/* // for( i=0; i<64; i++) printf("%x \n",bad_buf[i]);//??? */ |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
/* /\* *error=0; *\/ */ |
131 |
|
|
|
132 |
|
|
/* /\* /\\*** read the buffer ***\\/ *\/ */ |
133 |
|
|
/* /\* nread=read(*fd, bad_buf, 2*64); *\/ */ |
134 |
|
|
/* /\* if( nread==0 ) { *\/ */ |
135 |
|
|
/* /\* printf("readbad: Unexpected end of file %d at %d \n",*fd,nread); *\/ */ |
136 |
|
|
/* /\* *error=1; *\/ */ |
137 |
|
|
/* /\* return ; *\/ */ |
138 |
|
|
/* /\* } *\/ */ |
139 |
|
|
/* /\* if ( nread != 2*64) { *\/ */ |
140 |
|
|
/* /\* printf("readbad: Error on reading: nread = %d \n",nread); *\/ */ |
141 |
|
|
/* /\* *error=-1; *\/ */ |
142 |
|
|
/* /\* return ; *\/ */ |
143 |
|
|
/* /\* } *\/ */ |
144 |
|
|
|
145 |
|
|
|
146 |
|
|
/* /\* /\\*** correct byte ***\\/ //endianess... *\/ */ |
147 |
|
|
/* /\* for(i=0; i<64; i++) { *\/ */ |
148 |
|
|
/* /\* word = bad_buf[i]; *\/ */ |
149 |
|
|
/* /\* bad_buf[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); *\/ */ |
150 |
|
|
/* /\* } *\/ */ |
151 |
|
|
|
152 |
|
|
/* /\* //legge la parola di fine ladder... per saltarla... *\/ */ |
153 |
|
|
|
154 |
|
|
/* /\* /\\*** read the buffer ***\\/ *\/ */ |
155 |
|
|
/* /\* nread=read(*fd, &skip, 2); *\/ */ |
156 |
|
|
/* /\* if( nread==0 ) { *\/ */ |
157 |
|
|
/* /\* printf("readbad: Unexpected end of file %d at %d \n",*fd,nread); *\/ */ |
158 |
|
|
/* /\* *error=1; *\/ */ |
159 |
|
|
/* /\* return ; *\/ */ |
160 |
|
|
/* /\* } *\/ */ |
161 |
|
|
/* /\* if ( nread != 2) { *\/ */ |
162 |
|
|
/* /\* printf("readbad: Error on reading: nread = %d \n",nread); *\/ */ |
163 |
|
|
/* /\* *error=-1; *\/ */ |
164 |
|
|
/* /\* return ; *\/ */ |
165 |
|
|
/* /\* } *\/ */ |
166 |
kusanagi |
1.1 |
|
167 |
kusanagi |
5.1 |
|
168 |
kusanagi |
6.1 |
getbytes_(&nbytes2,buff,curpos,&skip); |
169 |
kusanagi |
5.1 |
|
170 |
kusanagi |
6.1 |
/* if( *curpos-1>*len ) { */ |
171 |
|
|
/* printf("readbad: Unexpected end of file \n"); */ |
172 |
|
|
/* *error=1; */ |
173 |
|
|
/* return ; */ |
174 |
|
|
/* } */ |
175 |
kusanagi |
5.1 |
/*****************************************************************/ |
176 |
kusanagi |
1.1 |
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
/* // for( i=0; i<64; i++) printf("%x \n",bad_buf[i]);//??? */ |
180 |
|
|
|
181 |
|
|
return; |
182 |
|
|
} |