Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation
This commit is contained in:
commit
13af2d6ff9
@ -12,54 +12,20 @@ import (
|
||||
//当CI系统给计轴设备发送计轴直接复零/预复零命令时,连续发送一定时间(具体发送时间调试后确定)的复零/预复零命令。
|
||||
//当RAC,RJO,RJT任意一个不为0时,终止发送复零/预复零命令。
|
||||
|
||||
// AxleSection 计轴物理区段状态
|
||||
type AxleSection struct {
|
||||
// PhysicalSectionState 物理区段
|
||||
type PhysicalSectionState struct {
|
||||
//true-占用,false-出清
|
||||
Occ bool
|
||||
}
|
||||
|
||||
// AxleSectionFault 计轴区段故障
|
||||
type AxleSectionFault struct {
|
||||
//true-设置区段故障占用,false-取消区段故障占用
|
||||
SectionFault bool
|
||||
}
|
||||
|
||||
// AxleCounter 计轴区段计轴器
|
||||
type AxleCounter struct {
|
||||
// AxlePhysicalSection 计轴物理区段
|
||||
type AxlePhysicalSection struct {
|
||||
//计轴区段内车轴数
|
||||
Count int
|
||||
//记录Count变化波形
|
||||
countPulse uint8
|
||||
}
|
||||
|
||||
func NewAxleCounter() *AxleCounter {
|
||||
return &AxleCounter{Count: 0, countPulse: 0}
|
||||
}
|
||||
func (c *AxleCounter) UpdateCount(count int) {
|
||||
cp := to1(c.Count)
|
||||
np := to1(count)
|
||||
//
|
||||
if cp != np {
|
||||
c.countPulse <<= 1
|
||||
if np > 0 {
|
||||
c.countPulse |= np
|
||||
}
|
||||
}
|
||||
c.Count = count
|
||||
}
|
||||
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 {
|
||||
return c.countPulse&0x01 == 0 && c.countPulse&0x02 > 0 && c.countPulse&0x04 == 0
|
||||
}
|
||||
|
||||
type AxleCounterRuntime struct {
|
||||
type AxleDeviceRuntime struct {
|
||||
//true-计轴复位反馈,表示计轴设备已收到CI系统发送的直接复零/预复零命令。
|
||||
Rac bool
|
||||
//true-运营原因拒绝计轴复位,如区段空闲时下发复位命令;或车轮压住传感器时收到复位命令。
|
||||
@ -76,34 +42,59 @@ type AxleCounterRuntime struct {
|
||||
DoingPdrst bool
|
||||
}
|
||||
|
||||
// FaDcAxleDevice 车站计轴管理设备
|
||||
type FaDcAxleDevice struct {
|
||||
//区段计轴器列表,实体(AxleCounterType,AxleCounterRuntimeType,AxleSectionFlag)
|
||||
Counters []*ecs.Entry
|
||||
//计轴区段实体列表,实体(AxleSectionType,AxleSectionFaultType)
|
||||
Sections []*ecs.Entry
|
||||
//key-section id ,value-counter
|
||||
CounterMap map[string]*ecs.Entry
|
||||
func NewAxleDeviceRuntime() *AxleDeviceRuntime {
|
||||
return &AxleDeviceRuntime{}
|
||||
}
|
||||
|
||||
func (f *FaDcAxleDevice) AddAxleSection(counter *ecs.Entry, section *ecs.Entry) {
|
||||
f.Counters = append(f.Counters, counter)
|
||||
f.Sections = append(f.Sections, section)
|
||||
f.CounterMap[AxleSectionFlag.Get(counter).Id] = counter
|
||||
// AxleManageDevice 计轴管理设备
|
||||
type AxleManageDevice struct {
|
||||
CentralizedStation string //所属集中站
|
||||
Adrs map[string]*AxleDeviceRuntime //key-sectionId
|
||||
}
|
||||
func (f *FaDcAxleDevice) GetAxleCounterEntry(sectionId string) *ecs.Entry {
|
||||
return f.CounterMap[sectionId]
|
||||
|
||||
func (d *AxleManageDevice) FindAdr(sectionId string) *AxleDeviceRuntime {
|
||||
return d.Adrs[sectionId]
|
||||
}
|
||||
func NewAxleManageDevice(centralizedStation string) *AxleManageDevice {
|
||||
return &AxleManageDevice{CentralizedStation: centralizedStation, Adrs: make(map[string]*AxleDeviceRuntime)}
|
||||
}
|
||||
|
||||
var (
|
||||
FaDcAxleDeviceType = ecs.NewComponentType[FaDcAxleDevice]()
|
||||
AxleSectionFaultType = ecs.NewComponentType[AxleSectionFault]()
|
||||
AxleSectionType = ecs.NewComponentType[AxleSection]()
|
||||
AxleCounterType = ecs.NewComponentType[AxleCounter]()
|
||||
AxleCounterRuntimeType = ecs.NewComponentType[AxleCounterRuntime]()
|
||||
AxleSectionFlag = ecs.NewComponentType[Uid]() //计轴区段id
|
||||
PhysicalSectionStateType = ecs.NewComponentType[PhysicalSectionState]()
|
||||
AxlePhysicalSectionType = ecs.NewComponentType[AxlePhysicalSection]()
|
||||
AxleSectionFaultTag = ecs.NewTag()
|
||||
AxleManageDeviceType = ecs.NewComponentType[AxleManageDevice]()
|
||||
)
|
||||
|
||||
/////////////////////////////AxlePhysicalSection/////////////////////////////////
|
||||
|
||||
func NewAxlePhysicalSection() *AxlePhysicalSection {
|
||||
return &AxlePhysicalSection{Count: 0, countPulse: 0}
|
||||
}
|
||||
func (c *AxlePhysicalSection) UpdateCount(count int) {
|
||||
cp := to1(c.Count)
|
||||
np := to1(count)
|
||||
//
|
||||
if cp != np {
|
||||
c.countPulse <<= 1
|
||||
if np > 0 {
|
||||
c.countPulse |= np
|
||||
}
|
||||
}
|
||||
c.Count = count
|
||||
}
|
||||
func (c *AxlePhysicalSection) ResetCountPulse() {
|
||||
c.countPulse = 0x00
|
||||
}
|
||||
func (c *AxlePhysicalSection) ShowCountWave() string {
|
||||
return fmt.Sprintf("%08b", c.countPulse)
|
||||
}
|
||||
|
||||
// IsCount010Pulse true-车进入计轴区段后出清计轴区段
|
||||
func (c *AxlePhysicalSection) IsCount010Pulse() bool {
|
||||
return c.countPulse&0x01 == 0 && c.countPulse&0x02 > 0 && c.countPulse&0x04 == 0
|
||||
}
|
||||
|
||||
// 归1
|
||||
func to1(c int) uint8 {
|
||||
if c > 0 {
|
@ -1,6 +1,7 @@
|
||||
package component
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component/component_proto"
|
||||
)
|
||||
@ -30,6 +31,20 @@ type PsdInterlockDriveCircuit struct {
|
||||
KMJ8 bool
|
||||
}
|
||||
|
||||
var AsdCannotOpenTag = ecs.NewTag()
|
||||
var AsdCannotCloseTag = ecs.NewTag()
|
||||
|
||||
func GetAsdFaultTag(fault component_proto.Psd_Fault) (ecs.IComponentType, error) {
|
||||
switch fault {
|
||||
case component_proto.Psd_AsdCannotClose:
|
||||
return AsdCannotCloseTag, nil
|
||||
case component_proto.Psd_AsdCannotOpen:
|
||||
return AsdCannotOpenTag, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("未知的屏蔽门故障类型[%s]", fault)
|
||||
}
|
||||
}
|
||||
|
||||
var AsdTag = ecs.NewTag()
|
||||
var AsdListType = ecs.NewComponentType[AsdList]()
|
||||
|
||||
|
@ -21,6 +21,8 @@ type WorldData struct {
|
||||
EntityMap map[string]*ecs.Entry
|
||||
// 联锁驱采卡实体
|
||||
CiQcEntities []*ecs.Entry
|
||||
// 集中站计轴管理设备实体
|
||||
AxleManageDeviceEntities []*ecs.Entry
|
||||
}
|
||||
|
||||
// 是否在驱动码表中
|
||||
|
@ -8,6 +8,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func newAxleManageDevice(w ecs.World, data *component.WorldData, centralizedStation string) *ecs.Entry {
|
||||
entry := w.Entry(w.Create(component.AxleManageDeviceType))
|
||||
component.AxleManageDeviceType.Set(entry, component.NewAxleManageDevice(centralizedStation))
|
||||
data.AxleManageDeviceEntities = append(data.AxleManageDeviceEntities, entry)
|
||||
return entry
|
||||
}
|
||||
|
||||
// LoadAxlePhysicalSections 加载计轴区段
|
||||
func LoadAxlePhysicalSections(w ecs.World) error {
|
||||
data := GetWorldData(w)
|
||||
@ -17,35 +24,27 @@ 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 {
|
||||
fadcDeviceEntry = createFadcDeviceEntity(w, section, data)
|
||||
data.EntityMap[fadcDeviceId] = fadcDeviceEntry
|
||||
amdEntry := FindAxleManageDevice(data, section.CentralizedStation())
|
||||
if amdEntry == nil {
|
||||
amdEntry = newAxleManageDevice(w, data, section.CentralizedStation())
|
||||
}
|
||||
fadcDevice := component.FaDcAxleDeviceType.Get(fadcDeviceEntry)
|
||||
counter := createAxleCounterEntity(w, section, data)
|
||||
axleSec := createAxleSectionEntity(w, section, data)
|
||||
fadcDevice.AddAxleSection(counter, axleSec)
|
||||
amd := component.AxleManageDeviceType.Get(amdEntry)
|
||||
//
|
||||
createAxleSectionEntity(w, section, data)
|
||||
//
|
||||
amd.Adrs[section.Id()] = component.NewAxleDeviceRuntime()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 联锁集中站计轴管理设备实体
|
||||
func createFadcDeviceEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
||||
uid := CreateFaDcAxleDeviceId(axleSection.CentralizedStation())
|
||||
entry, ok := worldData.EntityMap[uid]
|
||||
if !ok {
|
||||
entry = w.Entry(w.Create(component.UidType, component.FaDcAxleDeviceType))
|
||||
//
|
||||
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||||
component.FaDcAxleDeviceType.Set(entry, &component.FaDcAxleDevice{CounterMap: make(map[string]*ecs.Entry)})
|
||||
//
|
||||
worldData.EntityMap[uid] = entry
|
||||
func FindAxleManageDevice(data *component.WorldData, centralizedStation string) *ecs.Entry {
|
||||
for _, entry := range data.AxleManageDeviceEntities {
|
||||
amd := component.AxleManageDeviceType.Get(entry)
|
||||
if amd != nil && amd.CentralizedStation == centralizedStation {
|
||||
return entry
|
||||
}
|
||||
}
|
||||
return entry
|
||||
return nil
|
||||
}
|
||||
|
||||
// 计轴区段实体
|
||||
@ -53,27 +52,13 @@ func createAxleSectionEntity(w ecs.World, axleSection *repository.PhysicalSectio
|
||||
uid := axleSection.Id()
|
||||
entry, ok := worldData.EntityMap[uid]
|
||||
if !ok {
|
||||
entry = w.Entry(w.Create(component.UidType, component.AxleSectionType, component.AxleSectionFaultType))
|
||||
entry = w.Entry(w.Create(component.UidType, component.PhysicalSectionStateType, component.AxlePhysicalSectionType))
|
||||
//
|
||||
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||||
component.AxleSectionType.Set(entry, &component.AxleSection{Occ: false})
|
||||
component.AxleSectionFaultType.Set(entry, &component.AxleSectionFault{SectionFault: false})
|
||||
component.PhysicalSectionStateType.Set(entry, &component.PhysicalSectionState{Occ: false})
|
||||
component.AxlePhysicalSectionType.Set(entry, component.NewAxlePhysicalSection())
|
||||
//
|
||||
worldData.EntityMap[uid] = entry
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
// 计轴器实体
|
||||
func createAxleCounterEntity(w ecs.World, axleSection *repository.PhysicalSection, worldData *component.WorldData) *ecs.Entry {
|
||||
entry := w.Entry(w.Create(component.AxleCounterType, component.AxleCounterRuntimeType, component.AxleSectionFlag))
|
||||
component.AxleCounterType.Set(entry, component.NewAxleCounter())
|
||||
component.AxleCounterRuntimeType.Set(entry, &component.AxleCounterRuntime{Rac: false, Rjo: false, Rjt: false, Drst: false, Pdrst: false, DoingPdrst: false})
|
||||
component.AxleSectionFlag.SetValue(entry, component.Uid{Id: axleSection.Id()})
|
||||
return entry
|
||||
}
|
||||
|
||||
// CreateFaDcAxleDeviceId 设备集中站计轴管理设备id(通过联锁集中站centralizedStation来构建)
|
||||
func CreateFaDcAxleDeviceId(centralizedStation string) string {
|
||||
return fmt.Sprintf("fadc-axle-device-%s", centralizedStation)
|
||||
}
|
||||
|
43
fi/psd.go
43
fi/psd.go
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/component/component_proto"
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
)
|
||||
|
||||
@ -91,6 +92,48 @@ func CancelInterlockGm(world ecs.World, id string) error {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func SetPsdFault(world ecs.World, id string, fault component_proto.Psd_Fault, asdCodes []int32) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(world)
|
||||
psdEntry, ok := wd.EntityMap[id]
|
||||
if !ok {
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
|
||||
}
|
||||
tag, err := component.GetAsdFaultTag(fault)
|
||||
if err != nil {
|
||||
return ecs.NewErrResult(err)
|
||||
}
|
||||
asdList := component.AsdListType.Get(psdEntry).List
|
||||
for _, code := range asdCodes {
|
||||
asdEntry := asdList[int(code-1)]
|
||||
asdEntry.AddComponent(tag)
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func CancelPsdFault(world ecs.World, id string, fault component_proto.Psd_Fault, asdCodes []int32) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(world)
|
||||
psdEntry, ok := wd.EntityMap[id]
|
||||
if !ok {
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
|
||||
}
|
||||
tag, err := component.GetAsdFaultTag(fault)
|
||||
if err != nil {
|
||||
return ecs.NewErrResult(err)
|
||||
}
|
||||
asdList := component.AsdListType.Get(psdEntry).List
|
||||
for _, code := range asdCodes {
|
||||
asdEntry := asdList[int(code-1)]
|
||||
asdEntry.RemoveComponent(tag)
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func setPsdKm(psdEntry *ecs.Entry, group int) {
|
||||
if psdEntry.HasComponent(component.PsdInterlockDriveCircuitType) { //有联锁区段电路
|
||||
driveCircuit := component.PsdInterlockDriveCircuitType.Get(psdEntry)
|
||||
|
16
fi/relay.go
16
fi/relay.go
@ -30,8 +30,8 @@ func driveWjRelay(w ecs.World, entry *ecs.Entry, td bool) {
|
||||
}
|
||||
|
||||
// 驱动继电器到吸起位置
|
||||
func DriveRelayUp(w ecs.World, id string) {
|
||||
w.Execute(func() {
|
||||
func DriveRelayUp(w ecs.World, id string) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(w)
|
||||
entry, ok := wd.EntityMap[id]
|
||||
if ok {
|
||||
@ -41,14 +41,16 @@ func DriveRelayUp(w ecs.World, id string) {
|
||||
driveWjRelay(w, entry, true)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("未找到id=%s的继电器\n", id)
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的继电器", id))
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
||||
// 驱动继电器到落下位置
|
||||
func DriveRelayDown(w ecs.World, id string) {
|
||||
w.Execute(func() {
|
||||
func DriveRelayDown(w ecs.World, id string) error {
|
||||
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||||
wd := entity.GetWorldData(w)
|
||||
entry, ok := wd.EntityMap[id]
|
||||
if ok {
|
||||
@ -58,7 +60,9 @@ func DriveRelayDown(w ecs.World, id string) {
|
||||
driveWjRelay(w, entry, false)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("未找到id=%s的继电器\n", id)
|
||||
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的继电器", id))
|
||||
}
|
||||
return ecs.NewOkEmptyResult()
|
||||
})
|
||||
return result.Err
|
||||
}
|
||||
|
@ -18,17 +18,16 @@ func AxleSectionDrstDrive(w ecs.World, sectionId string, set bool) error {
|
||||
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))
|
||||
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
||||
|
||||
if faDcAxleDeviceEntry == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]实体不存在", sectionModel.CentralizedStation()))
|
||||
}
|
||||
//
|
||||
axleCounterEntry := component.FaDcAxleDeviceType.Get(faDcAxleDeviceEntry).GetAxleCounterEntry(sectionId)
|
||||
if axleCounterEntry == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴器实体", faDcAxleDeviceId, sectionId))
|
||||
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
||||
axleRuntime := faDcAxleDevice.FindAdr(sectionId)
|
||||
if axleRuntime == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴设备", sectionModel.CentralizedStation(), sectionId))
|
||||
}
|
||||
axleRuntime := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||||
axleRuntime.Drst = set
|
||||
//
|
||||
return ecs.NewOkEmptyResult()
|
||||
@ -47,17 +46,16 @@ func AxleSectionPdrstDrive(w ecs.World, sectionId string, set bool) error {
|
||||
return ecs.NewErrResult(fmt.Errorf("区段模型[%s]不存实体", sectionId))
|
||||
}
|
||||
//
|
||||
faDcAxleDeviceId := entity.CreateFaDcAxleDeviceId(sectionModel.CentralizedStation())
|
||||
faDcAxleDeviceEntry, ok := wd.EntityMap[faDcAxleDeviceId]
|
||||
faDcAxleDeviceEntry := entity.FindAxleManageDevice(wd, sectionModel.CentralizedStation())
|
||||
|
||||
if faDcAxleDeviceEntry == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]实体不存在", sectionModel.CentralizedStation()))
|
||||
}
|
||||
faDcAxleDevice := component.AxleManageDeviceType.Get(faDcAxleDeviceEntry)
|
||||
axleRuntime, ok := faDcAxleDevice.Adrs[sectionId]
|
||||
if !ok {
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]不存实体", faDcAxleDeviceId))
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴设备", sectionModel.CentralizedStation(), sectionId))
|
||||
}
|
||||
//
|
||||
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()
|
||||
@ -76,26 +74,21 @@ func AxleSectionFaultOccDrive(w ecs.World, sectionId string, set bool) error {
|
||||
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))
|
||||
sectionEntry := wd.EntityMap[sectionId]
|
||||
if sectionEntry == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
||||
}
|
||||
//
|
||||
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)
|
||||
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)
|
||||
}
|
||||
//
|
||||
return ecs.NewOkEmptyResult()
|
||||
@ -114,21 +107,15 @@ func AxleSectionTrainDrive(w ecs.World, sectionId string, trainIn bool) error {
|
||||
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))
|
||||
sectionEntry := wd.EntityMap[sectionId]
|
||||
if sectionEntry == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("区段[%s]实体不存在", sectionId))
|
||||
}
|
||||
//
|
||||
axleCounterEntry := component.FaDcAxleDeviceType.Get(faDcAxleDeviceEntry).GetAxleCounterEntry(sectionId)
|
||||
if axleCounterEntry == nil {
|
||||
return ecs.NewErrResult(fmt.Errorf("计轴管理设备[%s]中不存在区段[%s]的计轴器实体", faDcAxleDeviceId, sectionId))
|
||||
}
|
||||
axleCounter := component.AxleCounterType.Get(axleCounterEntry)
|
||||
axleDevice := component.AxlePhysicalSectionType.Get(sectionEntry)
|
||||
if trainIn {
|
||||
axleCounter.UpdateCount(1)
|
||||
axleDevice.UpdateCount(1)
|
||||
} else {
|
||||
axleCounter.UpdateCount(0)
|
||||
axleDevice.UpdateCount(0)
|
||||
}
|
||||
//
|
||||
return ecs.NewOkEmptyResult()
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 8b25469d6ef3e8aeb1a19326d879293a9958bfe8
|
||||
Subproject commit e1a4fb8476c783332fc58c9d44a670de85cd7261
|
@ -80,11 +80,11 @@ func (p *PsdSys) Update(world ecs.World) {
|
||||
//设置滑动门电机通断电状态
|
||||
repo := entity.GetWorldData(world).Repo
|
||||
psd := repo.FindPsd(component.UidType.Get(entry).Id)
|
||||
if psc.MkxGM { //优先门控箱的关门
|
||||
p.gm(asdList)
|
||||
} else if psc.MkxKM { //其次门控箱的开门
|
||||
if psc.MkxKM { //优先门控箱的开门
|
||||
group := psd.FindAsdGroup(8)
|
||||
p.km(group.Start, group.End, asdList)
|
||||
} else if psc.MkxKM { //其次门控箱的关门
|
||||
p.gm(asdList)
|
||||
} else if !psc.InterlockMPL { //联锁操作没有被旁路
|
||||
if psc.InterlockGM {
|
||||
p.gm(asdList)
|
||||
|
@ -25,16 +25,28 @@ func (s *AsdSys) Update(world ecs.World) {
|
||||
twoPosition := component.TwoPositionTransformType.Get(entry)
|
||||
asdState := component.AsdStateType.Get(entry)
|
||||
pos := twoPosition.Pos
|
||||
if psdMotorState.TD {
|
||||
if entry.HasComponent(component.AsdCannotOpenTag) {
|
||||
pos = consts.TwoPosMin
|
||||
speed = 0
|
||||
psdMotorState.TD = false
|
||||
} else if entry.HasComponent(component.AsdCannotCloseTag) {
|
||||
pos = consts.TwoPosMax
|
||||
speed = 0
|
||||
psdMotorState.TD = false
|
||||
} else if psdMotorState.TD {
|
||||
if psdMotorState.KM {
|
||||
twoPosition.Speed = speed
|
||||
if pos == consts.TwoPosMax { //开门到位后断电
|
||||
if pos == consts.TwoPosMax {
|
||||
psdMotorState.TD = false
|
||||
twoPosition.Speed = 0
|
||||
} else {
|
||||
twoPosition.Speed = speed
|
||||
}
|
||||
} else {
|
||||
twoPosition.Speed = -speed
|
||||
if pos == consts.TwoPosMin { //关门到位后断电
|
||||
psdMotorState.TD = false
|
||||
twoPosition.Speed = 0
|
||||
} else {
|
||||
twoPosition.Speed = -speed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/ecs/filter"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
@ -15,92 +16,83 @@ type FaDcAxleDeviceSystem struct {
|
||||
|
||||
func NewFaDcAxleDeviceSystem() *FaDcAxleDeviceSystem {
|
||||
return &FaDcAxleDeviceSystem{
|
||||
query: ecs.NewQuery(filter.Contains(component.FaDcAxleDeviceType)),
|
||||
query: ecs.NewQuery(filter.Contains(component.AxleManageDeviceType)),
|
||||
}
|
||||
}
|
||||
func (s *FaDcAxleDeviceSystem) Update(w ecs.World) {
|
||||
data := entity.GetWorldData(w)
|
||||
s.query.Each(w, func(entry *donburi.Entry) {
|
||||
faDcDevice := component.FaDcAxleDeviceType.Get(entry)
|
||||
for _, axleSectionEntry := range faDcDevice.Sections {
|
||||
axleSectionId := component.UidType.Get(axleSectionEntry).Id
|
||||
axleCounterEntry := faDcDevice.CounterMap[axleSectionId]
|
||||
faDcDevice := component.AxleManageDeviceType.Get(entry)
|
||||
for axleSectionId, axleRuntime := range faDcDevice.Adrs {
|
||||
axleSectionEntry := data.EntityMap[axleSectionId]
|
||||
sectionState := component.PhysicalSectionStateType.Get(axleSectionEntry)
|
||||
axleDevice := component.AxlePhysicalSectionType.Get(axleSectionEntry)
|
||||
//
|
||||
s.calculateHf(axleCounterEntry, axleSectionEntry)
|
||||
s.calculateDrst(axleCounterEntry)
|
||||
s.calculatePdrst(axleCounterEntry)
|
||||
s.calculateSectionState(axleCounterEntry, axleSectionEntry)
|
||||
s.calculateAxleCount(axleCounterEntry, axleSectionEntry)
|
||||
s.calculateHf(axleSectionEntry, sectionState, axleDevice, axleRuntime)
|
||||
s.calculateDrst(sectionState, axleDevice, axleRuntime)
|
||||
s.calculatePdrst(sectionState, axleDevice, axleRuntime)
|
||||
s.calculateSectionState(sectionState, axleDevice, axleRuntime)
|
||||
s.calculateAxleCount(sectionState, axleDevice, axleRuntime)
|
||||
|
||||
if "北京_12_酒仙桥_12G" == axleSectionId && false {
|
||||
section := component.AxleSectionType.Get(axleSectionEntry)
|
||||
counter := component.AxleCounterType.Get(axleCounterEntry)
|
||||
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||||
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
|
||||
sectionFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag)
|
||||
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())
|
||||
"Drst", axleRuntime.Drst,
|
||||
"Pdrst", axleRuntime.Pdrst,
|
||||
"DoingPdrst", axleRuntime.DoingPdrst,
|
||||
"Rac", axleRuntime.Rac,
|
||||
"Rjo", axleRuntime.Rjo,
|
||||
"Rjt", axleRuntime.Rjt,
|
||||
"SectionFault", sectionFault,
|
||||
"Occ", sectionState.Occ,
|
||||
"Count", axleDevice.Count,
|
||||
"Wave", axleDevice.ShowCountWave())
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 计算计轴区段内车轴数
|
||||
// 目前通过查看有哪些车在该计轴区段内实现,定性
|
||||
func (s *FaDcAxleDeviceSystem) calculateAxleCount(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
|
||||
func (s *FaDcAxleDeviceSystem) calculateAxleCount(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
||||
//检查该区段内有没有车
|
||||
// ...todo
|
||||
}
|
||||
|
||||
// 计算计轴区段状态
|
||||
func (s *FaDcAxleDeviceSystem) calculateSectionState(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
|
||||
section := component.AxleSectionType.Get(axleSectionEntry)
|
||||
counter := component.AxleCounterType.Get(axleCounterEntry)
|
||||
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||||
isIdle := counter.Count <= 0 && !counterRt.DoingPdrst //区段空闲:区段内车轴数为零且没有预复位
|
||||
section.Occ = !isIdle
|
||||
func (s *FaDcAxleDeviceSystem) calculateSectionState(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
||||
isIdle := axleDevice.Count <= 0 && !axleRuntime.DoingPdrst //区段空闲:区段内车轴数为零且没有预复位
|
||||
sectionState.Occ = !isIdle
|
||||
}
|
||||
|
||||
// 计轴直接复位
|
||||
func (s *FaDcAxleDeviceSystem) calculateDrst(axleCounterEntry *donburi.Entry) {
|
||||
counter := component.AxleCounterType.Get(axleCounterEntry)
|
||||
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||||
if counterRt.Drst && !counterRt.Rjo && !counterRt.Rjt { //直接复位且没有拒绝原因
|
||||
counter.UpdateCount(0)
|
||||
counter.ResetCountPulse()
|
||||
counterRt.DoingPdrst = false
|
||||
func (s *FaDcAxleDeviceSystem) calculateDrst(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
||||
|
||||
if axleRuntime.Drst && !axleRuntime.Rjo && !axleRuntime.Rjt { //直接复位且没有拒绝原因
|
||||
axleDevice.UpdateCount(0)
|
||||
axleDevice.ResetCountPulse()
|
||||
axleRuntime.DoingPdrst = false
|
||||
}
|
||||
}
|
||||
|
||||
// 计轴预复位
|
||||
func (s *FaDcAxleDeviceSystem) calculatePdrst(axleCounterEntry *donburi.Entry) {
|
||||
counter := component.AxleCounterType.Get(axleCounterEntry)
|
||||
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||||
if counterRt.Pdrst && !counterRt.Rjo && !counterRt.Rjt && !counterRt.DoingPdrst { //预复位且没有拒绝原因
|
||||
counter.UpdateCount(0)
|
||||
counter.ResetCountPulse()
|
||||
counterRt.DoingPdrst = true
|
||||
func (s *FaDcAxleDeviceSystem) calculatePdrst(sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
||||
|
||||
if axleRuntime.Pdrst && !axleRuntime.Rjo && !axleRuntime.Rjt && !axleRuntime.DoingPdrst { //预复位且没有拒绝原因
|
||||
axleDevice.UpdateCount(0)
|
||||
axleDevice.ResetCountPulse()
|
||||
axleRuntime.DoingPdrst = true
|
||||
}
|
||||
//压道车通过该计轴区段,完成计轴预复位
|
||||
if counter.IsCount010Pulse() {
|
||||
counterRt.DoingPdrst = false
|
||||
if axleDevice.IsCount010Pulse() {
|
||||
axleRuntime.DoingPdrst = false
|
||||
}
|
||||
}
|
||||
|
||||
// 复位回复运算
|
||||
func (s *FaDcAxleDeviceSystem) calculateHf(axleCounterEntry *donburi.Entry, axleSectionEntry *donburi.Entry) {
|
||||
section := component.AxleSectionType.Get(axleSectionEntry)
|
||||
sectionFault := component.AxleSectionFaultType.Get(axleSectionEntry)
|
||||
counterRt := component.AxleCounterRuntimeType.Get(axleCounterEntry)
|
||||
counterRt.Rac = counterRt.Drst || counterRt.Pdrst
|
||||
counterRt.Rjo = counterRt.Rac && !section.Occ && !counterRt.DoingPdrst //空闲拒绝复位(排除预复位过程中)
|
||||
counterRt.Rjt = counterRt.Rac && sectionFault.SectionFault // 技术原因拒绝复位
|
||||
func (s *FaDcAxleDeviceSystem) calculateHf(axleSectionEntry *ecs.Entry, sectionState *component.PhysicalSectionState, axleDevice *component.AxlePhysicalSection, axleRuntime *component.AxleDeviceRuntime) {
|
||||
sectionFault := axleSectionEntry.HasComponent(component.AxleSectionFaultTag)
|
||||
axleRuntime.Rac = axleRuntime.Drst || axleRuntime.Pdrst
|
||||
axleRuntime.Rjo = axleRuntime.Rac && !sectionState.Occ && !axleRuntime.DoingPdrst //空闲拒绝复位(排除预复位过程中)
|
||||
axleRuntime.Rjt = axleRuntime.Rac && sectionFault // 技术原因拒绝复位
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user