ISCS环境与设备监控系统ecs定义

This commit is contained in:
xzb 2023-12-13 14:54:23 +08:00
parent f624ae5f08
commit fbb92d2ea0
8 changed files with 412 additions and 4 deletions

View File

@ -0,0 +1,20 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// FlowSwitch 流量开关
//
// 主要是在水、气、油等介质管路中在线或者插入式安装监控水系统中水流量的大小。
// 在水流量高于或者低于某一个设定点时候触发输出报警信号传递给机组,
// 系统获取信号后即可作出相应的指示动作。避免或减少主机“干烧”。
type FlowSwitch struct {
Open bool //true-开启false-关闭
Exception consts.DeviceExceptionEnum //具体异常-通信中断
}
var (
FlowSwitchType = ecs.NewComponentType[FlowSwitch]()
)

View File

@ -0,0 +1,90 @@
package component
import "joylink.club/ecs"
//BAS 导向
// LightingGuidance 照明导向
type LightingGuidance struct {
Guidance LightingGd
}
// LightingGd 照明导向定义
type LightingGd = uint8
const (
LightingGdOpen LightingGd = iota //照明开启
LightingGdClose //照明关闭
LightingGdAbnormal //照明异常
LightingGdCommunicationInterrupt //照明通信中断
)
///////////////////////////
// PowerSwitchGuidance 电源开关导向
type PowerSwitchGuidance struct {
Guidance PowerSwitchGd
}
// PowerSwitchGd 电源开关导向定义
type PowerSwitchGd = uint8
const (
PowerSwitchGdOpen PowerSwitchGd = iota //电源开关分闸
PowerSwitchGdClose //电源开关合闸
PowerSwitchGdAbnormal //电源开关异常
PowerSwitchGdCommunicationInterrupt //电源开关通信中断
)
/////////////////////////////
// EscalatorGuidance 扶梯导向
type EscalatorGuidance struct {
Guidance EscalatorGd
}
// EscalatorGd 扶梯导向定义
type EscalatorGd = uint8
const (
EscalatorGdOpen EscalatorGd = iota //扶梯开启
EscalatorGdClose //扶梯关闭
EscalatorGdAbnormal //扶梯异常
EscalatorGdCommunicationInterrupt //扶梯通信中断
)
////////////////////////////////
// TicketGateGuidance 闸机导向
type TicketGateGuidance struct {
Guidance TicketGateGd
}
// TicketGateGd 闸机导向定义
type TicketGateGd = uint8
const (
TicketGateGdZ1F1 TicketGateGd = iota //正通反通
TicketGateGdZ1F0 //正通反禁
TicketGateGdZ0F1 //正禁反通
TicketGateGdZ0F0 //正禁反禁
TicketGateGdAbnormal //闸机异常
TicketGateGdCommunicationInterrupt //闸机通信中断
)
///////////////////////////////////////
// SectionEvacuationGuidance 区间疏散导向指示
type SectionEvacuationGuidance struct {
Open bool //true-开false-关
}
////////////////////////////////////////
var (
LightingGuidanceType = ecs.NewComponentType[LightingGuidance]()
PowerSwitchGuidanceType = ecs.NewComponentType[PowerSwitchGuidance]()
EscalatorGuidanceType = ecs.NewComponentType[EscalatorGuidance]()
TicketGateGuidanceType = ecs.NewComponentType[TicketGateGuidance]()
SectionEvacuationGuidanceType = ecs.NewComponentType[SectionEvacuationGuidance]()
)

View File

@ -0,0 +1,25 @@
package component
import "joylink.club/ecs"
// Sensor 传感器
type Sensor struct {
Value float32
}
// ThSensor 温湿度传感器
type ThSensor struct {
T float32 //温度
H float32 //湿度
}
var (
SensorType = ecs.NewComponentType[Sensor]()
ThSensorType = ecs.NewComponentType[ThSensor]()
CO2SensorTag = ecs.NewTag() //CO2 传感器
WaterTSensorTag = ecs.NewTag() //水温传感器
PressureSensorTag = ecs.NewTag() //压力传感器
FlowSensorTag = ecs.NewTag() //流量传感器
TemperatureSensorTag = ecs.NewTag() //温度传感器
)

