rts-sim-module/component/physical_section.go

106 lines
3.4 KiB
Go
Raw Normal View History

2023-10-31 11:30:17 +08:00
package component
2023-11-01 11:08:24 +08:00
import (
"fmt"
"joylink.club/ecs"
)
2023-10-31 11:30:17 +08:00
//计轴设备,管理联锁集中站内的所有计轴区段
2023-10-31 17:39:10 +08:00
//计轴直接复位:计轴的轮对计数清零,区段转换为空闲状态
//计轴预复位:将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
//
//当CI系统给计轴设备发送计轴直接复零/预复零命令时,连续发送一定时间(具体发送时间调试后确定)的复零/预复零命令。
//当RACRJORJT任意一个不为0时终止发送复零/预复零命令。
2023-10-31 11:30:17 +08:00
2023-11-06 14:35:32 +08:00
// PhysicalSectionState 物理区段
type PhysicalSectionState struct {
2023-10-31 11:30:17 +08:00
//true-占用false-出清
Occ bool
}
2023-11-06 14:35:32 +08:00
// AxlePhysicalSection 计轴物理区段
type AxlePhysicalSection struct {
2023-10-31 11:30:17 +08:00
//计轴区段内车轴数
Count int
2023-10-31 15:55:16 +08:00
//记录Count变化波形
countPulse uint8
2023-10-31 11:30:17 +08:00
}
2023-11-06 14:35:32 +08:00
type AxleDeviceRuntime struct {
2023-10-31 11:30:17 +08:00
//true-计轴复位反馈,表示计轴设备已收到CI系统发送的直接复零/预复零命令。
Rac bool
//true-运营原因拒绝计轴复位,如区段空闲时下发复位命令;或车轮压住传感器时收到复位命令。
Rjo bool
//true-技术原因拒绝计轴复位,主要指计轴相关设备故障时收到复位命令如车轮传感器的导线断开、AEB之间的通信故障等
Rjt bool
//true-计轴直接复位
//计轴的轮对计数清零,区段转换为空闲状态
Drst bool
//true-计轴预复位
//将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
Pdrst bool
//true-计轴系统正在执行直接预复位操作
DoingPdrst bool
}
2023-11-06 14:35:32 +08:00
func NewAxleDeviceRuntime() *AxleDeviceRuntime {
return &AxleDeviceRuntime{}
2023-10-31 15:55:16 +08:00
}
2023-11-06 14:35:32 +08:00
// AxleManageDevice 计轴管理设备
type AxleManageDevice struct {
CentralizedStation string //所属集中站
Adrs map[string]*AxleDeviceRuntime //key-sectionId
2023-10-31 11:30:17 +08:00
}
2023-11-06 14:35:32 +08:00
2023-11-06 15:30:57 +08:00
func (d *AxleManageDevice) FindAdr(sectionId string) *AxleDeviceRuntime {
return d.Adrs[sectionId]
}
2023-11-06 14:35:32 +08:00
func NewAxleManageDevice(centralizedStation string) *AxleManageDevice {
return &AxleManageDevice{CentralizedStation: centralizedStation, Adrs: make(map[string]*AxleDeviceRuntime)}
2023-11-01 11:08:24 +08:00
}
2023-10-31 11:30:17 +08:00
var (
2023-11-06 14:35:32 +08:00
PhysicalSectionStateType = ecs.NewComponentType[PhysicalSectionState]()
AxlePhysicalSectionType = ecs.NewComponentType[AxlePhysicalSection]()
AxleSectionFaultTag = ecs.NewTag()
AxleManageDeviceType = ecs.NewComponentType[AxleManageDevice]()
2023-10-31 11:30:17 +08:00
)
2023-10-31 15:55:16 +08:00
2023-11-06 14:35:32 +08:00
/////////////////////////////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
}
2023-10-31 15:55:16 +08:00
// 归1
func to1(c int) uint8 {
if c > 0 {
return 0x01
} else {
return 0x00
}
}