diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/README.md b/README.md index 50b73a3..a7d0f8e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,99 @@ -# pig-house-controller +# 猪舍主控 -猪舍主控节点,根据上位机的指令控制当前猪舍内所有设备(传感器,阀门,电机等),并汇聚当前猪舍传感器数据统一上报 \ No newline at end of file +## 简介 + +猪舍主控系统根据上位机的指令控制当前猪舍内所有设备(传感器,阀门,电机等),并汇聚当前猪舍传感器数据统一上报。本系统作为猪场智能化管理的重要组成部分,实现了猪舍环境的自动化监控与调节。 + +## 功能概述 + +### 与上位机交互 +1. 根据上位机指令定期采集栏内所有传感器的数据,并统一上报 +2. 根据上位机指令启动或关闭栏内设备,上位机发送的启动指令分两种: + - 常开指令:收到后启动设备,直到收到关闭指令后关闭设备 + - 短暂开启指令:收到后启动设备,但需要上位机每过两秒发送一次指令,超过五秒没收到下一个开启指令或受到关闭指令将会关闭设备 +3. 定期检查栏内设备状态,发现异常立即上报上位机 +4. 定期向上位机发送心跳包 +5. 接收上位机发送的总线上各机器的位置和类型 +6. 根据上位机指令调整设备功率大小 +7. 接收上位机批量控制指令并执行 +8. 接收上位机发送的配置信息 + +### 与设备交互 +1. 控制栏内设备启停 +2. 调整风机等功率可调设备的功率 +3. 定时检查栏内设备状态 +4. 定时采集栏内数据 + +### 数据管理 +1. 保存总线上各机器的位置和类型 +2. 临时保存上位机发送的指令 +3. 保存上位机发送的配置信息 +4. 汇总栏内所有传感器数据 +5. 临时保存栏内设备故障信息,直到上报成功后清除 +6. 根据批量指令控制对应设备工作 + +## 系统架构 + +### 通信协议 +- 上位机和猪舍主控间通过LoRa协议互联 +- 主控与设备/传感器通过Modbus RTU协议通信 + +### 硬件组成 +- 主控制器:树莓派PICO RP2040 +- 通信接口:RS485总线、LoRa无线模块 +- 传感器:硫化氢、氨气、二氧化碳、光照、温度、湿度、风速、气压等 +- 执行设备:风机、水帘、喷淋系统、除臭水帘、刮粪机、电磁阀等 + +### 硬件拓扑图 + +```mermaid +graph LR + A[猪场主控] -->|LoRa| B[猪舍主控] + B -->|Modbus RTU| C[RS485总线1] + B -->|Modbus RTU| D[RS485总线2] + C -->|Modbus RTU| E1[硫化氢传感器] + C -->|Modbus RTU| E2[氨气传感器] + C -->|Modbus RTU| E3[二氧化碳传感器] + C -->|Modbus RTU| E4[光照传感器] + C -->|Modbus RTU| E5[温度传感器] + C -->|Modbus RTU| E6[湿度传感器] + C -->|Modbus RTU| E7[风速传感器] + C -->|Modbus RTU| E8[气压传感器] + D -->|Modbus RTU| F[继电器] + F -->|通/断电| G1[风机] + F -->|通/断电| G2[水帘] + F -->|通/断电| G3[栏内喷淋] + F -->|通/断电| G4[除臭水帘] + F -->|通/断电| G5[刮粪机] + F -->|通/断电| H[电磁五通阀] + H -->|通/断气| I[气动三通阀] +``` + +## 使用说明 + +### 硬件准备 +1. 树莓派 PICO RP2040 开发板 +2. RS485 转 UART 模块 +3. LoRa 模块 (如 SX1276/SX1278) +4. 传感器和设备(如上述硬件拓扑图所示) + +### 安装步骤 +1. 按照硬件拓扑图连接所有设备和传感器 +2. 将程序上传到树莓派 PICO +3. 配置系统参数和设备信息 +4. 启动系统 + +### 启动系统 +```bash +# 使用 mpremote 运行主程序 +mpremote connect [设备路径] run main.py +``` +或者直接将 main.py 设置为启动脚本,让 PICO 上电后自动运行 + +## 开发相关 + +详细的开发指南、项目结构、配置说明和技术规范请参考 [DEVELOPMENT.md](DEVELOPMENT.md) 文件。 + +## 许可证 + +禁止未经授权使用本项目代码,否则后果自负。 \ No newline at end of file diff --git a/comms/__init__.py b/comms/__init__.py new file mode 100644 index 0000000..3134da5 --- /dev/null +++ b/comms/__init__.py @@ -0,0 +1 @@ +# 通信层 \ No newline at end of file diff --git a/comms/base_comm.py b/comms/base_comm.py new file mode 100644 index 0000000..00336a1 --- /dev/null +++ b/comms/base_comm.py @@ -0,0 +1 @@ +# 通信接口 \ No newline at end of file diff --git a/comms/lora.py b/comms/lora.py new file mode 100644 index 0000000..565c84d --- /dev/null +++ b/comms/lora.py @@ -0,0 +1 @@ +# lora实现 \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..e69de29 diff --git a/core/command_handler.py b/core/command_handler.py new file mode 100644 index 0000000..a57b964 --- /dev/null +++ b/core/command_handler.py @@ -0,0 +1 @@ +# 处理接收的指令 \ No newline at end of file diff --git a/core/heartbeat.py b/core/heartbeat.py new file mode 100644 index 0000000..22e9224 --- /dev/null +++ b/core/heartbeat.py @@ -0,0 +1 @@ +# 心跳包 \ No newline at end of file diff --git a/core/scheduler.py b/core/scheduler.py new file mode 100644 index 0000000..99d906d --- /dev/null +++ b/core/scheduler.py @@ -0,0 +1 @@ +# 定时任务 \ No newline at end of file diff --git a/devices/__init__.py b/devices/__init__.py new file mode 100644 index 0000000..1b17d99 --- /dev/null +++ b/devices/__init__.py @@ -0,0 +1 @@ +# 设备驱动 \ No newline at end of file diff --git a/devices/base_device.py b/devices/base_device.py new file mode 100644 index 0000000..ceb3ff9 --- /dev/null +++ b/devices/base_device.py @@ -0,0 +1 @@ +# 设备抽象层 \ No newline at end of file diff --git a/devices/feed_port.py b/devices/feed_port.py new file mode 100644 index 0000000..67db7f1 --- /dev/null +++ b/devices/feed_port.py @@ -0,0 +1 @@ +# 下料口 \ No newline at end of file diff --git a/devices/temperature.py b/devices/temperature.py new file mode 100644 index 0000000..c4a8a69 --- /dev/null +++ b/devices/temperature.py @@ -0,0 +1 @@ +# 温度传感器 \ No newline at end of file diff --git a/main.py b/main.py index e550481..62a1ccc 100644 --- a/main.py +++ b/main.py @@ -4,3 +4,4 @@ """ 猪舍主控系统主程序入口 """ + diff --git a/storage/__init__.py b/storage/__init__.py new file mode 100644 index 0000000..aaa74d0 --- /dev/null +++ b/storage/__init__.py @@ -0,0 +1 @@ +# 持久化存储 \ No newline at end of file diff --git a/storage/base_storage.py b/storage/base_storage.py new file mode 100644 index 0000000..0d47842 --- /dev/null +++ b/storage/base_storage.py @@ -0,0 +1,2 @@ +# 存储接口 + diff --git a/storage/json_storage.py b/storage/json_storage.py new file mode 100644 index 0000000..a8db291 --- /dev/null +++ b/storage/json_storage.py @@ -0,0 +1 @@ +# json 文件实现 \ No newline at end of file diff --git a/storage/memory_storage.py b/storage/memory_storage.py new file mode 100644 index 0000000..e84d94e --- /dev/null +++ b/storage/memory_storage.py @@ -0,0 +1 @@ +# 内存实现 \ No newline at end of file diff --git a/tests/test_comm.py b/tests/test_comm.py new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/tests/test_comm.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py new file mode 100644 index 0000000..a94ed01 --- /dev/null +++ b/tests/test_core.py @@ -0,0 +1 @@ +# 核心逻辑测试 \ No newline at end of file diff --git a/tests/test_devices.py b/tests/test_devices.py new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/tests/test_devices.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/tests/test_storage.py b/tests/test_storage.py new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/tests/test_storage.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/utils/crc.py b/utils/crc.py new file mode 100644 index 0000000..fb523cb --- /dev/null +++ b/utils/crc.py @@ -0,0 +1 @@ +# 校验工具 \ No newline at end of file diff --git a/utils/logger.py b/utils/logger.py new file mode 100644 index 0000000..f6d108d --- /dev/null +++ b/utils/logger.py @@ -0,0 +1 @@ +# 日志 \ No newline at end of file diff --git a/utils/parser.py b/utils/parser.py new file mode 100644 index 0000000..5290e54 --- /dev/null +++ b/utils/parser.py @@ -0,0 +1 @@ +# 数据解析工具 \ No newline at end of file