BetaFlight模块设计之二:SERIAL任务分析

  • SERIAL任务
    • 1.总体情况
    • 2.主要函数分析
      • 2.1 taskHandleSerial任务
      • 2.2 命令行处理函数cliProcess
      • 2.3 MSP协议处理函数mspFcProcessCommand & mspFcProcessReply

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

SERIAL任务

描述:主要用于BetaFlight飞控与上位机(配置程序)之间的通信。

1.总体情况

 ├──> 初始化│   ├──> [v]硬件初始化usbCableDetectInit/mspSerialInit│   └──> [v]业务初始化pgResetFn_serialConfig├──> 任务│   ├──> [x]实时任务│   ├──> [x]事件任务│   └──> [v]时间任务[TASK_SERIAL] = DEFINE_TASK("SERIAL", NULL, NULL, taskHandleSerial, TASK_PERIOD_HZ(100), TASK_PRIORITY_LOW)├──> 驱动│   ├──> [v]查询serialRead/serialRxBytesWaiting│   └──> [x]中断└──> 接口├──> 支持配置工具CLI命令行模式 \\const clicmd_t cmdTable[]\src\main\cli\cli.c└──> 支持MSP协议 v1.44

2.主要函数分析

2.1 taskHandleSerial任务

taskHandleSerial├──> <USE_VCP>│   ├──> usbCableIsInserted│   └──> usbVcpIsConnected├──> <USE_CLI> <cliMode>│   └──> cliProcess└──> mspSerialProcess(ARMING_FLAG(ARMED) ? MSP_SKIP_NON_MSP_DATA : MSP_EVALUATE_NON_MSP_DATA, mspFcProcessCommand, mspFcProcessReply);└──> 遍历支持MSP协议端口├──> <串口有数据>│   ├──> serialRead│   ├──> mspSerialProcessReceivedData│   ├──> <非SOF字符 且 未arm>│   │   └──> mspEvaluateNonMspData│   ├──> <MSP_COMMAND_RECEIVED>│   │   ├──> <MSP_PACKET_COMMAND>│   │   │   └──> mspPostProcessFn=mspSerialProcessReceivedCommand(mspFcProcessCommand)│   │   └──> <MSP_PACKET_REPLY>│   │       └──> mspSerialProcessReceivedReply(mspFcProcessReply)│   └──> <mspPostProcessFn>│       ├──> waitForSerialPortToFinishTransmitting│       └──> mspPostProcessFn└──> <串口无数据>└──> mspProcessPendingRequest├──> <MSP_PENDING_BOOTLOADER_ROM> systemResetToBootloader├──> <MSP_PENDING_BOOTLOADER_FLASH> systemResetToBootloader└──> <MSP_PENDING_CLI> cliEnter

2.2 命令行处理函数cliProcess

cliProcess├──> cliWriterFlush└──> serialRxBytesWaiting├──> serialRead└──> processCharacterInteractive└──> 循环比对,执行cmdTable中的命令

