Skip to content

Commit

Permalink
Merge branch 'feature/bandwidth-hotconfig'
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed Aug 19, 2019
2 parents e7e387d + 5a44a9c commit d3eaa79
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 283 deletions.
1 change: 1 addition & 0 deletions analyzer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ libanalyzer_la_SOURCES = \
spectsrcs/exp-4.c \
spectsrcs/exp-8.c \
spectsrcs/psd.c \
slow.c \
symbuf.c \
symbuf.h \
throttle.c \
Expand Down
286 changes: 3 additions & 283 deletions analyzer/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,167 +208,6 @@ suscan_analyzer_feed_inspectors(
return ok;
}

SUPRIVATE void
suscan_analyzer_gain_request_destroy(struct suscan_analyzer_gain_request *req)
{
if (req->name != NULL)
free(req->name);

free(req);
}

SUPRIVATE struct suscan_analyzer_gain_request *
suscan_analyzer_gain_request_new(const char *name, SUFLOAT value)
{
struct suscan_analyzer_gain_request *new = NULL;

SU_TRYCATCH(
new = calloc(1, sizeof(struct suscan_analyzer_gain_request)),
goto fail);

SU_TRYCATCH(new->name = strdup(name), goto fail);
new->value = value;

return new;

fail:
if (new != NULL)
suscan_analyzer_gain_request_destroy(new);

return NULL;
}

SUPRIVATE SUBOOL
suscan_analyzer_set_gain_cb(
struct suscan_mq *mq_out,
void *wk_private,
void *cb_private)
{
suscan_analyzer_t *analyzer = (suscan_analyzer_t *) wk_private;
SUBOOL mutex_acquired = SU_FALSE;
PTR_LIST_LOCAL(struct suscan_analyzer_gain_request, request);
unsigned int i;

/* vvvvvvvvvvvvvvvvvv Acquire hotconf request mutex vvvvvvvvvvvvvvvvvvvvvvvvv */
SU_TRYCATCH(pthread_mutex_lock(&analyzer->hotconf_mutex) != -1, goto fail);
mutex_acquired = SU_TRUE;

request_list = analyzer->gain_request_list;
request_count = analyzer->gain_request_count;

analyzer->gain_request_list = NULL;
analyzer->gain_request_count = 0;

pthread_mutex_unlock(&analyzer->hotconf_mutex);
mutex_acquired = SU_FALSE;
/* ^^^^^^^^^^^^^^^^^^ Release hotconf request mutex ^^^^^^^^^^^^^^^^^^^^^^^^^ */

/* Process all requests */
for (i = 0; i < request_count; ++i) {
SU_TRYCATCH(
suscan_source_set_gain(
analyzer->source,
request_list[i]->name,
request_list[i]->value),
goto fail);
}

fail:
if (mutex_acquired)
pthread_mutex_unlock(&analyzer->hotconf_mutex);

for (i = 0; i < request_count; ++i)
suscan_analyzer_gain_request_destroy(request_list[i]);

if (request_list != NULL)
free(request_list);

return SU_FALSE;
}

SUPRIVATE SUBOOL
suscan_analyzer_set_antenna_cb(
struct suscan_mq *mq_out,
void *wk_private,
void *cb_private)
{
suscan_analyzer_t *analyzer = (suscan_analyzer_t *) wk_private;
SUBOOL mutex_acquired = SU_FALSE;
char *req = NULL;
unsigned int i;

/* vvvvvvvvvvvvvvvvvv Acquire hotconf request mutex vvvvvvvvvvvvvvvvvvvvvvvvv */
SU_TRYCATCH(pthread_mutex_lock(&analyzer->hotconf_mutex) != -1, goto fail);
mutex_acquired = SU_TRUE;

req = analyzer->antenna_req;
analyzer->antenna_req = NULL;

pthread_mutex_unlock(&analyzer->hotconf_mutex);
mutex_acquired = SU_FALSE;
/* ^^^^^^^^^^^^^^^^^^ Release hotconf request mutex ^^^^^^^^^^^^^^^^^^^^^^^^^ */

suscan_source_set_antenna(analyzer->source, req);

fail:
if (mutex_acquired)
pthread_mutex_unlock(&analyzer->hotconf_mutex);

if (req != NULL)
free(req);

return SU_FALSE;
}

