acc_exploration_server_base.h
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2020-2025
2 // All rights reserved
3 
4 #ifndef ACC_EXPLORATION_SERVER_BASE_H_
5 #define ACC_EXPLORATION_SERVER_BASE_H_
6 
7 #include <stdbool.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include "acc_definitions_common.h"
12 
13 typedef enum
14 {
19 
20 /**
21  * @brief Function that writes data back to the client
22  *
23  * @param[in] data The data to be written
24  * @param[in] size The size of the data in bytes
25  */
26 typedef void(write_data_function_t)(const void *data, uint32_t size);
27 
28 /**
29  * @brief Function that stops streaming
30  */
31 typedef void(restart_input_function_t)(void);
32 
33 /**
34  * @brief Set baudrate of server
35  */
36 typedef void(set_baudrate_function_t)(uint32_t baudrate);
37 
38 /**
39  * @brief Get tick function of server
40  */
41 typedef uint32_t(get_tick_function_t)(void);
42 
43 /**
44  * @brief Struct to handle input for acc_exploration_server_process_cmds
45  */
46 typedef struct
47 {
51  uint32_t max_baudrate;
53  uint32_t ticks_per_second;
55 
56 /**
57  * @brief Initialize the exploration server
58  *
59  * @param[in] buffer pointer to a command buffer
60  * @param[in] buffer_size the size, in bytes, of the command buffer
61  * @param[in] hw The hardware name (module/board/system)
62  * @param[in] log_level The log level to use
63  *
64  * @return true if successful
65  */
66 bool acc_exploration_server_init(char *buffer, size_t buffer_size, const char *hw, acc_log_level_t log_level);
67 
68 /**
69  * @brief Stop the streaming from the exploration server
70  */
72 
73 /**
74  * @brief De-initialize the exploration server
75  */
77 
78 /**
79  * @brief Put string from client into input buffer
80  *
81  * @param[in] buffer data from client
82  * @param[in] buffer_size the size, in bytes, of the buffer
83  */
85 
86 /**
87  * @brief Reset and clear the input buffer
88  */
90 
91 /**
92  * @brief The exploration server process function
93  *
94  * This function will:
95  * - Check the input buffer and process any available commands.
96  * - It will also get frames from the sensor in the selected update rate
97  * - Send the sensor frames to the client.
98  * If the server cannot call this function at the rate it expects (the returned ticks until next),
99  * the client will not get the update rate it expects.
100  * There is no harm in calling this function too often.
101  *
102  * When the returned state equals ACC_EXPLORATION_SERVER_WAITING the server should call the
103  * acc_exploration_server_process function when new client data have been received.
104  *
105  * When the returned state equals ACC_EXPLORATION_SERVER_STREAMING the server should call the
106  * acc_exploration_server_process after maximum ticks_until_next ticks.
107  * The acc_exploration_server_process should be called immediately if state
108  * equals ACC_EXPLORATION_SERVER_STREAMING and ticks_until_next equals 0
109  *
110  * @param[in] server_if server interface functions
111  * @param[out] state The state the exploration server is in
112  * @param[out] ticks_until_next the number of ticks until the next frame is ready
113  *
114  * @return true if successful
115  */
118  int32_t *ticks_until_next);
119 
120 /**
121  * @brief End exploration server session, called to send end message to client
122  *
123  * @param[in] server_if server interface functions
124  */
126 
127 /**
128  * @brief Sends a log as a json package
129  *
130  * @param[in] write_func See write_data_function_t
131  * @param[in] level The severity level for the log
132  * @param[in] module The name of the SW module from where the log is called
133  * @param[in] buffer The information to be logged
134  *
135  * @return true if successful
136  */
137 bool acc_exploration_server_send_log(write_data_function_t write_func, acc_log_level_t level, const char *module, const char *buffer);
138 
139 #endif
ACC_EXPLORATION_SERVER_STOPPED
@ ACC_EXPLORATION_SERVER_STOPPED
Definition: acc_exploration_server_base.h:17
exploration_server_interface_t::max_baudrate
uint32_t max_baudrate
Definition: acc_exploration_server_base.h:51
write_data_function_t
void() write_data_function_t(const void *data, uint32_t size)
Function that writes data back to the client.
Definition: acc_exploration_server_base.h:26
buffer
void * buffer
Definition: i2c_example_cargo.c:40
acc_exploration_server_reset_input_buffer
void acc_exploration_server_reset_input_buffer(void)
Reset and clear the input buffer.
exploration_server_interface_t
Struct to handle input for acc_exploration_server_process_cmds.
Definition: acc_exploration_server_base.h:46
exploration_server_interface_t::get_tick
get_tick_function_t * get_tick
Definition: acc_exploration_server_base.h:52
exploration_server_interface_t::restart_input
restart_input_function_t * restart_input
Definition: acc_exploration_server_base.h:49
get_tick_function_t
uint32_t() get_tick_function_t(void)
Get tick function of server.
Definition: acc_exploration_server_base.h:41
acc_exploration_server_put_buffer_from_client
void acc_exploration_server_put_buffer_from_client(const void *buffer, size_t buffer_size)
Put string from client into input buffer.
acc_exploration_server_stop_streaming
void acc_exploration_server_stop_streaming(void)
Stop the streaming from the exploration server.
acc_log_level_t
acc_log_level_t
This enum represents the different log levels for RSS.
Definition: acc_definitions_common.h:23
buffer_size
uint32_t buffer_size
Definition: i2c_example_cargo.c:41
acc_exploration_server_init
bool acc_exploration_server_init(char *buffer, size_t buffer_size, const char *hw, acc_log_level_t log_level)
Initialize the exploration server.
server_if
static const exploration_server_interface_t server_if
Server interface functions.
Definition: acc_exploration_server_stm32.c:123
acc_exploration_server_deinit
void acc_exploration_server_deinit(void)
De-initialize the exploration server.
ACC_EXPLORATION_SERVER_STREAMING
@ ACC_EXPLORATION_SERVER_STREAMING
Definition: acc_exploration_server_base.h:16
acc_exploration_server_state_t
acc_exploration_server_state_t
Definition: acc_exploration_server_base.h:13
exploration_server_interface_t::set_baudrate
set_baudrate_function_t * set_baudrate
Definition: acc_exploration_server_base.h:50
ACC_EXPLORATION_SERVER_WAITING
@ ACC_EXPLORATION_SERVER_WAITING
Definition: acc_exploration_server_base.h:15
acc_exploration_server_end
void acc_exploration_server_end(const exploration_server_interface_t *server_if)
End exploration server session, called to send end message to client.
acc_exploration_server_send_log
bool acc_exploration_server_send_log(write_data_function_t write_func, acc_log_level_t level, const char *module, const char *buffer)
Sends a log as a json package.
acc_definitions_common.h
exploration_server_interface_t::ticks_per_second
uint32_t ticks_per_second
Definition: acc_exploration_server_base.h:53
exploration_server_interface_t::write
write_data_function_t * write
Definition: acc_exploration_server_base.h:48
acc_exploration_server_process
bool acc_exploration_server_process(const exploration_server_interface_t *server_if, acc_exploration_server_state_t *state, int32_t *ticks_until_next)
The exploration server process function.
set_baudrate_function_t
void() set_baudrate_function_t(uint32_t baudrate)
Set baudrate of server.
Definition: acc_exploration_server_base.h:36
restart_input_function_t
void() restart_input_function_t(void)
Function that stops streaming.
Definition: acc_exploration_server_base.h:31