# devctl **Repository Path**: cm_14/devctl ## Basic Information - **Project Name**: devctl - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-04 - **Last Updated**: 2026-01-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 基础命令格式 ```bash devctl [全局选项] <命令> [命令选项] [参数] ``` ## 全局选项 ```bash -v, --version 显示版本信息 -h, --help 显示帮助信息 -d, --device 指定设备地址/ID (默认: localhost:8080) -c, --config 指定配置文件路径 --verbose 详细输出模式 --json 以JSON格式输出结果 ``` ## 命令集设计 ### 1. 风扇控制 ```bash # 开启风扇 devctl fan on [--id=<风扇ID>] [--duty=<百分比>] # 关闭风扇 devctl fan off [--id=<风扇ID>] # 设置风扇占空比 devctl fan set --duty=<1-100> [--id=<风扇ID>] # 查询风扇状态 devctl fan status [--id=<风扇ID>] [--detailed] # 示例: devctl fan on --id=1 --duty=80 devctl fan status --id=1 --json ``` ### 水泵控制 ```bash # 开启水泵 devctl pump on [--id=<水泵ID>] [--duty=<百分比>] # 关闭水泵 devctl pump off [--id=<水泵ID>] # 设置水泵占空比 devctl pump set --duty=<1-100> [--id=<水泵ID>] # 查询水泵状态 devctl pump status [--id=<水泵ID>] [--detailed] # 示例: devctl pump on --id=main --duty=75 devctl pump status --detailed ``` ### 传感器数据查询 ```bash # 查询流量 devctl sensor flow [--id=<传感器ID>] # 查询压力 devctl sensor pressure [--id=<传感器ID>] # 查询温度 devctl sensor temperature [--id=<传感器ID>] # 查询所有传感器数据 devctl sensor all [--brief] [--watch] # 示例: devctl sensor flow --id=flow1 devctl sensor temperature --id=temp1,temp2 --json ``` ### 综合监控 ```bash # 显示系统状态概览 devctl status [--refresh=<秒数>] # 监控模式(实时更新) devctl monitor [--interval=<秒数>] [--sensors=<传感器列表>] # 获取设备信息 devctl device info # 示例: devctl status devctl monitor --interval=2 --sensors=flow,pressure,temperature ``` ## 使用示例 ### 基础示例 ```bash # 查看帮助 devctl --help devctl fan --help # 快速查看系统状态 devctl status # 开启1号风扇并设置占空比 devctl fan on --id=1 --duty=75 # 监控温度变化 devctl sensor temperature --watch # 使用配置文件中的预设模式 devctl mode set cooling --duration=60 # 实时监控所有传感器 devctl monitor --interval=3 ``` ### 高级示例 ```bash # 批量控制多个设备 devctl --device="10.0.0.5:8080" fan on --id=1,2,3 devctl --device="10.0.0.6:8080" pump set --power=80 # 脚本中使用(JSON输出) FLOW_DATA=$(devctl sensor flow --id=main --json) echo $FLOW_DATA | jq '.value' # 自动化监控脚本 while true; do TEMP=$(devctl sensor temperature --id=cpu --brief) if [ $TEMP -gt 80 ]; then devctl fan on --id=1 --duty=100 fi sleep 10 done ``` ## 输出格式 ### 标准文本输出 ```bash 设备状态概览 ============= 风扇1: 运行中 (75%) 风扇2: 停止 水泵: 运行中 (60%) 传感器读数 ---------- 流量: 12.5 L/min 压力: 2.3 bar 温度: 45.2°C ``` ### JSON输出(使用 --json 选项时) ```json { "status": "success", "timestamp": "2024-01-15T10:30:00Z", "data": { "fan": { "id": "1", "state": "on", "duty": 75, "speed": 4568, "current": 12.3 }, "sensors": { "flow": { "value": 12.5, "unit": "L/min" } } } } ``` ### 错误处理 ```bash # 错误代码 0 - 成功 1 - 通用错误 2 - 设备连接错误 3 - 无效参数 4 - 设备不支持的操作 5 - 权限不足 # 错误信息示例 Error 2: Cannot connect to device at 192.168.1.100:8080 Error 3: Invalid fan duty value. Expected 1-100, got 150 ```