138 lines
4.9 KiB
Go
138 lines
4.9 KiB
Go
package fi
|
||
|
||
import (
|
||
"fmt"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/component"
|
||
"joylink.club/rtsssimulation/entity"
|
||
)
|
||
|
||
// AxleSectionDrstDrive 计轴直接复位操作
|
||
//
|
||
// set : true-设置,false-取消
|
||
func AxleSectionDrstDrive(w ecs.World, sectionId string, set bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
faDcAxleDeviceId := entity.CreateFaDcAxleDeviceId(sectionModel.CentralizedStation())
|
||
faDcAxleDeviceEntry, ok := wd.EntityMap[faDcAxleDeviceId]
|
||
if !ok {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]不存实体", faDcAxleDeviceId))
|
||
}
|
||
//
|
||
axleCounterEntry := component.FaDcAxleDeviceType.Get(faDcAxleDeviceEntry).GetAxleCounterEntry(sectionId)
|
||
if axleCounterEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴器实体", faDcAxleDeviceId, sectionId))
|
||
}
|
||
axleRuntime := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||
axleRuntime.Drst = set
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
// AxleSectionPdrstDrive 计轴预复位操作
|
||
//
|
||
// set : true-设置,false-取消
|
||
func AxleSectionPdrstDrive(w ecs.World, sectionId string, set bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
faDcAxleDeviceId := entity.CreateFaDcAxleDeviceId(sectionModel.CentralizedStation())
|
||
faDcAxleDeviceEntry, ok := wd.EntityMap[faDcAxleDeviceId]
|
||
if !ok {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]不存实体", faDcAxleDeviceId))
|
||
}
|
||
//
|
||
axleCounterEntry := component.FaDcAxleDeviceType.Get(faDcAxleDeviceEntry).GetAxleCounterEntry(sectionId)
|
||
if axleCounterEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴器实体", faDcAxleDeviceId, sectionId))
|
||
}
|
||
axleRuntime := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||
axleRuntime.Pdrst = set
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
// AxleSectionFaultOccDrive 区段故障占用设置
|
||
//
|
||
// set : true - 设置故障占用;false - 取消故障占用
|
||
func AxleSectionFaultOccDrive(w ecs.World, sectionId string, set bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
faDcAxleDeviceId := entity.CreateFaDcAxleDeviceId(sectionModel.CentralizedStation())
|
||
faDcAxleDeviceEntry, ok := wd.EntityMap[faDcAxleDeviceId]
|
||
if !ok {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]不存实体", faDcAxleDeviceId))
|
||
}
|
||
//
|
||
axleCounterEntry := component.FaDcAxleDeviceType.Get(faDcAxleDeviceEntry).GetAxleCounterEntry(sectionId)
|
||
axleCounter := component.AxleCounterType.Get(axleCounterEntry)
|
||
//
|
||
sectionEntry, ok := wd.EntityMap[sectionId]
|
||
if !ok {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴区段[%s]不存实体", sectionId))
|
||
}
|
||
sectionFault := component.AxleSectionFaultType.Get(sectionEntry)
|
||
//计轴故障设置
|
||
sectionFault.SectionFault = set
|
||
if set {
|
||
axleCounter.UpdateCount(1)
|
||
} else {
|
||
axleCounter.UpdateCount(0)
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|
||
|
||
// AxleSectionTrainDrive 计轴区段内车进入出清设置
|
||
//
|
||
// trainIn : true - 计轴区段内有车;false-计轴区段出清
|
||
func AxleSectionTrainDrive(w ecs.World, sectionId string, trainIn bool) error {
|
||
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||
wd := entity.GetWorldData(w)
|
||
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
||
if sectionModel == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||
}
|
||
//
|
||
faDcAxleDeviceId := entity.CreateFaDcAxleDeviceId(sectionModel.CentralizedStation())
|
||
faDcAxleDeviceEntry, ok := wd.EntityMap[faDcAxleDeviceId]
|
||
if !ok {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]不存实体", faDcAxleDeviceId))
|
||
}
|
||
//
|
||
axleCounterEntry := component.FaDcAxleDeviceType.Get(faDcAxleDeviceEntry).GetAxleCounterEntry(sectionId)
|
||
if axleCounterEntry == nil {
|
||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴器实体", faDcAxleDeviceId, sectionId))
|
||
}
|
||
axleCounter := component.AxleCounterType.Get(axleCounterEntry)
|
||
if trainIn {
|
||
axleCounter.UpdateCount(1)
|
||
} else {
|
||
axleCounter.UpdateCount(0)
|
||
}
|
||
//
|
||
return ecs.NewOkEmptyResult()
|
||
})
|
||
return r.Err
|
||
}
|