计轴区段ecs
This commit is contained in:
parent
5c39cd418d
commit
dccb6164f4
@ -10,6 +10,10 @@ type AxleSectionState struct {
|
|||||||
Clr bool
|
Clr bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAxleSectionState() *AxleSectionState {
|
||||||
|
return &AxleSectionState{Clr: true, Occ: false}
|
||||||
|
}
|
||||||
|
|
||||||
//计轴直接复位:计轴的轮对计数清零,区段转换为空闲状态
|
//计轴直接复位:计轴的轮对计数清零,区段转换为空闲状态
|
||||||
//计轴预复位:将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
|
//计轴预复位:将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
|
||||||
//
|
//
|
||||||
@ -32,6 +36,10 @@ type AxleSectionDevice struct {
|
|||||||
Pdrst bool
|
Pdrst bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAxleSectionDevice() *AxleSectionDevice {
|
||||||
|
return &AxleSectionDevice{Rac: false, Rjo: false, Rjt: false, Drst: false, Pdrst: false}
|
||||||
|
}
|
||||||
|
|
||||||
// AxleSectionRuntime 计轴区段相关运算中间数据
|
// AxleSectionRuntime 计轴区段相关运算中间数据
|
||||||
type AxleSectionRuntime struct {
|
type AxleSectionRuntime struct {
|
||||||
//true-计轴系统正在执行直接预复位操作
|
//true-计轴系统正在执行直接预复位操作
|
||||||
@ -46,8 +54,13 @@ type AxleSectionRuntime struct {
|
|||||||
CountLast int16
|
CountLast int16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAxleSectionRuntime() *AxleSectionRuntime {
|
||||||
|
return &AxleSectionRuntime{DoingPdrst: false, CountTrainInPulse: false, CountTrainOutPulse: false, Count: 0, CountLast: 0}
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
AxleSectionStateType = ecs.NewComponentType[AxleSectionState]()
|
AxleSectionStateType = ecs.NewComponentType[AxleSectionState]()
|
||||||
AxleSectionDeviceType = ecs.NewComponentType[AxleSectionDevice]()
|
AxleSectionDeviceType = ecs.NewComponentType[AxleSectionDevice]()
|
||||||
AxleSectionRuntimeType = ecs.NewComponentType[AxleSectionRuntime]()
|
AxleSectionRuntimeType = ecs.NewComponentType[AxleSectionRuntime]()
|
||||||
|
AxleSectionTag = ecs.NewTag()
|
||||||
)
|
)
|
||||||
|
@ -34,5 +34,10 @@ func Load(w ecs.World, repo *repository.Repository) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// 加载计轴区段相关实体
|
||||||
|
err = LoadAxleSections(w)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
32
entity/section.go
Normal file
32
entity/section.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LoadAxleSections 加载计轴区段
|
||||||
|
func LoadAxleSections(w ecs.World) error {
|
||||||
|
data := GetWorldData(w)
|
||||||
|
sections := data.Repo.PhysicalSectionList()
|
||||||
|
for _, section := range sections {
|
||||||
|
if is, se := section.IsAxleSection(); se == nil && is {
|
||||||
|
newAxleSectionEntity(w, section, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func newAxleSectionEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
||||||
|
uid := axleSection.Id()
|
||||||
|
entry, ok := worldData.EntityMap[uid]
|
||||||
|
if !ok {
|
||||||
|
entry = w.Entry(w.Create(component.UidType, component.AxleSectionTag, component.AxleSectionStateType, component.AxleSectionDeviceType, component.AxleSectionRuntimeType))
|
||||||
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||||||
|
component.AxleSectionStateType.Set(entry, component.NewAxleSectionState())
|
||||||
|
component.AxleSectionDeviceType.Set(entry, component.NewAxleSectionDevice())
|
||||||
|
component.AxleSectionRuntimeType.Set(entry, component.NewAxleSectionRuntime())
|
||||||
|
worldData.EntityMap[uid] = entry
|
||||||
|
}
|
||||||
|
return entry
|
||||||
|
}
|
@ -77,6 +77,26 @@ func (s *PhysicalSection) BKilometer() *proto.Kilometer {
|
|||||||
return s.bKm
|
return s.bKm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAxleSection 判断是否为计轴区段
|
||||||
|
func (s *PhysicalSection) IsAxleSection() (bool, error) {
|
||||||
|
if len(s.checkPoints) > 0 {
|
||||||
|
axleCount := 0
|
||||||
|
for _, cp := range s.checkPoints {
|
||||||
|
if cp.pointType == proto.CheckPointType_AxleCounter {
|
||||||
|
axleCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if axleCount == len(s.checkPoints) {
|
||||||
|
return true, nil
|
||||||
|
} else if axleCount == 0 {
|
||||||
|
return false, nil
|
||||||
|
} else { //axleCount>0&&axleCount<len(s.checkPoints)
|
||||||
|
return false, fmt.Errorf("物理区段中检测点不纯")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false, fmt.Errorf("物理区段没有检测点")
|
||||||
|
}
|
||||||
|
}
|
||||||
func (s *PhysicalSection) bindDevicePort(port proto.Port, devicePort DevicePort) error {
|
func (s *PhysicalSection) bindDevicePort(port proto.Port, devicePort DevicePort) error {
|
||||||
_, isSectionPort := devicePort.(*PhysicalSectionPort)
|
_, isSectionPort := devicePort.(*PhysicalSectionPort)
|
||||||
_, isTurnoutPort := devicePort.(*TurnoutPort)
|
_, isTurnoutPort := devicePort.(*TurnoutPort)
|
||||||
|
@ -37,5 +37,7 @@ func BindSystem(w ecs.World) {
|
|||||||
// IBP
|
// IBP
|
||||||
circuit_sys.NewIBPSys(),
|
circuit_sys.NewIBPSys(),
|
||||||
device_sys.NewAlarmSys(),
|
device_sys.NewAlarmSys(),
|
||||||
|
//物理区段
|
||||||
|
device_sys.NewAxleSectionSystem(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user