BetaFlight模块设计之三十:Cli模块分析

2023-05-16

BetaFlight模块设计之三十:Cli模块分析

  • Cli模块
  • Cli接口
  • Cli框架
  • Cli命令结构
  • 主要函数分析
    • cliProcess函数
    • processCharacterInteractive函数
    • processCharacter函数
  • Cli命令汇总
    • Cli串口help命令
    • Cli内部命令列表

基于BetaFlight开源代码框架简介的框架设计,逐步分析内部模块功能设计。

Cli模块

描述:Cli模块主要用于处理Cli命令,并根据命令显示系统状态或系统配置参数修改。

src/main/cli/
├── cli.c
├── cli_debug_print.h
├── cli.h
├── settings.c
└── settings.h

0 directories, 5 files

注:该模块主要支持BetaFlight模块设计之二:SERIAL任务分析。

Cli接口

extern bool cliMode;                             //判断系统处于Cli模式

void cliProcess(void);                           //处理Cli命令
void cliEnter(struct serialPort_s *serialPort);  //进入Cli模式
bool resetConfigToCustomDefaults(void);          //支持命令行“defaults”命令
bool hasCustomDefaults(void);                    //支持命令行“defaults”命令

Cli框架

  1. cliMode:判断当前Cli模块状态(TRUE为Cli模式;反之则不在该模式)
  2. cliEnter:触发Cli模块进入工作模式
  3. cliProcess:处理Cli命令
  4. cliExit:“CTRL + D”,退出Cli模式 //这个命令是内嵌在CliProcess函数内部

Cli命令结构

一个Cli命令通过name(命令名字),description(命令描述),args(命令参数表),cliCommand(命令函数)组成。

typedef void cliCommandFn(const char* name, char *cmdline);

typedef struct {
    const char *name;
#ifndef MINIMAL_CLI
    const char *description;
    const char *args;
#endif
    cliCommandFn *cliCommand;
} clicmd_t;

例如:help命令

CLI_COMMAND_DEF("help", "display command help", "[search string]", cliHelp),

主要函数分析

cliProcess函数

cliProcess
 ├──> <!cliWriter>  //Cli模式下处理自定义命令或者尚未进入Cli模式,直接返回
 │   └──> return
 ├──> cliWriterFlush();
 └──> <serialRxBytesWaiting(cliPort)>  //非阻塞式数据等待
     ├──> c = serialRead(cliPort);
     └──> processCharacterInteractive(c); //交互式串口字节处理

processCharacterInteractive函数

processCharacterInteractive
 ├──> <c == '\t' || c == '?'> //实际在配置软件里面tab可以,?无法使用
 │   ├──> [遍历cmdTable,匹配相近的命令(pstart, pend)]
 │   ├──> [如果只有一个命令,尝试补全命令]
 │   └──> [如果多个匹配命令,反馈命令列表]
 ├──> <!bufferIndex && c == 4> // CTRL-D
 │   ├──> cliExit("", cliBuffer); //退出Cli模式
 │   └──> return
 ├──> <c == 12>  // NewPage(CTRL-L) 清屏
 │   ├──> cliPrint("\033[2J\033[1;1H");
 │   └──> cliPrompt();
 ├──> <c == 127><bufferIndex>  //回退一个字符
 │   ├──> cliBuffer[--bufferIndex] = 0;
 │   └──> cliPrint("\010 \010");
 └──> <other scenarios>
     └──> processCharacter(c);

注:ASCII表,详见链接

processCharacter函数

