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

This commit is contained in:
xzb 2023-12-12 13:08:37 +08:00
parent 8b32cfa4c7
commit 495002a16a
6 changed files with 167 additions and 1 deletions

View File

@ -0,0 +1,30 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/consts"
)
// ElectricControlValve 电动调节阀
//
// 电动风阀、电动调节阀、组合式风阀
type ElectricControlValve struct {
Opened bool //true-开到位
Closed bool //true-关到位
Moving bool //true-正在动作
OpenRate uint8 //开度
Exception consts.DeviceExceptionEnum //具体异常
FireOpen bool //true-触发开操作
FireClose bool //true-触发关操作
}
// ElectricControlValveOperationTime 电动调节阀动作耗时ms
const ElectricControlValveOperationTime int = 4000
var (
ElectricControlValveType = ecs.NewComponentType[ElectricControlValve]()
ElectricAirValveTag = ecs.NewTag() //电动风阀标签
CombinationAirValveTag = ecs.NewTag() //组合式风阀
ElectricTwoWayValveTag = ecs.NewTag() //电动两通调节阀
)

View File

@ -26,6 +26,7 @@ type FanState struct {
HighSpeed bool //true-双速风机之扇叶高速运转 HighSpeed bool //true-双速风机之扇叶高速运转
SlowSpeed bool //true-双速风机之扇叶低速运转 SlowSpeed bool //true-双速风机之扇叶低速运转
Exception consts.DeviceExceptionEnum //风机异常 Exception consts.DeviceExceptionEnum //风机异常
Hand bool //true-设备旁有手型图标
} }
// AirConditionerGroup 空调群控系统 // AirConditionerGroup 空调群控系统
@ -43,5 +44,9 @@ var (
LowSpeedModeFanTag = ecs.NewTag() //双速风机低速运行模式标签 LowSpeedModeFanTag = ecs.NewTag() //双速风机低速运行模式标签
HighSpeedModeFanTag = ecs.NewTag() //双速风机高速运行模式标签 HighSpeedModeFanTag = ecs.NewTag() //双速风机高速运行模式标签
AirConditionerTag = ecs.NewTag() //空调 AirConditionerTag = ecs.NewTag() //空调、空调器
CombinedAirConditionerTag = ecs.NewTag() //组合式空调
// HandTag 设备旁边的手型图标,手动含义?
HandTag = ecs.NewTag()
) )

View File

@ -28,3 +28,38 @@ func NewAirConditioner(w ecs.World, id string, fc bool) *ecs.Entry {
component.FanType.Get(entry).Fc = fc component.FanType.Get(entry).Fc = fc
return entry return entry
} }
// NewCombinedAirConditioner 组合式空调(变频空调)
func NewCombinedAirConditioner(w ecs.World, id string) *ecs.Entry {
entry := NewAirConditioner(w, id, true)
entry.AddComponent(component.CombinedAirConditionerTag)
return entry
}
// NewElectricControlValve 创建电动调节阀实体
func NewElectricControlValve(w ecs.World, id string) *ecs.Entry {
e := w.Entry(w.Create(component.UidType, component.ElectricControlValveType, component.TwoPositionTransformType))
component.UidType.SetValue(e, component.Uid{Id: id})
return e
}
// NewElectricAirValve 创建电动风阀实体
func NewElectricAirValve(w ecs.World, id string) *ecs.Entry {
entry := NewElectricControlValve(w, id)
entry.AddComponent(component.ElectricAirValveTag)
return entry
}
// NewCombinationAirValve 创建组合式风阀
func NewCombinationAirValve(w ecs.World, id string) *ecs.Entry {
entry := NewElectricControlValve(w, id)
entry.AddComponent(component.CombinationAirValveTag)
return entry
}
// NewElectricTwoWayValve 创建电动两通调节阀实体
func NewElectricTwoWayValve(w ecs.World, id string) *ecs.Entry {
entry := NewElectricControlValve(w, id)
entry.AddComponent(component.ElectricTwoWayValveTag)
return entry
}

View File

