Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
yids
kukuruku-fork
Commits
4377bbef
Commit
4377bbef
authored
Jul 26, 2016
by
Jenda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server: comments + measure spectrum in dB
parent
60913f2a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
6 deletions
+33
-6
server/bits.c
server/bits.c
+5
-2
server/client_parser.c
server/client_parser.c
+11
-0
server/init.sh
server/init.sh
+1
-2
server/metadata.c
server/metadata.c
+14
-2
server/xlate_worker.c
server/xlate_worker.c
+2
-0
No files found.
server/bits.c
View file @
4377bbef
...
...
@@ -8,17 +8,20 @@
#if OUR_ENDIAN != TARGET_ENDIAN
// Convert 4 bytes to target endian
void
LE32
(
void
*
x
)
{
uint32_t
i
;
memcpy
(
&
i
,
x
,
sizeof
(
i
));
i
=
hto
b
e32
(
i
);
i
=
hto
l
e32
(
i
);
memcpy
(
x
,
&
i
,
sizeof
(
i
));
}
// Convert 2 bytes to target endian
// ofc a more efficient implementation can be imagined
void
LE16
(
void
*
x
)
{
uint16_t
i
;
memcpy
(
&
i
,
x
,
sizeof
(
i
));
i
=
hto
b
e16
(
i
);
i
=
hto
l
e16
(
i
);
memcpy
(
x
,
&
i
,
sizeof
(
i
));
}
...
...
server/client_parser.c
View file @
4377bbef
...
...
@@ -32,6 +32,9 @@ extern char* recpath;
extern
FILE
*
sdr_cmd
;
/* Send RUNNING_XLATER to the originating client (respecting remoteID) and then
* to all other clients (with ID -1)
*/
void
msg_running_xlater
(
tcp_cli_t
*
me
,
worker
*
w
)
{
C2s__SRVRUNNINGXLATER
s
=
C2S__SRV__RUNNING__XLATER__INIT
;
...
...
@@ -76,6 +79,7 @@ void msg_running_xlater(tcp_cli_t * me, worker * w) {
free
(
buf
);
}
/* Send SRV_INFO to client *me */
void
msg_server_info
(
tcp_cli_t
*
me
,
bool
toall
)
{
C2s__SRVINFO
s
=
C2S__SRV__INFO__INIT
;
...
...
@@ -120,6 +124,7 @@ void msg_server_info(tcp_cli_t * me, bool toall) {
free
(
buf
);
}
/* Send DESTROYED_XLATER to all clients */
void
msg_destroyed_xlater
(
int32_t
xid
)
{
C2s__SRVDESTROYEDXLATER
s
=
C2S__SRV__DESTROYED__XLATER__INIT
;
...
...
@@ -146,9 +151,15 @@ void msg_destroyed_xlater(int32_t xid) {
free
(
buf
);
}
/* Main loop parsing messages from clients
* *me - originating client
* *buf2 - the message (incl. type header, but excl. length)
* len - length of the message
*/
int
parse_client_req
(
tcp_cli_t
*
me
,
const
uint8_t
*
buf2
,
int32_t
len
)
{
int
type
=
((
int
*
)
buf2
)[
0
];
LE32
(
&
type
);
// make protobufs happy with unsigned
const
uint8_t
*
buf
=
buf2
+
sizeof
(
int32_t
);
len
-=
sizeof
(
int32_t
);
// strip message type
...
...
server/init.sh
View file @
4377bbef
#!/bin/bash
-e
#!/bin/bash
if
[
$#
-ne
3
]
;
then
echo
"Usage:
$0
device rate ppm"
...
...
@@ -22,5 +22,4 @@ echo "Server PID $spid, use 'gdb ./server $spid -ex c' to debug"
trap
"kill
$spid
"
SIGINT SIGTERM
./osmosdr-input.py
-d
"
$1
"
-r
"
$2
"
-i
"
$tune
"
-o
"
$sdr
"
-f
"
$freq
"
-g
"
$gain
"
-p
"
$ppm
"
kill
$spid
server/metadata.c
View file @
4377bbef
...
...
@@ -19,6 +19,7 @@ float* fftw_avg;
fftwf_complex
*
fftw_in
,
*
fftw_out
;
fftwf_plan
p
;
/* Return i-th coefficient of Hamming window of a given length */
float
hamming
(
int
i
,
int
length
)
{
double
a
,
b
,
w
,
N1
;
a
=
25
.
0
/
46
.
0
;
...
...
@@ -28,6 +29,7 @@ float hamming(int i, int length) {
return
w
;
}
/* allocate FFTW buffers and window and init plan */
void
fftw_init
(
int
N
)
{
if
(
fftw_in
!=
NULL
)
{
...
...
@@ -51,6 +53,11 @@ void fftw_init(int N) {
fftsize
=
N
;
}
/* Calculate spectrum of packet *pkt and write it to pkt->spectrum
* spp - how many waterfall lines to compute
* fftskip - distance between beginning of transforms (we don't usually compute
* side-by-side or even overlapping FFT, but rather sample the signal once a while)
*/
void
calc_spectrum
(
sdr_packet
*
pkt
,
int
spp
,
int
fftskip
)
{
if
(
fftw_window
==
NULL
)
{
err
(
EXIT_FAILURE
,
"Internal consistency, calling calc_spectrum before fftw_init"
);
...
...
@@ -100,7 +107,8 @@ void calc_spectrum(sdr_packet * pkt, int spp, int fftskip) {
} else {
fftw_avg[k] *= hypotf(v1, v2);
}*/
fftw_avg
[
k
]
+=
logf
(
hypotf
(
v1
,
v2
)
*
dftscale
);
fftw_avg
[
k
]
+=
log10f
((
v1
*
v1
+
v2
*
v2
)
/
fftsize
);
//fftw_avg[k] += logf(hypotf(v1, v2) * dftscale);
}
...
...
@@ -109,7 +117,7 @@ void calc_spectrum(sdr_packet * pkt, int spp, int fftskip) {
}
for
(
int
k
=
0
;
k
<
fftsize
;
k
++
)
{
fftw_avg
[
k
]
=
fftw_avg
[
k
]
/
iters
;
fftw_avg
[
k
]
=
fftw_avg
[
k
]
/
(
iters
/
10
)
;
}
/* Per FFTW documentation:
...
...
@@ -123,6 +131,10 @@ void calc_spectrum(sdr_packet * pkt, int spp, int fftskip) {
}
/* Calculate histogram of first npoints samples
* write it to pkt->histo
* npoints <= UINT16_MAX as histo is currently array of 16-bits
*/
void
calc_histogram
(
sdr_packet
*
pkt
,
int
npoints
)
{
memset
(
pkt
->
histo
,
0
,
HISTOGRAM_RES
*
sizeof
(
uint16_t
));
for
(
int
i
=
0
;
i
<
npoints
;
i
++
)
{
...
...
server/xlate_worker.c
View file @
4377bbef
...
...
@@ -31,6 +31,7 @@ extern SLIST_HEAD(worker_head_t, worker) worker_head;
int
widx
;
/* Calculate the maximum amplitude a filter can produce. */
float
calc_max_amplitude
(
float
*
taps
,
int
tapslen
)
{
float
acc
=
0
;
...
...
@@ -42,6 +43,7 @@ float calc_max_amplitude(float * taps, int tapslen) {
}
/* Rotate the low-pass filter, so it becomes band-pass. */
float
*
get_complex_taps
(
float
*
taps
,
int
tapslen
,
float
rotate
)
{
size_t
align
=
volk_get_alignment
();
float
*
ctaps
=
volk_safe_malloc
(
tapslen
*
COMPLEX
*
sizeof
(
float
),
align
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment