forked from baycom/tfrec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.cpp
95 lines (81 loc) · 2.01 KB
/
engine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
tfrec - Receiver for TFA IT+ (and compatible) sensors
(c) 2017 Georg Acher, Deti Fliegl {acher|fliegl}(at)baycom.de
#include <GPL-v2>
*/
#include <string.h>
#include "engine.h"
//-------------------------------------------------------------------------
engine::engine(int _device, uint32_t freq, int gain, int filter, fsk_demod *_fsk, int _dbg,int _dumpmode, char* _dumpfile)
{
freq= freq*1000; // kHz->Hz
srate=1536000;
filter_type=filter;
fsk=_fsk;
dbg=_dbg;
dumpfile=_dumpfile;
dumpmode=_dumpmode;
if (filter_type)
puts("Wide filter");
if (dumpmode)
printf("Dumpmode %i (%s), dumpfile %s\n",dumpmode,
dumpmode==1?"SAVE":(dumpmode==-1?"LOAD":"NONE"),
dumpfile);
if (dumpmode>=0) {
s=new sdr(_device,dbg,dumpmode,dumpfile);
if (gain==-1)
s->set_gain(0,0);
else
s->set_gain(1,gain);
s->set_frequency(freq);
s->set_samplerate(srate);
}
}
//-------------------------------------------------------------------------
engine::~engine(void)
{
}
//-------------------------------------------------------------------------
void engine::run(int timeout)
{
FILE *dump_fd=NULL;
if (dumpmode>=0)
s->start();
else {
dump_fd=fopen(dumpfile,"rb");
if (!dump_fd) {
perror(dumpfile);
exit(-1);
}
}
downconvert dc(2);
time_t start=time(0);
while(1) {
int16_t *data;
int len;
if (dump_fd) {
#define RLS 65536
int16_t datab[RLS];
{
unsigned char buf[RLS];
int xx=fread(buf,RLS,1,dump_fd);
if (xx<1) {
printf("done reading dump\n");
exit(0);
}
for(int n=0;n<RLS;n++)
datab[n] = ((buf[n]) - 128)<<6; // scale like in sdr.cpp
data=datab;
len=RLS;
}
} else
s->wait(data,len); // len=total sample number = #i+#q
int ld=dc.process_iq(data,len,filter_type);
fsk->process(data,ld);
if (!dump_fd)
s->done(len);
if (timeout && (time(0)-start>timeout))
break;
}
}
//-------------------------------------------------------------------------