/************************************************************ * 12/9/2005 modified by david fedele to read buffer-data * instead raw-data-file ************************************************************** * * include needed system headers */ #include /* include standard i/o library */ #include /* include standard library */ #include /* include string library */ #include /* include unix standard library */ #include /* */ #include /* */ #include /* */ #include /* error simbol definitions */ #include /* system time definitions */ #include /* math library */ /************************************************************ * 12/9/2005 modified by david fedele void hunpacker_(unsigned short *buffer, int *error, int *fd)*/ void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); void hunpacker_(unsigned short *header, int *error,char *buffer, int *len,int *curpos,int *startcrc) /************************************************************/ { int i; int nhead; unsigned int buffer_temp[13], *oo, *oi, *o1; //packed mode /************************************************************ * 12/9/2005 modified by david fedele */ /* int nread,nhead; */ /* unsigned short word; */ /* ///\*** goes back a word***\/ */ /* // lseek(*fd, -2, SEEK_CUR); //SEEK_CUR ---> from current position */ /* *error=0; */ /* /\*** read the buffer ***\/ */ /* nhead = 13; /\* packed *\/ */ /* nread=read(*fd, buffer_temp, 2*nhead); */ /* if( nread==0 ) { */ /* printf("hunpacker: Unexpected end of file %d at %d \n",*fd,nread); */ /* *error=1; */ /* return ; */ /* } */ /* if ( nread != 2*nhead) { */ /* printf("hunpacker: Error on reading: nread = %d \n",nread); */ /* *error=-1; */ /* return ; */ /* } */ /* /\*** correct byte ***\/ //endianess... */ /* for(i=0; i> 8 ); */ /* } */ unsigned int word[16]; int nbytes2=2; char *buff=buffer; *error=0; /*** read the buffer ***/ nhead = 13; /* packed */ *startcrc=*curpos; if( *curpos+13>*len ) { printf("hunpacker: Unexpected end of file\n"); *error=1; return ; } for (i=0;i<13;i++) getbytes_(&nbytes2,buff,curpos,&buffer_temp[i]); /****************************************************************/ /*** buffer unpacking ***/ if( nhead == 16 ) { // NO!??? /************************************************************ * 12/9/2005 modified by david fedele */ /* oo=buffer; /\* nopacking buffer *\/ */ oo=word; /**********************************************************/ oi=buffer_temp; for( i=0; i> 3; *oo++ = ( (*o1 & 0x0007) << 10 ) | ( (*oi & 0xffc0) >> 6); o1 = oi++; *oo++ = ( (*o1 & 0x003f) << 7 ) | ( (*oi & 0xfe00) >> 9); o1 = oi++; *oo++ = ( (*o1 & 0x01ff) << 4 ) | ( (*oi & 0xf000) >> 12); o1 = oi++; *oo++ = ( (*o1 & 0x0fff) << 1 ) | ( (*oi & 0x8000) >> 15); *oo++ = (*oi & 0x7ffc) >> 2; o1 = oi++; *oo++ = ( (*o1 & 0x0003) << 11 ) | ( (*oi & 0xffe0) >> 5); o1 = oi++; *oo++ = ( (*o1 & 0x001f) << 8 ) | ( (*oi & 0xff00) >> 8); o1 = oi++; *oo++ = ( (*o1 & 0x00ff) << 5 ) | ( (*oi & 0xf800) >> 11); o1 = oi++; *oo++ = ( (*o1 & 0x07ff) << 2 ) | ( (*oi & 0xc000) >> 14); *oo++ = (*oi & 0x3ffe) >> 1; o1 = oi++; *oo++ = ( (*o1 & 0x0001) << 12 ) | ( (*oi & 0xfff0) >> 4); o1 = oi++; *oo++ = ( (*o1 & 0x000f) << 9 ) | ( (*oi & 0xff80) >> 7); o1 = oi++; *oo++ = ( (*o1 & 0x007f) << 6 ) | ( (*oi & 0xfc00) >> 10); o1 = oi++; *oo++ = ( (*o1 & 0x03ff) << 3 ) | ( (*oi & 0xe000) >> 13); *oo++ = *oi++ & 0x1fff; } /************************************************************ * 23/9/2005 modified by david fedele */ for( i=0; i<16; i++) { header[i]=word[i]; /* printf("%x \n",word[i]);//??? */ /* printf("%x \n",header[i]);//??? */ } /**************************************************************/ return; }