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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5.0 - (show annotations) (download)
Mon Aug 29 09:46:13 2005 UTC (19 years, 3 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA5_0/00, YODA5_0/01, YODA5_0/02
Changes since 4.4: +0 -0 lines
File MIME type: text/plain
Starting form this version:
1) includes are defined with relative (not absolute) path respect to the YODA aplication
2) RegistryEvent class is foreseen to contain post-unpack data.

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 // printf("dunpacker: Unexpected end of file %d at %d \n",*fd,nread);
37 *error=1;
38 return ;
39 }
40 if ( nread != 2**l_buffer) {
41 // printf("dunpacker: Error on reading: nread = %d \n",nread);
42 *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