BetaFlight4.3版本支持的命令汇总;关于Cli模块详细介绍,请参考BetaFlight模块设计之三十: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_BATCHCLI_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),
#endifCLI_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),
#elseCLI_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_MODECLI_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),
#elseCLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "{nosave}", cliDefaults),
#endifCLI_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_SPECCLI_COMMAND_DEF("dma", "show/set DMA assignments", "<> | <device> <index> list | <device> <index> [<option>|none] | list | show", cliDma),
#elseCLI_COMMAND_DEF("dma", "show DMA assignments", "show", cliDma),
#endif
#endif#endif
#ifdef USE_DSHOT_TELEMETRYCLI_COMMAND_DEF("dshot_telemetry_info", "display dshot telemetry info and stats", NULL, cliDshotTelemetryInfo),
#endif
#ifdef USE_DSHOTCLI_COMMAND_DEF("dshotprog", "program DShot ESC(s)", "<index> <command>+", cliDshotProg),
#endifCLI_COMMAND_DEF("dump", "dump configuration","[master|profile|rates|hardware|all] {defaults|bare}", cliDump),
#ifdef USE_ESCSERIALCLI_COMMAND_DEF("escprog", "passthrough esc to serial", "<mode [sk/bl/ki/cc]> <index>", cliEscPassthrough),
#endifCLI_COMMAND_DEF("exit", NULL, NULL, cliExit),CLI_COMMAND_DEF("feature", "configure features","list\r\n""\t<->[name]", cliFeature),
#ifdef USE_FLASHFSCLI_COMMAND_DEF("flash_erase", "erase flash chip", NULL, cliFlashErase),CLI_COMMAND_DEF("flash_info", "show flash chip info", NULL, cliFlashInfo),
#ifdef USE_FLASH_TOOLSCLI_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
#endifCLI_COMMAND_DEF("get", "get variable value", "[name]", cliGet),
#ifdef USE_GPSCLI_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),
#endifCLI_COMMAND_DEF("help", "display command help", "[search string]", cliHelp),
#ifdef USE_LED_STRIP_STATUS_MODECLI_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),
#endifCLI_COMMAND_DEF("map", "configure rc channel order", "[<map>]", cliMap),CLI_COMMAND_DEF("mcu_id", "id of the microcontroller", NULL, cliMcuId),
#ifndef USE_QUAD_MIXER_ONLYCLI_COMMAND_DEF("mixer", "configure mixer", "list\r\n\t<name>", cliMixer),
#endifCLI_COMMAND_DEF("mmix", "custom motor mixer", NULL, cliMotorMix),
#ifdef USE_LED_STRIP_STATUS_MODECLI_COMMAND_DEF("mode_color", "configure mode and special colors", NULL, cliModeColor),
#endifCLI_COMMAND_DEF("motor",  "get/set motor", "<index> [<value>]", cliMotor),
#ifdef USE_USB_MSC
#ifdef USE_RTC_TIMECLI_COMMAND_DEF("msc", "switch into msc mode", "[<timezone offset minutes>]", cliMsc),
#elseCLI_COMMAND_DEF("msc", "switch into msc mode", NULL, cliMsc),
#endif
#endif
#ifndef MINIMAL_CLICLI_COMMAND_DEF("play_sound", NULL, "[<index>]", cliPlaySound),
#endifCLI_COMMAND_DEF("profile", "change profile", "[<index>]", cliProfile),CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile),
#ifdef USE_RC_SMOOTHING_FILTERCLI_COMMAND_DEF("rc_smoothing_info", "show rc_smoothing operational settings", NULL, cliRcSmoothing),
#endif // USE_RC_SMOOTHING_FILTER
#ifdef USE_RESOURCE_MGMTCLI_COMMAND_DEF("resource", "show/set resources", "<> | <resource name> <index> [<pin>|none] | show [all]", cliResource),
#endifCLI_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_SDCARDCLI_COMMAND_DEF("sd_info", "sdcard info", NULL, cliSdInfo),
#endifCLI_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),
#elseCLI_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_SERVOSCLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
#endifCLI_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_SERVOSCLI_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),
#endifCLI_COMMAND_DEF("status", "show status", NULL, cliStatus),CLI_COMMAND_DEF("tasks", "show task stats", NULL, cliTasks),
#ifdef USE_TIMER_MGMTCLI_COMMAND_DEF("timer", "show/set timers", "<> | <pin> list | <pin> [af<alternate function>|none|<option(deprecated)>] | list | show", cliTimer),
#endifCLI_COMMAND_DEF("version", "show version", NULL, cliVersion),
#ifdef USE_VTX_CONTROL
#ifdef MINIMAL_CLICLI_COMMAND_DEF("vtx", "vtx channels on switch", NULL, cliVtx),
#elseCLI_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_TABLECLI_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
};

2.3 MSP协议处理函数mspFcProcessCommand & mspFcProcessReply

mspFcProcessCommand├──> mspCommonProcessOutCommand├──> mspProcessOutCommand├──> mspFcProcessOutCommandWithArg├──> <MSP_SET_PASSTHROUGH>│   └──> mspFcSetPassthroughCommand├──> <MSP_DATAFLASH_READ>│   └──> mspFcDataFlashReadCommand└──> mspCommonProcessInCommand

mspFcProcessReply //当前版本,代码没有处理完,且只有一个ADC模拟数据。

注:在MSP协议上,MSP_ANALOG当前是out message类型,而实际代码并没有类似mspCommonProcessOutCommand操作。

