This is an example on how the Service API can be used to measure vibrations
The example executes as follows:
- Set vibration configuration
- Create vibration processing handle using config from previous step
- Create a processing instance using an internally translated config from previous step
- Allocate sensor buffer
- Create a sensor instance
- Calibrate & prepare the sensor
- Loop:
- Perform a sensor measurement and read out the data
- Check & handle the 'calibration_needed' indication
- Process the measurement and print vibration result
- Destroy the sensor instance
- Destroy the processing instance
- Destroy the configuration
#include <float.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define SENSOR_ID (1U)
#define SENSOR_TIMEOUT_MS (1000U)
#define DISPLACEMENT_HISTORY_COLUMN_WIDTH (16U)
{
(void)argc;
(void)argv;
{
return EXIT_FAILURE;
}
{
printf(
"acc_vibration_handle_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(
"do_sensor_calibration_and_prepare() failed\n");
return EXIT_FAILURE;
}
while (true)
{
{
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(
"The current calibration is not valid for the current temperature.\n");
printf(
"The sensor needs to be re-calibrated.\n");
{
printf(
"do_sensor_calibration_and_prepare() failed\n");
return EXIT_FAILURE;
}
printf(
"The sensor was successfully re-calibrated.\n");
}
else
{
}
}
printf(
"Application finished OK\n");
return EXIT_SUCCESS;
}
{
bool 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)
{
}
return status;
}
{
char buf[80] = "";
size_t buf_size = sizeof(buf);
if (
result->max_displacement != FLT_MAX)
{
buf_size,
}
bool continuous_data_acquisition = true;
{
return;
}
uint16_t num_elems = 0U;
if (displacement_history != NULL)
{
printf(
"\nDisplacement history:\n");
for (uint16_t i = 0; i < num_elems; i++)
{
{
}
}
}
}
{
{
}
if (processing != NULL)
{
}
{
}
{
}
}
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.
Result provided by the processing module.
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
void acc_vibration_preset_set(acc_vibration_config_t *config, acc_vibration_preset_t preset)
void acc_vibration_config_log(const acc_vibration_config_t *config)
The result from a completed calibration.
#define SENSOR_TIMEOUT_MS
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.
#define DISPLACEMENT_HISTORY_COLUMN_WIDTH
Vibration config container.
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
acc_vibration_handle_t * acc_vibration_handle_create(const acc_vibration_config_t *config)
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
const float * acc_vibration_handle_displacement_history_get(acc_vibration_handle_t *handle, uint16_t *num_elem)
const acc_config_t * acc_vibration_handle_sensor_config_get(acc_vibration_handle_t *handle)
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
static void print_result(acc_vibration_handle_t *handle, acc_vibration_result_t *result)
const char * acc_version_get(void)
Get the version of the Acconeer software.
struct acc_config acc_config_t
@ ACC_VIBRATION_PRESET_LOW_FREQUENCY
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
void acc_vibration_process(acc_processing_result_t *proc_result, acc_vibration_handle_t *handle, acc_vibration_config_t *config, acc_vibration_result_t *result)
void acc_vibration_handle_destroy(acc_vibration_handle_t *handle)
Vibration processing result.
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
bool acc_vibration_handle_continuous_data_acquisition_get(acc_vibration_handle_t *handle, bool *continuous_data_acquisition)
static bool do_sensor_calibration_and_prepare(acc_sensor_t *sensor, void *buffer, uint32_t buffer_size, const acc_config_t *sensor_config)
struct acc_processing_handle acc_processing_t
#define ACC_LOG_FLOAT_TO_INTEGER(a)
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
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.
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.
#define PRIfloat
Specifier for printing float type using integers.
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.
struct acc_sensor acc_sensor_t
static void cleanup(acc_sensor_t *sensor, acc_processing_t *processing, void *buffer, acc_vibration_handle_t *handle)
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
int acconeer_main(int argc, char *argv[])
Assembly test example.
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.