SUPRIVATE SUBOOL
suscan_analyzer_set_dc_remove_cb(
struct suscan_mq *mq_out,
void *wk_private,
void *cb_private)
{
suscan_analyzer_t *analyzer = (suscan_analyzer_t *) wk_private;
SUBOOL remove = (SUBOOL) (uintptr_t) cb_private;

(void) suscan_source_set_dc_remove(analyzer->source, remove);

return SU_FALSE;
}

SUPRIVATE SUBOOL
suscan_analyzer_set_agc_cb(
struct suscan_mq *mq_out,
void *wk_private,
void *cb_private)
{
suscan_analyzer_t *analyzer = (suscan_analyzer_t *) wk_private;
SUBOOL set = (SUBOOL) (uintptr_t) cb_private;

(void) suscan_source_set_agc(analyzer->source, set);

return SU_FALSE;
}

SUPRIVATE SUBOOL
suscan_analyzer_set_freq_cb(
struct suscan_mq *mq_out,
void *wk_private,
void *cb_private)
{
suscan_analyzer_t *analyzer = (suscan_analyzer_t *) wk_private;
SUFREQ freq;

if (analyzer->freq_req) {
freq = analyzer->freq_req_value;
if (suscan_source_set_freq(analyzer->source, freq)) {
/* XXX: Use a proper frequency adjust method */
analyzer->detector->params.fc = freq;
}
analyzer->freq_req = analyzer->freq_req_value == freq;
}

return SU_FALSE;
}

/* Hacky way to perform IQ inversion without depending on the FPU */
SUPRIVATE SUBOOL
suscan_analyzer_do_iq_rev(SUCOMPLEX *buf, SUSCOUNT size)
Expand Down Expand Up @@ -1146,19 +985,12 @@ suscan_analyzer_destroy(suscan_analyzer_t *analyzer)
if (analyzer->source != NULL)
suscan_source_destroy(analyzer->source);

/* Release slow worker data */
suscan_analyzer_destroy_slow_worker_data(analyzer);

if (analyzer->throttle_mutex_init)
pthread_mutex_destroy(&analyzer->throttle_mutex);

/* Delete all pending gain requessts */
for (i = 0; i < analyzer->gain_request_count; ++i)
suscan_analyzer_gain_request_destroy(analyzer->gain_request_list[i]);

if (analyzer->gain_request_list != NULL)
free(analyzer->gain_request_list);

if (analyzer->gain_req_mutex_init)
pthread_mutex_destroy(&analyzer->hotconf_mutex);

/* Delete all baseband filters */
for (i = 0; i < analyzer->bbfilt_count; ++i)
if (analyzer->bbfilt_list[i] != NULL)
Expand Down Expand Up @@ -1198,125 +1030,13 @@ suscan_analyzer_source_init(
return SU_FALSE;
}

SUBOOL
suscan_analyzer_set_freq(suscan_analyzer_t *analyzer, SUFREQ freq)
{
analyzer->freq_req_value = freq;
analyzer->freq_req = SU_TRUE;

/* This operation is rather slow. Do it somewhere else. */
return suscan_worker_push(
analyzer->slow_wk,
suscan_analyzer_set_freq_cb,
NULL);
}

SUBOOL
suscan_analyzer_set_dc_remove(suscan_analyzer_t *analyzer, SUBOOL remove)
{
return suscan_worker_push(
analyzer->slow_wk,
suscan_analyzer_set_dc_remove_cb,
(void *) (uintptr_t) remove);
}

SUBOOL
suscan_analyzer_set_agc(suscan_analyzer_t *analyzer, SUBOOL set)
{
return suscan_worker_push(
analyzer->slow_wk,
suscan_analyzer_set_agc_cb,
(void *) (uintptr_t) set);
}

SUBOOL
suscan_analyzer_set_iq_reverse(suscan_analyzer_t *analyzer, SUBOOL rev)
{
analyzer->iq_rev = rev;
return SU_TRUE;
}

