This commit is contained in:
xzb 2023-10-26 13:49:21 +08:00
commit 61de82de1b
2 changed files with 44 additions and 20 deletions

View File

@ -13,9 +13,11 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/bj-rtsts-server/db/dbquery" "joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model" "joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/sys_error"
) )
var ( var (
@ -95,13 +97,14 @@ func QueryGiId(name string) int32 {
} }
// 根据区段道岔偏移量返回linkID和link相对偏移量 // 根据区段道岔偏移量返回linkID和link相对偏移量
func QueryEcsLinkByDeviceInfo(repo *repository.Repository, mapId int32, id string, devicePort string, offset int64, runDirection bool) (int32, int64, bool, bool, int64) { func QueryEcsLinkByDeviceInfo(repo *repository.Repository, mapId int32, status *state.TrainState) (int32, int64, bool, bool, int64) {
if devicePort == "" { id := status.HeadDeviceId
if status.DevicePort == "" {
uid := QueryUidByMidAndComId(mapId, id, &graphicData.Section{}) uid := QueryUidByMidAndComId(mapId, id, &graphicData.Section{})
return sectionMapToEcsLink(repo, uid, offset, runDirection) return sectionMapToEcsLink(repo, uid, status)
} else { } else {
uid := QueryUidByMidAndComId(mapId, id, &graphicData.Turnout{}) uid := QueryUidByMidAndComId(mapId, id, &graphicData.Turnout{})
return turnoutMapToEcsLink(repo, uid, devicePort, offset, runDirection) return turnoutMapToEcsLink(repo, uid, status)
} }
} }
@ -122,11 +125,15 @@ func getStorageIBPMapData(mapCode string) *graphicData.IBPGraphicStorage {
} }
// 根据物理区段上的偏移量基于区段A端找到所在link的linkId与偏移量 // 根据物理区段上的偏移量基于区段A端找到所在link的linkId与偏移量
func sectionMapToEcsLink(repo *repository.Repository, id string, offset int64, runDirection bool) (int32, int64, bool, bool, int64) { func sectionMapToEcsLink(repo *repository.Repository, id string, status *state.TrainState) (int32, int64, bool, bool, int64) {
runDirection := status.RunDirection
section := repo.FindPhysicalSection(id) section := repo.FindPhysicalSection(id)
if section == nil { if section == nil {
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("地图不存在uid:%s缓存", id)}) panic(sys_error.New(fmt.Sprintf("地图不存在uid:%s缓存", id)))
} }
link := section.ALinkPosition().Link()
// 检查link偏移
status.HeadOffset = checkOffsetInLink(status.HeadOffset, status.TrainLength, link)
ao, bo := section.ALinkPosition().Offset(), section.BLinkPosition().Offset() ao, bo := section.ALinkPosition().Offset(), section.BLinkPosition().Offset()
// 是否从A到B统一坐标 // 是否从A到B统一坐标
ak, bk := convertRepoBaseKm(repo, section.AKilometer()), convertRepoBaseKm(repo, section.BKilometer()) ak, bk := convertRepoBaseKm(repo, section.AKilometer()), convertRepoBaseKm(repo, section.BKilometer())
@ -148,20 +155,21 @@ func sectionMapToEcsLink(repo *repository.Repository, id string, offset int64, r
up = ao > bo up = ao > bo
} }
} }
linkId, _ := strconv.Atoi(section.ALinkPosition().Link().Identity.Id()) linkId, _ := strconv.Atoi(link.Identity.Id())
trainKilometer := concertTrainKilometer(akv, offset, up) trainKilometer := concertTrainKilometer(akv, status.HeadOffset, up)
if ao < bo { if ao < bo {
return int32(linkId), ao + offset, up, abDirection, trainKilometer return int32(linkId), ao + status.HeadOffset, up, abDirection, trainKilometer
} else { } else {
return int32(linkId), ao - offset, up, abDirection, trainKilometer return int32(linkId), ao - status.HeadOffset, up, abDirection, trainKilometer
} }
} }
// 根据道岔上的偏移量基于岔心位置找到所在link的linkId与偏移量 // 根据道岔上的偏移量基于岔心位置找到所在link的linkId与偏移量
func turnoutMapToEcsLink(repo *repository.Repository, id string, port string, offset int64, runDirection bool) (int32, int64, bool, bool, int64) { func turnoutMapToEcsLink(repo *repository.Repository, id string, status *state.TrainState) (int32, int64, bool, bool, int64) {
port, runDirection := status.DevicePort, status.RunDirection
turnout := repo.FindTurnout(id) turnout := repo.FindTurnout(id)
if turnout == nil { if turnout == nil {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【uid:%s】", id)}) panic(sys_error.New(fmt.Sprintf("不存在道岔【uid:%s】", id)))
} }
var portPosition *repository.LinkPosition var portPosition *repository.LinkPosition
var crossKm, portKm *proto2.Kilometer var crossKm, portKm *proto2.Kilometer
@ -176,30 +184,32 @@ func turnoutMapToEcsLink(repo *repository.Repository, id string, port string, of
portPosition = turnout.FindLinkPositionByPort(proto2.Port_C) portPosition = turnout.FindLinkPositionByPort(proto2.Port_C)
portKm = turnout.GetTurnoutKm(proto2.Port_C) portKm = turnout.GetTurnoutKm(proto2.Port_C)
default: default:
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("无效端口【%s】偏移量", port)}) panic(sys_error.New(fmt.Sprintf("无效端口【%s】偏移量", port)))
} }
// 关联link
link := portPosition.Link()
// 检查link偏移
status.HeadOffset = checkOffsetInLink(status.HeadOffset, status.TrainLength, link)
// 岔心公里标 // 岔心公里标
crossKm = turnout.GetTurnoutKm(proto2.Port_None) crossKm = turnout.GetTurnoutKm(proto2.Port_None)
portKm, err := repo.ConvertKilometer(portKm, crossKm.CoordinateSystem) portKm, err := repo.ConvertKilometer(portKm, crossKm.CoordinateSystem)
if err != nil { if err != nil {
panic(err) panic(sys_error.New("公里标转换出错", err))
} }
// 关联link
link := portPosition.Link()
isStart := link.ARelation().Device().Id() == id isStart := link.ARelation().Device().Id() == id
up := runDirection up := runDirection
if (portKm.Value > crossKm.Value) != isStart { if (portKm.Value > crossKm.Value) != isStart {
up = !runDirection up = !runDirection
} }
pointTo := (portKm.Value > crossKm.Value) == runDirection pointTo := (portKm.Value > crossKm.Value) == runDirection
trainKilometer := concertTrainKilometer(crossKm.Value, offset, pointTo) trainKilometer := concertTrainKilometer(crossKm.Value, status.HeadOffset, pointTo)
linkId, _ := strconv.Atoi(link.Identity.Id()) linkId, _ := strconv.Atoi(link.Identity.Id())
if isStart { if isStart {
return int32(linkId), offset, up, pointTo, trainKilometer return int32(linkId), status.HeadOffset, up, pointTo, trainKilometer
} else { } else {
// 道岔长度 // 道岔长度
turnoutLen := int64(math.Abs(float64(portKm.Value - crossKm.Value))) turnoutLen := int64(math.Abs(float64(portKm.Value - crossKm.Value)))
return int32(linkId), portPosition.Offset() + turnoutLen - offset, up, pointTo, trainKilometer return int32(linkId), portPosition.Offset() + turnoutLen - status.HeadOffset, up, pointTo, trainKilometer
} }
} }
@ -355,3 +365,17 @@ func convertRepoBaseKm(r *repository.Repository, km *proto2.Kilometer) *proto2.K
} }
return k return k
} }
// 检查偏移是否在link上,返回最终的offset
func checkOffsetInLink(offset, trainLen int64, link *repository.Link) int64 {
if offset > link.Length() {
panic(sys_error.New(fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())))
}
if trainLen > offset { // 如果列车长度超过设置offset
offset = trainLen
}
if offset > link.Length() {
panic(sys_error.New(fmt.Sprintf("列车长度【%d】超出link范围【%d】", trainLen, link.Length())))
}
return offset
}

View File

@ -26,7 +26,7 @@ func AddTrainState(vs *VerifySimulation, status *state.TrainState, mapId int32)
//向动力学发送初始化请求 //向动力学发送初始化请求
trainIndex, _ := strconv.ParseUint(status.Id, 10, 16) trainIndex, _ := strconv.ParseUint(status.Id, 10, 16)
// 映射link、偏移量、运行方向 // 映射link、偏移量、运行方向
linkId, loffset, up, pointTo, kilometer := QueryEcsLinkByDeviceInfo(vs.Repo, mapId, status.HeadDeviceId, status.DevicePort, status.HeadOffset, status.RunDirection) linkId, loffset, up, pointTo, kilometer := QueryEcsLinkByDeviceInfo(vs.Repo, mapId, status)
status.Up = up status.Up = up
status.PointTo = pointTo status.PointTo = pointTo
status.TrainKilometer = kilometer status.TrainKilometer = kilometer