2023-10-24 10:19:50 +08:00
|
|
|
|
package fi
|
2023-11-01 11:08:24 +08:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-11-07 13:22:39 +08:00
|
|
|
|
"strings"
|
2023-11-01 11:08:24 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-06 14:35:32 +08:00
|
|
|
|
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
|
|
|
|
|
|
|
|
|
if faDcAxleDeviceEntry == nil {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]实体不存在", sectionModel.CentralizedStation()))
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
2023-11-06 14:35:32 +08:00
|
|
|
|
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
2023-11-06 15:30:57 +08:00
|
|
|
|
axleRuntime := faDcAxleDevice.FindAdr(sectionId)
|
|
|
|
|
if axleRuntime == nil {
|
2023-11-06 14:35:32 +08:00
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴设备", sectionModel.CentralizedStation(), sectionId))
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-06 14:35:32 +08:00
|
|
|
|
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
|
|
|
|
|
|
|
|
|
if faDcAxleDeviceEntry == nil {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]实体不存在", sectionModel.CentralizedStation()))
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
2023-11-06 14:35:32 +08:00
|
|
|
|
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
|
|
|
|
axleRuntime, ok := faDcAxleDevice.Adrs[sectionId]
|
|
|
|
|
if !ok {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴设备", sectionModel.CentralizedStation(), sectionId))
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-06 14:35:32 +08:00
|
|
|
|
sectionEntry := wd.EntityMap[sectionId]
|
|
|
|
|
if sectionEntry == nil {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
2023-11-06 14:35:32 +08:00
|
|
|
|
axleDevice := component.AxlePhysicalSectionType.Get(sectionEntry)
|
|
|
|
|
if set { //计轴故障设置
|
|
|
|
|
if !sectionEntry.HasComponent(component.AxleSectionFaultTag) {
|
|
|
|
|
sectionEntry.AddComponent(component.AxleSectionFaultTag)
|
|
|
|
|
}
|
|
|
|
|
axleDevice.UpdateCount(1)
|
|
|
|
|
} else { //计轴故障取消
|
|
|
|
|
if sectionEntry.HasComponent(component.AxleSectionFaultTag) {
|
|
|
|
|
sectionEntry.RemoveComponent(component.AxleSectionFaultTag)
|
|
|
|
|
}
|
|
|
|
|
axleDevice.UpdateCount(0)
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-06 14:35:32 +08:00
|
|
|
|
sectionEntry := wd.EntityMap[sectionId]
|
|
|
|
|
if sectionEntry == nil {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
2023-11-06 14:35:32 +08:00
|
|
|
|
axleDevice := component.AxlePhysicalSectionType.Get(sectionEntry)
|
2023-11-01 11:08:24 +08:00
|
|
|
|
if trainIn {
|
2023-11-06 14:35:32 +08:00
|
|
|
|
axleDevice.UpdateCount(1)
|
2023-11-01 11:08:24 +08:00
|
|
|
|
} else {
|
2023-11-06 14:35:32 +08:00
|
|
|
|
axleDevice.UpdateCount(0)
|
2023-11-01 11:08:24 +08:00
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
2023-11-07 13:22:39 +08:00
|
|
|
|
|
|
|
|
|
// FindAxleSectionsStatus 获取计轴区段的相关状态
|
|
|
|
|
func FindAxleSectionsStatus(w ecs.World, sectionIds []string) ([]*AxleSectionState, error) {
|
|
|
|
|
r := <-ecs.Request[[]*AxleSectionState](w, func() ecs.Result[[]*AxleSectionState] {
|
|
|
|
|
wd := entity.GetWorldData(w)
|
|
|
|
|
var msg []*AxleSectionState
|
|
|
|
|
var esb = strings.Builder{} //收集未找到的区段的id
|
|
|
|
|
for _, sectionId := range sectionIds {
|
|
|
|
|
find := false
|
|
|
|
|
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
|
|
|
|
if sectionModel != nil {
|
|
|
|
|
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
|
|
|
|
if faDcAxleDeviceEntry != nil {
|
|
|
|
|
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
|
|
|
|
axleDevice := faDcAxleDevice.FindAdr(sectionId)
|
|
|
|
|
if axleDevice != nil {
|
|
|
|
|
sectionEntry, _ := entity.GetEntityByUid(w, sectionId)
|
|
|
|
|
if sectionEntry != nil {
|
|
|
|
|
if sectionEntry.HasComponent(component.AxlePhysicalSectionType) { //计轴物理区段实体
|
|
|
|
|
as := &AxleSectionState{}
|
|
|
|
|
state := component.PhysicalSectionStateType.Get(sectionEntry)
|
2023-11-07 17:47:41 +08:00
|
|
|
|
as.Id = component.UidType.Get(sectionEntry).Id
|
2023-11-07 13:22:39 +08:00
|
|
|
|
as.Clr = !state.Occ
|
|
|
|
|
as.Occ = state.Occ
|
|
|
|
|
as.Rac = axleDevice.Rac
|
|
|
|
|
as.Rjt = axleDevice.Rjt
|
|
|
|
|
as.Rjo = axleDevice.Rjo
|
|
|
|
|
//
|
|
|
|
|
msg = append(msg, as)
|
|
|
|
|
find = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
if !find {
|
|
|
|
|
esb.WriteString(fmt.Sprintf("%s,", sectionId))
|
|
|
|
|
}
|
|
|
|
|
} //for
|
|
|
|
|
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 AxleSectionState struct {
|
2023-11-07 17:47:41 +08:00
|
|
|
|
//uid
|
|
|
|
|
Id string
|
2023-11-07 13:22:39 +08:00
|
|
|
|
//0-bit7 计轴出清
|
|
|
|
|
Clr bool
|
|
|
|
|
//0-bit6 计轴占用
|
|
|
|
|
Occ bool
|
|
|
|
|
//1-bit6 计轴复位反馈
|
|
|
|
|
Rac bool
|
|
|
|
|
//1-bit5 运营原因拒绝计轴复位
|
|
|
|
|
Rjo bool
|
|
|
|
|
//1-bit4 技术原因拒绝计轴复位
|
|
|
|
|
Rjt bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AxleSectionRstDrive 复位(直接复位、预复位)
|
|
|
|
|
func AxleSectionRstDrive(w ecs.World, cmds []*AxleSectionCmd) error {
|
|
|
|
|
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
|
|
|
|
wd := entity.GetWorldData(w)
|
|
|
|
|
var esb = strings.Builder{} //收集未找到的区段的id
|
|
|
|
|
find := false
|
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
|
sectionId := cmd.SectionId
|
|
|
|
|
sectionModel := wd.Repo.FindPhysicalSection(sectionId)
|
|
|
|
|
if sectionModel != nil {
|
|
|
|
|
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
|
|
|
|
if faDcAxleDeviceEntry != nil {
|
|
|
|
|
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
|
|
|
|
axleRuntime := faDcAxleDevice.FindAdr(sectionId)
|
|
|
|
|
if axleRuntime != nil {
|
|
|
|
|
axleRuntime.Pdrst = cmd.Pdrst
|
|
|
|
|
axleRuntime.Drst = cmd.Drst
|
|
|
|
|
find = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !find {
|
|
|
|
|
esb.WriteString(fmt.Sprintf("%s,", sectionId))
|
|
|
|
|
}
|
|
|
|
|
} //for
|
|
|
|
|
if esb.Len() > 0 {
|
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("计轴区段复位操作,失败列表[%s]", esb.String()))
|
|
|
|
|
} else {
|
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return r.Err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AxleSectionCmd struct {
|
|
|
|
|
SectionId string
|
|
|
|
|
Drst bool
|
|
|
|
|
Pdrst bool
|
|
|
|
|
}
|