-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsquelch.c
55 lines (46 loc) · 1.16 KB
/
squelch.c
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
#include "rtl_rfm.h"
#include "squelch.h"
#define SQUELCH_THRESH 10
#define SQUELCH_NUM 16
bool squelch_state = false; // 0 is squelched, 1 is receiving
int squelch_count = 0;
int32_t magnitude_squared;
extern bool debugplot;
bool squelch(IQPair sample, CB_VOID close_cb)
{
magnitude_squared = sample.i * sample.i + sample.q * sample.q;
if (squelch_state)
{
if (magnitude_squared < (SQUELCH_THRESH * SQUELCH_THRESH))
{
squelch_count--;
if(squelch_count <= 0)
{
squelch_state = false;
if (debugplot) fprintf(stderr, "SQUELCH CLOSE");
close_cb();
}
}
else
{
squelch_count = SQUELCH_NUM;
}
return true;
}
else
{
if (magnitude_squared > (SQUELCH_THRESH * SQUELCH_THRESH))
{
squelch_count++;
if (squelch_count >= SQUELCH_NUM)
{
squelch_state = true;
if (debugplot) fprintf(stderr, "SQUELCH OPEN");
}
} else
{
squelch_count = 0;
}
return false;
}
}