Skip to content

Commit 28d7c44

Browse files
committed
fix(openthread): begin end
1 parent 7fece86 commit 28d7c44

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

libraries/OpenThread/src/OThreadCLI.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static void ot_cli_loop(void *context) {
6969
}
7070

7171
// process the CLI responses received from the OpenThread stack
72-
static int OTcli_output_callback(void *context, const char *format, va_list args)
72+
static int ot_cli_output_callback(void *context, const char *format, va_list args)
7373
{
7474
char prompt_check[3];
7575
int ret = 0;
@@ -188,6 +188,11 @@ void onReceive(OnReceiveCb_t func) {
188188

189189
// Stream object shall be already started and configured before calling this function
190190
void OpenThreadCLI::startOpenThreadConsole(Stream& otStream, bool echoback, const char *prompt) {
191+
if (!otStarted) {
192+
log_e("OpenThread CLI has not started. Please begin() it before starting the console.");
193+
return;
194+
}
195+
191196
if (s_console_cli_task == NULL) {
192197
otConsole.cliStream = &otStream;
193198
otConsole.echoback = echoback;
@@ -249,7 +254,7 @@ static void ot_task_worker(void *aContext) {
249254
}
250255
if (!err) {
251256
// Initialize the OpenThread cli
252-
otCliInit(esp_openthread_get_instance(), OTcli_output_callback, NULL);
257+
otCliInit(esp_openthread_get_instance(), ot_cli_output_callback, NULL);
253258

254259
// Initialize the esp_netif bindings
255260
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD();
@@ -279,6 +284,11 @@ static void ot_task_worker(void *aContext) {
279284
}
280285

281286
void OpenThreadCLI::begin(bool OThreadAutoStart) {
287+
if (otStarted) {
288+
log_w("OpenThread CLI already started. Please end() it before starting again.");
289+
return;
290+
}
291+
282292
xTaskCreate(ot_task_worker, "ot_main_loop", 10240, NULL, 20, &s_ot_task);
283293

284294
//RX Buffer default has 1024 bytes if not preset
@@ -318,9 +328,14 @@ void OpenThreadCLI::begin(bool OThreadAutoStart) {
318328
}
319329

320330
void OpenThreadCLI::end() {
331+
if (!otStarted) {
332+
log_w("OpenThread CLI already stopped. Please begin() it before stopping again.");
333+
return;
334+
}
321335
if (s_ot_task != NULL) {
322336
vTaskDelete(s_ot_task);
323337
// Clean up
338+
esp_openthread_deinit();
324339
esp_openthread_netif_glue_deinit();
325340
esp_netif_destroy(openthread_netif);
326341
esp_vfs_eventfd_unregister();
@@ -331,6 +346,7 @@ void OpenThreadCLI::end() {
331346
if (s_console_cli_task != NULL) {
332347
vTaskDelete(s_console_cli_task);
333348
}
349+
esp_event_loop_delete_default();
334350
setRxBufferSize(0);
335351
setTxBufferSize(0);
336352
otStarted = false;

0 commit comments

Comments
 (0)