<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基于STM32的环境监控系统框图</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
.system-container {
font-family: 'Arial', sans-serif;
margin: 20px;
}
.layer-box {
stroke: #3498db;
stroke-width: 2;
fill: #ecf0f1;
rx: 5;
ry: 5;
}
.module-box {
stroke: #2c3e50;
stroke-width: 1;
fill: white;
cursor: pointer;
rx: 3;
ry: 3;
}
.connection {
stroke: #7f8c8d;
stroke-width: 1.5;
marker-end: url(#arrowhead);
}
.title {
font-size: 24px;
font-weight: bold;
fill: #2c3e50;
text-anchor: middle;
}
.layer-title {
font-size: 18px;
font-weight: bold;
fill: #e74c3c;
}
.module-title {
font-size: 14px;
font-weight: bold;
fill: #34495e;
}
.module-detail {
font-size: 12px;
fill: #7f8c8d;
}
.hover-effect {
filter: url(#glow);
}
.tooltip {
position: absolute;
padding: 10px;
background: rgba(255, 255, 255, 0.9);
border: 1px solid #3498db;
border-radius: 5px;
pointer-events: none;
max-width: 300px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<div class="system-container" id="systemDiagram"></div>
<script>
// 系统架构数据定义
const systemData = {
title: "基于STM32的环境监控系统架构",
layers: [
{
name: "感知层",
modules: [
{ name: "温湿度传感器(DHT11)", detail: "温度:-20℃~60℃\n湿度:20%~90% RH" },
{ name: "空气质量传感器(MQ135)", detail: "检测有害气体浓度" },
{ name: "火焰传感器(H01)", detail: "响应时间<0.5s" },
{ name: "水位传感器(M04)", detail: "检测范围 0~10cm" },
{ name: "红外入侵传感器(E18-D80NK)", detail: "检测距离 3~80cm" }
]
},
{
name: "控制层",
modules: [
{ name: "数据融合与处理", detail: "多传感器数据滤波/整合" },
{ name: "阈值判断与逻辑控制", detail: "参数超标判断/异常优先级" },
{ name: "执行器控制策略", detail: "风扇启停/报警触发" },
{ name: "通信协议解析(MQTT)", detail: "数据封装/指令解析" },
{ name: "模式管理", detail: "自动/手动模式切换" }
]
},
{
name: "执行层",
modules: [
{ name: "通风风扇", detail: "DC风扇 5V/12V\nPWM调速" },
{ name: "声光报警模块", detail: "蜂鸣器+语音播报" },
{ name: "无线通信模块(ESP8266-01S)", detail: "UART串口通信" }
]
},
{
name: "交互层",
modules: [
{ name: "OLED显示屏", detail: "实时参数显示/状态提示" },
{ name: "物理按键", detail: "模式切换/参数设置" },
{ name: "移动端APP", detail: "远程监控与控制" }
]
},
{
name: "远程平台",
modules: [
{ name: "物联网云平台", detail: "数据存储/报警推送/远程控制" }
]
}
],
connections: [
{ source: "感知层", target: "控制层" },
{ source: "控制层", target: "执行层" },
{ source: "执行层", target: "交互层" },
{ source: "执行层", target: "远程平台" },
{ source: "交互层", target: "远程平台" },
{ source: "远程平台", target: "控制层", label: "远程指令反馈" }
]
};
// 创建SVG容器
const svg = d3.select("#systemDiagram")
.append("svg")
.attr("width", "100%")
.attr("height", "700")
.append("g")
.attr("transform", "translate(50, 50)");
// 创建箭头标记
svg.append("defs").append("marker")
.attr("id", "arrowhead")
.attr("viewBox", "-0 -5 10 10")
.attr("refX", 18)
.attr("refY", 0)
.attr("orient", "auto")
.attr("markerWidth", 10)
.attr("markerHeight", 10)
.append("path")
.attr("d", "M0,-5 L10,0 L0,5")
.attr("fill", "#7f8c8d");
// 创建发光效果滤镜
const defs = svg.append("defs");
const filter = defs.append("filter")
.attr("id", "glow")
.attr("height", "130%")
.attr("width", "130%");
filter.append("feGaussianBlur")
.attr("in", "SourceAlpha")
.attr("stdDeviation", "4")
.attr("result", "blur");
filter.append("feFlood")
.attr("flood-color", "#3498db")
.attr("flood-opacity", "0.5")
.attr("result", "glowColor");
filter.append("feComposite")
.attr("in", "glowColor")
.attr("in2", "blur")
.attr("operator", "in")
.attr("result", "glowAlpha");
filter.append("feMerge")
.selectAll("feMergeNode")
.data(["SourceGraphic", "glowAlpha"])
.enter().append("feMergeNode")
.attr("in", function(d) { return d; });
// 添加系统标题
svg.append("text")
.attr("class", "title")
.attr("x", 500)
.attr("y", 20)
.text(systemData.title);
// 工具提示创建
const tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// 创建各层容器
const layers = svg.selectAll(".layer")
.data(systemData.layers)
.enter().append("g")
.attr("class", "layer-group")
.attr("transform", (d, i) => `translate(0, ${i * 130 + 40})`);
// 添加层标题
layers.append("text")
.attr("class", "layer-title")
.attr("x", 500)
.attr("y", -10)
.text(d => d.name + " (点击展开/折叠)");
// 添加层矩形
const layerBoxes = layers.append("rect")
.attr("class", "layer-box")
.attr("width", 800)
.attr("height", 110)
.attr("x", 100);
// 添加模块
const moduleGroups = layers.selectAll(".module-group")
.data(d => d.modules)
.enter().append("g")
.attr("class", "module-group")
.attr("transform", function(将这个程序转换成图片
最新发布