Skip to content

Commit 9d30b10

Browse files
committed
Update proj_man.
1 parent 302e367 commit 9d30b10

File tree

18 files changed

+1447
-267
lines changed

18 files changed

+1447
-267
lines changed

docs/basic_coding/core/core-rw.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ LibXR::STDIO::Printf("Hello, %d", 123);
130130
131131
## 用例示例
132132
133+
对于数据大小为0的情况,Write会直接返回成功,Read会等待有任何数据可读再返回(阻塞模式下)。
134+
133135
```cpp
134136
// 阻塞写入串口,超时为 100ms (默认永远等待)
135137
WriteOperation op_block(sem, 100);

docs/code_gen/xrobot_inter.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ sidebar_position: 2
1111
## 示例
1212

1313
```bash
14-
xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp --xrobot
14+
xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp --xrobot
1515
[INFO] Detected FreeRTOS configuration
1616
[INFO] FlashLayout is generated and injected, MCU: STM32G431KBU6
17-
[INFO] Flash layout map written to: .\User\flash_map.hpp
18-
[INFO] Successfully generated: .\User
17+
[INFO] Flash layout map written to: ./User/flash_map.hpp
18+
[INFO] Successfully generated: ./User
1919
[INFO] Generated header file: app_main.h
2020
```
2121

docs/proj_man/README.md

Lines changed: 183 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,206 @@ sidebar_position: 7
66

77
# 项目管理(XRobot)
88

9-
本章简要介绍 XRobot 在嵌入式项目中的基本用法,包括模块拉取、配置和主函数生成等。详细的命令说明将在后续页面中分模块展开
9+
XRobot 是一套面向嵌入式系统(如 STM32)的自动化代码生成工具,配合模块化硬件抽象层 LibXR 使用。它支持模块仓库管理、参数配置和主函数自动生成等工作,极大提高嵌入式项目的工程组织和开发效率
1010

11-
## 使用前提
11+
本章介绍 XRobot 的安装、目录结构、主要功能、命令行工具用法,以及完整的快速上手流程。
1212

13-
确保已通过 pip 或 pipx 安装 `xrobot` 工具:
13+
---
1414

15-
```bash
16-
pip install xrobot
17-
# 或使用 pipx
15+
## 安装
16+
17+
推荐通过 pipx 安装(支持隔离环境):
18+
19+
**Windows:**
20+
```ps
21+
python -m pip install --user pipx
22+
python -m pipx ensurepath
1823
pipx install xrobot
24+
# 重启终端
1925
```
2026

21-
## 基本目录结构
27+
**Linux:**
28+
```bash
29+
sudo apt install pipx
30+
pipx install xrobot
31+
pipx ensurepath
32+
# 重启终端
33+
```
2234

23-
XRobot 使用约定的目录布局进行模块管理和代码生成:
35+
**或者使用 pip 安装:**
36+
```bash
37+
pip install xrobot
38+
```
2439

40+
**源码安装:**
2541
```bash
42+
git clone https://github.com/xrobot-org/XRobot.git
43+
cd XRobot
44+
pip install .
45+
```
46+
47+
---
48+
49+
## 目录结构约定
50+
51+
XRobot 推荐如下目录布局进行模块管理和代码生成:
52+
53+
```text
2654
YourProject/
2755
├── Modules/ # 存放模块仓库
2856
│ └── modules.yaml # 仓库列表
57+
│ └── sources.yaml # (可选)模块源索引
2958
├── User/ # 用户配置与生成输出
3059
│ ├── xrobot.yaml # 构造参数配置
3160
│ └── xrobot_main.hpp # 自动生成主函数
3261
```
3362