View File

@ -5,9 +5,11 @@ import (
"joylink.club/rtsssimulation/consts"
)
// 阀门开关
// ElectricControlValve 电动调节阀
//
// 电动风阀、电动调节阀、组合式风阀
// 电动风阀、电动调节阀、组合式风阀、电动两通调节阀、电动蝶阀
type ElectricControlValve struct {
Opened bool //true-开到位
Closed bool //true-关到位
@ -19,10 +21,19 @@ type ElectricControlValve struct {
// ElectricControlValveOperationTime 电动调节阀动作耗时ms
const ElectricControlValveOperationTime int = 4000
// ControlValve 调节阀
type ControlValve struct {
OpenRate uint8 //开度0-100%
}
var (
ElectricControlValveType = ecs.NewComponentType[ElectricControlValve]()
ElectricAirValveTag = ecs.NewTag() //电动风阀标签
CombinationAirValveTag = ecs.NewTag() //组合式风阀
ElectricTwoWayValveTag = ecs.NewTag() //电动两通调节阀
ElectricButterflyValveTag = ecs.NewTag() //电动蝶阀
ControlValveType = ecs.NewComponentType[ControlValve]()
BypassValveSwitchTag = ecs.NewTag() //旁通阀开关(ControlValve)
)

View File

@ -0,0 +1,18 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// WaterClosedContainer 水封闭式容器,如冷却塔、水处理器
type WaterClosedContainer struct {
Running bool //true-正常运行false-停止
Exception consts.DeviceExceptionEnum //具体异常-故障、异常、通信中断
}
var (
WaterClosedContainerType = ecs.NewComponentType[WaterClosedContainer]()
CoolingTowerTag = ecs.NewTag() //冷却塔
WaterProcessorTag = ecs.NewTag() //水处理器
)

View File

@ -74,6 +74,13 @@ func NewElectricTwoWayValveEntity(w ecs.World, id string) *ecs.Entry {
return entry
}
// NewElectricButterflyValveEntity 创建电动蝶阀实体
func NewElectricButterflyValveEntity(w ecs.World, id string) *ecs.Entry {
entry := NewElectricControlValveEntity(w, id)
entry.AddComponent(component.ElectricButterflyValveTag)
return entry
}
// NewPurificationDeviceEntity 创建净化装置实体
func NewPurificationDeviceEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
@ -152,3 +159,160 @@ func NewWaterTankEntity(w ecs.World, id string) *ecs.Entry {
}
return e
}
// NewWaterClosedContainerEntity 创建封闭式水容器,如冷却塔、水处理器
func NewWaterClosedContainerEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.WaterClosedContainerType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewCoolingTowerEntity 创建冷却塔实体
func NewCoolingTowerEntity(w ecs.World, id string) *ecs.Entry {
entry := NewWaterClosedContainerEntity(w, id)
entry.AddComponent(component.CoolingTowerTag)
return entry
}
// NewWaterProcessorEntity 创建水处理器实体
func NewWaterProcessorEntity(w ecs.World, id string) *ecs.Entry {
entry := NewWaterClosedContainerEntity(w, id)
entry.AddComponent(component.WaterProcessorTag)
return entry
}
// NewBypassValveSwitchEntity 创建旁通阀开关实体
func NewBypassValveSwitchEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.ControlValveType, component.BypassValveSwitchTag))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewSensorEntity 创建传感器实体
func NewSensorEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.SensorType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewThSensorEntity 创建温湿度传感器实体
func NewThSensorEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.ThSensorType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewCO2SensorEntity CO2 传感器
func NewCO2SensorEntity(w ecs.World, id string) *ecs.Entry {
entry := NewSensorEntity(w, id)
entry.AddComponent(component.CO2SensorTag)
return entry
}
// NewWaterTSensorEntity 水温传感器
func NewWaterTSensorEntity(w ecs.World, id string) *ecs.Entry {
entry := NewSensorEntity(w, id)
entry.AddComponent(component.WaterTSensorTag)
return entry
}
// NewPressureSensorEntity 压力传感器
func NewPressureSensorEntity(w ecs.World, id string) *ecs.Entry {
entry := NewSensorEntity(w, id)
entry.AddComponent(component.PressureSensorTag)
return entry
}
// NewFlowSensorEntity 流量传感器
func NewFlowSensorEntity(w ecs.World, id string) *ecs.Entry {
entry := NewSensorEntity(w, id)
entry.AddComponent(component.FlowSensorTag)
return entry
}
// NewTemperatureSensorEntity 温度传感器
func NewTemperatureSensorEntity(w ecs.World, id string) *ecs.Entry {
entry := NewSensorEntity(w, id)
entry.AddComponent(component.TemperatureSensorTag)
return entry
}
// NewLightingGuidanceEntity 创建照明导向实体
func NewLightingGuidanceEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.LightingGuidanceType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewPowerSwitchGuidanceEntity 创建电源开关导向实体
func NewPowerSwitchGuidanceEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.PowerSwitchGuidanceType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewEscalatorGuidanceEntity 创建扶梯导向实体
func NewEscalatorGuidanceEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.EscalatorGuidanceType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewTicketGateGuidanceEntity 创建闸机导向实体
func NewTicketGateGuidanceEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.TicketGateGuidanceType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
// NewSectionEvacuationGuidanceEntity 创建区间疏散导向实体
func NewSectionEvacuationGuidanceEntity(w ecs.World, id string) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
e := w.Entry(w.Create(component.UidType, component.SectionEvacuationGuidanceType))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}

