This is an example on how the sensor calibration can be cached
The example executes as follows:
- Retrieve and register HAL stuct
- Create config, processing, and sensor instances
- Calibrate and prepare sensor
- Measure, read and process radar data
- Check 'calibration_needed' indication
- If needed either use cached calibration or perform new calibration and store
- Destroy sensor, processing, and config instances
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define SENSOR_ID (1U)
#define SENSOR_TIMEOUT_MS (1000U)
#define MAX_DATA_ENTRY_LEN (15U) // "-32000+-32000i" + zero termination
#define MAX_CAL_TEMP_DIFF (16)
#define MAX_TEMP_VARIATION (125)
#define MAX_CACHE_COUNT ((MAX_TEMP_VARIATION / MAX_CAL_TEMP_DIFF) + 1)
static bool add_cache(uint16_t cache_index, int16_t temp);
bool temp_known,
int16_t temp);
{
(void)argc;
(void)argv;
{
return EXIT_FAILURE;
}
{
printf(
"acc_config_create() failed\n");
return EXIT_FAILURE;
}
if (processing == NULL)
{
printf(
"acc_processing_create() failed\n");
return EXIT_FAILURE;
}
{
printf(
"acc_rss_get_buffer_size() failed\n");
return EXIT_FAILURE;
}
{
printf(
"buffer allocation failed\n");
return EXIT_FAILURE;
}
{
printf(
"acc_sensor_create() failed\n");
return EXIT_FAILURE;
}
{
printf(
"calibration_caching_and_prepare() failed\n");
return EXIT_FAILURE;
}
uint32_t update_count = 5U;
for (uint32_t i = 0U; i < update_count; i++)
{
{
printf(
"acc_sensor_measure failed\n");
return EXIT_FAILURE;
}
{
printf(
"Sensor interrupt timeout\n");
return EXIT_FAILURE;
}
{
printf(
"acc_sensor_read failed\n");
return EXIT_FAILURE;
}
{
printf(
"New calibration needed due to temperature change\n");
{
printf(
"calibration_caching_and_prepare() failed\n");
return EXIT_FAILURE;
}
}
else
{
printf(
"IQ data retrieved\n");
}
}
printf(
"Application finished OK\n");
return EXIT_SUCCESS;
}
{
}
{
bool cache_found = false;
uint16_t min_temp_diff = UINT16_MAX;
{
uint16_t temp_diff = abs(
cal_temps[index] - temp);
{
min_temp_diff = temp_diff;
*cache_index = index;
cache_found = true;
}
}
return cache_found;
}
{
}
static bool add_cache(uint16_t cache_index, int16_t temp)
{
bool status = false;
{
status = true;
}
return status;
}
bool temp_known,
int16_t temp)
{
bool status = true;
bool use_cache = false;
uint16_t cache_index = 0;
if (temp_known)
{
{
use_cache = true;
}
}
if (!use_cache)
{
printf(
"New calibration is performed\n");
{
printf(
"No empty cache_index to store calibration result\n");
return false;
}
status = false;
bool cal_complete = false;
const uint16_t calibration_retries = 1U;
for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
{
do
{
if (status && !cal_complete)
{
}
} while (status && !cal_complete);
}
if (status)
{
}
}
else
{
printf(
"Using cached calibration for %u degrees Celsius\n",
cal_temps[cache_index]);
}
if (status)
{
}
return status;
}
{
{
}
if (processing != NULL)
{
}
{
}
{
}
}
void acc_config_start_point_set(acc_config_t *config, int32_t start_point)
Set the starting point of the sweep.
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
void acc_processing_destroy(acc_processing_t *handle)
Destroy a processing instance identified with the provided processing handle.
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
Information about calibration.
Result provided by the processing module.
#define SENSOR_TIMEOUT_MS
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
void acc_config_destroy(acc_config_t *config)
Destroy a configuration freeing any resources allocated.
The result from a completed calibration.
void acc_processing_execute(acc_processing_t *handle, void *buffer, acc_processing_result_t *result)
Process the data according to the configuration used in create.
static bool get_next_empty_cache_index(uint16_t *cache_index)
acc_config_t * acc_config_create(void)
Create a configuration.
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
static bool add_cache(uint16_t cache_index, int16_t temp)
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
int acconeer_main(int argc, char *argv[])
Assembly test example.
const char * acc_version_get(void)
Get the version of the Acconeer software.
struct acc_config acc_config_t
bool acc_sensor_get_cal_info(const acc_cal_result_t *cal_result, acc_cal_info_t *cal_info)
Gets calibration information from a calibration result.
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
void acc_config_num_points_set(acc_config_t *config, uint16_t num_points)
Set the number of data points to measure.
static bool find_cache_index(int16_t temp, uint16_t *cache_index)
static acc_cal_result_t cal_results[(((125)/(16))+1)]
static void cleanup(acc_config_t *config, acc_processing_t *processing, acc_sensor_t *sensor, void *buffer)
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
struct acc_processing_handle acc_processing_t
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
static bool calibration_caching_and_prepare(acc_sensor_t *sensor, acc_config_t *config, void *buffer, uint32_t buffer_size, bool temp_known, int16_t temp)
bool acc_sensor_prepare(acc_sensor_t *sensor, const acc_config_t *config, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare a sensor to do a measurement.
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
void acc_config_log(const acc_config_t *config)
Print a configuration to the log.
static uint16_t curr_cache_count
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.
static int16_t cal_temps[(((125)/(16))+1)]
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
acc_processing_t * acc_processing_create(const acc_config_t *config, acc_processing_metadata_t *processing_metadata)
Create a processing instance with the provided configuration.
static void set_config(acc_config_t *config)
struct acc_sensor acc_sensor_t
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
#define MAX_CAL_TEMP_DIFF
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.