1 |
/************************************************************ |
2 |
* 12/9/2005 modified by david fedele to read buffer-data |
3 |
* instead raw-data-file |
4 |
************************************************************** |
5 |
* |
6 |
* include needed system headers |
7 |
*/ |
8 |
#include <stdio.h> /* include standard i/o library */ |
9 |
#include <stdlib.h> /* include standard library */ |
10 |
#include <string.h> /* include string library */ |
11 |
#include <unistd.h> /* include unix standard library */ |
12 |
#include <sys/types.h> /* */ |
13 |
#include <sys/stat.h> /* */ |
14 |
#include <fcntl.h> /* */ |
15 |
#include <errno.h> /* error simbol definitions */ |
16 |
#include <time.h> /* system time definitions */ |
17 |
#include <math.h> /* math library */ |
18 |
/************************************************************ |
19 |
* 12/9/2005 modified by david fedele |
20 |
void hunpacker_(unsigned short *buffer, int *error, int *fd)*/ |
21 |
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); |
22 |
void hunpacker_(unsigned short *header, int *error,char *buffer, int *len,int *curpos,int *startcrc) |
23 |
/************************************************************/ |
24 |
{ |
25 |
|
26 |
int i; |
27 |
int nhead; |
28 |
unsigned int buffer_temp[13], *oo, *oi, *o1; //packed mode |
29 |
/************************************************************ |
30 |
* 12/9/2005 modified by david fedele */ |
31 |
/* int nread,nhead; */ |
32 |
/* unsigned short word; */ |
33 |
|
34 |
/* ///\*** goes back a word***\/ */ |
35 |
/* // lseek(*fd, -2, SEEK_CUR); //SEEK_CUR ---> from current position */ |
36 |
|
37 |
/* *error=0; */ |
38 |
|
39 |
/* /\*** read the buffer ***\/ */ |
40 |
/* nhead = 13; /\* packed *\/ */ |
41 |
/* nread=read(*fd, buffer_temp, 2*nhead); */ |
42 |
/* if( nread==0 ) { */ |
43 |
/* printf("hunpacker: Unexpected end of file %d at %d \n",*fd,nread); */ |
44 |
/* *error=1; */ |
45 |
/* return ; */ |
46 |
/* } */ |
47 |
/* if ( nread != 2*nhead) { */ |
48 |
/* printf("hunpacker: Error on reading: nread = %d \n",nread); */ |
49 |
/* *error=-1; */ |
50 |
/* return ; */ |
51 |
/* } */ |
52 |
|
53 |
/* /\*** correct byte ***\/ //endianess... */ |
54 |
/* for(i=0; i<nhead; i++) { */ |
55 |
/* word = buffer_temp[i]; */ |
56 |
/* buffer_temp[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */ |
57 |
/* } */ |
58 |
|
59 |
unsigned int word[16]; |
60 |
int nbytes2=2; |
61 |
char *buff=buffer; |
62 |
*error=0; |
63 |
/*** read the buffer ***/ |
64 |
nhead = 13; /* packed */ |
65 |
|
66 |
*startcrc=*curpos; |
67 |
|
68 |
if( *curpos+(2*13)-1>*len ) { |
69 |
// printf("hunpacker: Unexpected end of file\n"); |
70 |
*error=1; |
71 |
return ; |
72 |
} |
73 |
|
74 |
for (i=0;i<13;i++) |
75 |
getbytes_(&nbytes2,buff,curpos,&buffer_temp[i]); |
76 |
|
77 |
/****************************************************************/ |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
/*** buffer unpacking ***/ |
83 |
if( nhead == 16 ) { // NO!??? |
84 |
/************************************************************ |
85 |
* 12/9/2005 modified by david fedele */ |
86 |
/* oo=buffer; /\* nopacking buffer *\/ */ |
87 |
oo=word; |
88 |
/**********************************************************/ |
89 |
oi=buffer_temp; |
90 |
for( i=0; i<nhead; i++) *oo++ = *oi++; |
91 |
} |
92 |
if( nhead == 13 ) { |
93 |
/************************************************************ |
94 |
* 12/9/2005 modified by david fedele */ |
95 |
/* oo=buffer; /\* unpacking buffer *\/ */ |
96 |
oo=word; |
97 |
/**********************************************************/ |
98 |
oi=buffer_temp; |
99 |
o1 = oi++; |
100 |
*oo++ = (*o1 & 0xfff8) >> 3; |
101 |
*oo++ = ( (*o1 & 0x0007) << 10 ) | ( (*oi & 0xffc0) >> 6); |
102 |
o1 = oi++; |
103 |
*oo++ = ( (*o1 & 0x003f) << 7 ) | ( (*oi & 0xfe00) >> 9); |
104 |
o1 = oi++; |
105 |
*oo++ = ( (*o1 & 0x01ff) << 4 ) | ( (*oi & 0xf000) >> 12); |
106 |
o1 = oi++; |
107 |
*oo++ = ( (*o1 & 0x0fff) << 1 ) | ( (*oi & 0x8000) >> 15); |
108 |
*oo++ = (*oi & 0x7ffc) >> 2; |
109 |
o1 = oi++; |
110 |
*oo++ = ( (*o1 & 0x0003) << 11 ) | ( (*oi & 0xffe0) >> 5); |
111 |
o1 = oi++; |
112 |
*oo++ = ( (*o1 & 0x001f) << 8 ) | ( (*oi & 0xff00) >> 8); |
113 |
o1 = oi++; |
114 |
*oo++ = ( (*o1 & 0x00ff) << 5 ) | ( (*oi & 0xf800) >> 11); |
115 |
o1 = oi++; |
116 |
*oo++ = ( (*o1 & 0x07ff) << 2 ) | ( (*oi & 0xc000) >> 14); |
117 |
*oo++ = (*oi & 0x3ffe) >> 1; |
118 |
o1 = oi++; |
119 |
*oo++ = ( (*o1 & 0x0001) << 12 ) | ( (*oi & 0xfff0) >> 4); |
120 |
o1 = oi++; |
121 |
*oo++ = ( (*o1 & 0x000f) << 9 ) | ( (*oi & 0xff80) >> 7); |
122 |
o1 = oi++; |
123 |
*oo++ = ( (*o1 & 0x007f) << 6 ) | ( (*oi & 0xfc00) >> 10); |
124 |
o1 = oi++; |
125 |
*oo++ = ( (*o1 & 0x03ff) << 3 ) | ( (*oi & 0xe000) >> 13); |
126 |
*oo++ = *oi++ & 0x1fff; |
127 |
} |
128 |
|
129 |
/************************************************************ |
130 |
* 23/9/2005 modified by david fedele */ |
131 |
for( i=0; i<16; i++) { |
132 |
header[i]=word[i]; |
133 |
/* printf("%x \n",word[i]);//??? */ |
134 |
/* printf("%x \n",header[i]);//??? */ |
135 |
} |
136 |
/**************************************************************/ |
137 |
return; |
138 |
} |