Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include <ctype.h>
#include "esp_log.h"
#include <string.h>
#include <esp_log.h>
#include <esp_console.h>
#include "esp_vfs_dev.h"
#include "linenoise/linenoise.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#include <driver/uart.h>
#define BLE_RX_TIMEOUT
#define BLE_RX_PARAM
#define YES_NO_PARAM
cli_handle
key
conn_param
mtu
#define CONSOLE_PROMPT_LEN_MAX
repl_state_t
conn_param_handler(int, char **)
conn_mtu_handler(int, char **)
throughput_demo_handler(int, char **)
yesno_handler(int, char **)
scli_receive_yesno(bool *)
scli_receive_key(int *)
cli_receive_key(int *)
scli_reset_queue()
cmds
ble_register_cli()
Files
loading (1/4)...
SourceVuESP-IDF Framework and Examplesblecent_throughput samplemain/scli.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <stdio.h> #include <ctype.h> #include "esp_log.h" #include <string.h> #include <esp_log.h> #include <esp_console.h> #include "esp_vfs_dev.h" #include "linenoise/linenoise.h" #include <freertos/FreeRTOS.h> #include <freertos/task.h> #include <freertos/queue.h> #include <driver/uart.h>12 includes #define BLE_RX_TIMEOUT (30000 / portTICK_PERIOD_MS) #define BLE_RX_PARAM (10000 / portTICK_PERIOD_MS) #define YES_NO_PARAM (5000 / portTICK_PERIOD_MS) static QueueHandle_t cli_handle; static int key[2]; static int conn_param[10]; static int mtu; #define CONSOLE_PROMPT_LEN_MAX (32) typedef enum { CONSOLE_REPL_STATE_DEINIT, CONSOLE_REPL_STATE_INIT, CONSOLE_REPL_STATE_START, }{ ... } repl_state_t; static int conn_param_handler(int argc, char *argv[]) { ESP_LOGI("Conn param Arguments entered", "%d", argc); if (argc != 7) { return -1; }{...} sscanf(argv[1], "%d", &conn_param[0]); sscanf(argv[2], "%d", &conn_param[1]); sscanf(argv[3], "%d", &conn_param[2]); sscanf(argv[4], "%d", &conn_param[3]); sscanf(argv[5], "%d", &conn_param[4]); sscanf(argv[6], "%d", &conn_param[5]); ESP_LOGI("You entered", "%s %d %d %d %d %d %d", argv[0], conn_param[0], conn_param[1], conn_param[2], conn_param[3], conn_param[4], conn_param[5]); xQueueSend(cli_handle, &conn_param[0], 500 / portTICK_PERIOD_MS); return 0; }{ ... } static int conn_mtu_handler(int argc, char *argv[]) { ESP_LOGI("MTU Arguments entered", "%d", argc); if (argc != 2) { return -1; }{...} sscanf(argv[1], "%d", &mtu); ESP_LOGI("You entered", "%s %d", argv[0], mtu); xQueueSend(cli_handle, &mtu, 500 / portTICK_PERIOD_MS); return 0; }{ ... } static int throughput_demo_handler(int argc, char *argv[]) { char pkey[8]; if (argc != 3) { return -1; }{...} sscanf(argv[1], "%s", pkey); if (strcmp(pkey, "read") == 0) { key[0] = 1; }{...} else if (strcmp(pkey, "write") == 0) { key[0] = 2; }{...} else if (strcmp(pkey, "notify") == 0) { key[0] = 3; }{...} else { key[0] = 0; }{...} sscanf(argv[2], "%d", &key[1]); ESP_LOGI("Throughput demo handler", "%s %s %d", argv[0], argv[1], key[1]); xQueueSend(cli_handle, &key[0], 500 / portTICK_PERIOD_MS); return 0; }{ ... } static int yesno_handler(int argc, char *argv[]) { char yesno[4]; bool yes; if (argc != 2) { return -1; }{...} sscanf(argv[1], "%s", yesno); if (strcmp(yesno, "Yes") || strcmp (yesno, "YES") || strcmp(yesno, "yes")) { yes = 1; }{...} else { yes = 0; }{...} ESP_LOGI("User entered", "%s %s", argv[0], yesno); xQueueSend(cli_handle, &yes, 500 / portTICK_PERIOD_MS); return 0; }{ ... } int scli_receive_yesno(bool *console_key) { return xQueueReceive(cli_handle, console_key, YES_NO_PARAM); }{ ... } int scli_receive_key(int *console_key) { return xQueueReceive(cli_handle, console_key, BLE_RX_PARAM); }{ ... } int cli_receive_key(int *console_key) { return xQueueReceive(cli_handle, console_key, BLE_RX_TIMEOUT); }{ ... } void scli_reset_queue(void) { xQueueReset(cli_handle); }{ ... } static esp_console_cmd_t cmds[] = { { .command = "conn", .help = "Set connection parameters: min itvl, max itvl, latency," "supervision timeout, min CE, max CE", .func = &conn_param_handler, }{...}, { .command = "MTU", .help = "Set MTU value", .func = &conn_mtu_handler, }{...}, { .command = "throughput", .help = "Enter read/write/notify and time (in seconds)", .func = &throughput_demo_handler, }{...}, { .command = "Insert", .help = "Enter Insert Yes for YES or Insert No for NO", .func = &yesno_handler, }{...}, }{...}; void ble_register_cli(void) { int cmds_num = sizeof(cmds) / sizeof(esp_console_cmd_t); int i; for (i = 0; i < cmds_num; i++) { esp_console_cmd_register(&cmds[i]); }{...} cli_handle = xQueueCreate( 1, sizeof(int) * 6); if (cli_handle == NULL) { return; }{...} ESP_LOGI("CLI", "BLE CLI registered "); return; }{ ... }
Details