2026-08-04 15:32:16 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
"""点位字典 CSV schema —— 对齐 PRD 5.1「边缘采集网关」字段规范表。
|
|
|
|
|
|
|
2026-08-04 15:59:32 +08:00
|
|
|
|
字段表(PRD 5.1 + issue #21「协议」维度):
|
2026-08-04 15:32:16 +08:00
|
|
|
|
device_id string 必填,唯一 设备编号,如 CLF-01
|
|
|
|
|
|
point_id string 必填,唯一 测点编号,如 CLF-01.TEMP
|
|
|
|
|
|
name string 必填 中文名,如 炉温
|
|
|
|
|
|
unit enum 必填 ℃ / kPa / m³/h / % / ...
|
|
|
|
|
|
dataType enum 必填 float / int / bool
|
|
|
|
|
|
sampleRate int 必填, >0 采集周期(ms)
|
|
|
|
|
|
qualityCode bool 默认 true 是否启用质量码
|
|
|
|
|
|
opcNode string 选填 OPC UA 节点路径
|
2026-08-04 15:59:32 +08:00
|
|
|
|
protocol enum 选填 采集协议(opcua/s7/modbus/weighing/energy/simulator)。
|
|
|
|
|
|
空 = 由 gateway.yaml drivers 段按设备前缀路由(模板级默认)。
|
|
|
|
|
|
|
|
|
|
|
|
协议维度说明(issue #21):
|
|
|
|
|
|
点位字典 CSV schema 覆盖「点位/设备/量纲/采样率/协议」五维。
|
|
|
|
|
|
protocol 列提供**点位级协议覆盖**:同一模板内混接多种协议时,
|
|
|
|
|
|
可在 CSV 中逐点位/逐设备显式指定协议;为空时保持模板级
|
|
|
|
|
|
(gateway.yaml drivers 段 device_prefixes)路由,向后兼容。
|
2026-08-04 15:32:16 +08:00
|
|
|
|
"""
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
# 合法量纲集合(可按行业模板扩展;此处覆盖化工/氯化车间常用量纲)
|
|
|
|
|
|
VALID_UNITS: List[str] = [
|
|
|
|
|
|
"℃", "kPa", "MPa", "m³/h", "m3/h", "%", "kg", "t", "t/h", "m³", "m3",
|
|
|
|
|
|
"A", "V", "Hz", "kW", "kWh", "Pa", "bar", "mm", "L", "L/min", "m/s",
|
2026-08-05 04:44:58 +08:00
|
|
|
|
# 树脂行业模板(templates/resin)扩展:搅拌转速 rpm / 离子交换容量 mmol/g
|
|
|
|
|
|
"rpm", "mmol/g",
|
2026-08-04 15:32:16 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# 合法数据类型集合
|
|
|
|
|
|
VALID_DATA_TYPES: List[str] = ["float", "int", "bool"]
|
|
|
|
|
|
|
2026-08-04 15:59:32 +08:00
|
|
|
|
# 合法采集协议集合(与 drivers/__init__.py 注册表对齐)
|
|
|
|
|
|
VALID_PROTOCOLS: List[str] = ["opcua", "s7", "modbus", "weighing", "energy", "simulator"]
|
|
|
|
|
|
|
2026-08-04 15:32:16 +08:00
|
|
|
|
# 必填字段
|
|
|
|
|
|
REQUIRED_FIELDS: List[str] = ["device_id", "point_id", "name", "unit", "dataType", "sampleRate"]
|
|
|
|
|
|
|
|
|
|
|
|
# CSV 表头(列顺序固定,便于实施工程师对照 DCS 点表填写)
|
|
|
|
|
|
CSV_HEADERS: List[str] = [
|
|
|
|
|
|
"device_id", "point_id", "name", "unit", "dataType", "sampleRate",
|
2026-08-04 15:59:32 +08:00
|
|
|
|
"qualityCode", "opcNode", "protocol",
|
2026-08-04 15:32:16 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_valid_unit(unit: str) -> bool:
|
|
|
|
|
|
"""量纲合法性校验(大小写不敏感)。"""
|
|
|
|
|
|
if not unit or unit != unit.strip():
|
|
|
|
|
|
return False
|
|
|
|
|
|
return unit in VALID_UNITS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_valid_data_type(dtype: str) -> bool:
|
|
|
|
|
|
"""数据类型合法性校验。"""
|
|
|
|
|
|
return dtype in VALID_DATA_TYPES
|
2026-08-04 15:59:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_valid_protocol(protocol: str) -> bool:
|
|
|
|
|
|
"""采集协议合法性校验(小写,须在驱动注册表内)。"""
|
|
|
|
|
|
return protocol in VALID_PROTOCOLS
|