1 |
/* |
/************************************************************ |
2 |
|
* 20/9/2005 modified by david fedele to read buffer-data |
3 |
|
* instead raw-data-file |
4 |
|
************************************************************** |
5 |
* include needed system headers |
* include needed system headers |
6 |
*/ |
*/ |
7 |
#include <stdio.h> /* include standard i/o library */ |
#include <stdio.h> /* include standard i/o library */ |
17 |
|
|
18 |
void unpacking(int ndata, unsigned short *output); |
void unpacking(int ndata, unsigned short *output); |
19 |
|
|
20 |
void dunpacker_(int *l_buffer, unsigned short *buffer, int *error, int *fd) |
/************************************************************ |
21 |
|
* 20/9/2005 modified by david fedele */ |
22 |
|
/* void dunpacker_(int *l_buffer, unsigned short *buffer, int *error, int *fd) */ |
23 |
|
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); |
24 |
|
|
25 |
|
void dunpacker_(int *l_buffer, unsigned short *buff, int *error,char *buffer, int *len,int *curpos) |
26 |
|
/**************************************************************/ |
27 |
{ |
{ |
28 |
int i; |
int i; |
29 |
int nhead,nread; |
int nhead; |
|
unsigned short word; |
|
|
|
|
|
*error = 0; |
|
30 |
|
|
31 |
nhead = 13; /* packed */ |
nhead = 13; /* packed */ |
32 |
|
*error=0; |
33 |
|
/************************************************************ |
34 |
|
* 20/9/2005 modified by david fedele */ |
35 |
|
/* int nread; */ |
36 |
|
/* unsigned int word; */ |
37 |
|
|
38 |
|
/* nread=read(*fd, buffer, 2**l_buffer); */ |
39 |
|
|
40 |
|
/* if( nread==0 ) { */ |
41 |
|
/* printf("dunpacker: Unexpected end of file %d at %d \n",*fd,nread); */ |
42 |
|
/* *error=1; */ |
43 |
|
/* return ; */ |
44 |
|
/* } */ |
45 |
|
/* if ( nread != 2**l_buffer) { */ |
46 |
|
/* printf("dunpacker: Error on reading: nread = %d \n",nread); */ |
47 |
|
/* *error=-1; */ |
48 |
|
/* return ; */ |
49 |
|
/* } */ |
50 |
|
|
51 |
|
|
52 |
|
/* /\*** correct byte ***\/ */ |
53 |
|
/* for(i=0; i<*l_buffer; i++) { */ |
54 |
|
/* word = buffer[i]; */ |
55 |
|
/* buffer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */ |
56 |
|
/* } */ |
57 |
|
int nbytes2=2; |
58 |
|
unsigned int word_temp; |
59 |
|
unsigned short word[*l_buffer]; |
60 |
|
|
61 |
|
|
62 |
// printf("%i \n",*l_buffer); |
if( *curpos+(2*(*l_buffer))>*len ) { |
63 |
|
// printf("dunpacker: Unexpected end of file\n"); |
|
|
|
|
/* /\*** read the data ***\/ */ |
|
|
// if( nhead == 13) *l_buffer = (*l_buffer*13)/16+1; /* packed */ |
|
|
nread=read(*fd, buffer, 2**l_buffer); |
|
|
|
|
|
if( nread==0 ) { |
|
|
printf("dunpacker: Unexpected end of file %d at %d \n",*fd,nread); |
|
64 |
*error=1; |
*error=1; |
65 |
return ; |
return ; |
66 |
} |
} |
|
if ( nread != 2**l_buffer) { |
|
|
printf("dunpacker: Error on reading: nread = %d \n",nread); |
|
|
*error=-1; |
|
|
return ; |
|
|
} |
|
67 |
|
|
68 |
|
for(i=0;i<*l_buffer;i++){ |
69 |
/*** correct byte ***/ |
getbytes_(&nbytes2,buffer,curpos,&word_temp); |
70 |
for(i=0; i<*l_buffer; i++) { |
word[i]=word_temp; |
71 |
word = buffer[i]; |
buff[i]=word[i]; |
|
buffer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); |
|
72 |
} |
} |
73 |
|
|
74 |
/*** unpacking buffer data ***/ |
/*** unpacking buffer data ***/ |
75 |
if( nhead == 13) unpacking(*l_buffer, buffer); |
/************************************************************ |
76 |
|
* 20/9/2005 modified by david fedele */ |
77 |
// int num = (*l_buffer-13-1)/13*16+3;//??? |
/* if( nhead == 13) unpacking(*l_buffer, buffer); */ |
78 |
// for( i=0; i<num; i++) printf("%i %x \n",i,buffer[i]);//??? |
if( nhead == 13) unpacking(*l_buffer, buff); |
79 |
|
/**************************************************************/ |
80 |
|
|
81 |
|
|
82 |
|
/* int num = (*l_buffer-13-1)/13*16+3;//??? */ |
83 |
|
/* for( i=0; i<num; i++) printf("%i %x \n",i,buffer[i]);//??? */ |
84 |
|
|
85 |
/* /\*** Checksum ***\/ */ |
/*** Checksum ***/ |
86 |
/* oi = buffer; */ |
/* *oi = buffer; */ |
87 |
/* word = 0; */ |
/* word = 0; */ |
88 |
/* for( i=0; i<l_buffer; ++i) */ |
/* for( i=0; i<*l_buffer; ++i) */ |
89 |
/* word = (word + *oi++) & 0x03ff; */ |
/* word = (word + *oi++)& 0x03ff; */ |
90 |
/* if( word == ( header[6] & 0x03ff ) ) */ |
/* if( word == ( header[6] & 0x03ff ) ) */ |
91 |
/* /\* printf("Check Sum OK \n")*\/ ; */ |
/* /\* printf("Check Sum OK \n")*\/ ; */ |
92 |
/* else */ |
/* else */ |
103 |
/*========================================================= */ |
/*========================================================= */ |
104 |
/*========================================================= */ |
/*========================================================= */ |
105 |
void unpacking(int nwords, unsigned short *output) { |
void unpacking(int nwords, unsigned short *output) { |
106 |
unsigned short out[10000]; |
unsigned short out[nwords]; |
107 |
int k; |
int k; |
108 |
unsigned short *oi, *oo, *o1; |
unsigned short *oi, *oo, *o1; |
109 |
|
|
110 |
for( k=0; k<10000; ++k) |
for( k=0; k<nwords; ++k) |
111 |
out[k]=0; |
out[k]=0; |
112 |
oo=output; |
oo=output; |
113 |
oi=out; |
oi=out; |