34-
## 工具说明
63+
---
64+
65+
## 功能总览
66+
67+
- **模块仓库拉取与同步**
68+
自动拉取、同步和递归解析模块仓库,保证依赖与版本一致性。
69+
- **参数自动提取与配置**
70+
自动解析模块头文件参数,生成和管理 YAML 配置文件。
71+
- **自动主函数生成**
72+
根据配置自动生成 C++ 入口函数 `XRobotMain()`,支持多模块、实例和嵌套结构。
73+
- **manifest 解析**
74+
解析并格式化模块头文件清单(manifest)。
75+
- **模块模板快速生成**
76+
一键生成包含 CI 的标准化模块目录。
77+
- **多源模块管理**
78+
支持本地/远程 YAML 配置和多模块源索引管理。
79+
80+
---
81+
82+
## 命令行工具一览
83+
84+
| 命令 Command | 说明 | Description |
85+
| ------------------- | -------------------------------- | -------------------------------------------------- |
86+
| `xrobot_gen_main` | 自动生成 C++ 主函数 | Generate main C++ entry source file |
87+
| `xrobot_mod_parser` | 解析模块并打印 manifest 信息 | Parse and show module manifest |
88+
| `xrobot_create_mod` | 快速创建标准化模块目录 | Create a new module folder & header |
89+
| `xrobot_init_mod` | 拉取并递归同步所有模块仓库 | Clone and recursively sync all module repos |
90+
| `xrobot_setup` | 一键初始化工作区和生成主函数 | One-click workspace setup & main function generate |
91+
| `xrobot_add_mod` | 添加模块仓库或追加模块实例到配置 | Add repo or append module instance config |
92+
| `xrobot_src_man` | 多源模块仓库管理与索引工具 | Multi-source module repository management utility |
93+
94+
详细参数和用法见后续章节。
95+
96+
---
97+
98+
## 快速上手(推荐流程)
99+
100+
```bash
101+
# 1. 一键初始化环境、拉取模块、生成主函数(推荐)
102+
# 1. One-click initialize workspace, fetch modules, and generate main function (recommended)
103+
$ xrobot_setup
104+
Starting XRobot auto-configuration...
105+
[INFO] Created default Modules/modules.yaml
106+
Please edit this file; each line should be a full module name like:
107+
- xrobot-org/BlinkLED
108+
- your-namespace/YourModule@dev
109+
[INFO] Created default Modules/sources.yaml
110+
Please configure sources index.yaml for official or custom/private mirrors.
111+
Default official source already included.
112+
113+
$ xrobot_setup
114+
Starting XRobot auto-configuration...
115+
[EXEC] xrobot_init_mod --config Modules/modules.yaml --directory Modules --sources Modules/sources.yaml
116+
[INFO] Cloning new module: xrobot-org/BlinkLED
117+
Cloning into 'Modules/BlinkLED'...
118+
remote: Enumerating objects: 31, done.
119+
remote: Counting objects: 100% (31/31), done.
120+
remote: Compressing objects: 100% (21/21), done.
121+
remote: Total 31 (delta 10), reused 31 (delta 10), pack-reused 0 (from 0)
122+
Receiving objects: 100% (31/31), 4.43 KiB | 2.22 MiB/s, done.
123+
Resolving deltas: 100% (10/10), done.
124+
[SUCCESS] All modules and their dependencies processed.
125+
[INFO] Created default Modules/CMakeLists.txt: Modules/CMakeLists.txt
126+
[EXEC] xrobot_gen_main --output User/xrobot_main.hpp
127+
Discovered modules: BlinkLED
128+
[INFO] Successfully parsed manifest for BlinkLED
129+
[INFO] Writing configuration to User/xrobot.yaml
130+
[SUCCESS] Generated entry file: User/xrobot_main.hpp
131+
132+
All done! Main function generated at: User/xrobot_main.hpp
133+
134+
# 2. 单独拉取/同步模块仓库(可选)
135+
# 2. Pull or sync module repositories separately (optional)
136+
$ xrobot_init_mod --config Modules/modules.yaml --directory Modules
137+
[INFO] Updating module: xrobot-org/BlinkLED
138+
Already up to date.
139+
Already on 'master'
140+
Your branch is up to date with 'origin/master'.
141+
[SUCCESS] All modules and their dependencies processed.
35142

36-
XRobot 工具集包括以下命令,具体用法见后续子页面:
143+
# 3. 创建模块
144+
# 3. Create a module
145+
$ xrobot_create_mod MySensor --desc "IMU interface module" --hw i2c1
146+
[OK] Module MySensor generated at Modules/MySensor
37147

38-
- `xrobot_add_mod`:添加模块仓库或模块实例
39-
- `xrobot_init_mod`:拉取/更新模块仓库
40-
- `xrobot_gen_main`:生成主函数代码
41-
- `xrobot_create_mod`:创建模块模板
42-
- `xrobot_mod_parser`:解析模块头文件中的构造参数
43-
- `xrobot_setup`:一键生成入口文件和配置
148+
# 4. 查看模块信息
149+
# 4. View module information
150+
$ xrobot_mod_parser --path ./Modules/MySensor/
44151

45-
后续页面将逐个介绍这些命令的详细用法与参数。
152+
=== Module: MySensor.hpp ===
153+
Description : IMU interface module
154+
155+
Constructor Args :
156+
Required Hardware : i2c1
157+
Depends : None
158+
159+
# 5. 添加模块仓库(如需自定义来源)
160+
# 5. Add a module repository (custom source, optional)
161+
$ xrobot_add_mod your-namespace/YourModule@main
162+
[SUCCESS] Added repo module 'your-namespace/YourModule@main' to Modules/modules.yaml
163+
164+
# 6. 添加模块实例
165+
# 6. Add a module instance
166+
$ xrobot_add_mod MySensor
167+
[SUCCESS] Appended module instance 'MySensor' as id 'MySensor_0' to User/xrobot.yaml
168+
169+
# 7. 查看模块实例
170+
# 7. View module instances
171+
$ cat ./User/xrobot.yaml
172+
global_settings:
173+
monitor_sleep_ms: 1000
174+
modules:
175+
- name: BlinkLED
176+
constructor_args:
177+
blink_cycle: 250
178+
- id: MySensor_0
179+
name: MySensor
180+
constructor_args: {}
181+
182+
# 8. 重新生成主函数(支持自动扫描和配置)
183+
# 8. Regenerate main function (auto scan & config supported)
184+
$ xrobot_gen_main --output User/xrobot_main.hpp
185+
Discovered modules: BlinkLED, MySensor
186+
[SUCCESS] Generated entry file: User/xrobot_main.hpp
187+
188+
# 9. 查看主函数
189+
# 9. View main function
190+
$ cat ./User/xrobot_main.hpp
191+
#include "app_framework.hpp"
192+
#include "libxr.hpp"
193+
194+
// Module headers
195+
#include "BlinkLED.hpp"
196+
#include "MySensor.hpp"
197+
198+
static void XRobotMain(LibXR::HardwareContainer &hw) {
199+
using namespace LibXR;
200+
ApplicationManager appmgr;
201+
202+
// Auto-generated module instantiations
203+
static BlinkLED blinkled(hw, appmgr, 250);
204+
static MySensor MySensor_0(hw, appmgr);
205+
206+
while (true) {
207+
appmgr.MonitorAll();
208+
Thread::Sleep(1000);
209+
}
210+
}
211+
```

