【增加列车AB走向属性】
This commit is contained in:
parent
3402e3c721
commit
66702c7bd1
@ -122,11 +122,12 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, vs *memory.VerifyS
|
||||
zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset)
|
||||
sta.HeadLinkId = strconv.Itoa(int(info.Link))
|
||||
sta.HeadLinkOffset = int64(info.LinkOffset)
|
||||
id, port, offset, runDirection := memory.QueryDeviceByCalcLink(vs, int32(info.Link), sta.HeadLinkOffset, sta.Up, sta.RunDirection)
|
||||
zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v]", info.Number, id, offset, runDirection)
|
||||
id, port, offset, runDirection, pointTo := memory.QueryDeviceByCalcLink(vs, int32(info.Link), sta.HeadLinkOffset, sta.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.RunDirection = runDirection
|
||||
/*
|
||||
modeller := vs.LinkModelMap[int32(info.Link)]
|
||||
|
@ -129,7 +129,7 @@ func QueryMapVerifyStructure(mapId int32) *VerifyStructure {
|
||||
}
|
||||
|
||||
// 根据区段,道岔偏移量返回linkID和link相对偏移量
|
||||
func QueryMapCalcLinkByDeviceInfo(mapId int32, id string, devicePort string, offset int64, runDirection bool) (int32, int64, bool) {
|
||||
func QueryMapCalcLinkByDeviceInfo(mapId int32, id string, devicePort string, offset int64, runDirection bool) (int32, int64, bool, bool) {
|
||||
vm := QueryMapVerifyStructure(mapId)
|
||||
if devicePort == "" {
|
||||
return sectionMapToLink(vm, id, offset, runDirection)
|
||||
@ -139,7 +139,7 @@ func QueryMapCalcLinkByDeviceInfo(mapId int32, id string, devicePort string, off
|
||||
}
|
||||
|
||||
// 根据物理区段上的偏移量(基于区段A端),找到所在link的linkId与偏移量
|
||||
func sectionMapToLink(vm *VerifyStructure, id string, offset int64, runDirection bool) (int32, int64, bool) {
|
||||
func sectionMapToLink(vm *VerifyStructure, id string, offset int64, runDirection bool) (int32, int64, bool, bool) {
|
||||
sm := vm.PhysicalSectionModelMap[id]
|
||||
if sm == nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在区段【index:%s】", id)})
|
||||
@ -181,11 +181,13 @@ func sectionMapToLink(vm *VerifyStructure, id string, offset int64, runDirection
|
||||
bp = axlePointPositionMap[pointB.GetIndex()]
|
||||
bo = bp.Offset
|
||||
bk = (pointB.(*device.AxlePointDeviceModel)).KilometerSystem
|
||||
abDirection = convertPointTo(ak, bk, runDirection)
|
||||
}
|
||||
up := convertRunDirectionToUp(ak, bk, ap, bp, runDirection)
|
||||
if ao < bo {
|
||||
return linkId, int64(ao) + offset, convertRunDirectionToUp(ak, bk, ap, bp, runDirection)
|
||||
return linkId, int64(ao) + offset, up, abDirection
|
||||
} else {
|
||||
return linkId, int64(ao) - offset, convertRunDirectionToUp(ak, bk, ap, bp, runDirection)
|
||||
return linkId, int64(ao) - offset, up, abDirection
|
||||
}
|
||||
} else {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%d】缺失区段【id:%s,index:%s】A点缺失计轴", linkId, sectionModel.GraphicId, id)})
|
||||
@ -193,7 +195,7 @@ func sectionMapToLink(vm *VerifyStructure, id string, offset int64, runDirection
|
||||
}
|
||||
|
||||
// 根据道岔上的偏移量(基于岔心位置),找到所在link的linkId与偏移量
|
||||
func turnoutMapToLink(vm *VerifyStructure, id string, port string, offset int64, runDirection bool) (int32, int64, bool) {
|
||||
func turnoutMapToLink(vm *VerifyStructure, id string, port string, offset int64, runDirection bool) (int32, int64, bool, bool) {
|
||||
tm := vm.SwitchDeviceModelMap[id]
|
||||
if tm == nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", id)})
|
||||
@ -236,18 +238,19 @@ Outter:
|
||||
np = calcPositionArr[index-1]
|
||||
}
|
||||
up := convertRunDirectionToUp(vp.kilometer, np.kilometer, vp.position, np.position, runDirection)
|
||||
pointTo := convertPointTo(vp.kilometer, np.kilometer, runDirection)
|
||||
if isStart {
|
||||
return linkId, int64(vp.position.Offset) + offset, up
|
||||
return linkId, int64(vp.position.Offset) + offset, up, pointTo
|
||||
} else {
|
||||
return linkId, int64(vp.position.Offset) - offset, up
|
||||
return linkId, int64(vp.position.Offset) - offset, up, pointTo
|
||||
}
|
||||
}
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("link【%d】缺失道岔【id:%s,index:%s】端口【%s】偏移量", linkId, turnoutModel.GraphicId, id, port)})
|
||||
}
|
||||
|
||||
// 根据linkID和link相对偏移量返回区段,道岔偏移量
|
||||
// 设备ID、端口、偏移量、上下行
|
||||
func QueryDeviceByCalcLink(vm *VerifyStructure, id int32, offset int64, up, defaultRunDirection bool) (string, string, int64, bool) {
|
||||
// 设备ID、端口、偏移量、上下行、AB走向
|
||||
func QueryDeviceByCalcLink(vm *VerifyStructure, id int32, offset int64, up, defaultRunDirection bool) (string, string, int64, bool, bool) {
|
||||
linkModel := vm.LinkModelMap[id]
|
||||
if linkModel == nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到link【%d】", id)})
|
||||
@ -293,9 +296,9 @@ func QueryDeviceByCalcLink(vm *VerifyStructure, id int32, offset int64, up, defa
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", sid)})
|
||||
}
|
||||
if linkModel.ARelatedSwitchRef.SwitchDevice.GetIndex() == sid { // 起始点
|
||||
return sid, linkModel.ARelatedSwitchRef.Port.Name(), offset - op, runDirection
|
||||
return sid, linkModel.ARelatedSwitchRef.Port.Name(), offset - op, runDirection, up == false
|
||||
} else if linkModel.BRelatedSwitchRef.SwitchDevice.GetIndex() == sid { // 结束点
|
||||
return sid, linkModel.BRelatedSwitchRef.Port.Name(), op - offset, runDirection
|
||||
return sid, linkModel.BRelatedSwitchRef.Port.Name(), op - offset, runDirection, up == true
|
||||
} else {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("不存在道岔【index:%s】", devicePosition.index)})
|
||||
}
|
||||
@ -304,17 +307,21 @@ func QueryDeviceByCalcLink(vm *VerifyStructure, id int32, offset int64, up, defa
|
||||
if ok {
|
||||
isEnd := (calcPosition == nil) && (offset == int64(linkModel.Length)) // 是否已经走到尽头
|
||||
pointA := sectionModel.PortAxlePoints[face.A.Name()]
|
||||
var bk *graphicData.KilometerSystem
|
||||
if calcPosition != nil {
|
||||
bk = calcPosition.kilometer
|
||||
}
|
||||
if devicePosition.index == pointA.GetIndex() {
|
||||
return sectionModel.Index, "", offset - int64(devicePosition.position.Offset), runDirection
|
||||
return sectionModel.Index, "", offset - int64(devicePosition.position.Offset), runDirection, convertPointTo(devicePosition.kilometer, bk, runDirection)
|
||||
} else if calcPosition != nil {
|
||||
return sectionModel.Index, "", int64(calcPosition.position.Offset) - offset, runDirection
|
||||
return sectionModel.Index, "", int64(calcPosition.position.Offset) - offset, runDirection, convertPointTo(bk, devicePosition.kilometer, runDirection)
|
||||
} else {
|
||||
for _, v := range calcPositionArr {
|
||||
if v.deviceType == 1 && v.index == pointA.GetIndex() { // 计轴
|
||||
if isEnd {
|
||||
return sectionModel.Index, "", offset - int64(v.position.Offset), runDirection
|
||||
return sectionModel.Index, "", offset - int64(v.position.Offset), runDirection, convertPointTo(v.kilometer, nil, runDirection)
|
||||
} else {
|
||||
return sectionModel.Index, "", int64(v.position.Offset) - offset, runDirection
|
||||
return sectionModel.Index, "", int64(v.position.Offset) - offset, runDirection, convertPointTo(v.kilometer, devicePosition.kilometer, runDirection)
|
||||
}
|
||||
|
||||
}
|
||||
@ -905,3 +912,11 @@ func convertRunDirectionToUp(ak, bk *graphicData.KilometerSystem, ap, bp *ref.De
|
||||
return !direction
|
||||
}
|
||||
}
|
||||
|
||||
// 判断是否是否从A端到B端
|
||||
func convertPointTo(ak, bk *graphicData.KilometerSystem, direction bool) bool {
|
||||
if bk == nil {
|
||||
return true == direction
|
||||
}
|
||||
return (ak.Kilometer < bk.Kilometer) == direction
|
||||
}
|
||||
|
@ -28,8 +28,9 @@ func AddTrainState(simulation *VerifySimulation, status *state.TrainState) {
|
||||
//向动力学发送初始化请求
|
||||
trainIndex, _ := strconv.ParseUint(status.Id, 10, 16)
|
||||
// 映射link、偏移量、运行方向
|
||||
linkId, loffset, up := QueryMapCalcLinkByDeviceInfo(simulation.MapId, status.HeadDeviceId, status.DevicePort, status.HeadOffset, status.RunDirection)
|
||||
linkId, loffset, up, pointTo := QueryMapCalcLinkByDeviceInfo(simulation.MapId, status.HeadDeviceId, status.DevicePort, status.HeadOffset, status.RunDirection)
|
||||
status.Up = up
|
||||
status.PointTo = pointTo
|
||||
httpCode, _, err := dynamics.SendInitTrainReq(&dynamics.InitTrainInfo{
|
||||
TrainIndex: uint16(trainIndex),
|
||||
LinkIndex: uint16(linkId),
|
||||
|
Loading…
Reference in New Issue
Block a user