example_cargo.c File Reference
#include <stdbool.h>
#include <stddef.h>
#include "acc_config.h"
#include "acc_detector_distance.h"
#include "acc_detector_presence.h"
#include "acc_integration.h"
#include "acc_integration_log.h"
#include "acc_sensor.h"
#include "example_cargo.h"

Go to the source code of this file.

Data Structures

struct  cargo_handle
 Cargo handle. More...
 

Macros

#define MODULE   "example_cargo"
 
#define CARGO_CONFIG_MAGIC   0xACC0CA60
 
#define CARGO_PRESENCE_RUN_TIME_S   5.0f
 
#define CARGO_PRESENCE_MIN_UPDATE_RATE   1.0f
 
#define CARGO_PRESENCE_MIN_SWEEPS_PER_FRAME   4U
 

Functions

static bool validate_cargo_config (const cargo_config_t *cargo_config)
 
static bool populate_handle_with_distance_resources (const cargo_config_t *cargo_config, cargo_handle_t *cargo_handle)
 
static bool populate_handle_with_presence_resources (const cargo_config_t *cargo_config, cargo_handle_t *cargo_handle)
 
static bool translate_cargo_config_to_distance_config (const cargo_config_t *cargo_config, acc_detector_distance_config_t *distance_config)
 
static bool translate_cargo_config_to_presence_config (const cargo_config_t *cargo_config, acc_detector_presence_config_t *presence_config)
 
static uint16_t presence_calc_num_frames_per_burst (const cargo_config_t *cargo_config)
 
static float float_clip (float value, float min, float max)
 
void cargo_config_initialize (cargo_config_t *cargo_config, cargo_preset_t preset)
 Initialize cargo config struct with a preset. More...
 
void cargo_config_log (const cargo_config_t *cargo_config)
 Log cargo config to debug uart. More...
 
cargo_handle_tcargo_handle_create (const cargo_config_t *cargo_config)
 Create a cargo handle. More...
 
void cargo_handle_destroy (cargo_handle_t *handle)
 Destroy a cargo handle. More...
 
bool cargo_get_buffer_size (const cargo_handle_t *handle, uint32_t *buffer_size)
 Get the required buffer sensor data buffer size. More...
 
bool cargo_get_distance_cal_result_static_size (const cargo_handle_t *handle, uint32_t *distance_cal_result_static_size)
 Get the required buffer for static distance detector calibration. More...
 
bool cargo_calibrate (cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, uint8_t *distance_cal_result_static, uint32_t distance_cal_result_static_size, acc_detector_cal_result_dynamic_t *distance_cal_result_dynamic, bool *calibration_complete)
 Calibrate Cargo. More...
 
bool cargo_update_calibration (cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, acc_detector_cal_result_dynamic_t *distance_cal_result_dynamic, bool *calibration_complete)
 Update Cargo calibration. More...
 
