Line data Source code
1 0 : /*
2 : * Shell backend used for testing
3 : *
4 : * Copyright (c) 2018 Nordic Semiconductor ASA
5 : *
6 : * SPDX-License-Identifier: Apache-2.0
7 : */
8 :
9 : #ifndef ZEPHYR_INCLUDE_SHELL_DUMMY_H_
10 : #define ZEPHYR_INCLUDE_SHELL_DUMMY_H_
11 :
12 : #include <zephyr/shell/shell.h>
13 :
14 : #ifdef __cplusplus
15 : extern "C" {
16 : #endif
17 :
18 0 : extern const struct shell_transport_api shell_dummy_transport_api;
19 :
20 0 : struct shell_dummy {
21 0 : bool initialized;
22 :
23 : /** current number of bytes in buffer (0 if no output) */
24 1 : size_t len;
25 :
26 : /** output buffer to collect shell output */
27 1 : char buf[CONFIG_SHELL_BACKEND_DUMMY_BUF_SIZE];
28 : };
29 :
30 0 : #define SHELL_DUMMY_DEFINE(_name) \
31 : static struct shell_dummy _name##_shell_dummy; \
32 : struct shell_transport _name = { \
33 : .api = &shell_dummy_transport_api, \
34 : .ctx = (struct shell_dummy *)&_name##_shell_dummy \
35 : }
36 :
37 : /**
38 : * @brief This function shall not be used directly. It provides pointer to shell
39 : * dummy backend instance.
40 : *
41 : * Function returns pointer to the shell dummy instance. This instance can be
42 : * next used with shell_execute_cmd function in order to test commands behavior.
43 : *
44 : * @returns Pointer to the shell instance.
45 : */
46 1 : const struct shell *shell_backend_dummy_get_ptr(void);
47 :
48 : /**
49 : * @brief Returns the buffered output in the shell and resets the pointer
50 : *
51 : * The returned data is always followed by a nul character at position *sizep
52 : *
53 : * @param sh Shell pointer
54 : * @param sizep Returns size of data in shell buffer
55 : * @returns pointer to buffer containing shell output
56 : */
57 1 : const char *shell_backend_dummy_get_output(const struct shell *sh,
58 : size_t *sizep);
59 :
60 : /**
61 : * @brief Clears the output buffer in the shell backend.
62 : *
63 : * @param sh Shell pointer
64 : */
65 1 : void shell_backend_dummy_clear_output(const struct shell *sh);
66 :
67 : #ifdef __cplusplus
68 : }
69 : #endif
70 :
71 : #endif /* ZEPHYR_INCLUDE_SHELL_DUMMY_H_ */
|