docs/proj_man/add_mod.md

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,96 @@ sidebar_position: 4
66

77
# 添加模块
88

9-
通过`xrobot_add_mod`工具可以快速添加一个新模块到仓库,或者从仓库中选择一个模块创建实例。
9+
XRobot 提供了 `xrobot_add_mod` 工具,用于:
1010

11-
## 使用方法
11+
- **添加远程模块仓库**(添加到 `modules.yaml` 并拉取)
12+
- **添加模块实例**(添加到 `xrobot.yaml` 并生成代码)
1213

13-
### 添加远程模块到仓库
14+
---
15+
16+
## 1. 添加远程模块
1417

15-
--version可以省略,使用时要确保对应分支存在。
18+
你可以通过提供模块仓库地址快速添加模块:
1619

1720
```bash
18-
$ xrobot_add_mod https://github.com/yourorg/BlinkLED.git --version main
19-
[SUCCESS] Added repo module 'BlinkLED' to Modules/modules.yaml
21+
xrobot_add_mod xrobot-org/BlinkLED@master
2022
```
2123

22-
然后拉取模块
24+
输出示例
2325

2426
```bash
25-
$ xrobot_init_mod
26-
[INFO] Cloning new module: BlinkLED
27+
[SUCCESS] Added repo module 'xrobot-org/BlinkLED@master' to Modules/modules.yaml
28+
```
29+
30+
然后运行初始化命令:
31+
32+
```bash
33+
xrobot_init_mod
34+
```
35+
36+
该命令会自动拉取所有模块:
37+
38+
```bash
39+
[INFO] Cloning new module: xrobot-org/BlinkLED
2740
Cloning into 'Modules/BlinkLED'...
28-
remote: Enumerating objects: 22, done.
29-
remote: Counting objects: 100% (22/22), done.
30-
remote: Compressing objects: 100% (15/15), done.
31-
remote: Total 22 (delta 7), reused 22 (delta 7), pack-reused 0 (from 0)
32-
Receiving objects: 100% (22/22), done.
33-
Resolving deltas: 100% (7/7), done.
34-
[SUCCESS] All modules processed
41+
remote: Enumerating objects: 37, done.
42+
remote: Counting objects: 100% (37/37), done.
43+
remote: Compressing objects: 100% (25/25), done.
44+
remote: Total 37 (delta 11), reused 33 (delta 10), pack-reused 0 (from 0)
45+
Receiving objects: 100% (37/37), 7.48 KiB | 3.74 MiB/s, done.
46+
Resolving deltas: 100% (11/11), done.
47+
Already on 'master'
48+
Your branch is up to date with 'origin/master'.
49+
[SUCCESS] All modules and their dependencies processed.
50+
```
51+
52+
---
53+
54+
## 2. 添加模块实例(生成代码配置)
55+
56+
假设你已拉取 BlinkLED 模块:
57+
58+
```bash
59+
xrobot_add_mod BlinkLED
3560
```
3661

