Merge remote-tracking branch 'origin/master'

This commit is contained in:
joylink_zhangsai 2023-10-24 09:06:24 +08:00
commit 3c65650745
5 changed files with 72 additions and 0 deletions

View File

@ -10,6 +10,10 @@ type AxleSectionState struct {
Clr bool
}
func NewAxleSectionState() *AxleSectionState {
return &AxleSectionState{Clr: true, Occ: false}
}
//计轴直接复位:计轴的轮对计数清零,区段转换为空闲状态
//计轴预复位:将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
//
@ -32,6 +36,10 @@ type AxleSectionDevice struct {
Pdrst bool
}
func NewAxleSectionDevice() *AxleSectionDevice {
return &AxleSectionDevice{Rac: false, Rjo: false, Rjt: false, Drst: false, Pdrst: false}
}
// AxleSectionRuntime 计轴区段相关运算中间数据
type AxleSectionRuntime struct {
//true-计轴系统正在执行直接预复位操作
@ -46,8 +54,13 @@ type AxleSectionRuntime struct {
CountLast int16
}
func NewAxleSectionRuntime() *AxleSectionRuntime {
return &AxleSectionRuntime{DoingPdrst: false, CountTrainInPulse: false, CountTrainOutPulse: false, Count: 0, CountLast: 0}
}
var (
AxleSectionStateType = ecs.NewComponentType[AxleSectionState]()
AxleSectionDeviceType = ecs.NewComponentType[AxleSectionDevice]()
AxleSectionRuntimeType = ecs.NewComponentType[AxleSectionRuntime]()
AxleSectionTag = ecs.NewTag()
)

View File

@ -34,5 +34,10 @@ func Load(w ecs.World, repo *repository.Repository) error {
if err != nil {
return err
}
// 加载计轴区段相关实体
err = LoadAxleSections(w)
if err != nil {
return err
}
return err
}

32
entity/section.go Normal file
View 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
}

View File

@ -77,6 +77,26 @@ func (s *PhysicalSection) BKilometer() *proto.Kilometer {
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 {
_, isSectionPort := devicePort.(*PhysicalSectionPort)
_, isTurnoutPort := devicePort.(*TurnoutPort)

View File

@ -37,5 +37,7 @@ func BindSystem(w ecs.World) {
// IBP
circuit_sys.NewIBPSys(),
device_sys.NewAlarmSys(),
//物理区段
device_sys.NewAxleSectionSystem(),
)
}