Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ec691ab12c
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
type DynamicsMessageManager interface {
|
||||
CollectDynamicsTurnoutInfo() []*message.DynamicsTurnoutInfo
|
||||
CollectDynamicsTurnoutInfo() *message.DynamicsTurnoutInfo
|
||||
HandleDynamicsTrainInfo(info *message.DynamicsTrainInfo)
|
||||
GetDynamicsRunConfig() *config.DynamicsConfig
|
||||
GetDynamicsRunRepository() *message.LineBaseInfo
|
||||
|
@ -277,13 +277,10 @@ func (d *dynamics) sendTurnoutStateTask(ctx context.Context) {
|
|||
return
|
||||
default:
|
||||
}
|
||||
turnoutStates := d.manager.CollectDynamicsTurnoutInfo()
|
||||
// slog.Debug("发送道岔状态", "count", len(turnoutStates))
|
||||
for _, state := range turnoutStates {
|
||||
turnoutStateLifeSignal++
|
||||
state.LifeSignal = turnoutStateLifeSignal
|
||||
d.turnoutStateUdpClient.SendMsg(state)
|
||||
}
|
||||
turnoutState := d.manager.CollectDynamicsTurnoutInfo()
|
||||
turnoutStateLifeSignal++
|
||||
turnoutState.LifeSignal = turnoutStateLifeSignal
|
||||
d.turnoutStateUdpClient.SendMsg(turnoutState)
|
||||
time.Sleep(time.Millisecond * TurnoutMessageSendInterval)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,24 +6,30 @@ import (
|
|||
)
|
||||
|
||||
type DynamicsTurnoutInfo struct {
|
||||
LifeSignal uint16
|
||||
Code uint16
|
||||
NPosition bool
|
||||
RPosition bool
|
||||
LifeSignal uint16
|
||||
TurnoutInfos []*TurnoutInfo
|
||||
}
|
||||
|
||||
type TurnoutInfo struct {
|
||||
Code uint16
|
||||
NPosition bool
|
||||
RPosition bool
|
||||
}
|
||||
|
||||
func (t *DynamicsTurnoutInfo) Encode() []byte {
|
||||
var data []byte
|
||||
data = binary.BigEndian.AppendUint16(data, t.LifeSignal)
|
||||
data = binary.BigEndian.AppendUint16(data, t.Code)
|
||||
var b byte
|
||||
if t.NPosition {
|
||||
b |= 1 << 7
|
||||
for _, info := range t.TurnoutInfos {
|
||||
data = binary.BigEndian.AppendUint16(data, info.Code)
|
||||
var b byte
|
||||
if info.NPosition {
|
||||
b |= 1 << 7
|
||||
}
|
||||
if info.RPosition {
|
||||
b |= 1 << 6
|
||||
}
|
||||
data = append(data, b)
|
||||
}
|
||||
if t.RPosition {
|
||||
b |= 1 << 6
|
||||
}
|
||||
data = append(data, b)
|
||||
return data
|
||||
}
|
||||
|
||||
|
|
|
@ -219,21 +219,29 @@ func (s *VerifySimulation) CollectSectionStatus(city string, lineId string, cent
|
|||
}
|
||||
|
||||
// 采集动力学道岔状态
|
||||
func (s *VerifySimulation) CollectDynamicsTurnoutInfo() []*message.DynamicsTurnoutInfo {
|
||||
var turnoutStates []*message.DynamicsTurnoutInfo
|
||||
for _, o := range s.Repo.TurnoutList() {
|
||||
sta := s.uidMap[o.Id()]
|
||||
func (s *VerifySimulation) CollectDynamicsTurnoutInfo() *message.DynamicsTurnoutInfo {
|
||||
turnoutState := &message.DynamicsTurnoutInfo{}
|
||||
for _, turnout := range s.Repo.TurnoutList() {
|
||||
sta := s.uidMap[turnout.Id()]
|
||||
if sta == nil {
|
||||
continue
|
||||
}
|
||||
s := handlerDynamicsTurnoutState(s.World, o.Id())
|
||||
if s == nil {
|
||||
continue
|
||||
entry, ok := entity.GetEntityByUid(s.World, turnout.Id())
|
||||
if !ok {
|
||||
slog.Warn(fmt.Sprintf("id=%s的道岔不存在", turnout.Id()))
|
||||
return nil
|
||||
}
|
||||
s.Code = uint16(sta.CommonId)
|
||||
turnoutStates = append(turnoutStates, s)
|
||||
if !entry.HasComponent(component.TurnoutPositionType) {
|
||||
return nil
|
||||
}
|
||||
pos := component.TurnoutPositionType.Get(entry)
|
||||
turnoutState.TurnoutInfos = append(turnoutState.TurnoutInfos, &message.TurnoutInfo{
|
||||
Code: 0,
|
||||
NPosition: pos.Dw,
|
||||
RPosition: pos.Fw,
|
||||
})
|
||||
}
|
||||
return turnoutStates
|
||||
return turnoutState
|
||||
}
|
||||
|
||||
// HandleSectionCmdMsg 计轴设备接收到联锁发送来的控制命令
|
||||
|
@ -268,19 +276,6 @@ func (s *VerifySimulation) HandleSectionCmdMsg(city string, lineId string, centr
|
|||
fi.AxleSectionRstDrive(s.World, cmds)
|
||||
}
|
||||
|
||||
func handlerDynamicsTurnoutState(w ecs.World, uid string) *message.DynamicsTurnoutInfo {
|
||||
entry, ok := entity.GetEntityByUid(w, uid)
|
||||
if !ok {
|
||||
fmt.Printf("id=%s的道岔不存在", uid)
|
||||
return nil
|
||||
}
|
||||
if !entry.HasComponent(component.TurnoutPositionType) {
|
||||
return nil
|
||||
}
|
||||
pos := component.TurnoutPositionType.Get(entry)
|
||||
return &message.DynamicsTurnoutInfo{NPosition: pos.Dw, RPosition: pos.Fw}
|
||||
}
|
||||
|
||||
// 处理动力学列车速度消息
|
||||
func (s *VerifySimulation) HandleDynamicsTrainInfo(info *message.DynamicsTrainInfo) {
|
||||
trainId := strconv.Itoa(int(info.Number))
|
||||
|
|
Loading…
Reference in New Issue