summaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-09 14:18:09 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-09 14:18:09 +0100
commitb0a523248766c1e001ea0f5d2e40c23b3178e629 (patch)
treeed0387a9a8707e300c1186da859c0388e528f716 /controller
parent5997a24fcb28b07936f03a1f7c792c31b86451cc (diff)
downloadmaster-thesis-b0a523248766c1e001ea0f5d2e40c23b3178e629.tar.gz
master-thesis-b0a523248766c1e001ea0f5d2e40c23b3178e629.tar.bz2
master-thesis-b0a523248766c1e001ea0f5d2e40c23b3178e629.zip
Fix a bunch of compiler warnings
Diffstat (limited to 'controller')
-rw-r--r--controller/fw/Makefile3
-rw-r--r--controller/fw/src/dsss_demod.c30
-rw-r--r--controller/fw/src/dsss_demod.h4
-rw-r--r--controller/fw/tools/dsss_demod_test.c5
4 files changed, 22 insertions, 20 deletions
diff --git a/controller/fw/Makefile b/controller/fw/Makefile
index fac9169..a7d690a 100644
--- a/controller/fw/Makefile
+++ b/controller/fw/Makefile
@@ -111,7 +111,8 @@ COMMON_CFLAGS += -DTRANSMISSION_SYMBOLS=$(TRANSMISSION_SYMBOLS)
# for musl
CFLAGS += -Dhidden=
-SIM_CFLAGS += -lm -DSIMULATION
+SIM_CFLAGS += -lm -DSIMULATION -fsanitize=address
+SIM_CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -Wimplicit-function-declaration -Wundef
INT_CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -Wimplicit-function-declaration -Wundef
INT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
diff --git a/controller/fw/src/dsss_demod.c b/controller/fw/src/dsss_demod.c
index a561436..97cc039 100644
--- a/controller/fw/src/dsss_demod.c
+++ b/controller/fw/src/dsss_demod.c
@@ -28,7 +28,7 @@ static float run_biquad(float x, const struct iir_biquad *const q, struct iir_bi
static void matcher_init(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE]);
static void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE],
uint64_t ts, int peak_ch, float peak_ampl);
-static void group_received(struct dsss_demod_state *st, uint64_t ts);
+static void group_received(struct dsss_demod_state *st);
#ifdef SIMULATION
void debug_print_vector(const char *name, size_t len, const float *data, size_t stride, bool index, bool debug) {
@@ -38,7 +38,7 @@ void debug_print_vector(const char *name, size_t len, const float *data, size_t
if (index) {
DEBUG_PRINTN(" %16s [", "");
for (size_t i=0; i<len; i++)
- DEBUG_PRINTN("%8d ", i);
+ DEBUG_PRINTN("%8zd ", i);
DEBUG_PRINTN("]\n");
}
@@ -56,12 +56,7 @@ void dsss_demod_init(struct dsss_demod_state *st) {
matcher_init(st->matcher_cache);
}
-#ifdef SIMULATION
-void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts, int record_channel) {
-#else
-void dsss_demod_step(struct dsss_demod_state *st, float new_value) {
-#endif
-
+void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts) {
//const float hole_patching_threshold = 0.01 * DSSS_CORRELATION_LENGTH;
st->signal[st->signal_wpos] = new_value;
@@ -77,7 +72,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) {
for (size_t i=0; i<DSSS_GOLD_CODE_COUNT; i++)
cwt[i] = cwt_convolve_step(st->correlation[i], st->correlation_wpos);
- float avg;
+ float avg = 0.0f;
for (size_t i=0; i<DSSS_GOLD_CODE_COUNT; i++)
avg += fabs(cwt[i]);
avg /= (float)DSSS_GOLD_CODE_COUNT;
@@ -118,7 +113,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) {
return;
/* A group ended. Process result. */
- group_received(st, ts);
+ group_received(st);
/* reset grouping state */
st->group.len = 0;
@@ -151,7 +146,7 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
/* TODO make these constants configurable from Makefile */
const float skip_sampling_depreciation = 0.2f; /* 0.0 -> no depreciation, 1.0 -> complete disregard */
const float score_depreciation = 0.1f; /* 0.0 -> no depreciation, 1.0 -> complete disregard */
- const uint64_t current_phase = ts % DSSS_CORRELATION_LENGTH;
+ const int current_phase = ts % DSSS_CORRELATION_LENGTH;
const int max_skips = TRANSMISSION_SYMBOLS/4*3;
for (size_t i=0; i<DSSS_MATCHER_CACHE_SIZE; i++) {
@@ -163,6 +158,7 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
float score = fabs(peak_ampl) * (1.0f - skip_sampling_depreciation);
if (score > states[i].candidate_score) {
/* We win, update candidate */
+ assert(i < DSSS_MATCHER_CACHE_SIZE);
states[i].candidate_score = score;
states[i].candidate_phase = current_phase;
states[i].candidate_data = decode_peak(peak_ch, peak_ampl);
@@ -177,6 +173,8 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
*/
if (abs(states[i].last_phase - current_phase) == group_phase_tolerance + DSSS_DECIMATION) {
/* Process window results */
+ assert(i < DSSS_MATCHER_CACHE_SIZE);
+ assert(0 <= states[i].data_pos && states[i].data_pos < TRANSMISSION_SYMBOLS);
states[i].data[ states[i].data_pos ] = states[i].candidate_data;
states[i].data_pos = states[i].data_pos + 1;
states[i].last_score = score_depreciation * states[i].last_score +
@@ -208,7 +206,7 @@ static float score_group(const struct group *g, int phase_delta) {
return fabsf(g->max) * gaussian(1.0f, 0.0f, distance_func_phase_tolerance, phase_delta);
}
-void group_received(struct dsss_demod_state *st, uint64_t ts) {
+void group_received(struct dsss_demod_state *st) {
const int group_phase = st->group.max_ts % DSSS_CORRELATION_LENGTH;
/* This is the score of a decoding starting at this group (with no context) */
float base_score = score_group(&st->group, 0);
@@ -231,6 +229,8 @@ void group_received(struct dsss_demod_state *st, uint64_t ts) {
float group_score = score_group(&st->group, phase_delta);
if (st->matcher_cache[i].candidate_score < group_score) {
+ assert(i < DSSS_MATCHER_CACHE_SIZE);
+ /* Append to entry */
st->matcher_cache[i].candidate_score = group_score;
st->matcher_cache[i].candidate_phase = group_phase;
st->matcher_cache[i].candidate_data = decode_peak(st->group.max_ch, st->group.max);
@@ -248,6 +248,8 @@ void group_received(struct dsss_demod_state *st, uint64_t ts) {
/* If we found empty entries, replace one by a new decoding starting at this group */
if (empty_idx >= 0) {
+ DEBUG_PRINT("Writing to %zd", empty_idx);
+ assert(0 <= empty_idx && empty_idx < DSSS_MATCHER_CACHE_SIZE);
st->matcher_cache[empty_idx].last_phase = group_phase;
st->matcher_cache[empty_idx].candidate_score = base_score;
st->matcher_cache[empty_idx].last_score = base_score;
@@ -259,6 +261,8 @@ void group_received(struct dsss_demod_state *st, uint64_t ts) {
/* If the weakest decoding in cache is weaker than a new decoding starting here, replace it */
} else if (min_score < base_score && min_idx >= 0) {
+ DEBUG_PRINT("Writing to %zd", min_idx);
+ assert(0 <= min_idx && min_idx < DSSS_MATCHER_CACHE_SIZE);
st->matcher_cache[min_idx].last_phase = group_phase;
st->matcher_cache[min_idx].candidate_score = base_score;
st->matcher_cache[min_idx].last_score = base_score;
@@ -309,7 +313,7 @@ float gold_correlate_step(const size_t ncode, const float a[DSSS_CORRELATION_LEN
float acc_outer = 0.0f;
uint8_t table_byte = 0;
- if (debug) DEBUG_PRINTN("Correlate n=%d: ", ncode);
+ if (debug) DEBUG_PRINTN("Correlate n=%zd: ", ncode);
for (size_t i=0; i<DSSS_GOLD_CODE_LENGTH; i++) {
if ((i&7) == 0) {
diff --git a/controller/fw/src/dsss_demod.h b/controller/fw/src/dsss_demod.h
index 2e8c003..e7e5cf9 100644
--- a/controller/fw/src/dsss_demod.h
+++ b/controller/fw/src/dsss_demod.h
@@ -66,10 +66,6 @@ struct dsss_demod_state {
extern void handle_dsss_received(uint8_t data[TRANSMISSION_SYMBOLS]);
void dsss_demod_init(struct dsss_demod_state *st);
-#ifdef SIMULATION
-void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts, int record_channel);
-#else /* SIMULATION */
void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts);
-#endif /* SIMULATION */
#endif /* __DSSS_DEMOD_H__ */
diff --git a/controller/fw/tools/dsss_demod_test.c b/controller/fw/tools/dsss_demod_test.c
index fb08fb3..d09ce87 100644
--- a/controller/fw/tools/dsss_demod_test.c
+++ b/controller/fw/tools/dsss_demod_test.c
@@ -68,7 +68,7 @@ int main(int argc, char **argv) {
if (record_channel != -1)
fprintf(stderr, "Reading %zd samples test data...", st.st_size/sizeof(float));
- size_t nread = 0;
+ ssize_t nread = 0;
while (nread < st.st_size) {
ssize_t rc = read(fd, buf, st.st_size - nread);
@@ -100,8 +100,9 @@ int main(int argc, char **argv) {
dsss_demod_init(&demod);
for (size_t i=0; i<n_samples; i++) {
//fprintf(stderr, "Iteration %zd/%zd\n", i, n_samples);
- dsss_demod_step(&demod, buf_f[i], i, record_channel);
+ dsss_demod_step(&demod, buf_f[i], i);
}
+ free(buf);
return 0;
}