【修改加车逻辑】
This commit is contained in:
parent
0ee6bd11d9
commit
7e57a5d14d
@ -131,10 +131,10 @@ func sectionMapToEcsLink(repo *repository.Repository, id string, status *state.T
|
|||||||
if section == nil {
|
if section == nil {
|
||||||
panic(sys_error.New(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()
|
||||||
|
// 检查区段长度是否足够放下列车
|
||||||
|
status.HeadOffset = checkDeviceContainTrain(status.HeadOffset, status.TrainLength, bo-ao)
|
||||||
|
link := section.ALinkPosition().Link()
|
||||||
// 是否从A到B,统一坐标
|
// 是否从A到B,统一坐标
|
||||||
ak, bk := convertRepoBaseKm(repo, section.AKilometer()), convertRepoBaseKm(repo, section.BKilometer())
|
ak, bk := convertRepoBaseKm(repo, section.AKilometer()), convertRepoBaseKm(repo, section.BKilometer())
|
||||||
akv, bkv := ak.Value, bk.Value
|
akv, bkv := ak.Value, bk.Value
|
||||||
@ -186,16 +186,16 @@ func turnoutMapToEcsLink(repo *repository.Repository, id string, status *state.T
|
|||||||
default:
|
default:
|
||||||
panic(sys_error.New(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(sys_error.New("公里标转换出错", err))
|
panic(sys_error.New("公里标转换出错", err))
|
||||||
}
|
}
|
||||||
|
// 检查link偏移
|
||||||
|
status.HeadOffset = checkDeviceContainTrain(status.HeadOffset, status.TrainLength, crossKm.Value-portKm.Value)
|
||||||
|
// 关联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 {
|
||||||
@ -366,16 +366,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 {
|
func checkDeviceContainTrain(offset, trainLen, deviceLen int64) int64 {
|
||||||
if offset > link.Length() {
|
l := int64(math.Abs(float64(deviceLen)))
|
||||||
panic(sys_error.New(fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())))
|
if offset > l {
|
||||||
|
panic(sys_error.New(fmt.Sprintf("偏移【%d】超出设备范围【%d】", offset, l)))
|
||||||
}
|
}
|
||||||
if trainLen > offset { // 如果列车长度超过设置offset
|
if trainLen > offset { // 如果列车长度超过设置offset
|
||||||
offset = trainLen
|
offset = trainLen
|
||||||
}
|
}
|
||||||
if offset > link.Length() {
|
if offset > l {
|
||||||
panic(sys_error.New(fmt.Sprintf("列车长度【%d】超出link范围【%d】", trainLen, link.Length())))
|
panic(sys_error.New(fmt.Sprintf("列车长度【%d】超出设备范围【%d】", trainLen, l)))
|
||||||
}
|
}
|
||||||
return offset
|
return offset
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user