processCharacter
 ├──> <bufferIndex && (c == '\n' || c == '\r')>
 │   ├──> cliPrintLinefeed();
 │   ├──> <processingCustomDefaults>  //定制命令处理场景,配合cliPrompt打印
 │   │   └──> cliPrint("d: ");
 │   ├──> [Strip comment starting with # from line]  //注释行屏蔽
 │   ├──> [Strip trailing whitespace] //尾部空格屏蔽
 │   ├──> <bufferIndex > 0)>  // Process non-empty lines
 │   │   ├──> [遍历列表寻找命令index]
 │   │   └──> [执行index命令指定的命令函数执行,异常反馈错误类型]
 │   ├──> memset(cliBuffer, 0, sizeof(cliBuffer));
 │   ├──> <!cliMode>
 │   │   └──> return;
 │   └──> cliPrompt();
 └──> <bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126>
     ├──> <!bufferIndex && c == ' '>
     │   └──> return // 最前面的空格忽略,直接丢弃
     ├──> cliBuffer[bufferIndex++] = c;  //符合条件的字符保存下来,供后续处理使用
     └──> cliWrite(c);

Cli命令汇总

注:主要介绍BetaFlight4.3版本

Cli串口help命令

# help
adjrange - configure adjustment ranges
	<index> <unused> <range channel> <start> <end> <function> <select channel> [<center> <scale>]
aux - configure modes
	<index> <mode> <aux> <start> <end> <logic>
batch - start or end a batch of commands
	start | end
beacon - enable/disable Dshot beacon for a condition
	list
	<->[name]
beeper - enable/disable beeper for a condition
	list
	<->[name]
bind_rx - initiate binding for RX SPI or SRXL2
bl - reboot into bootloader
	[rom]
board_name - get / set the name of the board model
	[board name]
color - configure colors
defaults - reset to defaults and reboot
	[nosave|bare|show]
diff - list configuration changes from default
	[master|profile|rates|hardware|all] {defaults|bare}
dma - show/set DMA assignments
	<> | <device> <index> list | <device> <index> [<option>|none] | list | show
dshot_telemetry_info - display dshot telemetry info and stats
dshotprog - program DShot ESC(s)
	<index> <command>+
dump - dump configuration
	[master|profile|rates|hardware|all] {defaults|bare}
exit
feature - configure features
	list
	<->[name]
flash_erase - erase flash chip
flash_info - show flash chip info
flash_read
	<length> <address>
flash_scan - scan flash device for errors
flash_write
	<address> <message>
get - get variable value
	[name]
gpspassthrough - passthrough gps to serial
gyroregisters - dump gyro config registers contents
help - display command help
	[search string]
led - configure leds
manufacturer_id - get / set the id of the board manufacturer
	[manufacturer id]
map - configure rc channel order
	[<map>]
mcu_id - id of the microcontroller
mixer - configure mixer
	list
	<name>
mmix - custom motor mixer
mode_color - configure mode and special colors
motor - get/set motor
	<index> [<value>]
msc - switch into msc mode
	[<timezone offset minutes>]
play_sound
	[<index>]
profile - change profile
	[<index>]
rateprofile - change rate profile
	[<index>]
rc_smoothing_info - show rc_smoothing operational settings
resource - show/set resources
	<> | <resource name> <index> [<pin>|none] | show [all]
rxfail - show/set rx failsafe settings
rxrange - configure rx channel ranges
save - save and reboot
sd_info - sdcard info
serial - configure serial ports
serialpassthrough - passthrough serial data data from port 1 to VCP / port 2
	<id1> [<baud1>] [<mode1>] [none|<dtr pinio>|reset] [<id2>] [<baud2>] [<mode2>]
servo - configure servos
set - change setting
	[<name>=<value>]
signature - get / set the board type signature
	[signature]
smix - servo mixer
	<rule> <servo> <source> <rate> <speed> <min> <max> <box>
	reset
	load <mixer>
	reverse <servo> <source> r|n
status - show status
tasks - show task stats
timer - show/set timers
	<> | <pin> list | <pin> [af<alternate function>|none|<option(deprecated)>] | list | show
version - show version
vtx - vtx channels on switch
	<index> <aux_channel> <vtx_band> <vtx_channel> <vtx_power> <start_range> <end_range>
vtx_info - vtx power config dump
vtxtable - vtx frequency table
	<band> <bandname> <bandletter> [FACTORY|CUSTOM] <freq> ... <freq>

Cli内部命令列表

