计轴区段

This commit is contained in:
xzb 2023-11-01 11:08:24 +08:00
parent 8743d68657
commit a612c78c4e
6 changed files with 173 additions and 19 deletions

View File

@ -1,6 +1,9 @@
package component
import "joylink.club/ecs"
import (
"fmt"
"joylink.club/ecs"
)
//计轴设备,管理联锁集中站内的所有计轴区段
//计轴直接复位:计轴的轮对计数清零,区段转换为空闲状态
@ -47,6 +50,9 @@ func (c *AxleCounter) UpdateCount(count int) {
func (c *AxleCounter) ResetCountPulse() {
c.countPulse = 0x00
}
func (c *AxleCounter) ShowCountWave() string {
return fmt.Sprintf("%08b", c.countPulse)
}
// IsCount010Pulse true-车进入计轴区段后出清计轴区段
func (c *AxleCounter) IsCount010Pulse() bool {
@ -85,6 +91,9 @@ func (f *FaDcAxleDevice) AddAxleSection(counter *ecs.Entry, section *ecs.Entry)
f.Sections = append(f.Sections, section)
f.CounterMap[AxleSectionFlag.Get(counter).Id] = counter
}
func (f *FaDcAxleDevice) GetAxleCounterEntry(sectionId string) *ecs.Entry {
return f.CounterMap[sectionId]
}
var (
FaDcAxleDeviceType = ecs.NewComponentType[FaDcAxleDevice]()

View File

@ -17,6 +17,7 @@ func LoadAxlePhysicalSections(w ecs.World) error {
if len(strings.TrimSpace(section.CentralizedStation())) == 0 {
return fmt.Errorf("区段[%s]未设置所属集中站", section.Id())
}
//fmt.Println("=====>>>>>计轴区段:", section.Id())
fadcDeviceId := CreateFaDcAxleDeviceId(section.CentralizedStation())
fadcDeviceEntry, find := data.EntityMap[fadcDeviceId]
if !find {

View File

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

View File

@ -1 +1,137 @@
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
}

View File

@ -38,6 +38,6 @@ func BindSystem(w ecs.World) {
circuit_sys.NewIBPSys(),
device_sys.NewAlarmSys(),
//物理区段
//device_sys.NewFaDcAxleDeviceSystem(),
device_sys.NewFaDcAxleDeviceSystem(),
)
}

View File

@ -29,6 +29,25 @@ func (s *FaDcAxleDeviceSystem) Update(w ecs.World) {
s.calculateSectionState(axleCounterEntry, axleSectionEntry)
s.calculateHf(axleCounterEntry, axleSectionEntry)
s.calculateAxleCount(axleCounterEntry, axleSectionEntry)
/*
if "北京_12_酒仙桥_12G" == axleSectionId {
section := component.AxleSectionType.Get(axleSectionEntry)
counter := component.AxleCounterType.Get(axleCounterEntry)
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
slog.Info(axleSectionId,
"Drst", counterRt.Drst,
"Pdrst", counterRt.Pdrst,
"DoingPdrst", counterRt.DoingPdrst,
"Rac", counterRt.Rac,
"Rjo", counterRt.Rjo,
"Rjt", counterRt.Rjt,
"SectionFault", sectionFault.SectionFault,
"Occ", section.Occ,
"Count", counter.Count,
"Wave", counter.ShowCountWave())
}
*/
}
})
}
@ -36,17 +55,8 @@ func (s *FaDcAxleDeviceSystem) Update(w ecs.World) {
// 计算计轴区段内车轴数
// 目前通过查看有哪些车在该计轴区段内实现,定性
func (s *FaDcAxleDeviceSystem) calculateAxleCount(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
counter := component.AxleCounterType.Get(axleCounterEntry)
if sectionFault.SectionFault { //设置计轴故障
counter.UpdateCount(1)
} else {
//取消计轴故障
counter.UpdateCount(0)
//检查该区段内有没有车
// ...todo
}
//检查该区段内有没有车
// ...todo
}
// 计算计轴区段状态