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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4.0 - (hide annotations) (download)
Sun Mar 6 04:33:02 2005 UTC (19 years, 9 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA4_1/00, YODA4_0/04, YODA4_0/03, YODA4_0/02, YODA4_0/01, YODA4_3/02, YODA4_3/00, YODA4_3/01, YODA4_2/01, YODA4_2/00, YODA4_2/03
Branch point for: PreThermistores2
Changes since 3.0: +0 -0 lines
File MIME type: text/plain
Stable version 4.0 - 6 March 2005 - Maurizio Nagni

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 hunpacker_(unsigned short *buffer, int *error, int *fd)
16    
17     {
18     int i;
19     int nread,nhead;
20     unsigned short word;
21     unsigned short buffer_temp[13], *oo, *oi, *o1; //packed mode
22    
23     ///*** goes back a word***/
24     // lseek(*fd, -2, SEEK_CUR); //SEEK_CUR ---> from current position
25    
26     *error=0;
27    
28     /*** read the buffer ***/
29     nhead = 13; /* packed */
30     nread=read(*fd, buffer_temp, 2*nhead);
31     if( nread==0 ) {
32 kusanagi 1.2 //printf("hunpacker: Unexpected end of file %d at %d \n",*fd,nread);
33 kusanagi 1.1 *error=1;
34     return ;
35     }
36     if ( nread != 2*nhead) {
37 kusanagi 1.2 //printf("hunpacker: Error on reading: nread = %d \n",nread);
38 kusanagi 1.1 *error=-1;
39     return ;
40     }
41    
42     /*** correct byte ***/ //endianess...
43     for(i=0; i<nhead; i++) {
44     word = buffer_temp[i];
45     buffer_temp[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 );
46     }
47    
48    
49     /*** buffer unpacking ***/
50     if( nhead == 16 ) { // NO!???
51     oo=buffer; /* nopacking buffer */
52     oi=buffer_temp;
53     for( i=0; i<nhead; i++) *oo++ = *oi++;
54     }
55     if( nhead == 13 ) {
56     oo=buffer; /* unpacking buffer */
57     oi=buffer_temp;
58     o1 = oi++;
59     *oo++ = (*o1 & 0xfff8) >> 3;
60     *oo++ = ( (*o1 & 0x0007) << 10 ) | ( (*oi & 0xffc0) >> 6);
61     o1 = oi++;
62     *oo++ = ( (*o1 & 0x003f) << 7 ) | ( (*oi & 0xfe00) >> 9);
63     o1 = oi++;
64     *oo++ = ( (*o1 & 0x01ff) << 4 ) | ( (*oi & 0xf000) >> 12);
65     o1 = oi++;
66     *oo++ = ( (*o1 & 0x0fff) << 1 ) | ( (*oi & 0x8000) >> 15);
67     *oo++ = (*oi & 0x7ffc) >> 2;
68     o1 = oi++;
69     *oo++ = ( (*o1 & 0x0003) << 11 ) | ( (*oi & 0xffe0) >> 5);
70     o1 = oi++;
71     *oo++ = ( (*o1 & 0x001f) << 8 ) | ( (*oi & 0xff00) >> 8);
72     o1 = oi++;
73     *oo++ = ( (*o1 & 0x00ff) << 5 ) | ( (*oi & 0xf800) >> 11);
74     o1 = oi++;
75     *oo++ = ( (*o1 & 0x07ff) << 2 ) | ( (*oi & 0xc000) >> 14);
76     *oo++ = (*oi & 0x3ffe) >> 1;
77     o1 = oi++;
78     *oo++ = ( (*o1 & 0x0001) << 12 ) | ( (*oi & 0xfff0) >> 4);
79     o1 = oi++;
80     *oo++ = ( (*o1 & 0x000f) << 9 ) | ( (*oi & 0xff80) >> 7);
81     o1 = oi++;
82     *oo++ = ( (*o1 & 0x007f) << 6 ) | ( (*oi & 0xfc00) >> 10);
83     o1 = oi++;
84     *oo++ = ( (*o1 & 0x03ff) << 3 ) | ( (*oi & 0xe000) >> 13);
85     *oo++ = *oi++ & 0x1fff;
86     }
87    
88     // for( i=0; i<16; i++) printf("%x \n",buffer[i]);//???
89    
90     return;
91     }

  ViewVC Help
Powered by ViewVC 1.1.23