const clicmd_t cmdTable[] = {
    CLI_COMMAND_DEF("adjrange", "configure adjustment ranges", "<index> <unused> <range channel> <start> <end> <function> <select channel> [<center> <scale>]", cliAdjustmentRange),
    CLI_COMMAND_DEF("aux", "configure modes", "<index> <mode> <aux> <start> <end> <logic>", cliAux),
#ifdef USE_CLI_BATCH
    CLI_COMMAND_DEF("batch", "start or end a batch of commands", "start | end", cliBatch),
#endif
#if defined(USE_BEEPER)
#if defined(USE_DSHOT)
    CLI_COMMAND_DEF("beacon", "enable/disable Dshot beacon for a condition", "list\r\n"
        "\t<->[name]", cliBeacon),
#endif
    CLI_COMMAND_DEF("beeper", "enable/disable beeper for a condition", "list\r\n"
        "\t<->[name]", cliBeeper),
#endif // USE_BEEPER
#if defined(USE_RX_BIND)
    CLI_COMMAND_DEF("bind_rx", "initiate binding for RX SPI or SRXL2", NULL, cliRxBind),
#endif
#if defined(USE_FLASH_BOOT_LOADER)
    CLI_COMMAND_DEF("bl", "reboot into bootloader", "[flash|rom]", cliBootloader),
#else
    CLI_COMMAND_DEF("bl", "reboot into bootloader", "[rom]", cliBootloader),
#endif
#if defined(USE_BOARD_INFO)
    CLI_COMMAND_DEF("board_name", "get / set the name of the board model", "[board name]", cliBoardName),
#endif
#ifdef USE_LED_STRIP_STATUS_MODE
        CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor),
#endif
#if defined(USE_CUSTOM_DEFAULTS)
    CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "{show} {nosave} {bare} {group_id <id>}", cliDefaults),
#else
    CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "{nosave}", cliDefaults),
#endif
    CLI_COMMAND_DEF("diff", "list configuration changes from default", "[master|profile|rates|hardware|all] {defaults|bare}", cliDiff),
#ifdef USE_RESOURCE_MGMT

#ifdef USE_DMA
#ifdef USE_DMA_SPEC
    CLI_COMMAND_DEF("dma", "show/set DMA assignments", "<> | <device> <index> list | <device> <index> [<option>|none] | list | show", cliDma),
#else
    CLI_COMMAND_DEF("dma", "show DMA assignments", "show", cliDma),
#endif
#endif

#endif
#ifdef USE_DSHOT_TELEMETRY
    CLI_COMMAND_DEF("dshot_telemetry_info", "display dshot telemetry info and stats", NULL, cliDshotTelemetryInfo),
#endif
#ifdef USE_DSHOT
    CLI_COMMAND_DEF("dshotprog", "program DShot ESC(s)", "<index> <command>+", cliDshotProg),
#endif
    CLI_COMMAND_DEF("dump", "dump configuration",
        "[master|profile|rates|hardware|all] {defaults|bare}", cliDump),
#ifdef USE_ESCSERIAL
    CLI_COMMAND_DEF("escprog", "passthrough esc to serial", "<mode [sk/bl/ki/cc]> <index>", cliEscPassthrough),
#endif
    CLI_COMMAND_DEF("exit", NULL, NULL, cliExit),
    CLI_COMMAND_DEF("feature", "configure features",
        "list\r\n"
        "\t<->[name]", cliFeature),
#ifdef USE_FLASHFS
    CLI_COMMAND_DEF("flash_erase", "erase flash chip", NULL, cliFlashErase),
    CLI_COMMAND_DEF("flash_info", "show flash chip info", NULL, cliFlashInfo),
#ifdef USE_FLASH_TOOLS
    CLI_COMMAND_DEF("flash_read", NULL, "<length> <address>", cliFlashRead),
    CLI_COMMAND_DEF("flash_scan", "scan flash device for errors", NULL, cliFlashVerify),
    CLI_COMMAND_DEF("flash_write", NULL, "<address> <message>", cliFlashWrite),
#endif
#endif
    CLI_COMMAND_DEF("get", "get variable value", "[name]", cliGet),
