acc_control_helper.c

This is a simplified API that can be used to easier get started The implementation of this API is provided as source code which can be examined and modified in order to suit your needs.

// Copyright (c) Acconeer AB, 2022
// All rights reserved
// This file is subject to the terms and conditions defined in the file
// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
// of this source code package.
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "acc_rss_a121.h"
#define SENSOR_CALIBRATION_TIMEOUT_MS 500
#define SENSOR_MEASURE_TIMEOUT_MS 1000
{
bool cal_status;
bool cal_complete = false;
do
{
cal_status = acc_sensor_calibrate(radar->sensor, &cal_complete, &radar->cal_result, radar->buffer, radar->buffer_size);
if (cal_status && !cal_complete)
{
}
} while (cal_status && !cal_complete);
return cal_status;
}
{
memset(radar, 0, sizeof(acc_control_helper_t));
radar->sensor_id = sensor_id;
return radar->config != NULL ? true : false;
}
{
if (radar->sensor != NULL)
{
radar->sensor = NULL;
}
if (radar->buffer != NULL)
{
radar->buffer = NULL;
}
if (radar->config != NULL)
{
radar->config = NULL;
}
if (radar->processing != NULL)
{
radar->processing = NULL;
}
}
{
radar->processing = acc_processing_create(radar->config, &radar->proc_meta);
if (radar->processing == NULL)
{
fprintf(stderr, "Failed to create processing\n");
goto fail;
}
{
fprintf(stderr, "acc_rss_get_buffer_size() failed\n");
goto fail;
}
if (radar->buffer == NULL)
{
fprintf(stderr, "acc_rss_get_buffer_size() failed\n");
goto fail;
}
if (radar->sensor == NULL)
{
fprintf(stderr, "Failed to create sensor\n");
goto fail;
}
{
fprintf(stderr, "calibration failed\n");
goto fail;
}
if (!acc_sensor_prepare(radar->sensor, radar->config, &radar->cal_result, radar->buffer, radar->buffer_size))
{
fprintf(stderr, "acc_sensor_prepare failed\n");
goto fail;
}
return true;
fail:
if (radar->sensor != NULL)
{
radar->sensor = NULL;
}
if (radar->buffer != NULL)
{
radar->buffer = NULL;
}
if (radar->processing != NULL)
{
radar->processing = NULL;
}
return false;
}
{
if (!acc_sensor_measure(radar->sensor))
{
fprintf(stderr, "acc_sensor_measure failed\n");
goto fail;
}
{
fprintf(stderr, "Sensor interrupt timeout\n");
goto fail;
}
if (!acc_sensor_read(radar->sensor, radar->buffer, radar->buffer_size))
{
fprintf(stderr, "acc_sensor_read failed\n");
goto fail;
}
return true;
fail:
return false;
}
acc_control_helper_get_next
bool acc_control_helper_get_next(acc_control_helper_t *radar)
Perform a radar measurement and wait for the result.
Definition: acc_control_helper.c:157
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_espidf_xe121.c:192
acc_rss_a121.h
acc_control_helper_t::sensor_id
acc_sensor_id_t sensor_id
Definition: acc_control_helper.h:27
acc_processing_destroy
void acc_processing_destroy(acc_processing_t *handle)
Destroy a processing instance identified with the provided processing handle.
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_espidf_xe121.c:185
acc_control_helper_t::processing
acc_processing_t * processing
Definition: acc_control_helper.h:28
acc_control_helper_t::config
acc_config_t * config
Definition: acc_control_helper.h:25
acc_sensor_read
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
acc_rss_get_buffer_size
bool acc_rss_get_buffer_size(const acc_config_t *config, uint32_t *buffer_size)
Get the buffer size needed for the specified config.
acc_config_destroy
void acc_config_destroy(acc_config_t *config)
Destroy a configuration freeing any resources allocated.
SENSOR_MEASURE_TIMEOUT_MS
#define SENSOR_MEASURE_TIMEOUT_MS
Definition: acc_control_helper.c:19
acc_processing_execute
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.
acc_config_create
acc_config_t * acc_config_create(void)
Create a configuration.
acc_integration.h
acc_control_helper_t::buffer_size
uint32_t buffer_size
Definition: acc_control_helper.h:30
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_esp32.c:38
acc_control_helper_t::proc_meta
acc_processing_metadata_t proc_meta
Definition: acc_control_helper.h:32
acc_control_helper.h
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_espidf_xe121.c:100
acc_control_helper_calibrate
static bool acc_control_helper_calibrate(acc_control_helper_t *radar)
Definition: acc_control_helper.c:22
acc_hal_integration_a121.h
acc_control_helper_destroy
void acc_control_helper_destroy(acc_control_helper_t *radar)
Destroy a helper instance.
Definition: acc_control_helper.c:50
acc_control_helper_t::sensor
acc_sensor_t * sensor
Definition: acc_control_helper.h:26
acc_hal_integration_sensor_enable
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
Definition: acc_hal_integration_espidf_xe121.c:199
acc_control_helper_t::buffer
void * buffer
Definition: acc_control_helper.h:29
acc_hal_integration_sensor_disable
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
Definition: acc_hal_integration_espidf_xe121.c:214
acc_control_helper_t::cal_result
acc_cal_result_t cal_result
Definition: acc_control_helper.h:31
acc_sensor_id_t
uint32_t acc_sensor_id_t
Type representing a sensor ID.
Definition: acc_definitions_common.h:14
acc_sensor_status
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
acc_control_helper_t
Definition: acc_control_helper.h:23
acc_sensor_prepare
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.
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_esp32.c:57
SENSOR_CALIBRATION_TIMEOUT_MS
#define SENSOR_CALIBRATION_TIMEOUT_MS
Definition: acc_control_helper.c:18
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.
acc_sensor_measure
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
acc_processing_create
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.
acc_control_helper_t::proc_result
acc_processing_result_t proc_result
Definition: acc_control_helper.h:33
acc_control_helper_activate
bool acc_control_helper_activate(acc_control_helper_t *radar)
Activate the sensor.
Definition: acc_control_helper.c:81
acc_sensor_destroy
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
acc_control_helper_create
bool acc_control_helper_create(acc_control_helper_t *radar, acc_sensor_id_t sensor_id)
Create a helper instance.
Definition: acc_control_helper.c:41
acc_sensor_create
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.