ISCS环境与设备监控系统ecs定义
This commit is contained in:
parent
c06743297f
commit
64b74a0623
@ -14,8 +14,6 @@ type ElectricControlValve struct {
|
|||||||
Moving bool //true-正在动作
|
Moving bool //true-正在动作
|
||||||
OpenRate uint8 //开度
|
OpenRate uint8 //开度
|
||||||
Exception consts.DeviceExceptionEnum //具体异常
|
Exception consts.DeviceExceptionEnum //具体异常
|
||||||
FireOpen bool //true-触发开操作
|
|
||||||
FireClose bool //true-触发关操作
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ElectricControlValveOperationTime 电动调节阀动作耗时,ms
|
// ElectricControlValveOperationTime 电动调节阀动作耗时,ms
|
||||||
|
19
component/iscs_bas_purification.go
Normal file
19
component/iscs_bas_purification.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package component
|
||||||
|
|
||||||
|
import (
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PurificationDevice 净化装置
|
||||||
|
type PurificationDevice struct {
|
||||||
|
Running bool //true-运行;false-停止
|
||||||
|
Starting bool //true-正在启动
|
||||||
|
Exception consts.DeviceExceptionEnum //具体异常
|
||||||
|
}
|
||||||
|
|
||||||
|
const PurificationDeviceStartTime int = 3000 //净化装置启动耗时,ms
|
||||||
|
|
||||||
|
var (
|
||||||
|
PurificationDeviceType = ecs.NewComponentType[PurificationDevice]()
|
||||||
|
)
|
@ -164,6 +164,7 @@ var (
|
|||||||
DeviceAbnormalTag = ecs.NewTag() //异常
|
DeviceAbnormalTag = ecs.NewTag() //异常
|
||||||
DeviceFaultTag = ecs.NewTag() //故障 有预告信号产生
|
DeviceFaultTag = ecs.NewTag() //故障 有预告信号产生
|
||||||
DeviceAlarmTag = ecs.NewTag() //报警 有事故信号产生
|
DeviceAlarmTag = ecs.NewTag() //报警 有事故信号产生
|
||||||
|
DeviceStartTimeoutTag = ecs.NewTag() //启动超时
|
||||||
)
|
)
|
||||||
|
|
||||||
// 设备置牌标签定义
|
// 设备置牌标签定义
|
||||||
|
@ -9,4 +9,5 @@ const (
|
|||||||
DeviceAbnormal //异常
|
DeviceAbnormal //异常
|
||||||
DeviceFault //故障 有预告信号产生
|
DeviceFault //故障 有预告信号产生
|
||||||
DeviceAlarm //报警 有事故信号产生
|
DeviceAlarm //报警 有事故信号产生
|
||||||
|
DeviceStartTimeout //启动超时
|
||||||
)
|
)
|
||||||
|
@ -24,25 +24,25 @@ func NewIscsTwoSpeedFanEntity(w ecs.World, id string) *ecs.Entry {
|
|||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAirConditioner 创建空调实体/空调器实体
|
// NewAirConditionerEntity 创建空调实体/空调器实体
|
||||||
//
|
//
|
||||||
// fc-true变频空调;
|
// fc-true变频空调;
|
||||||
func NewAirConditioner(w ecs.World, id string, fc bool) *ecs.Entry {
|
func NewAirConditionerEntity(w ecs.World, id string, fc bool) *ecs.Entry {
|
||||||
entry := NewIscsFanEntity(w, id)
|
entry := NewIscsFanEntity(w, id)
|
||||||
entry.HasComponent(component.AirConditionerTag)
|
entry.HasComponent(component.AirConditionerTag)
|
||||||
component.FanType.Get(entry).Fc = fc
|
component.FanType.Get(entry).Fc = fc
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombinedAirConditioner 组合式空调(变频空调)
|
// NewCombinedAirConditionerEntity 组合式空调(变频空调)
|
||||||
func NewCombinedAirConditioner(w ecs.World, id string) *ecs.Entry {
|
func NewCombinedAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
entry := NewAirConditioner(w, id, true)
|
entry := NewAirConditionerEntity(w, id, true)
|
||||||
entry.AddComponent(component.CombinedAirConditionerTag)
|
entry.AddComponent(component.CombinedAirConditionerTag)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewElectricControlValve 创建电动调节阀实体
|
// NewElectricControlValveEntity 创建电动调节阀实体
|
||||||
func NewElectricControlValve(w ecs.World, id string) *ecs.Entry {
|
func NewElectricControlValveEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
wd := GetWorldData(w)
|
wd := GetWorldData(w)
|
||||||
e, ok := wd.EntityMap[id]
|
e, ok := wd.EntityMap[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -53,23 +53,35 @@ func NewElectricControlValve(w ecs.World, id string) *ecs.Entry {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewElectricAirValve 创建电动风阀实体
|
// NewElectricAirValveEntity 创建电动风阀实体
|
||||||
func NewElectricAirValve(w ecs.World, id string) *ecs.Entry {
|
func NewElectricAirValveEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
entry := NewElectricControlValve(w, id)
|
entry := NewElectricControlValveEntity(w, id)
|
||||||
entry.AddComponent(component.ElectricAirValveTag)
|
entry.AddComponent(component.ElectricAirValveTag)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombinationAirValve 创建组合式风阀
|
// NewCombinationAirValveEntity 创建组合式风阀
|
||||||
func NewCombinationAirValve(w ecs.World, id string) *ecs.Entry {
|
func NewCombinationAirValveEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
entry := NewElectricControlValve(w, id)
|
entry := NewElectricControlValveEntity(w, id)
|
||||||
entry.AddComponent(component.CombinationAirValveTag)
|
entry.AddComponent(component.CombinationAirValveTag)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewElectricTwoWayValve 创建电动两通调节阀实体
|
// NewElectricTwoWayValveEntity 创建电动两通调节阀实体
|
||||||
func NewElectricTwoWayValve(w ecs.World, id string) *ecs.Entry {
|
func NewElectricTwoWayValveEntity(w ecs.World, id string) *ecs.Entry {
|
||||||
entry := NewElectricControlValve(w, id)
|
entry := NewElectricControlValveEntity(w, id)
|
||||||
entry.AddComponent(component.ElectricTwoWayValveTag)
|
entry.AddComponent(component.ElectricTwoWayValveTag)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPurificationDeviceEntity 创建净化装置实体
|
||||||
|
func NewPurificationDeviceEntity(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.PurificationDeviceType, component.CounterType))
|
||||||
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||||
|
wd.EntityMap[id] = e
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
@ -149,9 +149,44 @@ func ElectricControlValveOperate(w ecs.World, deviceId string, optOpen bool) err
|
|||||||
if !(deviceEntry.HasComponent(component.ElectricControlValveType) && deviceEntry.HasComponent(component.TwoPositionTransformType)) {
|
if !(deviceEntry.HasComponent(component.ElectricControlValveType) && deviceEntry.HasComponent(component.TwoPositionTransformType)) {
|
||||||
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是电动调节阀", deviceId))
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是电动调节阀", deviceId))
|
||||||
}
|
}
|
||||||
valve := component.ElectricControlValveType.Get(deviceEntry)
|
tps := component.TwoPositionTransformType.Get(deviceEntry) //最小表示全关,最大表示全开
|
||||||
valve.FireOpen = optOpen
|
if optOpen {
|
||||||
valve.FireClose = !optOpen
|
tps.Speed = component.CalculateTwoPositionAvgSpeed(component.ElectricControlValveOperationTime, w.Tick())
|
||||||
|
} else {
|
||||||
|
tps.Speed = -component.CalculateTwoPositionAvgSpeed(component.ElectricControlValveOperationTime, w.Tick())
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return ecs.NewOkEmptyResult()
|
||||||
|
})
|
||||||
|
return r.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
// PurificationDeviceOperate 净化装置操作
|
||||||
|
//
|
||||||
|
// optStart : true-启动净化器;false-关停净化器
|
||||||
|
func PurificationDeviceOperate(w ecs.World, deviceId string, optStart 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.PurificationDeviceType) && deviceEntry.HasComponent(component.CounterType)) {
|
||||||
|
return ecs.NewErrResult(fmt.Errorf("设备[%s]不是净化装置", deviceId))
|
||||||
|
}
|
||||||
|
device := component.PurificationDeviceType.Get(deviceEntry)
|
||||||
|
counter := component.CounterType.Get(deviceEntry)
|
||||||
|
if optStart {
|
||||||
|
if device.Running {
|
||||||
|
return ecs.NewErrResult(fmt.Errorf("净化装置[%s]已经启动在运行", deviceId))
|
||||||
|
}
|
||||||
|
device.Starting = true
|
||||||
|
counter.Val = 0
|
||||||
|
counter.Step = w.Tick()
|
||||||
|
} else { //关停
|
||||||
|
device.Running = false
|
||||||
|
}
|
||||||
//
|
//
|
||||||
return ecs.NewOkEmptyResult()
|
return ecs.NewOkEmptyResult()
|
||||||
})
|
})
|
||||||
|
@ -86,6 +86,7 @@ const (
|
|||||||
DeviceExceptionAbnormal //异常
|
DeviceExceptionAbnormal //异常
|
||||||
DeviceExceptionFault //故障 有预告信号产生
|
DeviceExceptionFault //故障 有预告信号产生
|
||||||
DeviceExceptionAlarm //报警 有事故信号产生
|
DeviceExceptionAlarm //报警 有事故信号产生
|
||||||
|
DeviceExceptionStartTimeout //启动超时
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeviceExceptionOperate 设备例外操作
|
// DeviceExceptionOperate 设备例外操作
|
||||||
@ -101,6 +102,7 @@ func DeviceExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOpt
|
|||||||
deviceEntry.RemoveComponent(component.DeviceAbnormalTag)
|
deviceEntry.RemoveComponent(component.DeviceAbnormalTag)
|
||||||
deviceEntry.RemoveComponent(component.DeviceFaultTag)
|
deviceEntry.RemoveComponent(component.DeviceFaultTag)
|
||||||
deviceEntry.RemoveComponent(component.DeviceAlarmTag)
|
deviceEntry.RemoveComponent(component.DeviceAlarmTag)
|
||||||
|
deviceEntry.RemoveComponent(component.DeviceStartTimeoutTag)
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
switch opt {
|
switch opt {
|
||||||
@ -116,6 +118,9 @@ func DeviceExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOpt
|
|||||||
case DeviceExceptionFault:
|
case DeviceExceptionFault:
|
||||||
clearAllExceptions(deviceEntry)
|
clearAllExceptions(deviceEntry)
|
||||||
deviceEntry.AddComponent(component.DeviceFaultTag)
|
deviceEntry.AddComponent(component.DeviceFaultTag)
|
||||||
|
case DeviceExceptionStartTimeout:
|
||||||
|
clearAllExceptions(deviceEntry)
|
||||||
|
deviceEntry.AddComponent(component.DeviceStartTimeoutTag)
|
||||||
default:
|
default:
|
||||||
clearAllExceptions(deviceEntry)
|
clearAllExceptions(deviceEntry)
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,6 @@ func (s *ElectricControlValveSystem) Update(w ecs.World) {
|
|||||||
valve := component.ElectricControlValveType.Get(entry)
|
valve := component.ElectricControlValveType.Get(entry)
|
||||||
tps := component.TwoPositionTransformType.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.Moving = tps.Pos > consts.TwoPosMin && tps.Pos < consts.TwoPosMax
|
||||||
valve.Opened = tps.Pos >= consts.TwoPosMax
|
valve.Opened = tps.Pos >= consts.TwoPosMax
|
||||||
valve.Closed = tps.Pos <= consts.TwoPosMin
|
valve.Closed = tps.Pos <= consts.TwoPosMin
|
||||||
|
47
sys/iscs_sys/iscs_bas_purification_device.go
Normal file
47
sys/iscs_sys/iscs_bas_purification_device.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package iscs_sys
|
||||||
|
|
||||||
|
import (
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/ecs/filter"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PurificationDeviceSystem struct {
|
||||||
|
query *ecs.Query
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPurificationDeviceSystem() *PurificationDeviceSystem {
|
||||||
|
return &PurificationDeviceSystem{
|
||||||
|
query: ecs.NewQuery(filter.Contains(component.PurificationDeviceType, component.CounterType)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (s *PurificationDeviceSystem) Update(w ecs.World) {
|
||||||
|
s.query.Each(w, func(entry *ecs.Entry) {
|
||||||
|
pd := component.PurificationDeviceType.Get(entry)
|
||||||
|
counter := component.CounterType.Get(entry)
|
||||||
|
if pd.Starting {
|
||||||
|
counter.Step = w.Tick()
|
||||||
|
if counter.Val >= component.PurificationDeviceStartTime { //启动延时结束
|
||||||
|
pd.Starting = false
|
||||||
|
counter.Step = 0
|
||||||
|
if entry.HasComponent(component.DeviceStartTimeoutTag) { //设置启动超时故障
|
||||||
|
pd.Running = false //启动失败
|
||||||
|
} else {
|
||||||
|
pd.Running = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
pd.Exception = consts.DeviceExceptionNon
|
||||||
|
if entry.HasComponent(component.DeviceStartTimeoutTag) {
|
||||||
|
pd.Exception = consts.DeviceStartTimeout
|
||||||
|
}
|
||||||
|
if entry.HasComponent(component.DeviceAbnormalTag) {
|
||||||
|
pd.Exception = consts.DeviceAbnormal
|
||||||
|
}
|
||||||
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
||||||
|
pd.Exception = consts.DeviceCommunicationInterrupt
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user