@ -7,6 +7,29 @@ import (
"joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/entity"
) )
// DeviceHandTagOperate 设备设置手型图标操作
func DeviceHandTagOperate(w ecs.World, deviceId string, hand 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 hand {
if !deviceEntry.HasComponent(component.HandTag) {
deviceEntry.AddComponent(component.HandTag)
}
} else {
if deviceEntry.HasComponent(component.HandTag) {
deviceEntry.RemoveComponent(component.HandTag)
}
}
//
return ecs.NewOkEmptyResult()
})
return r.Err
}
// CommonFanOperate 一般风机控制,如排烟风机、正压送风机、射流风机、普通风机、硬线风机 // CommonFanOperate 一般风机控制,如排烟风机、正压送风机、射流风机、普通风机、硬线风机
// //
// power : 风机电源大于0接通正转相序电源小于0接通反转相序电源等于0关闭电源 // power : 风机电源大于0接通正转相序电源小于0接通反转相序电源等于0关闭电源
@ -111,3 +134,26 @@ func TwoSpeedFanOperate(w ecs.World, deviceId string, power int, highSpeedMode b
func FanExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) error { func FanExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) error {
return DeviceExceptionOperate(w, deviceId, opt) return DeviceExceptionOperate(w, deviceId, opt)
} }
// ElectricControlValveOperate 电动调节阀操作
//
// optOpen : true-触发开阀false-触发关阀
func ElectricControlValveOperate(w ecs.World, deviceId string, optOpen 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.ElectricControlValveType) && deviceEntry.HasComponent(component.TwoPositionTransformType)) {
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是电动调节阀", deviceId))
}
valve := component.ElectricControlValveType.Get(deviceEntry)
valve.FireOpen = optOpen
valve.FireClose = !optOpen
//
return ecs.NewOkEmptyResult()
})
return r.Err
}

View File

@ -0,0 +1,49 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// ElectricControlValveSystem 电动调节阀、电动风阀、组合式风阀、电动两通调节阀
type ElectricControlValveSystem struct {
query *ecs.Query
}
func NewElectricControlValveSystem() *ElectricControlValveSystem {
return &ElectricControlValveSystem{
query: ecs.NewQuery(filter.Contains(component.ElectricControlValveType, component.TwoPositionTransformType)),
}
}
func (s *ElectricControlValveSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
valve := component.ElectricControlValveType.Get(entry)
tps := component.TwoPositionTransformType.Get(entry) //最小表示全关,最大表示全开
//
if valve.FireClose {
valve.FireClose = false
tps.Speed = -component.CalculateTwoPositionAvgSpeed(component.ElectricControlValveOperationTime, w.Tick())
}
if valve.FireOpen {
valve.FireOpen = false
tps.Speed = component.CalculateTwoPositionAvgSpeed(component.ElectricControlValveOperationTime, w.Tick())
}
//
valve.Moving = tps.Pos > consts.TwoPosMin && tps.Pos < consts.TwoPosMax
valve.Opened = tps.Pos >= consts.TwoPosMax
valve.Closed = tps.Pos <= consts.TwoPosMin
valve.OpenRate = uint8(tps.Percentage() * 100) //xxx%
valve.Exception = consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
valve.Exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceAbnormalTag) {
valve.Exception = consts.DeviceAbnormal
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
valve.Exception = consts.DeviceCommunicationInterrupt
}
})
}

View File

@ -29,6 +29,7 @@ func (s *BasFanSystem) Update(w ecs.World) {
fanState.SoftStart = fan.SoftStart fanState.SoftStart = fan.SoftStart
fanState.HighSpeed = fanState.Running && entry.HasComponent(component.HighSpeedModeFanTag) fanState.HighSpeed = fanState.Running && entry.HasComponent(component.HighSpeedModeFanTag)
fanState.SlowSpeed = fanState.Running && entry.HasComponent(component.LowSpeedModeFanTag) fanState.SlowSpeed = fanState.Running && entry.HasComponent(component.LowSpeedModeFanTag)
fanState.Hand = entry.HasComponent(component.HandTag)
// //
if entry.HasComponent(component.DeviceFaultTag) { if entry.HasComponent(component.DeviceFaultTag) {
fanState.Exception = consts.DeviceFault fanState.Exception = consts.DeviceFault