#ifdef USE_GPS
    CLI_COMMAND_DEF("gpspassthrough", "passthrough gps to serial", NULL, cliGpsPassthrough),
#endif
#if defined(USE_GYRO_REGISTER_DUMP) && !defined(SIMULATOR_BUILD)
    CLI_COMMAND_DEF("gyroregisters", "dump gyro config registers contents", NULL, cliDumpGyroRegisters),
#endif
    CLI_COMMAND_DEF("help", "display command help", "[search string]", cliHelp),
#ifdef USE_LED_STRIP_STATUS_MODE
        CLI_COMMAND_DEF("led", "configure leds", NULL, cliLed),
#endif
#if defined(USE_BOARD_INFO)
    CLI_COMMAND_DEF("manufacturer_id", "get / set the id of the board manufacturer", "[manufacturer id]", cliManufacturerId),
#endif
    CLI_COMMAND_DEF("map", "configure rc channel order", "[<map>]", cliMap),
    CLI_COMMAND_DEF("mcu_id", "id of the microcontroller", NULL, cliMcuId),
#ifndef USE_QUAD_MIXER_ONLY
    CLI_COMMAND_DEF("mixer", "configure mixer", "list\r\n\t<name>", cliMixer),
#endif
    CLI_COMMAND_DEF("mmix", "custom motor mixer", NULL, cliMotorMix),
#ifdef USE_LED_STRIP_STATUS_MODE
    CLI_COMMAND_DEF("mode_color", "configure mode and special colors", NULL, cliModeColor),
#endif
    CLI_COMMAND_DEF("motor",  "get/set motor", "<index> [<value>]", cliMotor),
#ifdef USE_USB_MSC
#ifdef USE_RTC_TIME
    CLI_COMMAND_DEF("msc", "switch into msc mode", "[<timezone offset minutes>]", cliMsc),
#else
    CLI_COMMAND_DEF("msc", "switch into msc mode", NULL, cliMsc),
#endif
#endif
#ifndef MINIMAL_CLI
    CLI_COMMAND_DEF("play_sound", NULL, "[<index>]", cliPlaySound),
#endif
    CLI_COMMAND_DEF("profile", "change profile", "[<index>]", cliProfile),
    CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile),
#ifdef USE_RC_SMOOTHING_FILTER
    CLI_COMMAND_DEF("rc_smoothing_info", "show rc_smoothing operational settings", NULL, cliRcSmoothing),
#endif // USE_RC_SMOOTHING_FILTER
#ifdef USE_RESOURCE_MGMT
    CLI_COMMAND_DEF("resource", "show/set resources", "<> | <resource name> <index> [<pin>|none] | show [all]", cliResource),
#endif
    CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL, cliRxFailsafe),
    CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL, cliRxRange),
    CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave),
#ifdef USE_SDCARD
    CLI_COMMAND_DEF("sd_info", "sdcard info", NULL, cliSdInfo),
#endif
    CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial),
#if defined(USE_SERIAL_PASSTHROUGH)
#if defined(USE_PINIO)
    CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data data from port 1 to VCP / port 2", "<id1> [<baud1>] [<mode1>] [none|<dtr pinio>|reset] [<id2>] [<baud2>] [<mode2>]", cliSerialPassthrough),
#else
    CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data from port 1 to VCP / port 2", "<id1> [<baud1>] [<mode1>] [none|reset] [<id2>] [<baud2>] [<mode2>]", cliSerialPassthrough),
#endif
#endif
#ifdef USE_SERVOS
    CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
#endif
    CLI_COMMAND_DEF("set", "change setting", "[<name>=<value>]", cliSet),
#if defined(USE_SIGNATURE)
    CLI_COMMAND_DEF("signature", "get / set the board type signature", "[signature]", cliSignature),
#endif
#if defined(USE_SIMPLIFIED_TUNING)
    CLI_COMMAND_DEF("simplified_tuning", "applies or disables simplified tuning", "apply | disable", cliSimplifiedTuning),
