# CLI Command

mxos provides the user with a serial CLI command line debugging function to view the current device status to assist in debugging analysis.

#Introduction

CLI commands are input and output through the system debug serial port, whose baud rate is usually: 115200bps.

Input: help, you can see the help command list:

#CLI function implementation

If you need to open the mxos CLI function, according to the mxos SDK version, modify it as follows:

  • In the project (mxos_SDK_v2.3.0 and above), the serial command line debugging function has been enabled by default in the function: mxos_system_init( mxos_context ), and the user does not need to modify the code to add functions.

#Add and delete new CLI commands

Each command of the CLI is defined in the mxos_cli.h file and is defined as follows:

struct cli_command {
    /** The name of the CLI command */
    const char *name;
    /** The help text associated with the command */
    const char *help;
    /** The function that should be invoked for this command. */
    void (*function) (char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv);
    };
    int cli_register_command(const struct cli_command *command)
  • Function: Add a command
  • Parameter: command is a pointer to a command, the memory address must not be free, CLI is just a pointer to record the memory, will not do copy.
  • Returns: 0 is returned successfully, and 1 is returned by failure.

int cli_register_commands(const struct cli_command *commands, int num_commands)

  • Function: Add a set of commands
  • Parameters: command points to an array of commands, the array can not be free, CLI is just a pointer to each command that records the reorganized array; num_commands is the number of commands in this array.
  • Returns: 0 is returned successfully, and 1 is returned by failure.

int cli_unregister_command(const struct cli_command *command)

  • Function: Delete a command
  • Parameter: The command pointer must be the same as the register command successfully succeeded;
  • Return: 0 is returned successfully, and 1 is returned.

int cli_register_commands(const struct cli_command *commands, int num_commands)

  • Function: Remove the num_commands command from the commands array.
  • Returns: 0 is returned successfully, and 1 is returned by failure.

#CLI input and output function

int cli_printf(const char *msg, ...)

Similar to the output function of the printf function, the output of the CLI result is implemented.

int cli_putstr(const char *msg)

The CLI has no formatted output, and msg points to a string.

int cli_getchar(char *inbuf)

The input of the CLI, which takes one byte of data at a time, returns 1 successfully, and returns 0.

#CLI function API prototype

To facilitate debugging, the mxos 2.0 library provides a set of APIs for debugging. Each API prototype is:

void (*function) (char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)

where:

  • pcWriteBuffer: the cache address used to record the CLI results;
  • xWriteBufferLen: the maximum length of the cache;
  • argc: number of parameters for the CLI, including commands;
  • argv: a pointer to a parameter array containing argc strings.

#CLI serial port connection

#1. Confirm UART port

In the mxos SDK, the debug serial port and the debug command serial port usually share a UART port. The specific one needs to be confirmed in the SDK Board/platform.c according to the Wi-Fi module model.

Take MiCOKit-3165 as an example. The CLI serial port is defined as follows:

#2. Install the driver

Development board power cord, that is, the debug serial line is connected to the PC end, you need to install the USB to UART driver, download address: http://www.ftdichip.com/Drivers/VCP.htm (opens new window),

#3. PC side view port number

After the installation is successful, open the PC Device Manager and view the serial port information as shown below.

#4. SecureCRT connection serial port

Found port number COM11, indicating that the driver is successfully installed, open SecureCRT (or other serial debugging software), connect COM11 serial port, set as follows:

After the connection is successful, you can enter the command line to debug the serial port.

#CLI Command List

Input CLI Command in debug serial prot,you can get log information printed. Command are listed in tables:

Number

Command

Function

1

help

Query all serial commands and their functions

2

version

Query Device Firmware Version Information

3

echo

Query or set command postback function

4

exit

Exit Serial Command Line Status

5

scan

Scanning around WiFi access point AP

6

wifistate

Query wifi current status

7

wifidebug

View or set WiFi debugging function

8

ifconfig

Query Device IP Address

9

arp

Query or clear arp list

10

ping

Test whether the machine can communicate with an IP address

11

dns

Query or clear DNS domain name resolution IP address

12

sockshow

Query all socket socket status

13

tasklist

Query the names and states of all threads

14

memshow

Query Memory Usage Information

15

memdum

Copy data from specified memory address

16

memset

Setting data to the specified memory address

17

memp

Query Memory Space Allocation List

18

wifidriver

Query WiFi driver information

19

reboot

Restart System

20

tftp

Write the file to the device with the specified flash address

21

time

Query device system runtime

22

ota

System Auto OTA Upgrade

23

flash

Query flash space allocation list

24

mxosdebug

Turn off or turn on log output function

The following is a brief introduction to the CLI commands in the list.

#CLI command usage example

#help

Function: Query all serial commands and functions

In the Command Window command window, enter the command "help", press Enter, the serial port returns the content, as shown below:

#version

Function: Query device firmware version information

In the Command Window command window, enter the command "version", press Enter, the serial port returns the content, as shown below:

#echo

Function: Query or set the command return function

  1. Enter the command "echo" in the Command Window command window, press Enter, the serial port returns the content, as shown below:

The command postback function is turned off. Enter the command "version" and press Enter. No "# version" is seen in the return.

  1. Enter the command "echo off" in the Command Window command window, press Enter, the serial port returns the content, as shown below:

The command return function is enabled. Enter the command "version" and press Enter. You see "# version" in the return. It is generally recommended to enable the echo function to facilitate simultaneous viewing of command functions.

#exit

Function:Exit the serial port command line state

In the Command Window command window, enter the command "exit", press Enter, the serial port returns the content, as shown below:

After the input command is invalid, it must be powered on and restarted before it can take effect.

#scan

Function: scan the surrounding WiFi access point AP

void wifiscan_Command(CLI_ARGS)

In the Command Window command window, enter the command "scan", press Enter, the serial port returns the content, as shown below:

void wifiscan_Command(CLI_ARGS);

In the Command Window command window, enter the command "scan", press Enter, the serial port returns the content, as shown below:

Get the AP hotspot name, channel, encryption method, and signal strength near the mxos device.

#wifistate

Function: query wifi current status

void wifistate_Command(CLI_ARGS);

In the Command Window command window, enter the command "wifistate", press Enter, the serial port returns the content, as shown below:

First, the information of the AP to be connected is output, including the SSID, password, BSSID, and retry interval (in ms). Then the status of the connection is output. If the connection is successful, the detailed information of the connected AP, including SSID, channel, signal strength and BSSID, is output.

#wifidebug

Function: View or set WiFi debugging function

void wifidebug_Command(CLI_ARGS);

Where: argc must be 2, argv[1] can be "on" and "off", which are used to turn the wifi debug output on and off, respectively.

(1) When the device enters the distribution network and waits for the distribution network, enter the command “wifidebug on” in the Command Window command window, press Enter, and then perform the distribution network. The serial port returns the content, as shown below:

Note: This command is a dynamic command. It is valid during one power-on process. It is turned off when it is powered on again. It needs to be turned on again to take effect.

(2)Enter the command "wifidebug off" in the Command Window command window, press Enter, the serial port returns the content, as shown below:!

!

At this point, the debug information log in the WiFi library will stop outputting.

#ifconfig

Function: Query the device IP address

void ifconfig_Command(CLI_ARGS)

In the Command Window command window, enter the command "ifconfig", press Enter, the serial port returns the content, as shown below:

#arp

Function: Query or clear the arp list

void arp_Command(CLI_ARGS)

The arp command supports one parameter, show and clean. Clean is used to clear the ARP cache. Show is used to output the arp cache, using the following:

(1) Enter the command "arp" in the Command Window command window, press Enter, the serial port returns the content, as shown below: Return the arp command format to show and clean respectively.

(2) Enter the command "arp show" in the Command Window command window, press Enter, and then try to communicate with other IP addresses in the LAN through the ping command, and return the result through "arp show" again.

(3) Enter the command "arp clean" in the Command Window command window, clear the arp cache, press Enter, and then view it by the command "arp show". The serial port returns as shown below:

#ping

Function: Test whether the machine can communicate with an IP address.

void ping_Command(CLI_ARGS);

The ping command is used to ping an IP address. It only supports IP addresses and does not support domain names. Will ping 5 times in a row, each time delay 1 second, output after ping completion Enter the command "ping 192.168.1.1" in the Command Window command window, press Enter, the serial port returns the content, as shown below:

The device is connected to the IP address.

#dns

Function: Query or clear the DNS domain name resolution IP address

void dns_Command(CLI_ARGS);

(1) The command format of dns can be displayed. (At this time, the device runs demo: wifi_uart transparent transmission project, equipped with network)

(2) Enter the command "dns show" in the Command Window command window, press Enter, the serial port returns the following content:

At this point, enter the command "dns www.baidu.com" (opens new window) in the Command Window command window, and return the following:

At this point, enter the command "dns show" in the Command Window command window, press Enter, return to the following figure:

(3) Enter the command "dns clean" in the Command Window command window, press Enter, and the serial port returns the following content:

#sockshow

Function: Query all socket socket status

void socket_show_Command(CLI_ARGS);

Displays the status of the current system socket, showing the status of the BSD socket, the status of the TCP, and the status of the UDP. In the Command Window command window, enter the command "sockshow", press Enter, and the serial port returns the content, as shown below: Display all the socket connection status information of the device.

#tasklist

Function: query all thread names and status

void task_Command(CLI_ARGS);

Used to display the status of the current system's Thread thread. In the Command Window command window, enter the command "tasklist", press Enter, and the serial port returns the content, as shown below: Display all current thread status information of the device.

Among them:

  • Status - R stands for thread running, S stands for thread stop, and B stands for thread blocking;
  • Prio (priority) - thread priority level;
  • Stack - the size of the stack space occupied by the thread;
  • TCB (task fast) - thread task block size.

#memshow

Function:Query memory usage information

void memory_show_Command(CLI_ARGS);

Display the current system memory status Enter the command "memshow" in the Command Window command window, press Enter, the serial port returns the content, as shown below: display the current memory usage information of the device.

#memdump

Function: copy data from the specified memory address

void memory_dump_Command(CLI_ARGS);

DUMP formatted the contents of a memory address in HEX format. In the Command Window command window, enter the command "memdump 0x0001000 100", press Enter, the serial port returns the content, as shown below: Read the data of the specified memory address of the device.

0x200003c0 is the starting address of the memory address that needs to be dumped, and 10 is the length of the dump.

#memset

Function: set data to the specified memory address

void memory_set_Command(CLI_ARGS);

Set the data content of a certain memory address.

(1) Enter the command "memset 0x0001000 100" in the Command Window command window, press Enter, the serial port returns the content, as shown below: Write to the device specified memory address data, and read it through the memdump command to verify the written data content.

Among them, 0x200003c0 is the starting address, followed by multiple parameters, each parameter corresponding to the content of an address. But note: Sometimes some memory addresses are not allowed to be written.

#memp

Function: query memory space allocation list

void memp_dump_Command(CLI_ARGS);

Displays the usage of each cache address pool of the current protocol stack. In the Command Window command window, enter the command "memp", press Enter, and the serial port returns the content, as shown below: Display the current memory allocation of the device.

#wifidriver

Function: Query wifi driver status

void driver_state_Command(CLI_ARGS);

It is used to print out the running status of the wifi driver in the current system. Enter the command “wifidriver” in the Command Window command window, press Enter, and return the content on the serial port, as shown below.

#reboot

Function: Restart the mxos system

In the Command Window command window, enter the command "reboot" and press Enter. The serial port returns the content as shown in the figure and the device is restarted.

#tftp

Function:Write the file to the device with the specified flash address. Temporarily not supported.

#time

Function: Query the running time of the device system

In the Command Window command window, enter the command "time" to enter, the serial port returns the content as shown.

#ota

Function: System automatic OTA upgrade

Temporarily not supported.

#flash

Function: Query the flash space allocation list

In the Command Window command window, enter the command "flash" to enter, the serial port returns the content as shown.

#mxosdebug

Function: Turn off or turn on the mxos run log output function

  1. Enter the command "mxosdebug off" in the Command Window command window, and return the contents of the serial port as shown in the figure.

Verification: Perform related operations on the device, such as the transparent transmission routine: set the device to connect to the IP address of the server through Easylink, and see if there is any information output from the debug serial port. Result: no log information is output.

  1. Enter the command "mxosdebug on" in the Command Window command window, and return the contents of the serial port as shown in the figure.

Verification: Same as (1), related operations on the device, such as transparent transmission routine: set the device to connect to the IP address of the server through Easylink, and see if there is any information output from the debug serial port. Result: log information is output.


END

Last Updated: 11/29/2023, 1:52:34 PM