121 lines
3.7 KiB
Go
121 lines
3.7 KiB
Go
package fi
|
|
|
|
import (
|
|
"fmt"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"strings"
|
|
)
|
|
|
|
// PhysicalSectionFaultOccDrive 区段故障占用设置
|
|
func PhysicalSectionFaultOccDrive(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))
|
|
}
|
|
//
|
|
sectionEntry := wd.EntityMap[sectionId]
|
|
if sectionEntry == nil {
|
|
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
|
}
|
|
if set { //计轴故障设置
|
|
if !sectionEntry.HasComponent(component.PhysicalSectionForceOccupied) {
|
|
sectionEntry.AddComponent(component.PhysicalSectionForceOccupied)
|
|
}
|
|
} else { //计轴故障取消
|
|
if sectionEntry.HasComponent(component.PhysicalSectionForceOccupied) {
|
|
sectionEntry.RemoveComponent(component.PhysicalSectionForceOccupied)
|
|
}
|
|
}
|
|
return ecs.NewOkEmptyResult()
|
|
})
|
|
return r.Err
|
|
}
|
|
|
|
// PhysicalSectionDrstDrive 直接复位
|
|
func PhysicalSectionDrstDrive(w ecs.World, sectionId string) (*PhysicalSectionState, error) {
|
|
r := <-ecs.Request[*PhysicalSectionState](w, func() ecs.Result[*PhysicalSectionState] {
|
|
wd := entity.GetWorldData(w)
|
|
entry := wd.EntityMap[sectionId]
|
|
if entry == nil {
|
|
return ecs.NewResult[*PhysicalSectionState](nil, fmt.Errorf("区段[%s]实体不存在", sectionId))
|
|
}
|
|
axleManager := component.PhysicalSectionManagerType.Get(entry)
|
|
state := &PhysicalSectionState{}
|
|
if axleManager.Count != 0 {
|
|
state.Rjo = true
|
|
} else {
|
|
entry.RemoveComponent(component.PhysicalSectionForceOccupied)
|
|
state.Rac = true
|
|
}
|
|
return ecs.NewOkResult(state)
|
|
})
|
|
return r.Val, r.Err
|
|
}
|
|
|
|
// PhysicalSectionPdrstDrive 预复位
|
|
func PhysicalSectionPdrstDrive(w ecs.World, sectionId string) (*PhysicalSectionState, error) {
|
|
r := <-ecs.Request[*PhysicalSectionState](w, func() ecs.Result[*PhysicalSectionState] {
|
|
wd := entity.GetWorldData(w)
|
|
entry := wd.EntityMap[sectionId]
|
|
if entry == nil {
|
|
return ecs.NewResult[*PhysicalSectionState](nil, fmt.Errorf("区段[%s]实体不存在", sectionId))
|
|
}
|
|
axleManager := component.PhysicalSectionManagerType.Get(entry)
|
|
state := &PhysicalSectionState{}
|
|
if axleManager.Count != 0 {
|
|
state.Rjo = true
|
|
} else {
|
|
state.Rac = true
|
|
}
|
|
return ecs.NewOkResult(state)
|
|
})
|
|
return r.Val, r.Err
|
|
}
|
|
|
|
// FindPhysicalSectionsStatus 获取物理区段的相关状态
|
|
func FindPhysicalSectionsStatus(w ecs.World, sectionIds []string) ([]*PhysicalSectionState, error) {
|
|
r := <-ecs.Request[[]*PhysicalSectionState](w, func() ecs.Result[[]*PhysicalSectionState] {
|
|
wd := entity.GetWorldData(w)
|
|
var msg []*PhysicalSectionState
|
|
var esb = strings.Builder{} //收集未找到的区段的id
|
|
for _, sectionId := range sectionIds {
|
|
entry := wd.EntityMap[sectionId]
|
|
if entry == nil {
|
|
esb.WriteString(fmt.Sprintf("%s,", sectionId))
|
|
continue
|
|
}
|
|
axleManager := component.PhysicalSectionManagerType.Get(entry)
|
|
msg = append(msg, &PhysicalSectionState{
|
|
Id: sectionId,
|
|
Clr: !axleManager.Occupied,
|
|
Occ: axleManager.Occupied,
|
|
})
|
|
}
|
|
if esb.Len() > 0 {
|
|
return ecs.NewResult(msg, fmt.Errorf("区段非物理区段或物理区段状态不存在:[%s]", esb.String()))
|
|
} else {
|
|
return ecs.NewResult(msg, nil)
|
|
}
|
|
})
|
|
return r.Val, r.Err
|
|
}
|
|
|
|
type PhysicalSectionState struct {
|
|
//uid
|
|
Id string
|
|
//0-bit7 区段出清
|
|
Clr bool
|
|
//0-bit6 区段占用
|
|
Occ bool
|
|
//1-bit6 区段复位反馈
|
|
Rac bool
|
|
//1-bit5 运营原因拒绝计轴复位
|
|
Rjo bool
|
|
//1-bit4 技术原因拒绝计轴复位
|
|
Rjt bool
|
|
}
|