rts-sim-module/component/axle_device.go
2023-11-01 11:08:24 +08:00

115 lines
3.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package component
import (
"fmt"
"joylink.club/ecs"
)
//计轴设备,管理联锁集中站内的所有计轴区段
//计轴直接复位:计轴的轮对计数清零,区段转换为空闲状态
//计轴预复位:将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
//
//当CI系统给计轴设备发送计轴直接复零/预复零命令时,连续发送一定时间(具体发送时间调试后确定)的复零/预复零命令。
//当RACRJORJT任意一个不为0时终止发送复零/预复零命令。
// AxleSection 计轴物理区段状态
type AxleSection struct {
//true-占用false-出清
Occ bool
}
// AxleSectionFault 计轴区段故障
type AxleSectionFault struct {
//true-设置区段故障占用false-取消区段故障占用
SectionFault bool
}
// AxleCounter 计轴区段计轴器
type AxleCounter 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 {
//true-计轴复位反馈,表示计轴设备已收到CI系统发送的直接复零/预复零命令。
Rac bool
//true-运营原因拒绝计轴复位,如区段空闲时下发复位命令;或车轮压住传感器时收到复位命令。
Rjo bool
//true-技术原因拒绝计轴复位,主要指计轴相关设备故障时收到复位命令如车轮传感器的导线断开、AEB之间的通信故障等
Rjt bool
//true-计轴直接复位
//计轴的轮对计数清零,区段转换为空闲状态
Drst bool
//true-计轴预复位
//将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
Pdrst bool
//true-计轴系统正在执行直接预复位操作
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 (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
}
func (f *FaDcAxleDevice) GetAxleCounterEntry(sectionId string) *ecs.Entry {
return f.CounterMap[sectionId]
}
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
)
// 归1
func to1(c int) uint8 {
if c > 0 {
return 0x01
} else {
return 0x00
}
}