View File

@ -301,3 +301,49 @@ func WaterPumpOperate(w ecs.World, deviceId string, optRun bool) error {
})
return r.Err
}
// WaterClosedContainerOperate 封闭式水容器(如冷却塔、水处理器)
//
// optRun : true-正常运行false-停止
func WaterClosedContainerOperate(w ecs.World, deviceId string, optRun bool) error {
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
deviceEntry, ok := wd.EntityMap[deviceId]
if !ok {
return ecs.NewErrResult(fmt.Errorf("设备[%s]实体不存在", deviceId))
}
//
if !(deviceEntry.HasComponent(component.WaterClosedContainerType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是封闭式水容器(如冷却塔、水处理器)", deviceId))
}
container := component.WaterPumpType.Get(deviceEntry)
container.Running = optRun
//
return ecs.NewOkEmptyResult()
})
return r.Err
}
// BypassValveSwitchOperate 旁通阀开关操作
//
// openRate 旁通阀开关打开百分比[0,100]
func BypassValveSwitchOperate(w ecs.World, deviceId string, openRate uint8) error {
if openRate < 0 || openRate > 100 {
return fmt.Errorf("旁通阀开关打开百分比值须在[0,100]范围内")
}
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
deviceEntry, ok := wd.EntityMap[deviceId]
if !ok {
return ecs.NewErrResult(fmt.Errorf("设备[%s]实体不存在", deviceId))
}
//
if !(deviceEntry.HasComponent(component.ControlValveType) && deviceEntry.HasComponent(component.BypassValveSwitchTag)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是旁通阀开关", deviceId))
}
component.ControlValveType.Get(deviceEntry).OpenRate = openRate
//
return ecs.NewOkEmptyResult()
})
return r.Err
}

View File

@ -0,0 +1,34 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// WaterClosedContainerSystem 封闭冷却塔、水处理器
type WaterClosedContainerSystem struct {
query *ecs.Query
}
func NewWaterClosedContainerSystem() *WaterClosedContainerSystem {
return &WaterClosedContainerSystem{
query: ecs.NewQuery(filter.Contains(component.WaterClosedContainerType)),
}
}
func (s *WaterClosedContainerSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
container := component.WaterClosedContainerType.Get(entry)
container.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
container.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
container.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
container.Exception = consts.DeviceCommunicationInterrupt
}
})
}