Merge branch 'master' of https://git.code.tencent.com/beijing-rtss-test/bj-rtsts-server-go
This commit is contained in:
commit
2693c92bb0
@ -562,23 +562,26 @@ func turnoutOffsetToKilometer(repo *repository.Repository, uid string, runDirect
|
||||
// 输出:占用物理区段的ID
|
||||
func QueryDeviceRoutePath(sim *VerifySimulation, startUid, endUid, startPort string, pointTo bool) (paths []string, err error) {
|
||||
suid, port, direction := startUid, startPort, pointTo
|
||||
pathMap := make(map[string]bool)
|
||||
for {
|
||||
device := sim.Repo.FindById(suid)
|
||||
var nextRelation repository.DevicePort
|
||||
switch device.Type() {
|
||||
case proto2.DeviceType_DeviceType_PhysicalSection: // 区段
|
||||
d := device.(*repository.PhysicalSection)
|
||||
paths = append(paths, d.Id())
|
||||
pathMap[d.Id()] = true
|
||||
nextRelation = d.ARelation()
|
||||
if direction {
|
||||
nextRelation = d.BRelation()
|
||||
}
|
||||
case proto2.DeviceType_DeviceType_Turnout: // 道岔
|
||||
d := device.(*repository.Turnout)
|
||||
if d.GetPhysicalSection() == nil {
|
||||
physicalSection := d.GetPhysicalSection()
|
||||
if physicalSection == nil {
|
||||
err = sys_error.New(fmt.Sprintf("道岔%s没有绑定物理区段", device.Id()))
|
||||
break
|
||||
}
|
||||
paths = append(paths, d.GetPhysicalSection().Id())
|
||||
pathMap[physicalSection.Id()] = true
|
||||
var nextPort proto2.Port
|
||||
switch port {
|
||||
case "A":
|
||||
@ -588,7 +591,7 @@ func QueryDeviceRoutePath(sim *VerifySimulation, startUid, endUid, startPort str
|
||||
case "C":
|
||||
nextPort = proto2.Port_C
|
||||
}
|
||||
if pointTo { // -> 岔心
|
||||
if direction { // -> 岔心
|
||||
nextPort, err = getTurnoutNextPort(sim, d.Id(), port)
|
||||
}
|
||||
nextRelation = d.GindDevicePortByPort(nextPort)
|
||||
@ -596,13 +599,13 @@ func QueryDeviceRoutePath(sim *VerifySimulation, startUid, endUid, startPort str
|
||||
err = sys_error.New(fmt.Sprintf("查找路径设备类型%s无处理处理", device.Type().String()))
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
break
|
||||
}
|
||||
if suid == endUid {
|
||||
return
|
||||
break
|
||||
}
|
||||
if nextRelation == nil {
|
||||
return
|
||||
break
|
||||
}
|
||||
suid = nextRelation.Device().Id() // 下一个设备ID
|
||||
port = nextRelation.Port().String() // 下一个道岔端
|
||||
@ -613,4 +616,8 @@ func QueryDeviceRoutePath(sim *VerifySimulation, startUid, endUid, startPort str
|
||||
direction = true
|
||||
}
|
||||
}
|
||||
for k := range pathMap {
|
||||
paths = append(paths, k)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func AddTrainState(vs *VerifySimulation, status *state.TrainState, mapId int32)
|
||||
// 车尾相对车头link的偏移量
|
||||
calctailOffset := calcTrailTailOffset(loffset, status.TrainLength, up)
|
||||
// 车尾位置
|
||||
tailLink, tailDeviceId, _, tailLOffset, _, _, e1 := CalcInitializeLink(vs, linkId, calctailOffset, up)
|
||||
tailLink, _, _, tailLOffset, _, _, e1 := CalcInitializeLink(vs, linkId, calctailOffset, up)
|
||||
if e1 != nil {
|
||||
panic(sys_error.New("添加列车失败,列车车尾占用位置计算出错", e1))
|
||||
}
|
||||
@ -73,13 +73,17 @@ func AddTrainState(vs *VerifySimulation, status *state.TrainState, mapId int32)
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DynamicsError, Message: err.Error()})
|
||||
}
|
||||
occupySectionId, e2 := QueryDeviceRoutePath(vs, uid, tailDeviceId, status.DevicePort, !pointTo)
|
||||
if e2 != nil {
|
||||
panic(sys_error.New("添加列车失败,列车占用物理区段计算出错", e2))
|
||||
}
|
||||
// world中加车
|
||||
fi.AddTrainToWorld(vs.World, status.Id)
|
||||
fi.UpdateTrainFromDynamics(vs.World, status.Id, occupySectionId)
|
||||
fi.UpdateTrainPositionFromDynamics(vs.World, fi.TrainPositionInfo{
|
||||
TrainId: status.Id,
|
||||
Up: status.Up,
|
||||
Len: uint32(status.TrainLength),
|
||||
HeadLink: linkId,
|
||||
HeadLinkOffset: uint32(loffset),
|
||||
TailLink: tailLink,
|
||||
TailLinkOffset: uint32(tailLOffset),
|
||||
})
|
||||
// 将信息合并到当前设备状态中
|
||||
allTrainMap.Store(status.Id, status)
|
||||
}
|
||||
@ -108,12 +112,16 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
|
||||
panic(sys_error.New("动力学传输数据:列车车尾位置计算出错", e2))
|
||||
}
|
||||
slog.Debug("车尾位置", tailDeviceId, "偏移", tailDeviceOffset, "所在设备端", tailDevicePort)
|
||||
occupySectionId, e3 := QueryDeviceRoutePath(vs, id, tailDeviceId, port, !pointTo)
|
||||
if e3 != nil {
|
||||
panic(sys_error.New("动力学传输数据:计算列车占用轨道出错", e3))
|
||||
}
|
||||
// 修改world中的列车信息
|
||||
fi.UpdateTrainFromDynamics(vs.World, trainId, occupySectionId)
|
||||
// 修改world中的列车位置
|
||||
fi.UpdateTrainPositionFromDynamics(vs.World, fi.TrainPositionInfo{
|
||||
TrainId: trainId,
|
||||
Up: info.Up,
|
||||
Len: info.Len,
|
||||
HeadLink: outLinkId,
|
||||
HeadLinkOffset: uint32(outLinkOffset),
|
||||
TailLink: tailLinkId,
|
||||
TailLinkOffset: uint32(tailLinkOffset),
|
||||
})
|
||||
sta.HeadDeviceId = vs.GetComIdByUid(id)
|
||||
sta.DevicePort = port
|
||||
sta.HeadOffset = offset
|
||||
|
Loading…
Reference in New Issue
Block a user