ref_app_tank_level.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2023
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6
7 #include <math.h>
8 #include <stdbool.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #include "acc_definitions_a121.h"
14 #include "acc_detector_distance.h"
15 #include "acc_hal_definitions_a121.h"
16 #include "acc_hal_integration_a121.h"
17 #include "acc_integration.h"
18 #include "acc_integration_log.h"
19 #include "acc_rss_a121.h"
20 #include "acc_sensor.h"
21 #include "acc_version.h"
22
23
24 #define SENSOR_ID 1U
25 #define SENSOR_TIMEOUT_MS 1000U
26 #define DEFAULT_UPDATE_RATE 1.0f
27
28 // Settings for a small tank
29 #define SMALL_TANK_MEDIAN_FILTER_LENGTH 5U
30 #define SMALL_TANK_NUM_MEDIANS_TO_AVERAGE 5U
31 #define SMALL_TANK_RANGE_START_M 0.03f
32 #define SMALL_TANK_RANGE_END_M 0.5f
33 #define SMALL_TANK_MAX_STEP_LENGTH 2U
34 #define SMALL_TANK_MAX_PROFILE ACC_CONFIG_PROFILE_2
35 #define SMALL_TANK_NUM_FRAMES_REC 50U
36 #define SMALL_TANK_PEAK_SORTING ACC_DETECTOR_DISTANCE_PEAK_SORTING_CLOSEST
37 #define SMALL_TANK_REFLECTOR_SHAPE ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR
38 #define SMALL_TANK_THRESHOLD_SENSITIVITY 0.0f
39 #define SMALL_TANK_SIGNAL_QUALITY 20.0f
40 #define SMALL_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION true
41
42 // Settings for a medium tank
43 #define MEDIUM_TANK_MEDIAN_FILTER_LENGTH 3U
44 #define MEDIUM_TANK_NUM_MEDIANS_TO_AVERAGE 3U
45 #define MEDIUM_TANK_RANGE_START_M 0.05f
46 #define MEDIUM_TANK_RANGE_END_M 6.0f
47 #define MEDIUM_TANK_MAX_STEP_LENGTH 0U // 0 means no limit
48 #define MEDIUM_TANK_MAX_PROFILE ACC_CONFIG_PROFILE_3
49 #define MEDIUM_TANK_NUM_FRAMES_REC 50U
50 #define MEDIUM_TANK_PEAK_SORTING ACC_DETECTOR_DISTANCE_PEAK_SORTING_STRONGEST
51 #define MEDIUM_TANK_REFLECTOR_SHAPE ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR
52 #define MEDIUM_TANK_THRESHOLD_SENSITIVITY 0.0f
53 #define MEDIUM_TANK_SIGNAL_QUALITY 20.0f
54 #define MEDIUM_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION true
55
56 // Settings for a large tank
57 #define LARGE_TANK_MEDIAN_FILTER_LENGTH 3U
58 #define LARGE_TANK_NUM_MEDIANS_TO_AVERAGE 1U
59 #define LARGE_TANK_RANGE_START_M 0.1f
60 #define LARGE_TANK_RANGE_END_M 10.0f
61 #define LARGE_TANK_MAX_STEP_LENGTH 0U // 0 means no limit
62 #define LARGE_TANK_MAX_PROFILE ACC_CONFIG_PROFILE_5
63 #define LARGE_TANK_NUM_FRAMES_REC 50U
64 #define LARGE_TANK_PEAK_SORTING ACC_DETECTOR_DISTANCE_PEAK_SORTING_STRONGEST
65 #define LARGE_TANK_REFLECTOR_SHAPE ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR
66 #define LARGE_TANK_THRESHOLD_SENSITIVITY 0.0f
67 #define LARGE_TANK_SIGNAL_QUALITY 20.0f
68 #define LARGE_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION true
69
70 /** \example ref_app_tank_level.c
71 * @brief This is a reference application for measuring liquid level in tanks
72 * @n
73 * This reference application executes as follows:
74 * - Retrieve HAL integration
75 * - Initialize application resources:
76 * + Create application configuration
77 * + Create distance detector configuration
78 * + Update configuration settings
79 * + Create distance detector handle
80 * + Create buffer for detector calibration data
81 * + Create buffer for sensor data
82 * - Create and calibrate the sensor
83 * - Calibrate the detector
84 * - Measure distances with the detector (loop):
85 * + Prepare sensor with the detector
86 * + Measure and wait until a read can be done
87 * + Process sensor measurement and get distance detector result
88 * + Process distance detector result and print the result
89 * + Handle "sensor_calibration_needed" indication
90 * - Cleanup:
91 * + Destroy detector configuration
92 * + Destroy detector handle
93 * + Destroy sensor data buffer
94 * + Destroy detector calibration data buffer
95 */
96
97
98 typedef enum
99 {
100 TANK_LEVEL_PRESET_CONFIG_NONE = 0,
101 TANK_LEVEL_PRESET_CONFIG_SMALL_TANK,
102 TANK_LEVEL_PRESET_CONFIG_MEDIUM_TANK,
103 TANK_LEVEL_PRESET_CONFIG_LARGE_TANK,
104 } tank_level_preset_config_t;
105
106 #define DEFAULT_PRESET_CONFIG TANK_LEVEL_PRESET_CONFIG_SMALL_TANK
107
108
109 typedef struct
110 {
111 float tank_range_start_m;
112 float tank_range_end_m;
113 uint16_t median_filter_length;
114 uint16_t num_medians_to_average;
115 acc_detector_distance_config_t *distance_config;
116 } acc_ref_app_tank_level_config_t;
117
118 typedef struct
119 {
120 acc_ref_app_tank_level_config_t *app_config;
121 acc_sensor_t *sensor;
122 float *level_history;
123 uint16_t level_history_length;
124 float *median_vector;
125 uint16_t median_vector_length;
126 uint16_t median_counter;
127 uint16_t mean_counter;
128 uint16_t median_edge_status_count;
129 uint16_t mean_edge_status_count;
130 acc_detector_distance_handle_t *detector_handle;
131 void *buffer;
132 uint32_t buffer_size;
133 void *calibration_buffer;
134 uint32_t calibration_buffer_size;
135 } app_context_t;
136
137 typedef enum
138 {
139 PEAK_STATUS_IN_RANGE,
140 PEAK_STATUS_NO_DETECTION,
141 PEAK_STATUS_OVERFLOW,
142 PEAK_STATUS_OUT_OF_RANGE
143 } peak_status_t;
144
145 typedef struct
146 {
147 bool peak_detected;
148 peak_status_t peak_status;
149 float level;
150 bool result_ready;
151 } app_result_t;
152
153
154 static void cleanup(app_context_t *context);
155
156
157 static float get_detector_start_m(acc_ref_app_tank_level_config_t *app_config);
158
159
160 static float get_detector_end_m(acc_ref_app_tank_level_config_t *app_config);
161
162
163 static void set_config(acc_ref_app_tank_level_config_t *app_config, tank_level_preset_config_t preset);
164
165
166 static bool initialize_application_resources(app_context_t *context);
167
168
169 static bool sensor_calibration(acc_sensor_t *sensor,
170 acc_cal_result_t *cal_result,
171 void *buffer,
172 uint32_t buffer_size);
173
174
175 static bool full_detector_calibration(app_context_t *context,
176 const acc_cal_result_t *sensor_cal_result);
177
178
179 static bool detector_recalibration(app_context_t *context,
180 const acc_cal_result_t *sensor_cal_result);
181
182
183 static bool detector_get_next(app_context_t *context,
184 const acc_cal_result_t *sensor_cal_result,
185 acc_detector_distance_result_t *detector_result);
186
187
188 static void swap(float *array, uint16_t idx_a, uint16_t idx_b);
189
190
191 static void sort(float *array, uint16_t array_length);
192
193
194 static float median(float *array, uint16_t array_length);
195
196
197 static float nanmean(float *array, uint16_t array_length);
198
199
200 static void process_detector_result(const acc_detector_distance_result_t *distance_result, app_result_t *app_result,
201 app_context_t *context);
202
203
204 static void print_result(const app_result_t *app_result, const acc_ref_app_tank_level_config_t *app_config);
205
206
207 int acconeer_main(int argc, char *argv[]);
208
209
210 int acconeer_main(int argc, char *argv[])
211 {
212 (void)argc;
213 (void)argv;
214 app_context_t context = { 0 };
215 acc_ref_app_tank_level_config_t app_config = { 0 };
216 context.app_config = &app_config;
217 context.sensor = NULL;
218
219 printf("Acconeer software version %s\n", acc_version_get());
220
221 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
222
223 if (!acc_rss_hal_register(hal))
224 {
225 return EXIT_FAILURE;
226 }
227
228 context.app_config->distance_config = acc_detector_distance_config_create();
229 if (context.app_config->distance_config == NULL)
230 {
231 printf("acc_detector_distance_config_create() failed\n");
232 cleanup(&context);
233 return EXIT_FAILURE;
234 }
235
236 set_config(&app_config, DEFAULT_PRESET_CONFIG);
237
238 uint32_t sleep_time_ms = (uint32_t)(1000.0f / DEFAULT_UPDATE_RATE);
239
240 acc_integration_set_periodic_wakeup(sleep_time_ms);
241
242 if (!initialize_application_resources(&context))
243 {
244 printf("Initializing detector context failed\n");
245 cleanup(&context);
246 return EXIT_FAILURE;
247 }
248
249 /* Turn the sensor on */
250 acc_hal_integration_sensor_supply_on(SENSOR_ID);
251 acc_hal_integration_sensor_enable(SENSOR_ID);
252
253 context.sensor = acc_sensor_create(SENSOR_ID);
254 if (context.sensor == NULL)
255 {
256 printf("acc_sensor_create() failed\n");
257 cleanup(&context);
258 return EXIT_FAILURE;
259 }
260
261 acc_cal_result_t cal_result;
262
263 if (!sensor_calibration(context.sensor, &cal_result, context.buffer, context.buffer_size))
264 {
265 printf("Sensor calibration failed\n");
266 cleanup(&context);
267 return EXIT_FAILURE;
268 }
269
270 if (!full_detector_calibration(&context, &cal_result))
271 {
272 printf("Detector calibration failed\n");
273 cleanup(&context);
274 return EXIT_FAILURE;
275 }
276
277 while (true)
278 {
279 acc_detector_distance_result_t detector_result = { 0 };
280 app_result_t app_result = { 0 };
281
282 if (!detector_get_next(&context, &cal_result, &detector_result))
283 {
284 printf("Could not get next result\n");
285 cleanup(&context);
286 return EXIT_FAILURE;
287 }
288
289 process_detector_result(&detector_result, &app_result, &context);
290
291 /* If "sensor calibration needed" is indicated, the sensor and detector needs to be recalibrated */
292 if (detector_result.sensor_calibration_needed)
293 {
294 printf("Sensor- and detector recalibration needed ... \n");
295
296 if (!sensor_calibration(context.sensor, &cal_result, context.buffer, context.buffer_size))
297 {
298 printf("Sensor calibration failed\n");
299 cleanup(&context);
300 return EXIT_FAILURE;
301 }
302
303 /* Once the sensor is recalibrated, the detector should be recalibrated and measuring can continue. */
304 if (!detector_recalibration(&context, &cal_result))
305 {
306 printf("Detector recalibration failed\n");
307 cleanup(&context);
308 return EXIT_FAILURE;
309 }
310
311 printf("Sensor- and detector recalibration done!\n");
312 }
313
314 if (app_result.result_ready)
315 {
316 acc_hal_integration_sensor_disable(SENSOR_ID);
317
318 print_result(&app_result, context.app_config);
319
320 acc_integration_sleep_until_periodic_wakeup();
321
322 acc_hal_integration_sensor_enable(SENSOR_ID);
323 }
324 }
325
326 cleanup(&context);
327
328 printf("Application finished OK\n");
329
330 return EXIT_SUCCESS;
331 }
332
333
334 static void cleanup(app_context_t *context)
335 {
336 acc_hal_integration_sensor_disable(SENSOR_ID);
337 acc_hal_integration_sensor_supply_off(SENSOR_ID);
338
339 acc_detector_distance_config_destroy(context->app_config->distance_config);
340 acc_detector_distance_destroy(context->detector_handle);
341
342 acc_integration_mem_free(context->buffer);
343 acc_integration_mem_free(context->calibration_buffer);
344 acc_integration_mem_free(context->level_history);
345 acc_integration_mem_free(context->median_vector);
346
347 if (context->sensor != NULL)
348 {
349 acc_sensor_destroy(context->sensor);
350 }
351 }
352
353
354 static float get_detector_start_m(acc_ref_app_tank_level_config_t *app_config)
355 {
356 // Decrease start point by 15 mm to make sure that start of the tank is fully covered
357 return app_config->tank_range_start_m - 0.015f;
358 }
359
360
361 static float get_detector_end_m(acc_ref_app_tank_level_config_t *app_config)
362 {
363 // Increase end point by 5% to make sure that the bottom of the tank is fully covered
364 return app_config->tank_range_end_m * 1.05f;
365 }
366
367
368 static void set_config(acc_ref_app_tank_level_config_t *app_config, tank_level_preset_config_t preset)
369 {
370 switch (preset)
371 {
372 case TANK_LEVEL_PRESET_CONFIG_NONE:
373 break;
374 case TANK_LEVEL_PRESET_CONFIG_SMALL_TANK:
375 app_config->tank_range_start_m = SMALL_TANK_RANGE_START_M;
376 app_config->tank_range_end_m = SMALL_TANK_RANGE_END_M;
377 app_config->median_filter_length = SMALL_TANK_MEDIAN_FILTER_LENGTH;
378 app_config->num_medians_to_average = SMALL_TANK_NUM_MEDIANS_TO_AVERAGE;
379
380 acc_detector_distance_config_start_set(app_config->distance_config, get_detector_start_m(app_config));
381 acc_detector_distance_config_end_set(app_config->distance_config, get_detector_end_m(app_config));
382 acc_detector_distance_config_max_step_length_set(app_config->distance_config, SMALL_TANK_MAX_STEP_LENGTH);
383 acc_detector_distance_config_max_profile_set(app_config->distance_config, SMALL_TANK_MAX_PROFILE);
384 acc_detector_distance_config_num_frames_recorded_threshold_set(app_config->distance_config, SMALL_TANK_NUM_FRAMES_REC);
385 acc_detector_distance_config_peak_sorting_set(app_config->distance_config, SMALL_TANK_PEAK_SORTING);
386 acc_detector_distance_config_reflector_shape_set(app_config->distance_config, SMALL_TANK_REFLECTOR_SHAPE);
387 acc_detector_distance_config_threshold_sensitivity_set(app_config->distance_config, SMALL_TANK_THRESHOLD_SENSITIVITY);
388 acc_detector_distance_config_signal_quality_set(app_config->distance_config, SMALL_TANK_SIGNAL_QUALITY);
389 acc_detector_distance_config_close_range_leakage_cancellation_set(app_config->distance_config,
390 SMALL_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION);
391 break;
392 case TANK_LEVEL_PRESET_CONFIG_MEDIUM_TANK:
393 app_config->tank_range_start_m = MEDIUM_TANK_RANGE_START_M;
394 app_config->tank_range_end_m = MEDIUM_TANK_RANGE_END_M;
395 app_config->median_filter_length = MEDIUM_TANK_MEDIAN_FILTER_LENGTH;
396 app_config->num_medians_to_average = MEDIUM_TANK_NUM_MEDIANS_TO_AVERAGE;
397
398 acc_detector_distance_config_start_set(app_config->distance_config, get_detector_start_m(app_config));
399 acc_detector_distance_config_end_set(app_config->distance_config, get_detector_end_m(app_config));
400 acc_detector_distance_config_max_step_length_set(app_config->distance_config, MEDIUM_TANK_MAX_STEP_LENGTH);
401 acc_detector_distance_config_max_profile_set(app_config->distance_config, MEDIUM_TANK_MAX_PROFILE);
402 acc_detector_distance_config_num_frames_recorded_threshold_set(app_config->distance_config, MEDIUM_TANK_NUM_FRAMES_REC);
403 acc_detector_distance_config_peak_sorting_set(app_config->distance_config, MEDIUM_TANK_PEAK_SORTING);
404 acc_detector_distance_config_reflector_shape_set(app_config->distance_config, MEDIUM_TANK_REFLECTOR_SHAPE);
405 acc_detector_distance_config_threshold_sensitivity_set(app_config->distance_config, MEDIUM_TANK_THRESHOLD_SENSITIVITY);
406 acc_detector_distance_config_signal_quality_set(app_config->distance_config, MEDIUM_TANK_SIGNAL_QUALITY);
407 acc_detector_distance_config_close_range_leakage_cancellation_set(app_config->distance_config,
408 MEDIUM_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION);
409 break;
410 case TANK_LEVEL_PRESET_CONFIG_LARGE_TANK:
411 app_config->tank_range_start_m = LARGE_TANK_RANGE_START_M;
412 app_config->tank_range_end_m = LARGE_TANK_RANGE_END_M;
413 app_config->median_filter_length = LARGE_TANK_MEDIAN_FILTER_LENGTH;
414 app_config->num_medians_to_average = LARGE_TANK_NUM_MEDIANS_TO_AVERAGE;
415
416 acc_detector_distance_config_start_set(app_config->distance_config, get_detector_start_m(app_config));
417 acc_detector_distance_config_end_set(app_config->distance_config, get_detector_end_m(app_config));
418 acc_detector_distance_config_max_step_length_set(app_config->distance_config, LARGE_TANK_MAX_STEP_LENGTH);
419 acc_detector_distance_config_max_profile_set(app_config->distance_config, LARGE_TANK_MAX_PROFILE);
420 acc_detector_distance_config_num_frames_recorded_threshold_set(app_config->distance_config, LARGE_TANK_NUM_FRAMES_REC);
421 acc_detector_distance_config_peak_sorting_set(app_config->distance_config, LARGE_TANK_PEAK_SORTING);
422 acc_detector_distance_config_reflector_shape_set(app_config->distance_config, LARGE_TANK_REFLECTOR_SHAPE);
423 acc_detector_distance_config_threshold_sensitivity_set(app_config->distance_config, LARGE_TANK_THRESHOLD_SENSITIVITY);
424 acc_detector_distance_config_signal_quality_set(app_config->distance_config, LARGE_TANK_SIGNAL_QUALITY);
425 acc_detector_distance_config_close_range_leakage_cancellation_set(app_config->distance_config,
426 LARGE_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION);
427 break;
428 }
429 }
430
431
432 static bool initialize_application_resources(app_context_t *context)
433 {
434 context->detector_handle = acc_detector_distance_create(context->app_config->distance_config);
435 if (context->detector_handle == NULL)
436 {
437 printf("acc_detector_distance_create() failed\n");
438 return false;
439 }
440
441 if (!acc_detector_distance_get_buffer_sizes(context->detector_handle, &(context->buffer_size), &(context->calibration_buffer_size)))
442 {
443 printf("acc_detector_distance_get_buffer_sizes() failed\n");
444 return false;
445 }
446
447 context->buffer = acc_integration_mem_alloc(context->buffer_size);
448 if (context->buffer == NULL)
449 {
450 printf("sensor buffer allocation failed\n");
451 return false;
452 }
453
454 context->calibration_buffer = acc_integration_mem_alloc(context->calibration_buffer_size);
455 if (context->calibration_buffer == NULL)
456 {
457 printf("calibration buffer allocation failed\n");
458 return false;
459 }
460
461 context->level_history_length = context->app_config->median_filter_length;
462
463 context->level_history = acc_integration_mem_alloc(context->level_history_length * sizeof(*context->level_history));
464 if (context->level_history == NULL)
465 {
466 printf("level history buffer allocation failed\n");
467 return false;
468 }
469
470 context->median_vector_length = context->app_config->num_medians_to_average;
471
472 context->median_vector = acc_integration_mem_alloc(context->median_vector_length * sizeof(*context->median_vector));
473 if (context->median_vector == NULL)
474 {
475 printf("median vector allocation failed\n");
476 return false;
477 }
478
479 context->median_counter = 0U;
480 context->mean_counter = 0U;
481 context->median_edge_status_count = 0U;
482 context->mean_edge_status_count = 0U;
483
484 return true;
485 }
486
487
488 static bool sensor_calibration(acc_sensor_t *sensor,
489 acc_cal_result_t *sensor_cal_result,
490 void *buffer,
491 uint32_t buffer_size)
492 {
493 bool status = false;
494 bool cal_complete = false;
495 const uint16_t calibration_retries = 1U;
496
497 // Random disturbances may cause the calibration to fail. At failure, retry at least once.
498 for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
499 {
500 // Reset sensor before calibration by disabling/enabling it
501 acc_hal_integration_sensor_disable(SENSOR_ID);
502 acc_hal_integration_sensor_enable(SENSOR_ID);
503
504 do
505 {
506 status = acc_sensor_calibrate(sensor, &cal_complete, sensor_cal_result, buffer, buffer_size);
507
508 if (status && !cal_complete)
509 {
510 status = acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS);
511 }
512 } while (status && !cal_complete);
513 }
514
515 if (status)
516 {
517 /* Reset sensor after calibration by disabling/enabling it */
518 acc_hal_integration_sensor_disable(SENSOR_ID);
519 acc_hal_integration_sensor_enable(SENSOR_ID);
520 }
521 else
522 {
523 printf("acc_sensor_calibrate() failed\n");
524 acc_sensor_status(sensor);
525 }
526
527 return status;
528 }
529
530
531 static bool full_detector_calibration(app_context_t *context,
532 const acc_cal_result_t *sensor_cal_result)
533 {
534 bool done = false;
535 bool status;
536
537 do
538 {
539 status = acc_detector_distance_calibrate(context->sensor,
540 context->detector_handle,
541 sensor_cal_result,
542 context->buffer,
543 context->buffer_size,
544 context->calibration_buffer,
545 context->calibration_buffer_size,
546 &done);
547 } while (status && !done && acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS));
548
549 return status;
550 }
551
552
553 static bool detector_recalibration(app_context_t *context,
554 const acc_cal_result_t *sensor_cal_result)
555 {
556 bool done = false;
557 bool status;
558
559 do
560 {
561 status = acc_detector_distance_recalibrate(context->sensor,
562 context->detector_handle,
563 sensor_cal_result,
564 context->buffer,
565 context->buffer_size,
566 context->calibration_buffer,
567 context->calibration_buffer_size,
568 &done);
569 } while (status && !done && acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS));
570
571 return status;
572 }
573
574
575 static bool detector_get_next(app_context_t *context,
576 const acc_cal_result_t *sensor_cal_result,
577 acc_detector_distance_result_t *detector_result)
578 {
579 bool result_available = false;
580
581 do
582 {
583 if (!acc_detector_distance_prepare(context->detector_handle, context->app_config->distance_config, context->sensor, sensor_cal_result,
584 context->buffer,
585 context->buffer_size))
586 {
587 printf("acc_detector_distance_prepare() failed\n");
588 return false;
589 }
590
591 if (!acc_sensor_measure(context->sensor))
592 {
593 printf("acc_sensor_measure() failed\n");
594 return false;
595 }
596
597 if (!acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS))
598 {
599 printf("Sensor interrupt timeout\n");
600 return false;
601 }
602
603 if (!acc_sensor_read(context->sensor, context->buffer, context->buffer_size))
604 {
605 printf("acc_sensor_read() failed\n");
606 return false;
607 }
608
609 if (!acc_detector_distance_process(context->detector_handle, context->buffer, context->calibration_buffer, &result_available,
610 detector_result))
611 {
612 printf("acc_detector_distance_process() failed\n");
613 return false;
614 }
615 } while (!result_available);
616
617 return true;
618 }
619
620
621 static void swap(float *array, uint16_t idx_a, uint16_t idx_b)
622 {
623 float tmp = array[idx_a];
624
625 array[idx_a] = array[idx_b];
626 array[idx_b] = tmp;
627 }
628
629
630 static void sort(float *array, uint16_t array_length)
631 {
632 for (uint16_t i = 0; i < array_length - 1; i++)
633 {
634 for (uint16_t j = 0; j < array_length - i - 1; j++)
635 {
636 if (array[j] > array[j + 1])
637 {
638 swap(array, j, j + 1);
639 }
640 }
641 }
642 }
643
644
645 static float median(float *array, uint16_t array_length)
646 {
647 bool status = true;
648 float result = 0.0f;
649
650 for (uint16_t i = 0U; i < array_length && status; i++)
651 {
652 if (isnan(array[i]))
653 {
654 result = (float)NAN;
655 status = false;
656 }
657 }
658
659 if (status)
660 {
661 sort(array, array_length);
662
663 if (array_length % 2U == 0U)
664 {
665 uint16_t n = array_length / 2U;
666 result = (array[n - 1] + array[n]) / 2.0f;
667 }
668 else
669 {
670 uint16_t n = array_length / 2;
671 result = array[n];
672 }
673 }
674
675 return result;
676 }
677
678
679 static float nanmean(float *array, uint16_t array_length)
680 {
681 uint16_t samples = 0U;
682 float sum = 0.0f;
683
684 for (uint16_t i = 0U; i < array_length; i++)
685 {
686 if (!isnan(array[i]))
687 {
688 samples++;
689 sum += array[i];
690 }
691 }
692
693 return samples > 0U ? sum / (float)samples : (float)NAN;
694 }
695
696
697 static void process_detector_result(const acc_detector_distance_result_t *distance_result, app_result_t *app_result,
698 app_context_t *context)
699 {
700 app_result->peak_detected = false;
701 app_result->peak_status = PEAK_STATUS_NO_DETECTION;
702 app_result->level = 0.0f;
703 app_result->result_ready = false;
704 float level = 0.0f;
705
706 if (distance_result->num_distances > 0)
707 {
708 app_result->peak_detected = true;
709 level = context->app_config->tank_range_end_m - distance_result->distances[0];
710 }
711 else
712 {
713 level = (float)NAN;
714 }
715
716 if (distance_result->near_start_edge_status)
717 {
718 context->median_edge_status_count++;
719 }
720
721 context->level_history[context->median_counter++] = level;
722
723 if (context->median_counter == context->level_history_length)
724 {
725 float med = median(context->level_history, context->level_history_length);
726
727 context->median_vector[context->mean_counter++] = med;
728
729 if (context->median_edge_status_count > context->level_history_length / 2)
730 {
731 context->mean_edge_status_count++;
732 }
733
734 context->median_counter = 0U;
735 context->median_edge_status_count = 0U;
736 }
737
738 if (context->mean_counter == context->median_vector_length)
739 {
740 level = nanmean(context->median_vector, context->median_vector_length);
741
742 if (!isnan(level))
743 {
744 if (level < 0.0f)
745 {
746 app_result->peak_status = PEAK_STATUS_OUT_OF_RANGE;
747 }
748 else if (level > (context->app_config->tank_range_end_m - context->app_config->tank_range_start_m))
749 {
750 app_result->peak_status = PEAK_STATUS_OVERFLOW;
751 }
752 else
753 {
754 app_result->peak_status = PEAK_STATUS_IN_RANGE;
755 app_result->level = level;
756 }
757 }
758 else if (context->mean_edge_status_count > context->median_vector_length / 2)
759 {
760 app_result->peak_status = PEAK_STATUS_OVERFLOW;
761 }
762
763 if (app_result->peak_status == PEAK_STATUS_OVERFLOW || app_result->peak_status == PEAK_STATUS_OUT_OF_RANGE)
764 {
765 app_result->level = (float)NAN;
766 }
767
768 app_result->result_ready = true;
769 context->mean_counter = 0U;
770 context->mean_edge_status_count = 0U;
771 }
772 }
773
774
775 static void print_result(const app_result_t *app_result, const acc_ref_app_tank_level_config_t *app_config)
776 {
777 switch (app_result->peak_status)
778 {
779 case PEAK_STATUS_IN_RANGE:
780 printf("Level within range\n");
781 printf("Level: %" PRIfloat " cm, %" PRIfloat " %%\n", ACC_LOG_FLOAT_TO_INTEGER(
782 app_result->level * 100.0f),
783 ACC_LOG_FLOAT_TO_INTEGER((app_result->level /
784 (app_config->tank_range_end_m - app_config->tank_range_start_m) *
785 100.f)));
786 break;
787 case PEAK_STATUS_NO_DETECTION:
788 printf("No detection\n");
789 break;
790 case PEAK_STATUS_OVERFLOW:
791 printf("Overflow!\n");
792 break;
793 case PEAK_STATUS_OUT_OF_RANGE:
794 printf("Out of range\n");
795 break;
796 default:
797 break;
798 }
799 }
app_result_t::level
float level
Definition: ref_app_tank_level.c:149
SMALL_TANK_RANGE_START_M
#define SMALL_TANK_RANGE_START_M
Definition: ref_app_tank_level.c:31
full_detector_calibration
static bool full_detector_calibration(app_context_t *context, const acc_cal_result_t *sensor_cal_result)
Definition: ref_app_tank_level.c:531
SMALL_TANK_SIGNAL_QUALITY
#define SMALL_TANK_SIGNAL_QUALITY
Definition: ref_app_tank_level.c:39
app_context_t::median_counter
uint16_t median_counter
Definition: ref_app_tank_level.c:126
app_context_t::buffer_size
uint32_t buffer_size
Definition: ref_app_tank_level.c:132
acc_hal_integration_sensor_supply_off
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:113
app_context_t::level_history_length
uint16_t level_history_length
Definition: ref_app_tank_level.c:123
acc_rss_a121.h
PEAK_STATUS_IN_RANGE
@ PEAK_STATUS_IN_RANGE
Definition: ref_app_tank_level.c:139
TANK_LEVEL_PRESET_CONFIG_MEDIUM_TANK
@ TANK_LEVEL_PRESET_CONFIG_MEDIUM_TANK
Definition: ref_app_tank_level.c:102
acc_ref_app_tank_level_config_t::median_filter_length
uint16_t median_filter_length
Definition: ref_app_tank_level.c:113
app_context_t::app_config
acc_ref_app_smart_presence_config_t * app_config
Definition: ref_app_smart_presence.c:148
acc_detector_distance_config_peak_sorting_set
void acc_detector_distance_config_peak_sorting_set(acc_detector_distance_config_t *config, acc_detector_distance_peak_sorting_t peak_sorting)
Set the peak sorting method.
app_result_t::peak_status
peak_status_t peak_status
Definition: ref_app_tank_level.c:148
app_context_t::mean_counter
uint16_t mean_counter
Definition: ref_app_tank_level.c:127
acc_hal_integration_sensor_supply_on
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:107
nanmean
static float nanmean(float *array, uint16_t array_length)
Definition: ref_app_tank_level.c:679
TANK_LEVEL_PRESET_CONFIG_SMALL_TANK
@ TANK_LEVEL_PRESET_CONFIG_SMALL_TANK
Definition: ref_app_tank_level.c:101
acc_sensor_read
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
LARGE_TANK_SIGNAL_QUALITY
#define LARGE_TANK_SIGNAL_QUALITY
Definition: ref_app_tank_level.c:67
acc_version.h
acc_ref_app_tank_level_config_t::tank_range_end_m
float tank_range_end_m
Definition: ref_app_tank_level.c:112
SMALL_TANK_MAX_STEP_LENGTH
#define SMALL_TANK_MAX_STEP_LENGTH
Definition: ref_app_tank_level.c:33
app_context_t::buffer
void * buffer
Definition: ref_app_smart_presence.c:156
PEAK_STATUS_OVERFLOW
@ PEAK_STATUS_OVERFLOW
Definition: ref_app_tank_level.c:141
app_context_t
Definition: ref_app_smart_presence.c:146
app_result_t::peak_detected
bool peak_detected
Definition: ref_app_tank_level.c:147
process_detector_result
static void process_detector_result(const acc_detector_distance_result_t *distance_result, app_result_t *app_result, app_context_t *context)
Definition: ref_app_tank_level.c:697
SMALL_TANK_PEAK_SORTING
#define SMALL_TANK_PEAK_SORTING
Definition: ref_app_tank_level.c:36
acc_ref_app_tank_level_config_t::tank_range_start_m
float tank_range_start_m
Definition: ref_app_tank_level.c:111
set_config
static void set_config(acc_ref_app_tank_level_config_t *app_config, tank_level_preset_config_t preset)
Definition: ref_app_tank_level.c:368
MEDIUM_TANK_MAX_STEP_LENGTH
#define MEDIUM_TANK_MAX_STEP_LENGTH
Definition: ref_app_tank_level.c:47
acc_cal_result_t
Definition: acc_definitions_a121.h:19
acc_detector_distance_config_start_set
void acc_detector_distance_config_start_set(acc_detector_distance_config_t *config, float start_m)
Set the start of measured interval in meters.
MEDIUM_TANK_MAX_PROFILE
#define MEDIUM_TANK_MAX_PROFILE
Definition: ref_app_tank_level.c:48
SMALL_TANK_RANGE_END_M
#define SMALL_TANK_RANGE_END_M
Definition: ref_app_tank_level.c:32
MEDIUM_TANK_PEAK_SORTING
#define MEDIUM_TANK_PEAK_SORTING
Definition: ref_app_tank_level.c:50
app_context_t::app_config
acc_ref_app_tank_level_config_t * app_config
Definition: ref_app_tank_level.c:120
get_detector_end_m
static float get_detector_end_m(acc_ref_app_tank_level_config_t *app_config)
Definition: ref_app_tank_level.c:361
median
static float median(float *array, uint16_t array_length)
Definition: ref_app_tank_level.c:645
app_context_t::detector_handle
acc_detector_distance_handle_t * detector_handle
Definition: ref_app_tank_level.c:130
acc_detector_distance_get_buffer_sizes
bool acc_detector_distance_get_buffer_sizes(const acc_detector_distance_handle_t *handle, uint32_t *buffer_size, uint32_t *calibration_buffer_size)
Get the buffer sizes needed given the provided detector handle.
app_context_t::calibration_buffer
void * calibration_buffer
Definition: ref_app_tank_level.c:133
acc_detector_distance_recalibrate
bool acc_detector_distance_recalibrate(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, void *calibration_buffer, uint32_t calibration_buffer_size, bool *calibration_complete)
Do a detector recalibration.
acc_integration.h
acc_detector_distance_result_t::num_distances
uint8_t num_distances
Definition: acc_detector_distance.h:62
swap
static void swap(float *array, uint16_t idx_a, uint16_t idx_b)
Definition: ref_app_tank_level.c:621
acc_detector_distance_create
acc_detector_distance_handle_t * acc_detector_distance_create(const acc_detector_distance_config_t *config)
Create a distance detector with the provided configuration.
LARGE_TANK_PEAK_SORTING
#define LARGE_TANK_PEAK_SORTING
Definition: ref_app_tank_level.c:64
acc_detector_distance_config_destroy
void acc_detector_distance_config_destroy(acc_detector_distance_config_t *config)
Destroy a configuration for a distance detector.
acc_hal_rss_integration_get_implementation
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
Definition: acc_hal_integration_stm32cube_xm.c:166
SMALL_TANK_NUM_FRAMES_REC
#define SMALL_TANK_NUM_FRAMES_REC
Definition: ref_app_tank_level.c:35
app_context_t::mean_edge_status_count
uint16_t mean_edge_status_count
Definition: ref_app_tank_level.c:129
MEDIUM_TANK_MEDIAN_FILTER_LENGTH
#define MEDIUM_TANK_MEDIAN_FILTER_LENGTH
Definition: ref_app_tank_level.c:43
acc_detector_distance_process
bool acc_detector_distance_process(acc_detector_distance_handle_t *handle, void *buffer, void *calibration_buffer, bool *result_available, acc_detector_distance_result_t *result)
Process the data according to the configuration used in acc_detector_distance_config_create.
TANK_LEVEL_PRESET_CONFIG_LARGE_TANK
@ TANK_LEVEL_PRESET_CONFIG_LARGE_TANK
Definition: ref_app_tank_level.c:103
PEAK_STATUS_NO_DETECTION
@ PEAK_STATUS_NO_DETECTION
Definition: ref_app_tank_level.c:140
app_result_t::result_ready
bool result_ready
Definition: ref_app_tank_level.c:150
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:632
LARGE_TANK_RANGE_START_M
#define LARGE_TANK_RANGE_START_M
Definition: ref_app_tank_level.c:59
MEDIUM_TANK_THRESHOLD_SENSITIVITY
#define MEDIUM_TANK_THRESHOLD_SENSITIVITY
Definition: ref_app_tank_level.c:52
acc_ref_app_tank_level_config_t
Definition: ref_app_tank_level.c:109
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
acc_detector_distance_calibrate
bool acc_detector_distance_calibrate(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, void *calibration_buffer, uint32_t calibration_buffer_size, bool *calibration_complete)
Do a detector calibration.
SMALL_TANK_NUM_MEDIANS_TO_AVERAGE
#define SMALL_TANK_NUM_MEDIANS_TO_AVERAGE
Definition: ref_app_tank_level.c:30
LARGE_TANK_MAX_PROFILE
#define LARGE_TANK_MAX_PROFILE
Definition: ref_app_tank_level.c:62
MEDIUM_TANK_SIGNAL_QUALITY
#define MEDIUM_TANK_SIGNAL_QUALITY
Definition: ref_app_tank_level.c:53
acc_rss_hal_register
bool acc_rss_hal_register(const acc_hal_a121_t *hal)
Register an integration.
acc_integration_set_periodic_wakeup
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Definition: acc_integration_stm32.c:531
acc_sensor.h
detector_get_next
static bool detector_get_next(app_context_t *context, const acc_cal_result_t *sensor_cal_result, acc_detector_distance_result_t *detector_result)
Definition: ref_app_tank_level.c:575
acc_detector_distance_config_close_range_leakage_cancellation_set
void acc_detector_distance_config_close_range_leakage_cancellation_set(acc_detector_distance_config_t *config, bool enable)
Enable the close range leakage cancellation logic.
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: ref_app_tank_level.c:210
LARGE_TANK_REFLECTOR_SHAPE
#define LARGE_TANK_REFLECTOR_SHAPE
Definition: ref_app_tank_level.c:65
acc_detector_distance_config_max_profile_set
void acc_detector_distance_config_max_profile_set(acc_detector_distance_config_t *config, acc_config_profile_t max_profile)
Set the max profile.
acc_detector_distance_destroy
void acc_detector_distance_destroy(acc_detector_distance_handle_t *handle)
Destroy the distance detector handle, freeing its resources.
acc_hal_integration_wait_for_sensor_interrupt
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
Definition: acc_hal_integration_stm32cube_xm.c:142
acc_hal_integration_a121.h
acc_detector_distance_config_signal_quality_set
void acc_detector_distance_config_signal_quality_set(acc_detector_distance_config_t *config, float signal_quality)
Set the signal quality.
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
app_context_t::median_vector_length
uint16_t median_vector_length
Definition: ref_app_tank_level.c:125
printf
#define printf
Definition: printf.h:60
sensor_calibration
static bool sensor_calibration(acc_sensor_t *sensor, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Definition: ref_app_tank_level.c:488
acc_hal_integration_sensor_enable
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:119
LARGE_TANK_NUM_FRAMES_REC
#define LARGE_TANK_NUM_FRAMES_REC
Definition: ref_app_tank_level.c:63
acc_hal_definitions_a121.h
SMALL_TANK_THRESHOLD_SENSITIVITY
#define SMALL_TANK_THRESHOLD_SENSITIVITY
Definition: ref_app_tank_level.c:38
acc_ref_app_tank_level_config_t::num_medians_to_average
uint16_t num_medians_to_average
Definition: ref_app_tank_level.c:114
TANK_LEVEL_PRESET_CONFIG_NONE
@ TANK_LEVEL_PRESET_CONFIG_NONE
Definition: ref_app_tank_level.c:100
acc_detector_distance_prepare
bool acc_detector_distance_prepare(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
Prepare the detector for measurements.
acc_ref_app_tank_level_config_t::distance_config
acc_detector_distance_config_t * distance_config
Definition: ref_app_tank_level.c:115
acc_detector_distance_result_t
Distance detector result.
Definition: acc_detector_distance.h:49
SMALL_TANK_MAX_PROFILE
#define SMALL_TANK_MAX_PROFILE
Definition: ref_app_tank_level.c:34
app_context_t::calibration_buffer_size
uint32_t calibration_buffer_size
Definition: ref_app_tank_level.c:134
MEDIUM_TANK_RANGE_END_M
#define MEDIUM_TANK_RANGE_END_M
Definition: ref_app_tank_level.c:46
MEDIUM_TANK_REFLECTOR_SHAPE
#define MEDIUM_TANK_REFLECTOR_SHAPE
Definition: ref_app_tank_level.c:51
MEDIUM_TANK_RANGE_START_M
#define MEDIUM_TANK_RANGE_START_M
Definition: ref_app_tank_level.c:45
acc_hal_integration_sensor_disable
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:130
sort
static void sort(float *array, uint16_t array_length)
Definition: ref_app_tank_level.c:630
acc_detector_distance_config_end_set
void acc_detector_distance_config_end_set(acc_detector_distance_config_t *config, float end_m)
Set the end of measured interval in meters.
app_context_t::median_edge_status_count
uint16_t median_edge_status_count
Definition: ref_app_tank_level.c:128
acc_detector_distance_result_t::sensor_calibration_needed
bool sensor_calibration_needed
Definition: acc_detector_distance.h:74
DEFAULT_UPDATE_RATE
#define DEFAULT_UPDATE_RATE
Definition: ref_app_tank_level.c:26
initialize_application_resources
static bool initialize_application_resources(app_context_t *context)
Definition: ref_app_tank_level.c:432
cleanup
static void cleanup(app_context_t *context)
Definition: ref_app_tank_level.c:334
acc_detector_distance_config_num_frames_recorded_threshold_set
void acc_detector_distance_config_num_frames_recorded_threshold_set(acc_detector_distance_config_t *config, uint16_t num_frames)
Set the number frames to use for recorded threshold.
acc_integration_log.h
LARGE_TANK_NUM_MEDIANS_TO_AVERAGE
#define LARGE_TANK_NUM_MEDIANS_TO_AVERAGE
Definition: ref_app_tank_level.c:58
acc_detector_distance_handle_t
struct acc_detector_distance_handle acc_detector_distance_handle_t
Definition: acc_detector_distance.h:35
LARGE_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
#define LARGE_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
Definition: ref_app_tank_level.c:68
SMALL_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
#define SMALL_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
Definition: ref_app_tank_level.c:40
tank_level_preset_config_t
tank_level_preset_config_t
Definition: ref_app_tank_level.c:98
ACC_LOG_FLOAT_TO_INTEGER
#define ACC_LOG_FLOAT_TO_INTEGER(a)
Definition: acc_integration_log.h:26
SENSOR_ID
#define SENSOR_ID
Definition: ref_app_tank_level.c:24
LARGE_TANK_RANGE_END_M
#define LARGE_TANK_RANGE_END_M
Definition: ref_app_tank_level.c:60
acc_sensor_status
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
acc_detector_distance_result_t::near_start_edge_status
bool near_start_edge_status
Definition: acc_detector_distance.h:66
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_stm32.c:644
acc_detector_distance_config_reflector_shape_set
void acc_detector_distance_config_reflector_shape_set(acc_detector_distance_config_t *config, acc_detector_distance_reflector_shape_t reflector_shape)
Set reflector shape.
MEDIUM_TANK_NUM_FRAMES_REC
#define MEDIUM_TANK_NUM_FRAMES_REC
Definition: ref_app_tank_level.c:49
acc_integration_sleep_until_periodic_wakeup
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
Definition: acc_integration_stm32.c:590
app_context_t::sensor
acc_sensor_t * sensor
Definition: ref_app_smart_presence.c:155
acc_detector_distance_config_threshold_sensitivity_set
void acc_detector_distance_config_threshold_sensitivity_set(acc_detector_distance_config_t *config, float threshold_sensitivity)
Set threshold sensitivity.
acc_detector_distance_config_create
acc_detector_distance_config_t * acc_detector_distance_config_create(void)
Create a configuration for a distance detector.
SMALL_TANK_MEDIAN_FILTER_LENGTH
#define SMALL_TANK_MEDIAN_FILTER_LENGTH
Definition: ref_app_tank_level.c:29
app_context_t::level_history
float * level_history
Definition: ref_app_tank_level.c:122
acc_detector_distance_result_t::distances
float distances[(10U)]
Definition: acc_detector_distance.h:54
acc_detector_distance.h
acc_sensor_calibrate
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
PRIfloat
#define PRIfloat
Specifier for printing float type using integers.
Definition: acc_integration_log.h:31
SENSOR_TIMEOUT_MS
#define SENSOR_TIMEOUT_MS
Definition: ref_app_tank_level.c:25
app_result_t
Definition: ref_app_tank_level.c:145
acc_detector_distance_config_t
struct acc_detector_distance_config acc_detector_distance_config_t
Definition: acc_detector_distance.h:43
LARGE_TANK_THRESHOLD_SENSITIVITY
#define LARGE_TANK_THRESHOLD_SENSITIVITY
Definition: ref_app_tank_level.c:66
LARGE_TANK_MEDIAN_FILTER_LENGTH
#define LARGE_TANK_MEDIAN_FILTER_LENGTH
Definition: ref_app_tank_level.c:57
acc_detector_distance_config_max_step_length_set
void acc_detector_distance_config_max_step_length_set(acc_detector_distance_config_t *config, uint16_t max_step_length)
Set the maximum step length.
print_result
static void print_result(const app_result_t *app_result, const acc_ref_app_tank_level_config_t *app_config)
Definition: ref_app_tank_level.c:775
peak_status_t
peak_status_t
Definition: ref_app_tank_level.c:137
acc_sensor_measure
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
get_detector_start_m
static float get_detector_start_m(acc_ref_app_tank_level_config_t *app_config)
Definition: ref_app_tank_level.c:354
detector_recalibration
static bool detector_recalibration(app_context_t *context, const acc_cal_result_t *sensor_cal_result)
Definition: ref_app_tank_level.c:553
PEAK_STATUS_OUT_OF_RANGE
@ PEAK_STATUS_OUT_OF_RANGE
Definition: ref_app_tank_level.c:142
MEDIUM_TANK_NUM_MEDIANS_TO_AVERAGE
#define MEDIUM_TANK_NUM_MEDIANS_TO_AVERAGE
Definition: ref_app_tank_level.c:44
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
DEFAULT_PRESET_CONFIG
#define DEFAULT_PRESET_CONFIG
Definition: ref_app_tank_level.c:106
app_context_t::median_vector
float * median_vector
Definition: ref_app_tank_level.c:124
MEDIUM_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
#define MEDIUM_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
Definition: ref_app_tank_level.c:54
SMALL_TANK_REFLECTOR_SHAPE
#define SMALL_TANK_REFLECTOR_SHAPE
Definition: ref_app_tank_level.c:37
acc_sensor_destroy
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
acc_definitions_a121.h
acc_sensor_create
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.
LARGE_TANK_MAX_STEP_LENGTH
#define LARGE_TANK_MAX_STEP_LENGTH
Definition: ref_app_tank_level.c:61