37-
### 创建模块实例
62+
输出如下:
3863

3964
```bash
40-
$ xrobot_add_mod BlinkLED
41-
[SUCCESS] Appended module instance 'BlinkLED' to User/xrobot.yaml
65+
[SUCCESS] Appended module instance 'BlinkLED' as id 'BlinkLED_0' to User/xrobot.yaml
66+
```
67+
68+
此时 `xrobot.yaml` 配置文件中将新增:
4269

43-
# 重新生成代码
44-
$ xrobot_gen_main
45-
...
70+
```yaml
71+
modules:
72+
- id: BlinkLED_0
73+
name: BlinkLED
74+
constructor_args:
75+
blink_cycle: 250
4676
```
77+
78+
你可以直接运行 `xrobot_gen_main` 生成主函数:
79+
80+
```bash
81+
xrobot_gen_main
82+
```
83+
84+
---
85+
86+
## 3. 自定义实例 ID
87+
88+
默认实例 ID 为 `模块名_序号`,如 `BlinkLED_0`,可手动指定:
89+
90+
```bash
91+
xrobot_add_mod BlinkLED --instance-id myled
92+
```
93+
94+
---
95+
96+
## 5. 配置文件位置说明
97+
98+
| 配置类型 | 默认路径 | 内容 |
99+
|--------------|-----------------------|-----------------------------|
100+
| 模块仓库列表 | `Modules/modules.yaml` | 存储模块地址/版本信息 |
101+
| 实例配置文件 | `User/xrobot.yaml` | 存储模块实例参数和 ID 等信息 |

0 commit comments

Comments
 (0)