#endif
#ifdef USE_SERVOS
    CLI_COMMAND_DEF("smix", "servo mixer", "<rule> <servo> <source> <rate> <speed> <min> <max> <box>\r\n"
        "\treset\r\n"
        "\tload <mixer>\r\n"
        "\treverse <servo> <source> r|n", cliServoMix),
#endif
    CLI_COMMAND_DEF("status", "show status", NULL, cliStatus),
    CLI_COMMAND_DEF("tasks", "show task stats", NULL, cliTasks),
#ifdef USE_TIMER_MGMT
    CLI_COMMAND_DEF("timer", "show/set timers", "<> | <pin> list | <pin> [af<alternate function>|none|<option(deprecated)>] | list | show", cliTimer),
#endif
    CLI_COMMAND_DEF("version", "show version", NULL, cliVersion),
#ifdef USE_VTX_CONTROL
#ifdef MINIMAL_CLI
    CLI_COMMAND_DEF("vtx", "vtx channels on switch", NULL, cliVtx),
#else
    CLI_COMMAND_DEF("vtx", "vtx channels on switch", "<index> <aux_channel> <vtx_band> <vtx_channel> <vtx_power> <start_range> <end_range>", cliVtx),
#endif
#endif
#ifdef USE_VTX_TABLE
    CLI_COMMAND_DEF("vtx_info", "vtx power config dump", NULL, cliVtxInfo),
    CLI_COMMAND_DEF("vtxtable", "vtx frequency table", "<band> <bandname> <bandletter> [FACTORY|CUSTOM] <freq> ... <freq>\r\n", cliVtxTable),
#endif
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

BetaFlight模块设计之三十:Cli模块分析 的相关文章

