ref_app_parking_main.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2024
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 <stdbool.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 #include "acc_hal_definitions_a121.h"
12 #include "acc_hal_integration_a121.h"
13 #include "acc_integration.h"
14 #include "acc_rss_a121.h"
15 #include "acc_version.h"
16 #include "ref_app_parking.h"
17
18 #define SENSOR_ID (1U)
19
20 int acconeer_main(int argc, char *argv[]);
21
22 int acconeer_main(int argc, char *argv[])
23 {
24 (void)argc;
25 (void)argv;
26
27 ref_app_parking_config_t parking_config = {0};
28 ref_app_parking_handle_t *handle = NULL;
29
30 printf("Acconeer software version %s\n", acc_version_get());
31
32 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
33
34 if (!acc_rss_hal_register(hal))
35 {
36 return EXIT_FAILURE;
37 }
38
39 ref_app_parking_set_config(PARKING_PRESET_GROUND, &parking_config);
40
41 handle = ref_app_parking_handle_create(&parking_config, SENSOR_ID);
42 if (handle == NULL)
43 {
44 printf("ref_app_parking_handle_create() failed\n");
45 ref_app_parking_handle_destroy(handle);
46 return EXIT_FAILURE;
47 }
48
49 if (!ref_app_parking_sensor_calibration(handle))
50 {
51 printf("ref_app_parking_sensor_calibration() failed\n");
52 ref_app_parking_handle_destroy(handle);
53 return EXIT_FAILURE;
54 }
55
56 if (!ref_app_parking_noise_calibration(handle))
57 {
58 printf("ref_app_parking_noise_calibration() failed\n");
59 ref_app_parking_handle_destroy(handle);
60 return EXIT_FAILURE;
61 }
62
63 if (parking_config.obstruction_detection_enabled)
64 {
65 if (!ref_app_parking_obstruction_calibration(handle))
66 {
67 printf("ref_app_parking_obstruction_calibration() failed\n");
68 ref_app_parking_handle_destroy(handle);
69 return EXIT_FAILURE;
70 }
71 }
72
73 if (!ref_app_parking_sensor_prepare(handle))
74 {
75 printf("ref_app_parking_sensor_prepare() failed\n");
76 ref_app_parking_handle_destroy(handle);
77 return EXIT_FAILURE;
78 }
79
80 if (parking_config.frame_rate_app_driven)
81 {
82 uint32_t sleep_time_ms = (uint32_t)(1000.0f / parking_config.frame_rate);
83 acc_integration_set_periodic_wakeup(sleep_time_ms);
84 }
85
86 bool obstruction_detected = false;
87 bool car_detected = false;
88
89 while (true)
90 {
91 if (!ref_app_parking_measure(handle, parking_config.frame_rate_app_driven))
92 {
93 printf("ref_app_parking_measure() failed\n");
94 ref_app_parking_handle_destroy(handle);
95 return EXIT_FAILURE;
96 }
97
98 bool data_reliable;
99
100 if (!ref_app_parking_handle_indications(handle, &data_reliable))
101 {
102 printf("ref_app_parking_handle_indications() failed\n");
103 ref_app_parking_handle_destroy(handle);
104 return EXIT_FAILURE;
105 }
106
107 if (data_reliable)
108 {
109 if (parking_config.obstruction_detection_enabled)
110 {
111 ref_app_parking_obstruction_process(handle, &obstruction_detected);
112
113 printf("obstruction_detected: %s\n", obstruction_detected ? "true" : "false");
114 }
115
116 ref_app_parking_process(handle, &car_detected);
117
118 printf("car_detected: %s\n", car_detected ? "true" : "false");
119 }
120
121 if (parking_config.frame_rate_app_driven)
122 {
123 acc_integration_sleep_until_periodic_wakeup();
124 }
125 }
126
127 ref_app_parking_handle_destroy(handle);
128
129 printf("Application finished OK\n");
130
131 return EXIT_SUCCESS;
132 }
acc_rss_a121.h
ref_app_parking_sensor_calibration
bool ref_app_parking_sensor_calibration(ref_app_parking_handle_t *handle)
Sensor calibration.
Definition: ref_app_parking.c:355
PARKING_PRESET_GROUND
@ PARKING_PRESET_GROUND
Definition: ref_app_parking.h:34
acc_version.h
ref_app_parking_config_t
Overall configuration for parking application.
Definition: ref_app_parking.h:77
ref_app_parking_set_config
void ref_app_parking_set_config(ref_app_parking_parking_preset_t preset, ref_app_parking_config_t *parking_config)
Set parking config according to specified preset.
Definition: ref_app_parking.c:201
ref_app_parking_measure
bool ref_app_parking_measure(ref_app_parking_handle_t *handle, bool hibernate)
Perform a sensor measurement.
Definition: ref_app_parking.c:554
ref_app_parking_obstruction_process
void ref_app_parking_obstruction_process(ref_app_parking_handle_t *handle, bool *obstruction_detected)
Do obstruction processing.
Definition: ref_app_parking.c:663
acc_integration.h
ref_app_parking_config_t::frame_rate_app_driven
bool frame_rate_app_driven
Definition: ref_app_parking.h:81
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:152
ref_app_parking_config_t::obstruction_detection_enabled
bool obstruction_detection_enabled
Definition: ref_app_parking.h:82
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
ref_app_parking_sensor_prepare
bool ref_app_parking_sensor_prepare(ref_app_parking_handle_t *handle)
Prepare sensor for measurement.
Definition: ref_app_parking.c:537
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:496
ref_app_parking_process
void ref_app_parking_process(ref_app_parking_handle_t *handle, bool *car_detected)
Do parking processing.
Definition: ref_app_parking.c:711
ref_app_parking_handle
Definition: ref_app_parking.c:34
acc_hal_integration_a121.h
handle
cargo_handle_t * handle
Definition: i2c_example_cargo.c:35
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
printf
#define printf
Definition: printf.h:60
ref_app_parking_noise_calibration
bool ref_app_parking_noise_calibration(ref_app_parking_handle_t *handle)
Noise calibration.
Definition: ref_app_parking.c:390
ref_app_parking_config_t::frame_rate
float frame_rate
Definition: ref_app_parking.h:80
acc_hal_definitions_a121.h
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: ref_app_parking_main.c:22
ref_app_parking_handle_create
ref_app_parking_handle_t * ref_app_parking_handle_create(ref_app_parking_config_t *parking_config, acc_sensor_id_t sensor_id)
Create parking handle.
Definition: ref_app_parking.c:252
ref_app_parking_obstruction_calibration
bool ref_app_parking_obstruction_calibration(ref_app_parking_handle_t *handle)
Obstruction calibration.
Definition: ref_app_parking.c:445
ref_app_parking_handle_destroy
void ref_app_parking_handle_destroy(ref_app_parking_handle_t *handle)
Destroy parking handle.
Definition: ref_app_parking.c:284
ref_app_parking_handle_indications
bool ref_app_parking_handle_indications(ref_app_parking_handle_t *handle, bool *data_reliable)
Handle indications from a measurement.
Definition: ref_app_parking.c:597
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:552
ref_app_parking.h
SENSOR_ID
#define SENSOR_ID
Definition: ref_app_parking_main.c:18