/[PAMELA software]/yoda/techmodel/forroutines/tracker/readraw/dunpacker.c
ViewVC logotype

Annotation of /yoda/techmodel/forroutines/tracker/readraw/dunpacker.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Aug 25 10:55:28 2004 UTC (20 years, 3 months ago) by kusanagi
Branch: MAIN
Changes since 1.1: +2 -2 lines
File MIME type: text/plain
Commented out some prints

1 kusanagi 1.1 /*
2     * include needed system headers
3     */
4     #include <stdio.h> /* include standard i/o library */
5     #include <stdlib.h> /* include standard library */
6     #include <string.h> /* include string library */
7     #include <unistd.h> /* include unix standard library */
8     #include <sys/types.h> /* */
9     #include <sys/stat.h> /* */
10     #include <fcntl.h> /* */
11     #include <errno.h> /* error simbol definitions */
12     #include <time.h> /* system time definitions */
13     #include <math.h> /* math library */
14    
15     void unpacking(int ndata, unsigned short *output);
16    
17     void dunpacker_(int *l_buffer, unsigned short *buffer, int *error, int *fd)
18    
19     {
20     int i;
21     int nhead,nread;
22     unsigned short word;
23    
24     *error = 0;
25    
26     nhead = 13; /* packed */
27    
28     // printf("%i \n",*l_buffer);
29    
30    
31     /* /\*** read the data ***\/ */
32     // if( nhead == 13) *l_buffer = (*l_buffer*13)/16+1; /* packed */
33     nread=read(*fd, buffer, 2**l_buffer);
34    
35     if( nread==0 ) {
36 kusanagi 1.2 // printf("dunpacker: Unexpected end of file %d at %d \n",*fd,nread);
37 kusanagi 1.1 *error=1;
38     return ;
39     }
40     if ( nread != 2**l_buffer) {
41 kusanagi 1.2 // printf("dunpacker: Error on reading: nread = %d \n",nread);
42 kusanagi 1.1 *error=-1;
43     return ;
44     }
45    
46    
47     /*** correct byte ***/
48     for(i=0; i<*l_buffer; i++) {
49     word = buffer[i];
50     buffer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 );
51     }
52    
53     /*** unpacking buffer data ***/
54     if( nhead == 13) unpacking(*l_buffer, buffer);
55    
56     // int num = (*l_buffer-13-1)/13*16+3;//???
57     // for( i=0; i<num; i++) printf("%i %x \n",i,buffer[i]);//???
58    
59     /* /\*** Checksum ***\/ */
60     /* oi = buffer; */
61     /* word = 0; */
62     /* for( i=0; i<l_buffer; ++i) */
63     /* word = (word + *oi++) & 0x03ff; */
64     /* if( word == ( header[6] & 0x03ff ) ) */
65     /* /\* printf("Check Sum OK \n")*\/ ; */
66     /* else */
67     /* printf("Wrong Check Sum: %x, %x \n",word,header[6]&0x03ff); */
68    
69     }
70    
71     /*========================================================= */
72     /*========================================================= */
73     /*
74     * Routine to unpacking buffer file
75     *
76     */
77     /*========================================================= */
78     /*========================================================= */
79     void unpacking(int nwords, unsigned short *output) {
80     unsigned short out[10000];
81     int k;
82     unsigned short *oi, *oo, *o1;
83    
84     for( k=0; k<10000; ++k)
85     out[k]=0;
86     oo=output;
87     oi=out;
88     for( k=0; k<nwords; ++k) {
89     *oi++ = *oo;
90     *oo++ = 0;
91     }
92    
93     oo=output;
94     oi=out;
95    
96     for(k=0; k<nwords; k+=13) {
97     o1 = oi++;
98     *oo++ = (*o1 & 0xfff8) >> 3;
99     *oo++ = ( (*o1 & 0x0007) << 10 ) | ( (*oi & 0xffc0) >> 6);
100     o1 = oi++;
101     *oo++ = ( (*o1 & 0x003f) << 7 ) | ( (*oi & 0xfe00) >> 9);
102     o1 = oi++;
103     *oo++ = ( (*o1 & 0x01ff) << 4 ) | ( (*oi & 0xf000) >> 12);
104     o1 = oi++;
105     *oo++ = ( (*o1 & 0x0fff) << 1 ) | ( (*oi & 0x8000) >> 15);
106     *oo++ = (*oi & 0x7ffc) >> 2;
107     o1 = oi++;
108     *oo++ = ( (*o1 & 0x0003) << 11 ) | ( (*oi & 0xffe0) >> 5);
109     o1 = oi++;
110     *oo++ = ( (*o1 & 0x001f) << 8 ) | ( (*oi & 0xff00) >> 8);
111     o1 = oi++;
112     *oo++ = ( (*o1 & 0x00ff) << 5 ) | ( (*oi & 0xf800) >> 11);
113     o1 = oi++;
114     *oo++ = ( (*o1 & 0x07ff) << 2 ) | ( (*oi & 0xc000) >> 14);
115     *oo++ = (*oi & 0x3ffe) >> 1;
116     o1 = oi++;
117     *oo++ = ( (*o1 & 0x0001) << 12 ) | ( (*oi & 0xfff0) >> 4);
118     o1 = oi++;
119     *oo++ = ( (*o1 & 0x000f) << 9 ) | ( (*oi & 0xff80) >> 7);
120     o1 = oi++;
121     *oo++ = ( (*o1 & 0x007f) << 6 ) | ( (*oi & 0xfc00) >> 10);
122     o1 = oi++;
123     *oo++ = ( (*o1 & 0x03ff) << 3 ) | ( (*oi & 0xe000) >> 13);
124     *oo++ = *oi++ & 0x1fff;
125     }
126    
127    
128     return;
129     }

  ViewVC Help
Powered by ViewVC 1.1.23