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