diff --git a/.gitignore b/.gitignore index 6e4b5c4..b75bf61 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,4 @@ output/ # vendor/ # Go workspace file -go.work /pom.xml diff --git a/ats/verify/simulation/simulation_manage.go b/ats/verify/simulation/simulation_manage.go index ca34445..6e09eca 100644 --- a/ats/verify/simulation/simulation_manage.go +++ b/ats/verify/simulation/simulation_manage.go @@ -186,55 +186,45 @@ func GetSimulationArr() []*memory.VerifySimulation { } func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory.VerifySimulation) *state.TrainState { - //var vs *memory.VerifyStructure - //linkId := int32(info.Link) - //for _, mapId := range simulation.MapIds { - // vm := memory.QueryMapVerifyStructure(mapId) - // if vm.LinkModelMap[linkId] == nil { - // continue - // } - // vs = vm - // break - //} - //zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset) - //id, port, offset, runDirection, pointTo, kilometer := memory.QueryDeviceByCalcLink(vs, linkId, int64(info.LinkOffset), info.Up, sta.RunDirection) - //zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v-是否ab:%v]", info.Number, id, offset, runDirection, pointTo) - //sta.HeadDeviceId = id - //sta.DevicePort = port - //sta.HeadOffset = offset - //sta.PointTo = pointTo - //sta.TrainKilometer = kilometer - //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 = strconv.Itoa(int(info.Link)) - //sta.DynamicState.HeadLinkOffset = int64(info.LinkOffset) - //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) + zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset) + id, port, offset, runDirection, pointTo, kilometer := memory.QueryDeviceByCalcLink(simulation.Repo, strconv.Itoa(int(info.Link)), int64(info.LinkOffset), info.Up) + zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v-是否ab:%v]", info.Number, id, offset, runDirection, pointTo) + sta.HeadDeviceId = id + sta.DevicePort = port + sta.HeadOffset = offset + sta.PointTo = pointTo + sta.TrainKilometer = kilometer + 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 = strconv.Itoa(int(info.Link)) + sta.DynamicState.HeadLinkOffset = int64(info.LinkOffset) + 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) return sta } diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_map.go b/ats/verify/simulation/wayside/memory/wayside_memory_map.go index 8397ed1..aa4bbe4 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory_map.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory_map.go @@ -4,6 +4,7 @@ import ( "container/list" "fmt" "joylink.club/rtsssimulation/repository" + proto2 "joylink.club/rtsssimulation/repository/model/proto" "math" "sort" "strconv" @@ -293,126 +294,54 @@ Outter: // 根据linkID和link相对偏移量返回区段,道岔偏移量 // 设备ID、端口、偏移量、上下行、AB走向 -func QueryDeviceByCalcLink(repo *repository.Repository, id int32, offset int64, up, defaultRunDirection bool) (string, string, int64, bool, bool, int64) { - //link := repo.FindLink(strconv.Itoa(int(id))) - //if link == nil { - // panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到link【%d】", id)}) - //} - //if offset > link.Length() { - // panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("偏移超出link范围【%d】", id)}) - //} - //for _, model := range link.Devices() { - // physicalSection, ok := model.(*repository.PhysicalSection) - // if ok { - // if number.IsBetween(offset, physicalSection.StartLinkPosition().Offset(), physicalSection.EndLinkPosition().Offset()) { - // - // } - // } - // - //} - // - //calcPositionArr := convertPositionToCalcPosition(linkModel) // 转换位置对象 - //var devicePosition, calcPosition *calcLinkPositionStruct // 获取当前、下一个节点,偏移量在这个范围中 - //for _, v := range calcPositionArr { - // if v.position.Offset > int32(offset) { - // calcPosition = v - // break - // } else { - // devicePosition = v - // } - //} - //// 运行方向 - //var runDirection bool - //if calcPosition != nil { - // runDirection = (calcPosition.kilometer.Kilometer >= devicePosition.kilometer.Kilometer) == up - //} else { - // runDirection = defaultRunDirection - //} - //isSwitch := (devicePosition.deviceType == 2) // 道岔 - //// 获取另一个端点 - //if calcPosition != nil { - // isSwitch = isSwitch || calcPosition.deviceType == 2 // 道岔 - //} - //if isSwitch { - // var sid string - // var port string - // var op int64 - // var trainOffset int64 - // var trainKilometer int64 - // var tendTo bool - // if devicePosition.deviceType == 2 { - // sid = devicePosition.index - // op = int64(devicePosition.position.Offset) - // trainKilometer = devicePosition.kilometer.Kilometer - // } else { - // sid = calcPosition.index - // op = int64(calcPosition.position.Offset) - // trainKilometer = calcPosition.kilometer.Kilometer - // } - // tm := vm.SwitchDeviceModelMap[sid] - // if tm == nil { - // panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", sid)}) - // } - // if linkModel.ARelatedSwitchRef.SwitchDevice != nil && linkModel.ARelatedSwitchRef.SwitchDevice.GetIndex() == sid { // 起始点 - // port, trainOffset, tendTo = linkModel.ARelatedSwitchRef.Port.Name(), offset-op, !up - // } else if linkModel.BRelatedSwitchRef.SwitchDevice != nil && linkModel.BRelatedSwitchRef.SwitchDevice.GetIndex() == sid { // 结束点 - // port, trainOffset, tendTo = linkModel.BRelatedSwitchRef.Port.Name(), op-offset, up - // } else { - // panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", devicePosition.index)}) - // } - // trainKilometer = concertTrainKilometer(trainKilometer, trainOffset, tendTo) - // // return sid, linkModel.ARelatedSwitchRef.Port.Name(), offset - op, runDirection, !up - // // return sid, linkModel.BRelatedSwitchRef.Port.Name(), op - offset, runDirection, up - // return sid, port, trainOffset, runDirection, tendTo, trainKilometer - //} else { - // sectionModel, ok := linkOffsetQuerySection(vm, devicePosition, calcPosition) - // if ok { - // isEnd := (calcPosition == nil) && (offset == int64(linkModel.Length)) // 是否已经走到尽头 - // pointA := sectionModel.PortAxlePoints[face.A.Name()] - // var trainOffset int64 - // var trainKilometer int64 - // var tendTo bool - // var bk *graphicData.KilometerSystem - // if calcPosition != nil { - // bk = calcPosition.kilometer - // } - // if devicePosition.index == pointA.GetIndex() { - // trainOffset = offset - int64(devicePosition.position.Offset) - // trainKilometer = devicePosition.kilometer.Kilometer - // tendTo = convertPointTo(devicePosition.kilometer, bk, runDirection) - // } else if calcPosition != nil { - // trainOffset = int64(calcPosition.position.Offset) - offset - // trainKilometer = bk.Kilometer - // tendTo = convertPointTo(bk, devicePosition.kilometer, runDirection) - // } else { - // for _, v := range calcPositionArr { - // if v.deviceType == 1 && v.index == pointA.GetIndex() { // 计轴 - // trainKilometer = v.kilometer.Kilometer - // if isEnd { - // trainOffset = offset - int64(v.position.Offset) - // tendTo = convertPointTo(v.kilometer, nil, runDirection) - // } else { - // trainOffset = int64(v.position.Offset) - offset - // tendTo = convertPointTo(v.kilometer, devicePosition.kilometer, runDirection) - // } - // break - // } - // } - // if trainKilometer == 0 { - // panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("区段【%s】A端计轴缺失", sectionModel.GraphicId)}) - // } - // } - // trainKilometer = concertTrainKilometer(trainKilometer, trainOffset, tendTo) - // // return sectionModel.Index, "", offset - int64(devicePosition.position.Offset), runDirection, convertPointTo(devicePosition.kilometer, bk, runDirection) - // // return sectionModel.Index, "", int64(calcPosition.position.Offset) - offset, runDirection, convertPointTo(bk, devicePosition.kilometer, runDirection) - // // return sectionModel.Index, "", offset - int64(v.position.Offset), runDirection, convertPointTo(v.kilometer, nil, runDirection) - // // return sectionModel.Index, "", int64(v.position.Offset) - offset, runDirection, convertPointTo(v.kilometer, devicePosition.kilometer, runDirection) - // return sectionModel.Index, "", trainOffset, runDirection, tendTo, trainKilometer - // } else { - // panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到区段【index:%s-index:%s】", devicePosition.index, calcPosition.index)}) - // } - //} - return "", "", 0, false, false, 0 +func QueryDeviceByCalcLink(repo *repository.Repository, id string, offset int64, up bool) ( + deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) { + + link := repo.FindLink(id) + if link == nil { + panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到link【%s】", id)}) + } + if offset > link.Length() { + panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())}) + } + aTp := link.ARelation() + bTp := link.BRelation() + aOffset := aTp.Turnout().FindLinkPositionByPort(aTp.Port()).Offset() + bOffset := bTp.Turnout().FindLinkPositionByPort(bTp.Port()).Offset() + if offset <= aOffset { + deviceId = aTp.Turnout().Id() + deviceOffset = aOffset - (aOffset - offset) + if up { + pointTo = false + } else { + pointTo = true + } + switch aTp.Port() { + case proto2.Port_A: + port = "A" + case proto2.Port_B: + port = "B" + case proto2.Port_C: + port = "C" + } + } else if offset >= bOffset { + deviceId = bTp.Turnout().Id() + deviceOffset = link.Length() - offset + if up { + pointTo = true + } else { + pointTo = false + } + switch bTp.Port() { + case proto2.Port_A: + port = "A" + case proto2.Port_B: + port = "B" + case proto2.Port_C: + port = "C" + } + } + return } //// 根据linkID和link相对偏移量返回区段,道岔偏移量 diff --git a/go.work b/go.work new file mode 100644 index 0000000..9cf054a --- /dev/null +++ b/go.work @@ -0,0 +1,7 @@ +go 1.20 + +use ( + . + ./rtss_simulation + ./rtss_simulation/jl-ecs-go +) diff --git a/rtss_simulation b/rtss_simulation index 6edac11..49a3003 160000 --- a/rtss_simulation +++ b/rtss_simulation @@ -1 +1 @@ -Subproject commit 6edac119a197cbc717584f4f6ad5b7c8ec33acfe +Subproject commit 49a30032e01e60c6b235c12e5ffd5f893b31f76b