SUBOOL
suscan_analyzer_set_antenna(
suscan_analyzer_t *analyzer,
const char *name)
{
char *req = NULL;
SUBOOL mutex_acquired = SU_FALSE;

SU_TRYCATCH(req = strdup(name), goto fail);

/* vvvvvvvvvvvvvvvvvv Acquire hotconf request mutex vvvvvvvvvvvvvvvvvvvvvvv */
SU_TRYCATCH(
pthread_mutex_lock(&analyzer->hotconf_mutex) != -1,
goto fail);
mutex_acquired = SU_TRUE;

if (analyzer->antenna_req != NULL)
free(analyzer->antenna_req);
analyzer->antenna_req = req;
req = NULL;

pthread_mutex_unlock(&analyzer->hotconf_mutex);
mutex_acquired = SU_FALSE;
/* ^^^^^^^^^^^^^^^^^^ Release hotconf request mutex ^^^^^^^^^^^^^^^^^^^^^^^ */

return suscan_worker_push(
analyzer->slow_wk,
suscan_analyzer_set_antenna_cb,
NULL);

fail:
if (mutex_acquired)
pthread_mutex_unlock(&analyzer->hotconf_mutex);

if (req != NULL)
free(req);

return SU_FALSE;
}

SUBOOL
suscan_analyzer_set_gain(
suscan_analyzer_t *analyzer,
const char *name,
SUFLOAT value)
{
struct suscan_analyzer_gain_request *req = NULL;
SUBOOL mutex_acquired = SU_FALSE;

SU_TRYCATCH(req = suscan_analyzer_gain_request_new(name, value), goto fail);

/* vvvvvvvvvvvvvvvvvv Acquire hotconf request mutex vvvvvvvvvvvvvvvvvvvvvvv */
SU_TRYCATCH(
pthread_mutex_lock(&analyzer->hotconf_mutex) != -1,
goto fail);
mutex_acquired = SU_TRUE;

SU_TRYCATCH(
PTR_LIST_APPEND_CHECK(analyzer->gain_request, req) != -1,
goto fail);
req = NULL;

pthread_mutex_unlock(&analyzer->hotconf_mutex);
mutex_acquired = SU_FALSE;
/* ^^^^^^^^^^^^^^^^^^ Release hotconf request mutex ^^^^^^^^^^^^^^^^^^^^^^^ */

return suscan_worker_push(
analyzer->slow_wk,
suscan_analyzer_set_gain_cb,
NULL);

fail:
if (mutex_acquired)
pthread_mutex_unlock(&analyzer->hotconf_mutex);

if (req != NULL)
suscan_analyzer_gain_request_destroy(req);

return SU_FALSE;
}


suscan_analyzer_t *
suscan_analyzer_new(
Expand Down
8 changes: 8 additions & 0 deletions analyzer/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,17 @@ struct suscan_analyzer {
SUSCOUNT per_cnt_psd;

/* This mutex shall protect hot-config requests */
/* XXX: This is cumbersome. Create a hotconf object to handle these things */
pthread_mutex_t hotconf_mutex;

/* Frequency request */
SUBOOL freq_req;
SUFREQ freq_req_value;

/* Bandwidth request */
SUBOOL bw_req;
SUFLOAT bw_req_value;

/* Gain request */
SUBOOL gain_req_mutex_init;
PTR_LIST(struct suscan_analyzer_gain_request, gain_request);
Expand Down Expand Up @@ -146,6 +151,7 @@ suscan_analyzer_get_samp_rate(const suscan_analyzer_t *analyzer)
}

SUBOOL suscan_analyzer_set_freq(suscan_analyzer_t *analyzer, SUFREQ freq);
SUBOOL suscan_analyzer_set_bw(suscan_analyzer_t *analyzer, SUFLOAT bw);
SUBOOL suscan_analyzer_set_gain(
suscan_analyzer_t *analyzer,
const char *name,
Expand All @@ -157,6 +163,8 @@ SUBOOL suscan_analyzer_set_dc_remove(suscan_analyzer_t *analyzer, SUBOOL val);
SUBOOL suscan_analyzer_set_iq_reverse(suscan_analyzer_t *analyzer, SUBOOL val);
SUBOOL suscan_analyzer_set_agc(suscan_analyzer_t *analyzer, SUBOOL val);

void suscan_analyzer_destroy_slow_worker_data(suscan_analyzer_t *);

void *suscan_analyzer_read(suscan_analyzer_t *analyzer, uint32_t *type);
struct suscan_analyzer_inspector_msg *suscan_analyzer_read_inspector_msg(
suscan_analyzer_t *analyzer);
Expand Down
Loading

0 comments on commit d3eaa79

Please sign in to comment.