diff --git a/component/axle_device.go b/component/axle_device.go index e33d961..6a44b54 100644 --- a/component/axle_device.go +++ b/component/axle_device.go @@ -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]() diff --git a/entity/fadc_axle.go b/entity/fadc_axle.go index 31c2b97..e36c4f4 100644 --- a/entity/fadc_axle.go +++ b/entity/fadc_axle.go @@ -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 { diff --git a/entity/init.go b/entity/init.go index 97be716..6bb3521 100644 --- a/entity/init.go +++ b/entity/init.go @@ -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 } diff --git a/fi/section.go b/fi/section.go index 5672d5e..d321762 100644 --- a/fi/section.go +++ b/fi/section.go @@ -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 +} diff --git a/sys/bind.go b/sys/bind.go index e466f67..963fa23 100644 --- a/sys/bind.go +++ b/sys/bind.go @@ -38,6 +38,6 @@ func BindSystem(w ecs.World) { circuit_sys.NewIBPSys(), device_sys.NewAlarmSys(), //物理区段 - //device_sys.NewFaDcAxleDeviceSystem(), + device_sys.NewFaDcAxleDeviceSystem(), ) } diff --git a/sys/device_sys/fadc_axle_device.go b/sys/device_sys/fadc_axle_device.go index c2594d1..e6d0d64 100644 --- a/sys/device_sys/fadc_axle_device.go +++ b/sys/device_sys/fadc_axle_device.go @@ -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 } // 计算计轴区段状态