注:关于MSP协议,请参阅BetaFlight模块设计之三十二:MSP协议模块分析

BetaFlight模块设计之二:SERIAL任务分析相关推荐

  1. BetaFlight模块设计之二十六:接收机任务分析

    BetaFlight模块设计之二十六:接收机任务分析 接收机任务 配置情况 硬件配置 软件配置 驱动配置 sbus驱动函数分析 sbusDataReceive函数 sbusFrameStatus函数 ...

  2. BetaFlight模块设计之二十四:transponder任务分析

    BetaFlight模块设计之二十四:transponder任务分析 transponder任务 配置情况 硬件配置 驱动配置 业务配置 初始化 MSP协议 三种IR transponder type ...

  3. BetaFlight模块设计之八:GPS任务分析

    BetaFlight模块设计之八:GPS任务分析 GPS任务 gpsUpdate函数分析 gpsNewData函数分析 gpsNewFrame函数分析 onGpsNewData 函数分析 基于Beta ...

  4. BetaFlight模块设计之二十九:滤波模块分析

    BetaFlight模块设计之二十九:滤波模块分析 滤波模块 滤波类型 1. slewFilter 2. simpleLowpassFilter 3. laggedMovingAverage 4. p ...

  5. BetaFlight模块设计之二十:CMS菜单模块分析

    BetaFlight模块设计之二十:CMS菜单模块分析 CMS菜单模块 CMS菜单按键控制 CMS菜单Elements CMS_Menu OSD_Etnry Element类型 可调Element类型 ...

  6. BetaFlight模块设计之七:LEDSTRIP任务分析

    BetaFlight模块设计之七:LEDSTRIP任务分析 1. LEDSTRIP任务 2. ledStripUpdate函数分析 2.1 StatusProfile 2.2 SimpleProfil ...

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

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

  8. BetaFlight模块设计之三十五:RSSI信号强度链路稳定性分析

    BetaFlight模块设计之三十五:RSSI信号强度&链路稳定性分析 1. RSSI信号强度 1.1 RSSI Value 1.2 RSSI dBm Value 2. 链路稳定性 3. RS ...

  9. BetaFlight模块设计之三十三:Pid模块分析

    BetaFlight模块设计之三十三:Pid模块分析 Pid模块 1. Pid_audio子模块 2. Pid_init子模块 3. Pid算法子模块 3.1 TPA模式 3.2 飞行模式 3.3 L ...

最新文章

  1. SpringMVC常用Maven POM.xml依赖包片段
  2. python 计时_Python计时相关操作详解【time,datetime】
  3. python中什么是关键字参数_如何使用python语言中函数的关键字参数的用法
  4. python 隐含波动率_【BSM模型】用实际市场数据计算隐含波动率并验证波动率微笑...
  5. mysql无法启动服务,错误1067
  6. keepalived track script introduce
  7. 我是小白一个,如何快速学会C++?
  8. 如何在Mac上的Pages文稿中设置对开页?
  9. JVM监控及诊断工具命令行篇之jstack
  10. vrep_Nao控制_学习记录
  11. 搭建sip软电话环境
  12. 华为Datacom认证和Routing Switching认证并行多久?
  13. 梯度下降优化算法Momentum
  14. html表单导入图片,from 表单上传图片
  15. ❤️大学三年沉淀,把我的学习经验分享给你,爆肝万字带你走进编程世界!❤️
  16. 聚类分析在用户行为中的实例_聚类分析案例
  17. H5 捕鱼游戏搭建教程
  18. windows系统搜索本地文件缓慢怎么办?
  19. lap.lapjv使用方法
  20. java入口函数_Java 函数入口

热门文章

  1. 【一】先进先出页面置换算法
  2. 股票 MACD指标的买入形态图解
  3. 商场/购物中心会员营销活动方案
  4. lio-sam实车调试之定位测试
  5. Home, sweet home.
  6. 从农村穷小子到互联网大咖,郭盛华的传奇人生
  7. Linux卡死的解决方法 solution of server stuck or freezes
  8. CAD迷你看图最喜欢的操作方法
  9. 好用计算机,六款让你电脑更好用的软件
  10. 虚拟光驱(virtual drive) v7.12 个人版 绿色