| 1 |
kusanagi |
5.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 |
kusanagi |
1.1 |
* include needed system headers |
| 8 |
|
|
*/ |
| 9 |
|
|
#include <stdio.h> /* include standard i/o library */ |
| 10 |
|
|
#include <stdlib.h> /* include standard library */ |
| 11 |
|
|
#include <string.h> /* include string library */ |
| 12 |
|
|
#include <unistd.h> /* include unix standard library */ |
| 13 |
|
|
#include <sys/types.h> /* */ |
| 14 |
|
|
#include <sys/stat.h> /* */ |
| 15 |
|
|
#include <fcntl.h> /* */ |
| 16 |
|
|
#include <errno.h> /* error simbol definitions */ |
| 17 |
|
|
#include <time.h> /* system time definitions */ |
| 18 |
|
|
#include <math.h> /* math library */ |
| 19 |
kusanagi |
5.1 |
/************************************************************ |
| 20 |
|
|
/* 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 |
kusanagi |
1.1 |
{ |
| 28 |
|
|
int i; |
| 29 |
|
|
|
| 30 |
|
|
*error=0; |
| 31 |
kusanagi |
5.1 |
/************************************************************ |
| 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 |
kusanagi |
1.1 |
|
| 59 |
kusanagi |
6.1 |
if( *curpos+3>*len ) { |
| 60 |
kusanagi |
5.1 |
printf("readtrailer: Unexpected end of file \n"); |
| 61 |
kusanagi |
1.1 |
*error=1; |
| 62 |
|
|
return ; |
| 63 |
|
|
} |
| 64 |
kusanagi |
6.1 |
|
| 65 |
|
|
for (i=0;i<3;i++) |
| 66 |
|
|
getbytes_(&nbytes2,buff,curpos,&word[i]); |
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
kusanagi |
5.1 |
for( i=0; i<3; i++) trailer[i]=word[i]; |
| 70 |
|
|
/****************************************************************/ |
| 71 |
kusanagi |
1.1 |
|
| 72 |
kusanagi |
5.1 |
// for( i=0; i<3; i++) printf("%x \n",trailer[i]);//??? |
| 73 |
kusanagi |
1.1 |
|
| 74 |
|
|
|
| 75 |
kusanagi |
5.1 |
/************************************************************ |
| 76 |
|
|
* 29/11/2005 modified by david fedele */ |
| 77 |
|
|
stopcrc=curpos; |
| 78 |
|
|
*crctemp=0; |
| 79 |
|
|
for(i=*startcrc-1;i<*stopcrc-2;i++) |
| 80 |
|
|
*crctemp=crc8_8(*crctemp,buffer[i]); |
| 81 |
|
|
/****************************************************************/ |
| 82 |
kusanagi |
1.1 |
return; |
| 83 |
|
|
} |