Commit 4377bbef authored by Jenda's avatar Jenda

server: comments + measure spectrum in dB

parent 60913f2a
......@@ -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 = htobe32(i);
i = htole32(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 = htobe16(i);
i = htole16(i);
memcpy(x, &i, sizeof(i));
}
......
......@@ -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
......
#!/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
......@@ -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++) {
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment