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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.0 by kusanagi, Tue Sep 21 20:51:20 2004 UTC revision 6.0 by kusanagi, Tue Feb 7 17:11:11 2006 UTC
# Line 1  Line 1 
1  /*  /************************************************************
2    *     20/9/2005 modified by david fedele to read buffer-data
3    *     instead raw-data-file
4    **************************************************************
5   * include needed system headers   * include needed system headers
6   */   */
7  #include <stdio.h>       /* include standard i/o library */  #include <stdio.h>       /* include standard i/o library */
# Line 14  Line 17 
17    
18  void unpacking(int ndata, unsigned short *output);  void unpacking(int ndata, unsigned short *output);
19    
20  void dunpacker_(int *l_buffer, unsigned short *buffer, int *error, int *fd)  /************************************************************
21     *     20/9/2005 modified by david fedele                     */
22    /* void dunpacker_(int *l_buffer, unsigned short *buffer, int *error, int *fd) */
23    void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value);
24    
25    void dunpacker_(int *l_buffer, unsigned short *buff, int *error,char *buffer, int *len,int *curpos)
26    /**************************************************************/
27  {  {
28      int i;      int i;
29      int nhead,nread;      int nhead;
     unsigned short word;  
   
     *error = 0;  
30    
31      nhead = 13;  /* packed */      nhead = 13;  /* packed */
32        *error=0;
33  //    printf("%i \n",*l_buffer);  /************************************************************
34     *     20/9/2005 modified by david fedele                     */
35     /*    int nread; */
36  /* /\*** read the data ***\/ */      /* unsigned int word; */
37  //    if( nhead == 13) *l_buffer = (*l_buffer*13)/16+1; /* packed */  
38      nread=read(*fd, buffer, 2**l_buffer);  /*     nread=read(*fd, buffer, 2**l_buffer); */
39    
40      if( nread==0 ) {  /*     if( nread==0 ) { */
41  //      printf("dunpacker: Unexpected end of file %d at %d \n",*fd,nread);  /*      printf("dunpacker: Unexpected end of file %d at %d \n",*fd,nread); */
42          *error=1;  /*      *error=1; */
43          return ;  /*      return ; */
44      }  /*     } */
45      if ( nread != 2**l_buffer) {  /*     if ( nread != 2**l_buffer) { */
46  //      printf("dunpacker: Error on reading: nread = %d \n",nread);  /*      printf("dunpacker: Error on reading: nread = %d \n",nread); */
47          *error=-1;  /*      *error=-1; */
48          return ;  /*      return ;  */
49    /*     } */
50    
51    
52    /* /\*** correct byte ***\/ */
53    /*     for(i=0; i<*l_buffer; i++) { */
54    /*      word = buffer[i]; */
55    /*      buffer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */
56    /*     } */
57        int nbytes2=2;
58        unsigned int word_temp;
59        unsigned short word[10000];
60        
61        for(i=0;i<*l_buffer;i++){
62          getbytes_(&nbytes2,buffer,curpos,&word_temp);
63          word[i]=word_temp;
64          buff[i]=word[i];
65      }      }
66        
67        
68  /*** correct byte ***/      
69      for(i=0; i<*l_buffer; i++) {      if( *curpos-1>*len ) {
70          word = buffer[i];        printf("dunpacker: Unexpected end of file\n");
71          buffer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 );        *error=1;
72          return ;
73      }      }
   
74  /*** unpacking buffer data ***/  /*** unpacking buffer data ***/
75      if( nhead == 13) unpacking(*l_buffer, buffer);  /************************************************************
76     *     20/9/2005 modified by david fedele                     */
77  //    int num = (*l_buffer-13-1)/13*16+3;//???  /*     if( nhead == 13) unpacking(*l_buffer, buffer); */
78  //  for( i=0; i<num; i++) printf("%i %x \n",i,buffer[i]);//???      if( nhead == 13) unpacking(*l_buffer, buff);
79    /**************************************************************/
80        
81        
82    /*    int num = (*l_buffer-13-1)/13*16+3;//??? */
83    /*  for( i=0; i<num; i++) printf("%i %x \n",i,buffer[i]);//??? */
84    
85  /* /\***   Checksum ***\/ */  /***   Checksum ***/
86  /*      oi = buffer; */    /* *oi = buffer; */
87  /*      word = 0; */  /*      word = 0; */
88  /*      for( i=0; i<l_buffer; ++i) */  /*      for( i=0; i<*l_buffer; ++i) */
89  /*          word = (word + *oi++) & 0x03ff; */  /*        word = (word + *oi++)& 0x03ff; */
90  /*      if( word == ( header[6] & 0x03ff ) ) */  /*      if( word == ( header[6] & 0x03ff ) ) */
91  /* /\*              printf("Check Sum OK \n")*\/ ; */  /* /\*              printf("Check Sum OK \n")*\/ ; */
92  /*      else */  /*      else */

Legend:
Removed from v.2.0  
changed lines
  Added in v.6.0

  ViewVC Help
Powered by ViewVC 1.1.23