随机推荐

  • 教程:使用DroneKit在室内控制无人机

    教程 xff1a 使用DroneKit在室内控制无人机 DroneKit Python是一个用于控制无人机的Python库 DroneKit提供了用于控制无人机的API xff0c 其代码独立于飞控 xff0c 单独运行在机载电脑 xff0
  • OpenCV 3.3+VS2017+Win10环境配置指南

    OpenCV 3 3 43 VS2017 43 Win10环境配置指南 最近开始接触OpenCV xff0c 没想到安装和环境配置又踩了不少坑 一开始本着对官网的信任 xff0c 按着官方tutorial里的步骤走 xff0c 但是怎么样都
  • 朴素贝叶斯算法原理

    朴素贝叶斯算法原理 朴素贝叶斯分类器 xff08 Naive Bayes Classifier xff09 的优点是运算时间短 数学原理清晰 xff0c 我在MNIST和CIFAR 10数据集上测试 xff0c 错误率分别为15 74 和5
  • ubuntu18.04更新源方法

    前言 Ubuntu自带默认的软件源指向的服务器是部署在国外的 xff0c 在国内进行软件下载更新时会非常慢 xff0c 可以通过更改源地址指向国内的镜像数据源 xff0c 比如阿里 网易 清华 中科等等 PS xff1a 因为今天群里有人在
  • 数据结构算法学习总结-慕课网(五)冒泡排序,与选择,插入排序的异同(从小到大)

    数据结构算法学习总结 慕课网 xff08 五 xff09 冒泡排序 xff0c 与选择 xff0c 插入排序的异同 xff08 从小到大 xff09 1 回顾 上一节讲到了插入排序的优化 xff0c 了解了插入排序的优势 xff0c 这一节
  • 拒绝采样(reject sampling)原理详解

    文章转自 xff1a https blog csdn net jteng article details 54344766 版权归原作者 xff01 蒙特 卡罗方法 Monte Carlo method 也称统计模拟方法 xff0c 通过重
  • Ubuntu sudo 命令行直接输入密码

    在 sh 文件中输入命令时碰上输入密码的最让人头疼 xff0c 就要想一个办法密码自动填充 xff1b 例子 xff1a echo 123 sudo S su 假之密码为123 原命令为 sudo su
  • ESP32+Blufi+Tcp+UART

    ESP32 43 Blufi 43 TCP 43 UART 在上上一篇文章的基础上添加了蓝牙配网的功能 xff0c 第一次连接WiFi时 xff0c 通过手机微信小程序蓝牙配网 xff0c 第二次通过记录的WiFi内容就能够直接连接 参考的
  • ESP32+UART+TCP_Client+OTA

    在上一篇博客的基础上添加了OTA空中升级功能 实现的功能是一个WiFi DTU模块 xff0c ESP32板子通过串口与下位机连接 xff0c 我目前使用的下位机为51 xff0c ESP32第一次启动时 xff0c 通过微信小程序连接wi
  • ubuntu 网络编程

    ubuntu的网络编程 网络编程 一般有两种 TCP 和 UDP TCP 是面向连接层的传输协议 是无误的 数据没有丢失的失序 和 数据不会重复到达的 UDP是用户数据协议 是不可靠的无连接的协议 xff0c 但是可以进行高效率的传输 说起
  • 头文件intrins.h的用法

    KEIL 中 头文件 INTRINS H的作用 在 C51 单片机编程中 xff0c 头文件 INTRINS H 的函数使用起来 xff0c 就会让你像在用汇编时一样简便 内部函数 描述 crol 字符循环左移 cror 字符循环右移 ir
  • 4G DTU 透传模块简单使用方法

    不是打广告 xff0c 纯记录用途 最近由于项目需要 xff0c 买了一批4g 透传模块 众所周知 xff0c 两个4g模块一般不能直连 xff0c 需要中间通过搭建服务器来搭桥 卖家把桥搭好了 xff0c 自己简单配置下 xff0c 就可
  • ucos多任务与linux进程、多线程的比较分析

    从最初使用51片机 xff0c 再到avr msp430 xff0c arm7 arm9裸机 xff0c 单片机的处理速度越来越快 xff0c 而产品需求的日新月异 xff0c 在硬件成本 功耗 体积以及开发周期等的限制下 xff0c 开发
  • 【记录】Ubuntu下简单的软件安装-aptitude安装,samba安装,terminator软件

    Ubuntu下安装简单的软件 一 安装aptitude管理软件 sudo apt get install aptitude 这样可以使用aptitude来管理软件 如下命令 xff1a sudo aptitude update 更新软件源
  • freeRTOS开源项目crazyflie

    不小心接触到了开源飞控 xff0c 有一个小四轴的项目 xff1a crazyflie xff0c 有兴趣百度搜 使用的就是freeRTOS内核 xff0c 可以作为学习freeRTOS应用的一个参考 另外freeRTOS官方源码包里面就有
  • ROS serial串口通讯

    目录 ROS serial 串口通讯安装基本使用代码示例 Reference ROS serial 串口通讯 安装 sudo apt get install ros kinetic serial 基本使用 代码示例 include lt r
  • 四轴飞控DIY简明步骤介绍

    新手四轴飞控DIY组装简明步骤介绍 1 什么叫做新手 xff1f 2 新手如何思考 xff1f 3 上手步骤Step1 xff1a 四轴飞控介绍定义运动原理组成 Step2 xff1a 四轴飞控组装视频Step3 xff1a 四轴飞控新手规
  • BetaFlight开源工程结构简明介绍

    BetaFlight开源工程结构简明介绍 Step1 获取开源代码开源代码版本克隆开源代码 Step2 了解工程情况支持模型类型 xff1a 多旋翼 amp 固定翼支持特性 amp 功能安装 amp 文档链接配置工具下载其他介绍 xff08
  • 四轴FPV无人机手动操作简明介绍

    四轴FPV无人机手动操作简明介绍 通常航拍机都是有自稳算法 43 GPS导航 43 辅助功能 避障 的支持 xff0c 从而保证飞手能够相对容易且稳定的操作模型飞机 xff0c 通常通过阅读说明书都能很快上手 xff0c 这里就不在赘述 本
  • BetaFlight模块设计之三十:Cli模块分析

    BetaFlight模块设计之三十 xff1a Cli模块分析 Cli模块Cli接口Cli框架Cli命令结构主要函数分析cliProcess函数processCharacterInteractive函数processCharacter函数