@@ -69,7 +69,7 @@ static void ot_cli_loop(void *context) {
69
69
}
70
70
71
71
// 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)
73
73
{
74
74
char prompt_check[3 ];
75
75
int ret = 0 ;
@@ -188,6 +188,11 @@ void onReceive(OnReceiveCb_t func) {
188
188
189
189
// Stream object shall be already started and configured before calling this function
190
190
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
+
191
196
if (s_console_cli_task == NULL ) {
192
197
otConsole.cliStream = &otStream;
193
198
otConsole.echoback = echoback;
@@ -249,7 +254,7 @@ static void ot_task_worker(void *aContext) {
249
254
}
250
255
if (!err) {
251
256
// 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 );
253
258
254
259
// Initialize the esp_netif bindings
255
260
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD ();
@@ -279,6 +284,11 @@ static void ot_task_worker(void *aContext) {
279
284
}
280
285
281
286
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
+
282
292
xTaskCreate (ot_task_worker, " ot_main_loop" , 10240 , NULL , 20 , &s_ot_task);
283
293
284
294
// RX Buffer default has 1024 bytes if not preset
@@ -318,9 +328,14 @@ void OpenThreadCLI::begin(bool OThreadAutoStart) {
318
328
}
319
329
320
330
void OpenThreadCLI::end () {
331
+ if (!otStarted) {
332
+ log_w (" OpenThread CLI already stopped. Please begin() it before stopping again." );
333
+ return ;
334
+ }
321
335
if (s_ot_task != NULL ) {
322
336
vTaskDelete (s_ot_task);
323
337
// Clean up
338
+ esp_openthread_deinit ();
324
339
esp_openthread_netif_glue_deinit ();
325
340
esp_netif_destroy (openthread_netif);
326
341
esp_vfs_eventfd_unregister ();
@@ -331,6 +346,7 @@ void OpenThreadCLI::end() {
331
346
if (s_console_cli_task != NULL ) {
332
347
vTaskDelete (s_console_cli_task);
333
348
}
349
+ esp_event_loop_delete_default ();
334
350
setRxBufferSize (0 );
335
351
setTxBufferSize (0 );
336
352
otStarted = false ;
0 commit comments