diff --git a/component/iscs_bas_emergency_lighting.go b/component/iscs_bas_emergency_lighting.go new file mode 100644 index 0000000..bfbc025 --- /dev/null +++ b/component/iscs_bas_emergency_lighting.go @@ -0,0 +1,24 @@ +package component + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/consts" +) + +// EmergencyLighting 应急照明 +type EmergencyLighting struct { + Mode EmergencyLightingMode + Exception consts.DeviceExceptionEnum //具体异常-故障、异常、通信中断 +} + +// EmergencyLightingMode 应急照明模式定义 +type EmergencyLightingMode = uint8 + +const ( + ElmAuto EmergencyLightingMode = iota //应急照明自动/正常运行 + ElmEmergency //应急照明开启应急模式 + ElmFirefighting //应急照明开启消防强制启动模式 + ElmNon //应急照明非正常模式 +) + +var EmergencyLightingType = ecs.NewComponentType[EmergencyLighting]() diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index 593a794..b73d8a9 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -352,3 +352,15 @@ func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry { } return e } + +// NewEmergencyLightingEntity 创建应急照明实体 +func NewEmergencyLightingEntity(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.EmergencyLightingType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} diff --git a/fi/iscs_bas.go b/fi/iscs_bas.go index 720444b..9bd4cf9 100644 --- a/fi/iscs_bas.go +++ b/fi/iscs_bas.go @@ -4,6 +4,7 @@ import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/consts" "joylink.club/rtsssimulation/entity" ) @@ -369,3 +370,42 @@ func CivilDefenseDoorOperate(w ecs.World, deviceId string, optOpen bool) error { }) return r.Err } + +// 应急照明操作 +func emergencyLightingOperate(w ecs.World, deviceId string, opt component.EmergencyLightingMode) 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.EmergencyLightingType)) { + return ecs.NewErrResult(fmt.Errorf("设备[%s]不是应急照明", deviceId)) + } + el := component.EmergencyLightingType.Get(deviceEntry) + if el.Exception != consts.DeviceExceptionNon { + return ecs.NewErrResult(fmt.Errorf("应急照明[%s]有故障,不能设置工作模式", deviceId)) + } + // + el.Mode = opt + // + return ecs.NewOkEmptyResult() + }) + return r.Err +} + +// EmergencyLightingAutoOperate 应急照明自动/正常运行 +func EmergencyLightingAutoOperate(w ecs.World, deviceId string) error { + return emergencyLightingOperate(w, deviceId, component.ElmAuto) +} + +// EmergencyLightingEmergencyOperate 应急照明开启应急模式 +func EmergencyLightingEmergencyOperate(w ecs.World, deviceId string) error { + return emergencyLightingOperate(w, deviceId, component.ElmEmergency) +} + +// EmergencyLightingFirefightingOperate 应急照明开启消防强制启动模式 +func EmergencyLightingFirefightingOperate(w ecs.World, deviceId string) error { + return emergencyLightingOperate(w, deviceId, component.ElmFirefighting) +} diff --git a/sys/iscs_sys/iscs_bas_emergency_lighting.go b/sys/iscs_sys/iscs_bas_emergency_lighting.go new file mode 100644 index 0000000..2998192 --- /dev/null +++ b/sys/iscs_sys/iscs_bas_emergency_lighting.go @@ -0,0 +1,45 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/consts" +) + +// EmergencyLightingSystem 应急照明 +type EmergencyLightingSystem struct { + query *ecs.Query +} + +func NewEmergencyLightingSystem() *EmergencyLightingSystem { + return &EmergencyLightingSystem{ + query: ecs.NewQuery(filter.Contains(component.EmergencyLightingType)), + } +} +func (s *EmergencyLightingSystem) Update(w ecs.World) { + s.query.Each(w, func(entry *ecs.Entry) { + el := component.EmergencyLightingType.Get(entry) + // + el.Exception = consts.DeviceExceptionNon + if entry.HasComponent(component.DeviceFaultTag) { + el.Exception = consts.DeviceFault + } + if entry.HasComponent(component.DeviceAbnormalTag) { + el.Exception = consts.DeviceAbnormal + } + if entry.HasComponent(component.DeviceCommunicationInterruptTag) { + el.Exception = consts.DeviceCommunicationInterrupt + } + // + if el.Exception != consts.DeviceExceptionNon { + el.Mode = component.ElmNon + } else { + //当应急照明异常解除后,自动恢复到正常模式 + if el.Mode == component.ElmNon { + el.Mode = component.ElmAuto + } + } + + }) +}