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

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

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

revision 5.0 by kusanagi, Mon Aug 29 09:46:13 2005 UTC revision 5.1 by kusanagi, Sat Feb 4 12:37:45 2006 UTC
# Line 1  Line 1 
1  /*  /************************************************************
2    *     13/9/2005 modified by david fedele to read buffer-data
3    *     instead raw-data-file
4    *     29/11/2005 modified by david fedele to include crc control
5    **************************************************************
6     **
7   * include needed system headers   * include needed system headers
8   */   */
9  #include <stdio.h>       /* include standard i/o library */  #include <stdio.h>       /* include standard i/o library */
# Line 11  Line 16 
16  #include <errno.h>       /* error simbol definitions */  #include <errno.h>       /* error simbol definitions */
17  #include <time.h>        /* system time definitions */  #include <time.h>        /* system time definitions */
18  #include <math.h>        /* math library */  #include <math.h>        /* math library */
19    /************************************************************
20  void readtrailer_(unsigned short *trailer, int *error, int *fd)  /*     13/9/2005 modified by david fedele                     */
21    /*     29/11/2005 modified by david fedele                     */
22    /*void readtrailer_(unsigned short *trailer, int *error, int *fd)*/
23    void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value);
24    unsigned char crc8_8(unsigned char old, unsigned char data);
25    void readtrailer_(unsigned short *trailer, int *error,char *buffer, int *len,int *curpos,int *startcrc,int *stopcrc,unsigned int *crctemp)
26    /**************************************************************/
27  {  {
     int nread;  
28      int i;      int i;
     unsigned short word;  
29    
30      *error=0;      *error=0;
31    /************************************************************
32     *     13/9/2005 modified by david fedele                     */
33      /*   int nread; */
34        /* unsigned short word; */
35    
36    /* /\*** read the buffer ***\/ */
37    /*     nread=read(*fd, trailer, 2*3);//il trailer e' lungo 6 parole da 8 bits */
38    /*     if( nread==0 ) { */
39    /*      printf("readtrailer: Unexpected end of file %d at %d \n",*fd,nread); */
40    /*      *error=1; */
41    /*      return ; */
42    /*     } */
43    /*     if ( nread != 6) { */
44    /*      printf("readtrailer: Error on reading: nread = %d \n",nread); */
45    /*      *error=-1; */
46    /*      return ;  */
47    /*     } */
48    
49    
50    /* /\*** correct byte ***\/ //endianess... */
51    /*     for(i=0; i<3; i++) { */
52    /*      word = trailer[i]; */
53    /*      trailer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */
54    /*     } */
55        unsigned int word[3];
56        int nbytes2=2;
57        char *buff=buffer;
58    
59  /*** read the buffer ***/      for (i=0;i<3;i++){
60      nread=read(*fd, trailer, 2*3);//il trailer e' lungo 6 parole da 8 bits        getbytes_(&nbytes2,buff,curpos,&word[i]);
61      if( nread==0 ) {  
62          printf("readtrailer: Unexpected end of file %d at %d \n",*fd,nread);        if( *curpos-1>*len ) {
63            printf("readtrailer: Unexpected end of file \n");
64          *error=1;          *error=1;
65          return ;          return ;
66          }
67      }      }
68      if ( nread != 6) {      for( i=0; i<3; i++) trailer[i]=word[i];
69          printf("readtrailer: Error on reading: nread = %d \n",nread);  /****************************************************************/
         *error=-1;  
         return ;  
     }  
   
   
 /*** correct byte ***/ //endianess...  
     for(i=0; i<3; i++) {  
         word = trailer[i];  
         trailer[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 );  
     }  
70    
71  //    for( i=0; i<3; i++) printf("%x \n",trailer[i]);//???  //    for( i=0; i<3; i++) printf("%x \n",trailer[i]);//???
72    
73    
74    /************************************************************
75    *     29/11/2005 modified by david fedele                     */
76        stopcrc=curpos;
77        *crctemp=0;
78        for(i=*startcrc-1;i<*stopcrc-2;i++)
79          *crctemp=crc8_8(*crctemp,buffer[i]);
80    /****************************************************************/
81      return;      return;
82  }  }

Legend:
Removed from v.5.0  
changed lines
  Added in v.5.1

  ViewVC Help
Powered by ViewVC 1.1.23