【动力学列车信息变化逻辑修改】
This commit is contained in:
parent
de7d72b92a
commit
1c074ff258
|
@ -5,12 +5,13 @@ import (
|
|||
"log/slog"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
"joylink.club/bj-rtsts-server/third_party/dynamics"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"joylink.club/rtsssimulation/fi"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ts/protos/state"
|
||||
)
|
||||
|
@ -41,14 +42,9 @@ func AddTrainState(vs *VerifySimulation, status *state.TrainState, mapId int32)
|
|||
// 车头所在公里标
|
||||
kilometer := CalcTrainKilometer(vs.Repo, uid, status.DevicePort, status.RunDirection, status.HeadOffset)
|
||||
// 车尾相对车头link的偏移量
|
||||
var calctailOffset int64
|
||||
if up {
|
||||
calctailOffset = loffset - status.TrainLength
|
||||
} else {
|
||||
calctailOffset = loffset + status.TrainLength
|
||||
}
|
||||
calctailOffset := calcTrailTailOffset(loffset, status.TrainLength, up)
|
||||
// 车尾位置
|
||||
tailLink, _, _, tailLOffset, _, _ := CalcInitializeLink(vs, linkId, calctailOffset, up)
|
||||
tailLink, tailDeviceId, _, tailLOffset, _, _ := CalcInitializeLink(vs, linkId, calctailOffset, up)
|
||||
status.Up = up
|
||||
status.PointTo = pointTo
|
||||
status.TrainKilometer = kilometer.Value
|
||||
|
@ -73,24 +69,74 @@ func AddTrainState(vs *VerifySimulation, status *state.TrainState, mapId int32)
|
|||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DynamicsError, Message: err.Error()})
|
||||
}
|
||||
occupySectionId := QueryDeviceRoutePath(vs, uid, tailDeviceId, status.DevicePort, !pointTo)
|
||||
// world中加车
|
||||
fi.AddTrainToWorld(vs.World, status.Id)
|
||||
fi.UpdateTrainFromDynamics(vs.World, status.Id, occupySectionId)
|
||||
// 将信息合并到当前设备状态中
|
||||
allTrainMap.Store(status.Id, status)
|
||||
}
|
||||
|
||||
// 修改列车状态
|
||||
func UpdateTrainState(vs *VerifySimulation, status *state.TrainState) {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
d, ok := allTrainMap.Load(status.Id)
|
||||
// 根据动力学发来的信息修改列车状态
|
||||
func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *message.DynamicsTrainInfo) {
|
||||
data, ok := vs.Memory.Status.TrainStateMap.Load(trainId)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("列车【%s】不存在", status.Id))
|
||||
panic(fmt.Sprintf("列车【%s】不存在", trainId))
|
||||
}
|
||||
t := d.(*state.TrainState)
|
||||
t.RunDirection = status.RunDirection
|
||||
t.PointTo = status.PointTo
|
||||
// 合并其他信息
|
||||
proto.Merge(t, status)
|
||||
// 更新全量信息
|
||||
allTrainMap.Store(status.Id, t)
|
||||
sta := data.(*state.TrainState)
|
||||
delayTime := time.Now().UnixMilli() - sta.VobcState.UpdateTime
|
||||
sta.ControlDelayTime = (int64(sta.VobcState.LifeSignal)-int64(info.VobcLifeSignal))*20 + delayTime
|
||||
slog.Debug("收到动力学原始消息", "Number", info.Number, "Link", info.Link, "LinkOffset", info.LinkOffset)
|
||||
inLinkId, inLinkOffset := strconv.Itoa(int(info.Link)), int64(info.LinkOffset)
|
||||
outLinkId, id, port, outLinkOffset, offset, kilometer := CalcInitializeLink(vs, inLinkId, inLinkOffset, info.Up)
|
||||
runDirection, pointTo := QueryDirectionAndABByDevice(vs.Repo, id, port, info.Up)
|
||||
slog.Debug("处理动力学转换后的消息", "number", info.Number, "车头位置", id, "偏移", offset, "是否上行", runDirection, "是否ab", pointTo)
|
||||
// 车尾相对车头link的偏移量
|
||||
calctailOffset := calcTrailTailOffset(outLinkOffset, sta.TrainLength, info.Up)
|
||||
tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailDeviceOffset, _ := CalcInitializeLink(vs, outLinkId, calctailOffset, info.Up)
|
||||
slog.Debug("车尾位置", tailDeviceId, "偏移", tailDeviceOffset, "所在设备端", tailDevicePort)
|
||||
occupySectionId := QueryDeviceRoutePath(vs, id, tailDeviceId, port, !pointTo)
|
||||
// 修改world中的列车信息
|
||||
fi.UpdateTrainFromDynamics(vs.World, trainId, occupySectionId)
|
||||
sta.HeadDeviceId = vs.GetComIdByUid(id)
|
||||
sta.DevicePort = port
|
||||
sta.HeadOffset = offset
|
||||
sta.PointTo = pointTo
|
||||
sta.TrainKilometer = kilometer.Value
|
||||
sta.RunDirection = runDirection
|
||||
//判定车头方向
|
||||
sta.HeadDirection = runDirection
|
||||
if sta.VobcState != nil {
|
||||
if sta.VobcState.DirectionForward {
|
||||
sta.HeadDirection = runDirection
|
||||
} else if sta.VobcState.DirectionBackward {
|
||||
sta.HeadDirection = !runDirection
|
||||
}
|
||||
}
|
||||
if info.Speed < 0 {
|
||||
sta.RunDirection = !sta.RunDirection
|
||||
}
|
||||
// 赋值动力学信息
|
||||
sta.DynamicState.Heartbeat = int32(info.LifeSignal)
|
||||
sta.DynamicState.HeadLinkId = outLinkId
|
||||
sta.DynamicState.HeadLinkOffset = outLinkOffset
|
||||
sta.DynamicState.TailLinkId = tailLinkId
|
||||
sta.DynamicState.TailLinkOffset = tailLinkOffset
|
||||
sta.DynamicState.Slope = int32(info.Slope)
|
||||
sta.DynamicState.Upslope = info.UpSlope
|
||||
sta.DynamicState.RunningUp = info.Up
|
||||
sta.DynamicState.RunningResistanceSum = float32(info.TotalResistance) / 1000
|
||||
sta.DynamicState.AirResistance = float32(info.AirResistance) / 1000
|
||||
sta.DynamicState.RampResistance = float32(info.SlopeResistance) / 1000
|
||||
sta.DynamicState.CurveResistance = float32(info.CurveResistance) / 1000
|
||||
sta.DynamicState.Speed = speedParse(info.Speed)
|
||||
sta.DynamicState.HeadSensorSpeed1 = speedParse(info.HeadSpeed1)
|
||||
sta.DynamicState.HeadSensorSpeed2 = speedParse(info.HeadSpeed2)
|
||||
sta.DynamicState.TailSensorSpeed1 = speedParse(info.TailSpeed1)
|
||||
sta.DynamicState.TailSensorSpeed2 = speedParse(info.TailSpeed2)
|
||||
sta.DynamicState.HeadRadarSpeed = speedParse(info.HeadRadarSpeed)
|
||||
sta.DynamicState.TailRadarSpeed = speedParse(info.TailRadarSpeed)
|
||||
sta.DynamicState.Acceleration = info.Acceleration
|
||||
}
|
||||
|
||||
// 删除列车状态
|
||||
|
@ -108,8 +154,19 @@ func RemoveTrainState(vs *VerifySimulation, id string) {
|
|||
}
|
||||
// 从仿真内存中移除列车
|
||||
t.Show = false
|
||||
// 移除车
|
||||
fi.RemoveTrainFromWorld(vs.World, id)
|
||||
allTrainMap.Store(id, t)
|
||||
} else {
|
||||
panic(fmt.Sprintf("列车【%s】不存在", id))
|
||||
}
|
||||
}
|
||||
|
||||
func calcTrailTailOffset(headerOffset, length int64, up bool) (calctailOffset int64) {
|
||||
if up {
|
||||
calctailOffset = headerOffset - length
|
||||
} else {
|
||||
calctailOffset = headerOffset + length
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
|
@ -271,73 +270,15 @@ func handlerDynamicsTurnoutState(w ecs.World, uid string) *message.DynamicsTurno
|
|||
|
||||
// 处理动力学列车速度消息
|
||||
func (s *VerifySimulation) HandleDynamicsTrainInfo(info *message.DynamicsTrainInfo) {
|
||||
sta, ok := s.Memory.Status.TrainStateMap.Load(strconv.Itoa(int(info.Number)))
|
||||
trainId := strconv.Itoa(int(info.Number))
|
||||
_, ok := s.Memory.Status.TrainStateMap.Load(trainId)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// 给半实物仿真发送速度
|
||||
semi_physical_train.Default().SendTrainControlMessage(info)
|
||||
// 更新列车状态
|
||||
UpdateTrainState(s, convert(info, sta.(*state.TrainState), s))
|
||||
}
|
||||
|
||||
func convert(info *message.DynamicsTrainInfo, sta *state.TrainState, simulation *VerifySimulation) *state.TrainState {
|
||||
delayTime := time.Now().UnixMilli() - sta.VobcState.UpdateTime
|
||||
sta.ControlDelayTime = (int64(sta.VobcState.LifeSignal)-int64(info.VobcLifeSignal))*20 + delayTime
|
||||
slog.Debug("收到动力学原始消息", "Number", info.Number, "Link", info.Link, "LinkOffset", info.LinkOffset)
|
||||
inLinkId, inLinkOffset := strconv.Itoa(int(info.Link)), int64(info.LinkOffset)
|
||||
outLinkId, id, port, outLinkOffset, offset, kilometer := CalcInitializeLink(simulation, inLinkId, inLinkOffset, info.Up)
|
||||
runDirection, pointTo := QueryDirectionAndABByDevice(simulation.Repo, id, port, info.Up)
|
||||
slog.Debug("处理动力学转换后的消息", "number", info.Number, "车头位置", id, "偏移", offset, "是否上行", runDirection, "是否ab", pointTo)
|
||||
// 车尾相对车头link的偏移量
|
||||
var calctailOffset int64
|
||||
if info.Up {
|
||||
calctailOffset = outLinkOffset - sta.TrainLength
|
||||
} else {
|
||||
calctailOffset = outLinkOffset + sta.TrainLength
|
||||
}
|
||||
tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailDeviceOffset, _ := CalcInitializeLink(simulation, outLinkId, calctailOffset, info.Up)
|
||||
slog.Debug("车未位置", tailDeviceId, "偏移", tailDeviceOffset, "所在设备端", tailDevicePort)
|
||||
sta.HeadDeviceId = simulation.GetComIdByUid(id)
|
||||
sta.DevicePort = port
|
||||
sta.HeadOffset = offset
|
||||
sta.PointTo = pointTo
|
||||
sta.TrainKilometer = kilometer.Value
|
||||
sta.RunDirection = runDirection
|
||||
//判定车头方向
|
||||
sta.HeadDirection = runDirection
|
||||
if sta.VobcState != nil {
|
||||
if sta.VobcState.DirectionForward {
|
||||
sta.HeadDirection = runDirection
|
||||
} else if sta.VobcState.DirectionBackward {
|
||||
sta.HeadDirection = !runDirection
|
||||
}
|
||||
}
|
||||
if info.Speed < 0 {
|
||||
sta.RunDirection = !sta.RunDirection
|
||||
}
|
||||
// 赋值动力学信息
|
||||
sta.DynamicState.Heartbeat = int32(info.LifeSignal)
|
||||
sta.DynamicState.HeadLinkId = outLinkId
|
||||
sta.DynamicState.HeadLinkOffset = outLinkOffset
|
||||
sta.DynamicState.TailLinkId = tailLinkId
|
||||
sta.DynamicState.TailLinkOffset = tailLinkOffset
|
||||
sta.DynamicState.Slope = int32(info.Slope)
|
||||
sta.DynamicState.Upslope = info.UpSlope
|
||||
sta.DynamicState.RunningUp = info.Up
|
||||
sta.DynamicState.RunningResistanceSum = float32(info.TotalResistance) / 1000
|
||||
sta.DynamicState.AirResistance = float32(info.AirResistance) / 1000
|
||||
sta.DynamicState.RampResistance = float32(info.SlopeResistance) / 1000
|
||||
sta.DynamicState.CurveResistance = float32(info.CurveResistance) / 1000
|
||||
sta.DynamicState.Speed = speedParse(info.Speed)
|
||||
sta.DynamicState.HeadSensorSpeed1 = speedParse(info.HeadSpeed1)
|
||||
sta.DynamicState.HeadSensorSpeed2 = speedParse(info.HeadSpeed2)
|
||||
sta.DynamicState.TailSensorSpeed1 = speedParse(info.TailSpeed1)
|
||||
sta.DynamicState.TailSensorSpeed2 = speedParse(info.TailSpeed2)
|
||||
sta.DynamicState.HeadRadarSpeed = speedParse(info.HeadRadarSpeed)
|
||||
sta.DynamicState.TailRadarSpeed = speedParse(info.TailRadarSpeed)
|
||||
sta.DynamicState.Acceleration = info.Acceleration
|
||||
return sta
|
||||
UpdateTrainStateByDynamics(s, trainId, info)
|
||||
}
|
||||
|
||||
// 获取动力学配置信息
|
||||
|
@ -1424,24 +1365,20 @@ func findTurnoutIds(axleCountingMap map[string]*graphicData.AxleCounting, axleId
|
|||
if len(axleIds) <= 2 {
|
||||
return nil
|
||||
}
|
||||
turnoutMap := make(map[string]bool)
|
||||
turnoutMap := make(map[string]int)
|
||||
for _, axleId := range axleIds {
|
||||
axle := axleCountingMap[axleId]
|
||||
relTurnoutCount := 0
|
||||
var turnoutId string
|
||||
for _, ref := range axle.AxleCountingRef {
|
||||
if ref.DeviceType == graphicData.RelatedRef_Turnout {
|
||||
relTurnoutCount++
|
||||
turnoutId = ref.Id
|
||||
turnoutMap[ref.Id] = turnoutMap[ref.Id] + 1
|
||||
}
|
||||
}
|
||||
if relTurnoutCount == 1 {
|
||||
turnoutMap[turnoutId] = true
|
||||
}
|
||||
}
|
||||
var turnoutIds []string
|
||||
for id := range turnoutMap {
|
||||
turnoutIds = append(turnoutIds, id)
|
||||
for id, num := range turnoutMap {
|
||||
if num > 1 {
|
||||
turnoutIds = append(turnoutIds, id)
|
||||
}
|
||||
}
|
||||
return turnoutIds
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue