Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add custom cli commands to AliOS Things applications

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to add custom cli commands for AliOS Things applications". The explanation in this article is simple and clear, and is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to add custom cli commands for AliOS Things applications".

Parameter name

Parameter description

Char * pwbuf

A pointer to a string printed through the console when the function is finished. It can not be passed in.

Int blen

The length of the above string

Int argc

The length of the parameter passed in when the command is called, and 1 if no parameter is passed in

Char * * argv

Pass in parameter cache, string. The corner mark of the first valid parameter starts at 1.

Next, fill in the registration structure to pass the command information to the cli service. According to the previous design, register the structure information as follows, and copy the structure to the blink.c file.

Struct cli_command led_switch_command [] = {{.name = "led_switch", / / command name .help = "[on] turn on led2; [off] trun off led2", / / help text .function = function / / the function pointer to which the command is executed}}

Register the cli command with the system. Registration of the cli command requires only one function as follows:

Aos_cli_register_commands (& led_switch_command [0], 1)

The function needs to pass two parameters, parameter 1 is the pointer to the structure of the command information body just created, and parameter 2 is the number of commands to be registered this time, that is, you can register multiple commands at a time, as long as you fill in the information of several commands in the command information structure in an array.

Add the above function call to the following location of the application_start function in the blink.c file:

Aos_cli_register_commands (& led_switch_command [0], 1); / / register the cli command function aos_loop_run ()

At this point, the coding part of the implementation and registration of a cli command is complete. Compile and download to the development board to run. Enter help in the cli console and see that the led_switch command has been registered successfully.

# help====Build-in Commands=Support 4 cmds once, seperate by = help: print thisp: print memorym: modify memoryecho: echo for commandexit: close CLIdevname: print device namesysver: system versionreboot: reboot systemtime: system timeota: system ota====User Commands====loglevel: set log leveltasklist: list all thread infodumpsys: dump system infoudp: [ip] [port] [string data] send udp datawifi_debug: wifi debug modemac: get/set mackv: kv [set Key value | get key | del key | list] version: show versionled_switch: [on] turn on led2 [off] trun off led2

To test whether the command is executed, enter the following command at the command prompt and enter:

# led_switch on

Led2 light up

To judge the validity of the test parameters, enter the following instructions without parameters. The command returns an error alarm as designed.

# # led_switch [1291080] Parameter error Thank you for your reading. The above is the content of "how to add custom cli commands to AliOS Things applications". After the study of this article, I believe you have a deeper understanding of how to add custom cli commands to AliOS Things applications, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report