Command Line Interface

This module includes functions that control the Thread stack's execution.

Summary

Typedefs

otCliCommand typedef
struct otCliCommand
Represents a user provided CLI command entry.
otCliInterpreter typedef
Opaque type for a CLI interpreter.
otCliOutputCallback)(void *aContext, const char *aFormat, va_list aArguments) typedef
int(*
Pointer is called to notify about CLI interpreter output.

Functions

otCliAppendResult(otError aError)
void
Write a given error code as the result of previous command to the static CLI interpreter output.
otCliGetStaticInterpreter(void)
Gets the pointer to the static CLI interpreter.
otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
void
Initialize the static CLI interpreter.
otCliInputLine(char *aLine)
void
Feeds input to the static CLI interpreter.
otCliInterpreterFinalize(otCliInterpreter *aInterpreter)
void
Finalizes the CLI interpreter.
otCliInterpreterGetSize(void)
size_t
Gets the size of the CLI interpreter object.
otCliInterpreterInit(void *aBuffer, size_t aSize, otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
Initializes a CLI interpreter.
otCliInterpreterInputLine(otCliInterpreter *aInterpreter, char *aLine)
void
Feeds input to the CLI interpreter.
otCliInterpreterSetPromptConfig(otCliInterpreter *aInterpreter, bool aEnable)
void
Configures whether or not the CLI interpreter outputs the prompt string.
otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength)
void
Write a number of bytes to the static CLI interpreter output as a hex string.
otCliOutputFormat(const char *aFmt, ...)
void
Write formatted string to the static CLI interpreter output.
otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs)
void
Callback to write the OpenThread Log to the static CLI interpreter output.
otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength, void *aContext)
Set a user command table on the static CLI interpreter.
otCliVendorSetUserCommands(void)
void
Callback to allow vendor specific commands to be added to the user command table.

Structs

otCliCommand

Represents a user provided CLI command entry.

Typedefs

otCliCommand

struct otCliCommand otCliCommand

Represents a user provided CLI command entry.

otCliInterpreter

struct otCliInterpreter otCliInterpreter

Opaque type for a CLI interpreter.

otCliOutputCallback

int(* otCliOutputCallback)(void *aContext, const char *aFormat, va_list aArguments)

Pointer is called to notify about CLI interpreter output.

Details
Parameters
[out] aContext
A user context pointer.
[in] aFormat
The format string.
[in] aArguments
The format string arguments.
Returns
Number of bytes written by the callback.

Functions

otCliAppendResult

void otCliAppendResult(
  otError aError
)

Write a given error code as the result of previous command to the static CLI interpreter output.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

This is intended for use by user-provided CLI command handlers.

If the aError is OT_ERROR_PENDING nothing will be outputted.

Details
Parameters
[in] aError
Error code value.

otCliGetStaticInterpreter

otCliInterpreter * otCliGetStaticInterpreter(
  void
)

Gets the pointer to the static CLI interpreter.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

Details
Returns
A pointer to the static CLI interpreter.

otCliInit

void otCliInit(
  otInstance *aInstance,
  otCliOutputCallback aCallback,
  void *aContext
)

Initialize the static CLI interpreter.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

Details
Parameters
[in] aInstance
The OpenThread instance structure.
[in] aCallback
A callback method called to process CLI output.
[in] aContext
A user context pointer.

otCliInputLine

void otCliInputLine(
  char *aLine
)

Feeds input to the static CLI interpreter.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

Details
Parameters
[in] aLine
A pointer to a null-terminated string.

otCliInterpreterFinalize

void otCliInterpreterFinalize(
  otCliInterpreter *aInterpreter
)

Finalizes the CLI interpreter.

Details
Parameters
[in] aInterpreter
A pointer to a CLI interpreter.

otCliInterpreterGetSize

size_t otCliInterpreterGetSize(
  void
)

Gets the size of the CLI interpreter object.

Details
Returns
The size of the CLI interpreter object in bytes.

otCliInterpreterInit

otCliInterpreter * otCliInterpreterInit(
  void *aBuffer,
  size_t aSize,
  otInstance *aInstance,
  otCliOutputCallback aCallback,
  void *aContext
)

Initializes a CLI interpreter.

Details
Parameters
[in] aBuffer
A pointer to a memory buffer for the CLI interpreter.
[in] aSize
The size of the memory buffer.
[in] aInstance
The OpenThread instance structure.
[in] aCallback
A callback method called to process CLI output.
[in] aContext
A user context pointer.
Returns
A pointer to the initialized CLI interpreter, or NULL if aSize is too small.

otCliInterpreterInputLine

void otCliInterpreterInputLine(
  otCliInterpreter *aInterpreter,
  char *aLine
)

Feeds input to the CLI interpreter.

Details
Parameters
[in] aInterpreter
A pointer to a CLI interpreter.
[in] aLine
A pointer to a null-terminated string.

otCliInterpreterSetPromptConfig

void otCliInterpreterSetPromptConfig(
  otCliInterpreter *aInterpreter,
  bool aEnable
)

Configures whether or not the CLI interpreter outputs the prompt string.

Requires OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE.

It is enabled by default.

Details
Parameters
[in] aInterpreter
A pointer to a CLI interpreter.
[in] aEnable
TRUE to enable outputting the prompt, FALSE to disable.

otCliOutputBytes

void otCliOutputBytes(
  const uint8_t *aBytes,
  uint8_t aLength
)

Write a number of bytes to the static CLI interpreter output as a hex string.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

This is intended for use by user-provided CLI command handlers.

Details
Parameters
[in] aBytes
A pointer to data which should be printed.
[in] aLength
aBytes length.

otCliOutputFormat

void otCliOutputFormat(
  const char *aFmt,
  ...
)

Write formatted string to the static CLI interpreter output.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

This is intended for use by user-provided CLI command handlers.

Details
Parameters
[in] aFmt
A pointer to the format string.
[in] ...
A matching list of arguments.

otCliPlatLogv

void otCliPlatLogv(
  otLogLevel aLogLevel,
  otLogRegion aLogRegion,
  const char *aFormat,
  va_list aArgs
)

Callback to write the OpenThread Log to the static CLI interpreter output.

Details
Parameters
[in] aLogLevel
The log level.
[in] aLogRegion
The log region.
[in] aFormat
A pointer to the format string.
[in] aArgs
va_list matching aFormat.

otCliSetUserCommands

otError otCliSetUserCommands(
  const otCliCommand *aUserCommands,
  uint8_t aLength,
  void *aContext
)

Set a user command table on the static CLI interpreter.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

Details
Parameters
[in] aUserCommands
A pointer to an array with user commands.
[in] aLength
The aUserCommands length.
[in] aContext
The context passed to the handler.
Return Values
OT_ERROR_NONE
Successfully updated command table with commands from aUserCommands.
OT_ERROR_NO_BUFS
Maximum number of command entries have already been set.

otCliVendorSetUserCommands

void otCliVendorSetUserCommands(
  void
)

Callback to allow vendor specific commands to be added to the user command table.

Available when OPENTHREAD_CONFIG_CLI_VENDOR_COMMANDS_ENABLE is enabled and OPENTHREAD_CONFIG_CLI_MAX_USER_CMD_ENTRIES is greater than 1.

Requires OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE.

Resources

OpenThread API Reference topics originate from the source code, available on GitHub. For more information, or to contribute to our documentation, refer to Resources.