This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Openthread CLI API add custom commands

Hello Support

I have an error when I try to add a custom CLI command with the API "otCliSetUserCommands()". I added two commands for my example. The commands work fine but if I make a typo, usually the info "Error 35: InvalidCommand" pops up. But as soon as I set my own commands the programm crashes somewhere with no error. Am I doing something wrong with the initialization? The code below shows how I implemented my two user defined cli commands.

I work with:

- SDK for Thread and Zigbee Version 4.1.0

- CLI Example for the PCA10059 (Addad just the code below and call the init function in the main)

- NRF52840 Dongle

#include "bm_master_cli.h"

#include "nrf_log_ctrl.h"
#include "nrf_log.h"
#include "nrf_log_default_backends.h"

#include <openthread/cli.h>


void bm_cli_benchmark_start(uint8_t aArgsLength, char *aArgs[]);
void bm_cli_benchmark_stop(uint8_t aArgsLength, char *aArgs[]);

otCliCommand bm_cli_usercommands[2] = {
  {"benchmark_start", bm_cli_benchmark_start},
  {"benchmark_stop" , bm_cli_benchmark_stop}
};


void bm_cli_benchmark_start(uint8_t aArgsLength, char *aArgs[]) {
    NRF_LOG_INFO("Benchmark start");

    otCliOutput("done \r\n", sizeof("done \r\n"));
}

void bm_cli_benchmark_stop(uint8_t aArgsLength, char *aArgs[]) {
    NRF_LOG_INFO("Benchmark stop");

    otCliOutput("done \r\n", sizeof("done \r\n"));
}

/**@brief Function for initialize custom cli commands */
void bm_custom_cli_init(void){
    otCliSetUserCommands(bm_cli_usercommands, sizeof(bm_cli_usercommands));
}

  • Hello Rouben,

    Have you tried to run this on a DK and debug? What happens when the application crashes? Are you sure no error handlers are reached? Is the callbacks, bm_cli_benchmark_start/stop(), reached? 

  • Hello Edvin,

    thank you for your support. I tried to debug my code on the DK. Unfortunately the program doesn't reached an error handler. The debugger stocked in a "unknown function" error. The callback ist successfully reached if I type the command on the cli. The program crashes only if I do a typo. (Then normally should pop up "Error 35: InvalidCommand")

    After a while I tried to move the code from my previous post to the main.c file and there it works fine. I think there is something wrong with my includes. I have to check this next week.

    Best regards

    Rouben

Related