【动力学link转换】
This commit is contained in:
parent
9799ed41d1
commit
88c54e23b8
@ -166,7 +166,7 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory
|
||||
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.HeadDeviceId = strconv.Itoa(int(simulation.GetComIdByIndex(id)))
|
||||
sta.DevicePort = port
|
||||
sta.HeadOffset = offset
|
||||
sta.PointTo = pointTo
|
||||
|
@ -181,35 +181,59 @@ func QueryDeviceByCalcLink(repo *repository.Repository, id string, offset int64,
|
||||
if offset > link.Length() {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())})
|
||||
}
|
||||
// 判断是否在道岔上
|
||||
onTurnout, isA := isOnLinkTurnout(link, offset)
|
||||
if onTurnout {
|
||||
return ecsLinkMapToTurnout(isA, offset, up, link)
|
||||
} else {
|
||||
return ecsLinkMapToSection(offset, up, link)
|
||||
}
|
||||
}
|
||||
|
||||
// 是否在link的道岔上
|
||||
func isOnLinkTurnout(link *repository.Link, offset int64) (bool, bool) {
|
||||
aTp := link.ARelation()
|
||||
var turnoutOffset int64
|
||||
if aTp != nil {
|
||||
turnoutOffset = aTp.Turnout().FindLinkPositionByPort(aTp.Port()).Offset()
|
||||
}
|
||||
if offset <= turnoutOffset {
|
||||
return true, true
|
||||
}
|
||||
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
|
||||
if bTp != nil {
|
||||
turnoutOffset = bTp.Turnout().FindLinkPositionByPort(bTp.Port()).Offset()
|
||||
return offset >= turnoutOffset, false
|
||||
}
|
||||
return false, false
|
||||
}
|
||||
|
||||
// 处理在道岔上link映射
|
||||
func ecsLinkMapToTurnout(isA bool, offset int64, up bool, link *repository.Link) (
|
||||
deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) {
|
||||
tp := link.ARelation()
|
||||
if !isA {
|
||||
tp = link.BRelation()
|
||||
}
|
||||
deviceId = tp.Turnout().Id()
|
||||
tpOffset := tp.Turnout().FindLinkPositionByPort(tp.Port()).Offset()
|
||||
crossKm, portKm := tp.Turnout().GetTurnoutKm(proto2.Port_None).Value, tp.Turnout().GetTurnoutKm(tp.Port()).Value
|
||||
if isA {
|
||||
deviceOffset = tpOffset - (tpOffset - offset)
|
||||
pointTo = !up
|
||||
} 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
|
||||
pointTo = up
|
||||
}
|
||||
switch bTp.Port() {
|
||||
// 查询公里标大于端口公里标
|
||||
if crossKm > portKm {
|
||||
km = crossKm - deviceOffset
|
||||
runDirection = pointTo
|
||||
} else {
|
||||
km = crossKm + deviceOffset
|
||||
runDirection = !pointTo
|
||||
}
|
||||
switch tp.Port() {
|
||||
case proto2.Port_A:
|
||||
port = "A"
|
||||
case proto2.Port_B:
|
||||
@ -217,6 +241,46 @@ func QueryDeviceByCalcLink(repo *repository.Repository, id string, offset int64,
|
||||
case proto2.Port_C:
|
||||
port = "C"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 处理在道岔上link映射
|
||||
func ecsLinkMapToSection(offset int64, up bool, link *repository.Link) (
|
||||
deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) {
|
||||
var section *repository.PhysicalSection
|
||||
for _, s := range link.PhysicalSections() {
|
||||
ao, bo := s.ALinkPosition().Offset(), s.BLinkPosition().Offset()
|
||||
if (ao <= offset && offset <= bo) || (bo <= offset && offset <= ao) {
|
||||
section = s
|
||||
break
|
||||
}
|
||||
}
|
||||
if section == nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到link设备偏移【%d】", offset)})
|
||||
}
|
||||
// 元素ID
|
||||
deviceId = section.Id()
|
||||
// link偏移变大方向
|
||||
ao, bo := section.ALinkPosition().Offset(), section.BLinkPosition().Offset()
|
||||
ak, bk := section.AKilometer().Value, section.BKilometer().Value
|
||||
if up {
|
||||
pointTo = ao < bo
|
||||
runDirection = ((ak < bk) == (ao < bo))
|
||||
} else {
|
||||
pointTo = bo > ao
|
||||
runDirection = ((ak > bk) == (ao > bo))
|
||||
}
|
||||
// a点偏移 大于 b点偏移
|
||||
if ao > bo {
|
||||
deviceOffset = ao - offset
|
||||
} else {
|
||||
deviceOffset = offset - ao
|
||||
}
|
||||
// a点公里标 大于 b点公里标
|
||||
if ak > bk {
|
||||
km = ak - deviceOffset
|
||||
} else {
|
||||
km = ak + deviceOffset
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -158,6 +158,18 @@ func (s *VerifySimulation) GetComIdByUid(uid string) string {
|
||||
return es[uid].CommonId
|
||||
}
|
||||
|
||||
// 获取仿真世界信息
|
||||
func (s *VerifySimulation) GetComIdByIndex(uid string) int32 {
|
||||
es := s.uidMap
|
||||
if es == nil {
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无映射信息"})
|
||||
}
|
||||
if es[uid] == nil {
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无【uid】映射信息"})
|
||||
}
|
||||
return es[uid].Index
|
||||
}
|
||||
|
||||
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
||||
repo := &proto.Repository{}
|
||||
var exceptStationGiMapIds []int32
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5833de36fbb1e153672aa1ddf049f7006eefca60
|
||||
Subproject commit be88137f2ab670707c7bd80f708ad1379c62f141
|
Loading…
Reference in New Issue
Block a user