/[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 6.1 - (hide annotations) (download)
Tue Jun 27 10:25:42 2006 UTC (18 years, 5 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA6_3/13, YODA6_3/12, YODA6_3/11, YODA6_3/10, YODA6_3/06, YODA6_3/04, YODA6_3/05, YODA6_3/07, YODA6_3/08, YODA6_3/09
Changes since 6.0: +6 -6 lines
File MIME type: text/plain
Final release for the Traker's routines.

1 kusanagi 5.1 /************************************************************
2     * 12/9/2005 modified by david fedele to read buffer-data
3     * instead raw-data-file
4     **************************************************************
5     *
6 kusanagi 1.1 * 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 kusanagi 5.1 /************************************************************
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 kusanagi 1.1
26     int i;
27 kusanagi 5.1 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 kusanagi 1.1
34 kusanagi 5.1 /* ///\*** goes back a word***\/ */
35     /* // lseek(*fd, -2, SEEK_CUR); //SEEK_CUR ---> from current position */
36 kusanagi 1.1
37 kusanagi 5.1 /* *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 kusanagi 1.1 *error=0;
63     /*** read the buffer ***/
64     nhead = 13; /* packed */
65 kusanagi 5.1
66     *startcrc=*curpos;
67 kusanagi 6.1
68     if( *curpos+13>*len ) {
69 kusanagi 5.1 printf("hunpacker: Unexpected end of file\n");
70 kusanagi 1.1 *error=1;
71     return ;
72     }
73 kusanagi 6.1
74     for (i=0;i<13;i++)
75     getbytes_(&nbytes2,buff,curpos,&buffer_temp[i]);
76    
77 kusanagi 5.1 /****************************************************************/
78    
79 kusanagi 1.1
80    
81    
82     /*** buffer unpacking ***/
83     if( nhead == 16 ) { // NO!???
84 kusanagi 5.1 /************************************************************
85     * 12/9/2005 modified by david fedele */
86     /* oo=buffer; /\* nopacking buffer *\/ */
87     oo=word;
88     /**********************************************************/
89 kusanagi 1.1 oi=buffer_temp;
90     for( i=0; i<nhead; i++) *oo++ = *oi++;
91     }
92     if( nhead == 13 ) {
93 kusanagi 5.1 /************************************************************
94     * 12/9/2005 modified by david fedele */
95     /* oo=buffer; /\* unpacking buffer *\/ */
96     oo=word;
97     /**********************************************************/
98 kusanagi 1.1 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 kusanagi 5.1 /************************************************************
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 kusanagi 1.1 return;
138     }

  ViewVC Help
Powered by ViewVC 1.1.23