当前位置:网站首页>RT thread add MSH command
RT thread add MSH command
2022-06-23 09:54:00 【Xiaohui_ Super】
In this paper, the reference 《RT-Thread Programming manual 》https://www.bookstack.cn/read/rtthread-manual-doc/10.6.md
List of articles
How to add a command
In the use of FinSH when , The system provides some useful commands , such as :

In fact, we can add some commands to msh in , The method is as follows :
MSH_CMD_EXPORT(command, desc);
command Is the command to be added ( Function name ),desc It's a description of the command .
A simple test
Here's a simple my_hello Command to test , Add the following code to the project :
void my_hello(void)
{
rt_kprintf("hello world\n");
}
MSH_CMD_EXPORT(my_hello, msh cmd test);
stay msh Type... On the command line help command , You can see our my_hello The command has been added to the command list :

Input my_hello command , Successfully run my_hello() function :

Variable parameter commands
Functions can usually take arguments ,msh Commands can also take parameters , also msh It also supports commands for adding variable parameters , The format of the definition is :
void my_cmd(int argc, char **argv)
Again , Let's write a simple test example :( Remember to open it. MicroLIB)
#include <string.h>
#include <stdio.h>
void led_ctrl(int argc, char **argv)
{
if(argc != 3)
{
rt_kprintf(" Correct format :led_ctrl LEDx ON/OFF\n");
return;
}
if(!strcmp(argv[1] , "LED0"))
{
if(!strcmp(argv[2] , "ON"))
{
rt_kprintf("led0 on!\n");
}
else if(!strcmp(argv[2] , "OFF"))
{
rt_kprintf("led0 off!\n");
}
}
else if(!strcmp(argv[1] , "LED1"))
{
if(!strcmp(argv[2] , "ON"))
{
rt_kprintf("led1 on!\n");
}
else if(!strcmp(argv[2] , "OFF"))
{
rt_kprintf("led1 off!\n");
}
}
}
MSH_CMD_EXPORT(led_ctrl, "LEDx ON/OFF"); // No double quotes ,ON/OFF Will be displayed as 1/0
test result :( Different parameters , The content of operation is also different )

边栏推荐
- After the uncommitted transactions in the redo log buffer of MySQL InnoDB are persisted to the redo log, what happens if the transaction rollback occurs? How does the redo log handle this transaction
- AI: the Elephant in Room
- web--信息泄漏
- Successful experience in postgraduate entrance examination for MTI master of English translation major of Beijing University of science and technology in 2023
- NiO example
- 135137138445 unable to remotely connect to the database due to disabling
- 我被提拔了,怎么和原来平级的同事相处?
- RT-Thread 添加 msh 命令
- RBtree
- J. Med. Chem. | Release: a new drug design model for deep learning based on target structure
猜你喜欢

必须知道的RPC内核细节(值得收藏)!!!

JSP getting started summary

J. Med. Chem. | RELATION: 一种基于靶标结构的深度学习全新药物设计模型
![[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist](/img/1f/dde52dc63de58d67f51161e318a9fb.png)
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist

Web -- Information Disclosure

Bioinformatics | effective drug target correlation prediction based on interacting neural network
![[SUCTF 2019]CheckIn](/img/0e/75bb14e7a3e55ddc5126581a663bfb.png)
[SUCTF 2019]CheckIn

Cloud native database Amazon RDS

汇编语言中断及外部设备操作篇--06

Go 单元测试
随机推荐
JSP getting started summary
快速排序的简单理解
Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023
高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
[极客大挑战 2019]HardSQL
高性能算力中心 — RDMA — 实现技术
UEFI learning 3.6 - ACPI table on ARM QEMU
陆奇首次出手投资量子计算
[MRCTF2020]Ez_ bypass
Learn SCI thesis drawing skills (f)
Gorm 高级查询
2021-04-15
RBtree
2022高考季征文获奖名单公布
[geek challenge 2019] hardsql
Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
Multithreaded exercises
【CTF】bjdctf_ 2020_ babyrop
RPC kernel details you must know (worth collecting)!!!