# FH_cmdline
**Repository Path**: ischen-x/fh_cmdline
## Basic Information
- **Project Name**: FH_cmdline
- **Description**: No description available
- **Primary Language**: C
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 4
- **Forks**: 0
- **Created**: 2024-07-25
- **Last Updated**: 2025-08-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#
FH_cmdline
## 介绍:
* 面向嵌入式MCU
* 助力程序调试
* 基于linenoise
* 支持TAB补全, 方向键查询命令历史记录
## 使用方法
* 确保移植的linenoise以及getopt()可以正常使用。
* 设置用户名
```C
#define CMDLINE_USER "chen@STM32F407: "
```
* 编写将要在命令行中是使用的函数,函数类型为 `typedef int (*cmdline_cb)(int argc, char **argv);`
```C
int hello(int argc, char **argv) {
printf("Hello World\r\n");
return 0;
}
```
* 使用`int cmdline_new(const char *cmd, cmdline_cb cb)`注册函数,cmd为在命令行中调用该函数的名字, cb为该函数指针。
```C
cmdline_new("hello", hello);
```
* 启用命令行
```C
while (true) {
cmdine_start();
}
```
## Example
```C
#include
#include "cmdline.h"
#define CMDLINE_USER "chen@STM32F407: "
static int hello(int argc, char **argv) {
printf("Hello World: argc: %d, argv[0]: %s\r\n", argc, argv[0]);
return 0;
}
int main(int argc, char **argv) {
cmdline_new("hello", hello);
cmdine_start(CMDLINE_USER);
return 0;
}
```
### 运行效果

## 注:
* example程序基于STM32F407
* 工具链: arm-none-eabi(此工具链中的getopt()貌似不符合posix标准, 本项目依赖标准的getopt())
## 实例
* stm32f103c8t6, I2C设备扫描
