1 |
mocchiut |
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 |
6 |
|
|
*/ |
7 |
|
|
#include <stdio.h> /* include standard i/o library */ |
8 |
|
|
#include <stdlib.h> /* include standard library */ |
9 |
|
|
#include <string.h> /* include string library */ |
10 |
|
|
#include <unistd.h> /* include unix standard library */ |
11 |
|
|
#include <sys/types.h> /* */ |
12 |
|
|
#include <sys/stat.h> /* */ |
13 |
|
|
#include <fcntl.h> /* */ |
14 |
|
|
#include <errno.h> /* error simbol definitions */ |
15 |
|
|
#include <time.h> /* system time definitions */ |
16 |
|
|
#include <math.h> /* math library */ |
17 |
|
|
/************************************************************ |
18 |
|
|
* 20/9/2005 modified by david fedele */ |
19 |
|
|
/* void readsig_(float *sig_buf, int *error, int *fd) */ |
20 |
|
|
void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value); |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
void readsig_(float *sig_buf, int *error,char *buffer, int *len,int *curpos) |
24 |
|
|
{ |
25 |
|
|
int i; |
26 |
|
|
unsigned int word; |
27 |
|
|
unsigned int decimals,units; |
28 |
|
|
unsigned int sig_buf_temp[1024]; |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
*error=0; |
32 |
|
|
/************************************************************ |
33 |
|
|
* 20/9/2005 modified by david fedele */ |
34 |
|
|
/* int nread; */ |
35 |
|
|
|
36 |
|
|
/* /\*** read the buffer ***\/ */ |
37 |
|
|
/* nread=read(*fd, sig_buf_temp, 2*1024); */ |
38 |
|
|
/* if( nread==0 ) { */ |
39 |
|
|
/* printf("readsig: Unexpected end of file %d at %d \n",*fd,nread); */ |
40 |
|
|
/* *error=1; */ |
41 |
|
|
/* return ; */ |
42 |
|
|
/* } */ |
43 |
|
|
/* if ( nread != 2*1024) { */ |
44 |
|
|
/* printf("readsig: Error on reading: nread = %d \n",nread); */ |
45 |
|
|
/* *error=-1; */ |
46 |
|
|
/* return ; */ |
47 |
|
|
/* } */ |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
/* /\*** correct byte ***\/ //endianess... */ |
51 |
|
|
/* for(i=0; i<1024; i++) { */ |
52 |
|
|
/* word = sig_buf_temp[i]; */ |
53 |
|
|
/* sig_buf_temp[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */ |
54 |
|
|
/* } */ |
55 |
|
|
|
56 |
|
|
int nbytes2=2; |
57 |
|
|
char *buff=buffer; |
58 |
|
|
|
59 |
|
|
if( *curpos+(2*1024)-1>*len ) { |
60 |
|
|
printf("readsig: Unexpected end of file \n"); |
61 |
|
|
*error=1; |
62 |
|
|
return ; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
for(i=0; i<1024; i++) |
66 |
|
|
getbytes_(&nbytes2,buff,curpos,&sig_buf_temp[i]); |
67 |
|
|
|
68 |
|
|
/*****************************************************************/ |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
/***interpreta*/ |
72 |
|
|
for(i=0; i<1024; i++) { |
73 |
|
|
|
74 |
|
|
word = sig_buf_temp[i]; |
75 |
|
|
units = ( (word >> 4) & 0x0fff ) ; |
76 |
|
|
decimals = (word & 0x000f) ; |
77 |
|
|
sig_buf[i] = (float)units + (float)decimals / 16.; |
78 |
|
|
// printf("%i %i %i %f \n",i,units,decimals,sig_buf[i]); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
// for( i=0; i<1024; i++) printf("%x \n",sig_buf[i]);//??? |
84 |
|
|
|
85 |
|
|
return; |
86 |
|
|
} |