1 |
kusanagi |
1.1 |
/* |
2 |
|
|
* include needed system headers |
3 |
|
|
*/ |
4 |
|
|
#include <stdio.h> /* include standard i/o library */ |
5 |
|
|
#include <stdlib.h> /* include standard library */ |
6 |
|
|
#include <string.h> /* include string library */ |
7 |
|
|
#include <unistd.h> /* include unix standard library */ |
8 |
|
|
#include <sys/types.h> /* */ |
9 |
|
|
#include <sys/stat.h> /* */ |
10 |
|
|
#include <fcntl.h> /* */ |
11 |
|
|
#include <errno.h> /* error simbol definitions */ |
12 |
|
|
#include <time.h> /* system time definitions */ |
13 |
|
|
#include <math.h> /* math library */ |
14 |
|
|
|
15 |
|
|
void readsig_(float *sig_buf, int *error, int *fd) |
16 |
|
|
|
17 |
|
|
{ |
18 |
|
|
int nread; |
19 |
|
|
int i; |
20 |
|
|
unsigned short word; |
21 |
|
|
unsigned short decimals,units; |
22 |
|
|
unsigned short sig_buf_temp[1024]; |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
*error=0; |
26 |
|
|
|
27 |
|
|
/*** read the buffer ***/ |
28 |
|
|
nread=read(*fd, sig_buf_temp, 2*1024); |
29 |
|
|
if( nread==0 ) { |
30 |
|
|
printf("readsig: Unexpected end of file %d at %d \n",*fd,nread); |
31 |
|
|
*error=1; |
32 |
|
|
return ; |
33 |
|
|
} |
34 |
|
|
if ( nread != 2*1024) { |
35 |
|
|
printf("readsig: Error on reading: nread = %d \n",nread); |
36 |
|
|
*error=-1; |
37 |
|
|
return ; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
|
41 |
|
|
/*** correct byte ***/ //endianess... |
42 |
|
|
for(i=0; i<1024; i++) { |
43 |
|
|
word = sig_buf_temp[i]; |
44 |
|
|
sig_buf_temp[i] = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
/***interpreta*/ |
49 |
|
|
for(i=0; i<1024; i++) { |
50 |
|
|
|
51 |
|
|
word = sig_buf_temp[i]; |
52 |
|
|
units = ( (word >> 4) & 0x0fff ) ; |
53 |
|
|
decimals = (word & 0x000f) ; |
54 |
|
|
sig_buf[i] = (float)units + (float)decimals / 16.; |
55 |
|
|
// printf("%i %i %i %f \n",i,units,decimals,sig_buf[i]); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
// for( i=0; i<1024; i++) printf("%x \n",sig_buf[i]);//??? |
61 |
|
|
|
62 |
|
|
return; |
63 |
|
|
} |