bool cargo_prepare_utilization (cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
 Prepare Cargo utilization for measurements. More...
 
bool cargo_prepare_presence (cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
 Prepare Cargo presence for measurements. More...
 
bool cargo_process_utilization (cargo_handle_t *handle, uint8_t *distance_cal_result_static, acc_detector_cal_result_dynamic_t *distance_cal_result_dynamic, void *buffer, cargo_result_t *cargo_result, bool *result_available, acc_detector_distance_result_t *nullable_distance_result)
 Process Sparse IQ data into a Cargo result. More...
 
bool cargo_process_presence (cargo_handle_t *handle, void *buffer, cargo_result_t *cargo_result, acc_detector_presence_result_t *nullable_presence_result)
 Process Sparse IQ data into a Cargo result. More...
 
cargo_mode_t cargo_current_mode_get (const cargo_handle_t *handle)
 Get current mode of the cargo handle. More...
 
bool cargo_presence_metadata_get (cargo_handle_t *handle, acc_detector_presence_metadata_t *presence_metadata)
 Get presence detector metadata. More...
 

Macro Definition Documentation

◆ CARGO_CONFIG_MAGIC

#define CARGO_CONFIG_MAGIC   0xACC0CA60

Definition at line 19 of file example_cargo.c.

◆ CARGO_PRESENCE_MIN_SWEEPS_PER_FRAME

#define CARGO_PRESENCE_MIN_SWEEPS_PER_FRAME   4U

Definition at line 22 of file example_cargo.c.

◆ CARGO_PRESENCE_MIN_UPDATE_RATE

#define CARGO_PRESENCE_MIN_UPDATE_RATE   1.0f

Definition at line 21 of file example_cargo.c.

◆ CARGO_PRESENCE_RUN_TIME_S

#define CARGO_PRESENCE_RUN_TIME_S   5.0f

Definition at line 20 of file example_cargo.c.

◆ MODULE

#define MODULE   "example_cargo"

Definition at line 18 of file example_cargo.c.

Function Documentation

◆ cargo_calibrate()

bool cargo_calibrate ( cargo_handle_t handle,
acc_sensor_t sensor,
const acc_cal_result_t sensor_cal_result,
void *  buffer,
uint32_t  buffer_size,
uint8_t *  distance_cal_result_static,
uint32_t  distance_cal_result_static_size,
acc_detector_cal_result_dynamic_t distance_cal_result_dynamic,
bool *  calibration_complete 
)

Calibrate Cargo.

Calibrating Cargo's internal Detector is needed to ensure reliable Detector results.

See the calibration sections in the Distance Detector User Guide for more information.

Parameters
[in]sensorThe sensor instance to use for calibration
[in]handleThe Cargo handle
[in]sensor_cal_resultSensor calibration result
[in]bufferWorking memory buffer needed by function
[in]buffer_sizeThe size of buffer. Needs to be at least the result of cargo_get_buffer_size
[out]distance_cal_result_staticStatic result of calibration
[in]distance_cal_result_static_sizeThe size of distance_cal_result_static. Needs to be at least the result of cargo_get_distance_cal_result_static_size
[out]distance_cal_result_dynamicDynamic result of calibration
[out]calibration_completeWill be set to true when the calibration is complete. If false; at least one more call to this function is needed. Note that it's necessary to wait for interrupt between calls.
Returns
True if successful, false otherwise

Definition at line 318 of file example_cargo.c.

◆ cargo_config_initialize()

void cargo_config_initialize ( cargo_config_t cargo_config,
cargo_preset_t  preset 
)

Initialize cargo config struct with a preset.

Parameters
[out]cargo_configThe cargo config to initialize
[in]presetA cargo_preset_t to initialize the config to

Definition at line 80 of file example_cargo.c.

◆ cargo_config_log()

void cargo_config_log ( const cargo_config_t cargo_config)

Log cargo config to debug uart.

Parameters
[in]cargo_configThe cargo config to log

Definition at line 135 of file example_cargo.c.

◆ cargo_current_mode_get()

cargo_mode_t cargo_current_mode_get ( const cargo_handle_t handle)

Get current mode of the cargo handle.

Really only useful when doing both Presence- & Utilization level measurements.

Parameters
[in]handleThe cargo handle
Returns
The current cargo mode. See cargo_mode_t

Definition at line 622 of file example_cargo.c.

◆ cargo_get_buffer_size()

bool cargo_get_buffer_size ( const cargo_handle_t handle,
uint32_t *  buffer_size 
)

Get the required buffer sensor data buffer size.

Parameters
[in]handleThe cargo handle
[out]buffer_sizeThe required buffer size
Returns
True if successful, false otherwise

Definition at line 272 of file example_cargo.c.

◆ cargo_get_distance_cal_result_static_size()

bool cargo_get_distance_cal_result_static_size ( const cargo_handle_t handle,
uint32_t *  distance_cal_result_static_size 
)

Get the required buffer for static distance detector calibration.

Parameters
[in]handleThe cargo handle
[out]distance_cal_result_static_sizeThe required buffer size. Will be 0U if activate_utilization_level is false.
Returns
True if successful, false otherwise

Definition at line 298 of file example_cargo.c.

◆ cargo_handle_create()

cargo_handle_t* cargo_handle_create ( const cargo_config_t cargo_config)

Create a cargo handle.

Parameters
[in]cargo_configCargo configuration
Returns
A cargo handle, or NULL if creation failed

Definition at line 164 of file example_cargo.c.

◆ cargo_handle_destroy()

void cargo_handle_destroy ( cargo_handle_t handle)

Destroy a cargo handle.

Parameters
[in]handleThe cargo handle to destroy

Definition at line 240 of file example_cargo.c.

◆ cargo_prepare_presence()

bool cargo_prepare_presence ( cargo_handle_t handle,
acc_sensor_t sensor,
const acc_cal_result_t sensor_cal_result,
void *  buffer,
uint32_t  buffer_size 
)

Prepare Cargo presence for measurements.

Parameters
[in,out]handleThe Cargo handle
[in]sensorThe sensor instance
[in]sensor_cal_resultThe sensor calibration result
[in]bufferMemory used by the detector. Should be at least buffer_size bytes
[in]buffer_sizeThe buffer size received by acc_detector_distance_get_sizes
Returns
True if successful, false otherwise

Definition at line 423 of file example_cargo.c.

◆ cargo_prepare_utilization()

bool cargo_prepare_utilization ( cargo_handle_t handle,
acc_sensor_t sensor,
const acc_cal_result_t sensor_cal_result,
void *  buffer,
uint32_t  buffer_size 
)

Prepare Cargo utilization for measurements.

Parameters
[in,out]handleThe Cargo handle
[in]sensorThe sensor instance
[in]sensor_cal_resultThe sensor calibration result
[in]bufferMemory used by the detector. Should be at least buffer_size bytes
[in]buffer_sizeThe buffer size received by acc_detector_distance_get_sizes
Returns
True if successful, false otherwise

Definition at line 384 of file example_cargo.c.

◆ cargo_presence_metadata_get()

bool cargo_presence_metadata_get ( cargo_handle_t handle,
acc_detector_presence_metadata_t presence_metadata 
)

Get presence detector metadata.

Parameters
[in]handleThe cargo handle
[out]presence_metadataThe Presence Detector metadata
Returns
True if handle is valid & configured with presence activated, false otherwise

Definition at line 634 of file example_cargo.c.

◆ cargo_process_presence()

bool cargo_process_presence ( cargo_handle_t handle,
void *  buffer,
cargo_result_t cargo_result,
acc_detector_presence_result_t nullable_presence_result 
)

Process Sparse IQ data into a Cargo result.

Parameters
[in]handleThe Cargo handle
[in]bufferA reference to the buffer (populated by acc_sensor_read) containing the data to be processed.
[out]cargo_resultCargo result
[out]nullable_presence_resultPointer to auxilliary acc_detector_presence_result_t Can be NULL.
Returns
True if successful, false otherwise

Definition at line 558 of file example_cargo.c.

◆ cargo_process_utilization()

bool cargo_process_utilization ( cargo_handle_t handle,
uint8_t *  distance_cal_result_static,
acc_detector_cal_result_dynamic_t distance_cal_result_dynamic,
void *  buffer,
cargo_result_t cargo_result,
bool *  result_available,
acc_detector_distance_result_t nullable_distance_result 
)

Process Sparse IQ data into a Cargo result.

Parameters
[in]handleThe Cargo handle
[in]distance_cal_result_staticThe result from cargo_calibrate
[in]distance_cal_result_dynamicThe result from cargo_calibrate
[in]bufferA reference to the buffer (populated by acc_sensor_read) containing the data to be processed.
[out]cargo_resultCargo result
[out]result_availableTrue if the cargo_result is valid
[out]nullable_distance_resultPointer to auxilliary acc_detector_distance_result_t Can be NULL.
Returns
True if successful, false otherwise

Definition at line 462 of file example_cargo.c.

◆ cargo_update_calibration()

bool cargo_update_calibration ( cargo_handle_t handle,
acc_sensor_t sensor,
const acc_cal_result_t sensor_cal_result,
void *  buffer,
uint32_t  buffer_size,
acc_detector_cal_result_dynamic_t distance_cal_result_dynamic,
bool *  calibration_complete 
)

Update Cargo calibration.

Updates Cargo's internal calibration.

If calibration_needed has been set to true, you should do the following:

  1. Recalibrate sensor (see acc_sensor_calibrate)
  2. Call this function in a loop until calibration_complete=true (and while true is returned)
  3. Redo the Utilization- or Presence measurement
Parameters
[in]sensorThe sensor instance to use for calibration
[in]handleThe Cargo handle
[in]sensor_cal_resultSensor calibration result
[in]bufferWorking memory buffer needed by function
[in]buffer_sizeThe size of buffer. Needs to be at least the result of cargo_get_buffer_size
[out]distance_cal_result_dynamicDynamic result of calibration
[out]calibration_completeWill be set to true when the calibration is complete. If false; at least one more call to this function is needed. Note that it's necessary to wait for interrupt between calls.
Returns
True if successful, false otherwise

Definition at line 353 of file example_cargo.c.

◆ float_clip()

static float float_clip ( float  value,
float  min,
float  max 
)
static

Definition at line 837 of file example_cargo.c.

◆ populate_handle_with_distance_resources()

static bool populate_handle_with_distance_resources ( const cargo_config_t cargo_config,
cargo_handle_t cargo_handle 
)
static

Definition at line 696 of file example_cargo.c.

◆ populate_handle_with_presence_resources()

static bool populate_handle_with_presence_resources ( const cargo_config_t cargo_config,
cargo_handle_t cargo_handle 
)
static

Definition at line 720 of file example_cargo.c.

◆ presence_calc_num_frames_per_burst()

static uint16_t presence_calc_num_frames_per_burst ( const cargo_config_t cargo_config)
static

Definition at line 830 of file example_cargo.c.

◆ translate_cargo_config_to_distance_config()

static bool translate_cargo_config_to_distance_config ( const cargo_config_t cargo_config,
acc_detector_distance_config_t distance_config 
)
static

Definition at line 744 of file example_cargo.c.

◆ translate_cargo_config_to_presence_config()

static bool translate_cargo_config_to_presence_config ( const cargo_config_t cargo_config,
acc_detector_presence_config_t presence_config 
)
static

Definition at line 780 of file example_cargo.c.

◆ validate_cargo_config()

static bool validate_cargo_config ( const cargo_config_t cargo_config)
static

Definition at line 655 of file example_cargo.c.