package fi import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "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 一般风机控制,如排烟风机、正压送风机、射流风机、普通风机、硬线风机 // // power : 风机电源,大于0接通正转相序电源,小于0接通反转相序电源,等于0关闭电源 func CommonFanOperate(w ecs.World, deviceId string, power int) 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.FanType) { return ecs.NewErrResult(fmt.Errorf("设备[%s]不是风机", deviceId)) } // fan := component.FanType.Get(deviceEntry) fan.Power = power // return ecs.NewOkEmptyResult() }) return r.Err } // SoftBypassFanOperate 如软启风机、隧道风机 func SoftBypassFanOperate(w ecs.World, deviceId string, power int, softStart bool, bypass 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.FanType) { return ecs.NewErrResult(fmt.Errorf("设备[%s]不是风机", deviceId)) } // fan := component.FanType.Get(deviceEntry) fan.Bypass = bypass fan.SoftStart = softStart fan.Power = power // return ecs.NewOkEmptyResult() }) return r.Err } // FcBypassFanOperate (变频、旁路)回排风机 func FcBypassFanOperate(w ecs.World, deviceId string, power int, fc bool, bypass 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.FanType) { return ecs.NewErrResult(fmt.Errorf("设备[%s]不是风机", deviceId)) } // fan := component.FanType.Get(deviceEntry) fan.Bypass = bypass fan.Fc = fc fan.Power = power // return ecs.NewOkEmptyResult() }) return r.Err } // TwoSpeedFanOperate 双速风机,转速模式设置 // // highSpeedMode-true高速模式,false-低速模式 func TwoSpeedFanOperate(w ecs.World, deviceId string, power int, highSpeedMode 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.FanType) && deviceEntry.HasComponent(component.TwoSpeedFanTag)) { return ecs.NewErrResult(fmt.Errorf("设备[%s]不是双速风机", deviceId)) } // fan := component.FanType.Get(deviceEntry) fan.Power = power // deviceEntry.RemoveComponent(component.HighSpeedModeFanTag) deviceEntry.RemoveComponent(component.LowSpeedModeFanTag) if highSpeedMode { deviceEntry.AddComponent(component.HighSpeedModeFanTag) } else { deviceEntry.AddComponent(component.LowSpeedModeFanTag) } // return ecs.NewOkEmptyResult() }) return r.Err } // FanExceptionOperate 风机异常设置(故障、异常、通信中断) func FanExceptionOperate(w ecs.World, deviceId string, opt DeviceExceptionOptEnum) error { 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)) } tps := component.TwoPositionTransformType.Get(deviceEntry) //最小表示全关,最大表示全开 if 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 r.Err } ///////////////////////////////////////////////////////////////////////// // EscalatorOptEnum 自动扶梯操作定义 type EscalatorOptEnum = uint8 const ( EscalatorOptUp EscalatorOptEnum = iota //上行 EscalatorOptDown //下行 EscalatorOptStop //停止 EscalatorOptEs //急停 ) // EscalatorDeviceOperate 自动扶梯操作 func EscalatorDeviceOperate(w ecs.World, deviceId string, opt EscalatorOptEnum) 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.EscalatorType)) { return ecs.NewErrResult(fmt.Errorf("设备[%s]不是自动扶梯", deviceId)) } // escalator := component.EscalatorType.Get(deviceEntry) escalator.EmergencyStop = false switch opt { case EscalatorOptUp: escalator.Running = 1 case EscalatorOptDown: escalator.Running = -1 case EscalatorOptStop: escalator.Running = 0 case EscalatorOptEs: escalator.EmergencyStop = true } // return ecs.NewOkEmptyResult() }) return r.Err } // ElevatorDeviceOperate 垂直电梯操作 // // optRun : true-运行;false-停止 func ElevatorDeviceOperate(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.ElevatorType)) { return ecs.NewErrResult(fmt.Errorf("设备[%s]不是垂直电梯", deviceId)) } elevator := component.ElevatorType.Get(deviceEntry) elevator.Running = optRun // return ecs.NewOkEmptyResult() }) return r.Err }